How to handle the case of repeatable and non mandatory sections/groups in the host data?

63 views
Skip to first unread message

Sridhar

unread,
May 7, 2013, 10:58:20 AM5/7/13
to legsta...@googlegroups.com
Hi Fady,
               I have data in which the data part corresponding to a section may repeat or not present at all. Could this be handled? Thanks

                               
##HOZ512 RE61ENM116AROP500 RE611PN 390101 OP500 XE21
@@H18P1 99930276
##IOZ512 RE61ENM1 AROP500 RE611PN 390101 OP500 TE61
##JOZ512 RE61ENM1 AROP500 RE611PN 390201 OP500 TF61
@@ECO011OA021508151302160701130215081513 RE61 02160701130216150113 ZLC
@@PENGSTEIN JM0000234615OK OP500 RE61CO01ENGNNNNNNN Y
@@S00000000000
@@ECO701AA0215221513021522501302161220130216145013
@@C0216105013
@@PENGEDWARDS JB0000304923LV OP500 RE61CO70ENGNNNNNNN Y OK02


                                

Fady

unread,
May 7, 2013, 1:22:38 PM5/7/13
to legsta...@googlegroups.com
Hard to tell without seeing the COBOL description.

If this is a case of DEPENDING ON where the counter could be zero, then yes, this is supported.

Fady 

Sridhar

unread,
May 8, 2013, 6:48:40 AM5/8/13
to legsta...@googlegroups.com


 Hi Fady,
                I have attached the CobolCopy book and data.  For the sections, I am not sure if we have DEPENDING ON or OCCURS present.  For some fields it might be there. Each section starts with a Header Id like ##H, @@E etc. So, Could you tell me if we can identify the start of a section in the data and use corresponding xsd element to populate the data?
CobolLayout.txt
Data.txt

Fady

unread,
May 8, 2013, 7:52:45 AM5/8/13
to legsta...@googlegroups.com
Thanks for posting this.

At first sight your issue is not related to DEPENDING ON or REDEFINES.

It seems to me your input is based on a file that has several different types of records, each described with its own copybook.

The COBOL copybook you sent though, seems to be the concatenation of all these different copybooks.

The concatenation of the copybooks does not represent the concatenation of the data, so this will not work.

Can you confirm the COBOL copybook concatenation was done manually? Can you also confirm you input data is made of different records, 72 bytes long each?



Sridhar

unread,
May 8, 2013, 9:37:06 AM5/8/13
to legsta...@googlegroups.com
  I also felt the same. But, my source confirmed that data is a single data which is compliant with the layout. I am not a COBOL guy, so I may not be able to verify  this. Right now all I got are some flat files with which I am playing. May be I will try to modify the generated XSD and see if I can proceed with it.   Thanks.

Fady

unread,
May 10, 2013, 5:54:09 AM5/10/13
to legsta...@googlegroups.com

Better than a long explanation, I have attached a working sample.

This is a maven project and also an eclipse project.

There is a junit test that runs the conversion of your Data.txt file with just a few lines of code:

    public void testApp() throws Exception {
        WsOutDataTransformers tf = new WsOutDataTransformers();
        LineIterator it = FileUtils.lineIterator(new File("Data.txt"));
        try {
            while (it.hasNext()) {
                String line = it.nextLine();
                if (StringUtils.isNotBlank(line)) {
                    WsOutData outData = tf.toJava(line.getBytes(), "ASCII");
                    System.out.println(new Gson().toJson(outData));
                }
            }
        } finally {
            LineIterator.closeQuietly(it);
        }
    }

You will notice that I have changed your COBOL definition to use REDEFINES (see file CobolLayout_with_redefines.txt).

There is also a custom redefine handler that I wrote:

public class RedefineResolver implements ICobolUnmarshalChoiceStrategy {
    /** {@inheritDoc} */
    public ICobolBinding choose(final ICobolChoiceBinding choice,
            final Hashtable < String, Object > variablesMap,
            final CobolElementVisitor visitor) throws HostException {
        try {
            byte[] recordTypeBytes = new byte[3];
            System.arraycopy(visitor.getHostBytes(), visitor.getOffset(),
                    recordTypeBytes, 0, recordTypeBytes.length);
            String recordType = new String(recordTypeBytes, visitor
                    .getCobolConverters().getCobolContext()
                    .getHostCharsetName());
            if (recordType.equals("##H")) {
                return choice.getAlternativeByName("Hdr");
            } else if (recordType.equals("@@H")) {
                return choice.getAlternativeByName("Hdr2");
            } else if (recordType.equals("$$H")) {
                return choice.getAlternativeByName("Hdr3");
            } else if (recordType.equals("@@E")) {
                return choice.getAlternativeByName("OndutyDetailData");
            } else if (recordType.equals("@@T")) {
                return choice.getAlternativeByName("OndutyDetailData");
                // TODO OffdutyDetailData has same 3 first bytes as
                // OndutyDetailData
            } else if (recordType.equals("@@W")) {
                return choice.getAlternativeByName("OffdutyWindowPoolData");
            } else if (recordType.equals("@@P")) {
                return choice.getAlternativeByName("PosDetailData");
            } else if (recordType.equals("@@M")) {
                return choice.getAlternativeByName("PosDetailData");
            } else if (recordType.equals("@@V")) {
                return choice.getAlternativeByName("PosDetailData");
            } else if (recordType.equals("@@S")) {
                return choice.getAlternativeByName("RsaDetailData");
            } else {
                return choice.getAlternativeByName("OutCrewRestDetailData");
            }
        } catch (UnsupportedEncodingException e) {
            throw new HostException(e);
        }
    }


The redefine handler needs to be added to the generated XSD, see line:

                            <cb:cobolElement cobolName="HDR" isRedefined="true" levelNumber="5" srceLine="2" type="GROUP_ITEM" unmarshalChoiceStrategyClassName="com.legsem.legstar.legstar.sridhar2.RedefineResolver"/>

Let me know if you can get it to work.

Fady



legstar.sridhar2.zip

Sridhar

unread,
May 10, 2013, 9:57:36 AM5/10/13
to legsta...@googlegroups.com

    Thank you very much. This will simplify my work a lot.
 
    Meanwhile,  I tried to work with a modified xsd.  If this is any significant have a look at this.
            I have modified my XSD and added choice element to make it generalized.  So, that elements are  unbound and any order.

       <complexType name="WsOutData">
        <sequence>
            <choice minOccurs="0" maxOccurs="unbounded">
                <element name="headerLine" type="tns:HeaderLine">
             ........
          </complexType>

      
       In the generated WsOutData.java

            @XmlAccessorType(XmlAccessType.FIELD)
           @XmlType(name = "WsOutData", propOrder = {
                "headerLineOrHeaderLine2OrHeaderLine3"
            })
          public class WsOutData
            implements Serializable
             {

                private final static long serialVersionUID = 1L;
                @XmlElements({
                      @XmlElement(name = "offdutyWindowPoolData", type = OffdutyWindowPoolData.class),
                       @XmlElement(name = "positionLine", type = PositionLine.class),
                     @XmlElement(name = "offdutyDetailData", type = CrewOffdutyDetail.class),
                    @XmlElement(name = "crewOndutyDetail", type = CrewOndutyDetail.class),
               @XmlElement(name = "headerLine3", type = HeaderLine3 .class),
                 @XmlElement(name = "headerLine2", type = HeaderLine2 .class),
                 @XmlElement(name = "crewRestDetail", type = CrewRestDetail.class),
                 @XmlElement(name = "headerLine", type = HeaderLine.class),
               @XmlElement(name = "rsaDetail", type = RsaDetail.class)
              })
               protected List<Object> headerLineOrHeaderLine2OrHeaderLine3;
              .......

         Here the  instance variable does not have coxb annotation. so the Ant task is failing with exception.

           \COXB3\buildscript\build-coxb.xml:109: HostException No cobol annotations found for field headerLineOrHeaderLine2OrHeaderLine3
nd for field headerLineOrHeaderLine2OrHeaderLine3
te(CoxbBindingGenerator.java:135)

        [coxbgen] No cobol annotations found for field headerLineOrHeaderLine2OrHeaderLine3
  [coxbgen]     at com.legstar.coxb.impl.reflect.ReflectBindingFactory.createBinding(ReflectBindingFactory.java:82)
  [coxbgen]     at com.legstar.coxb.impl.reflect.CComplexReflectBinding.initChildren(CComplexReflectBinding.java:217)
  [coxbgen]     at com.legstar.coxb.impl.reflect.CComplexReflectBinding.initComplexElement(CComplexReflectBinding.java:174)
  [coxbgen]     at com.legstar.coxb.impl.reflect.CComplexReflectBinding.<init>(CComplexReflectBinding.java:127)
  [coxbgen]     at com.legstar.coxb.impl.reflect.CComplexReflectBinding.<init>(CComplexReflectBinding.java:87)
  [coxbgen]     at com.legstar.coxb.gen.CoxbBindingGenerator.execute(CoxbBindingGenerator.java:112)
         

Fady Moussallam

unread,
May 10, 2013, 11:50:28 AM5/10/13
to legsta...@googlegroups.com
The solution is not to tweak the XSD but to change the COBOL, which is wrong, despite what your mainframe people say.

Take a look at the modified COBOL I sent you and compare with yours.

With these changes, the generated XSD will automatically contain the correct choices. Again, take a look at the XSD I sent you.

The only change to the XSD should be the reference to the redefine handling custom code.

Hope this helps.





         

--
You received this message because you are subscribed to the Google Groups "legstar-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to legstar-user...@googlegroups.com.
To post to this group, send email to legsta...@googlegroups.com.
Visit this group at http://groups.google.com/group/legstar-user?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sridhar

unread,
May 14, 2013, 3:30:20 AM5/14/13
to legsta...@googlegroups.com

 Thanks again. I was able produce xml from the redefine code and by marshaling an additional modified Wsoutdata object.   Also, I have noticed that the enums are not generated in the generated classes despite xsd having enumeration elements. Is there a way to produce them again? Thanks
Reply all
Reply to author
Forward
Message has been deleted
0 new messages