Menu

Data2Xml - Multiple Level 01

2015-09-28
2015-10-14
  • Brian Reynolds

    Brian Reynolds - 2015-09-28

    Hi Bruce,

    I have a copybook with multiple level 01 elements, and am trying to generate an XML doc from this using Cobol2Xml.newCobol2Xml. The setSplitCopybook function throws a "not yet implemented" exception, so I was wondering what sort of effort do you feel would be involved in doing this? I'd be happy to give it a shot myself if you can provide me with some high-level pointers.

    E.g.

    000100 01  DATA-HDR.
    000300     03  MSG-HDR-FIELDS.
    000400         05  VRICWS-MSG-NAME PIC  X(30).
    000600         05  VRICWS-MSG-VER  PIC  X(6).
    000900 01  DATA-OUTPUT.                                                 
    001100     03  SVC-RETURN PIC  X(01).                                  
    001300         88  SVC-PASSED           VALUE 'P'.                       
    001400         88  SVC-FAILED           VALUE 'F'.                       
    001600     03  RETURN-CODE-DATA.                                         
    001900         05  RC-DATA OCCURS 20 TIMES.
    002200             07  RETURN-CODE PIC  X(10).                                  
    002400             07  RETURN-DESC PIC  X(79).                                  
    
    Msgname                       0001  P1110080021This is a description of the error
    

    I had a quick look at this in a debugger, and the cause is obviously the pos field in FieldDetail starts at 0 when we come around to processing the DATA-OUTPUT data.

    Thanks.

     
  • Bruce Martin

    Bruce Martin - 2015-09-30

    Sorry for the delay responding, I started to yesterday but got distracted before
    I finished. I am getting snowed under with requests at the moment.

    With regards to supporting multiple records, there are 2 changes required:

    1) Splitting the copybook up into seperate records
    2) Working out which record you have

    With regards 1) you should be able to manage this for Split=01 and Split=Highest-Repeating,
    As you want split=01, I will provide more information about this (tomorrow ???).
    Split=Redefine will be more difficult and I suggest leaving it for the moment

    With regards 2) it looks like the Position in the file determines the record type
    (i.e. the first record is the Header-Record. This is probably best done by me

    Bruce

     
  • Bruce Martin

    Bruce Martin - 2015-10-01

    Currentl

                                                                      +-------------> JRecord LayoutDetail class 
                                                                      !
    Cobol-Copybook ---> (cb2xml pgm) ----> xml-document  +
                                                                      !
                                                                      +-->(jaxb) --> Copybook/Item class's
    

    Basically the Copybook/Item are used to create the Xml structure and
    the LayoutDetail is used to retrieve values via JRecord.

    If you you Split=01, you will get:

    LayoutDetail +--- RecordDetail name=Record1
                              !
                              +--- RecordDetail name=Record2
                              !
                              +--- RecordDetail name=Record3
    
    Copybook --- Item +----- Item nameToUse=Record1
                      ! 
                      +----- Item nameToUse=Record2
                      ! 
                      +----- Item nameToUse=Record2
    

    in class Cobol2GroupXml, method cobol2xml , the following code needs to change

        if (items.size() == 1) {
             Item item = items.get(0);
                while ((l = r.read()) != null) {
                    //System.out.println(l.getFullLine());
                    writeItem(writer, l, item, new IntStack());
                }
            } else {
                while ((l = r.read()) != null) {
                    writer.writeStartElement("Line");
                    writeItems(writer, l, items, new IntStack());
                    writer.writeEndElement();
                }
           }
    
     

    Last edit: Bruce Martin 2015-10-01
  • Bruce Martin

    Bruce Martin - 2015-10-02

    I have done most of it now; just testing + Change to support arrays in Xml2Data program to go

     
  • Bruce Martin

    Bruce Martin - 2015-10-06

    I have released a new version of JRecord:

    where the cobol <==> xml programs support multi-rcord files. You must use
    the program interface (to set Record-Selection-Criteria):

        Cobol2GroupXml.newCobol2Xml(copybookFileName)
                           .setFileOrganization(Constants.IO_BIN_TEXT)
                           .setDialect(ICopybookDialects.FMT_INTEL)
                          .setSplitCopybook(CopybookLoader.SPLIT_01_LEVEL)
                               .setRecordSelection("PO-Record", newFieldSelection("Record-Type","H1"))
                               .setRecordSelection("Product-Record", newFieldSelection("Record-Type","D1"))
                               .setRecordSelection("Location-Record", newFieldSelection("Record-Type","S1"))
                       .cobol2xml(new FileInputStream(dataFileName), os);
    

    At the moment, each different record appears a level 2 in the hierarchy. But does have parent Record field. This is not currently used in JRecord (in the RecordEditor it is) this would allow
    files like

    PO-Header-Record
    Product-Record
    Store-Record
    Stroe-Record
    
       i.e
    
       Po        
          +---  Product
                                     +--- Store 
                                     +--- Store
           +--- Product
    

    to be represented properly in Xml

     

    Last edit: Bruce Martin 2015-10-06
  • Brian Reynolds

    Brian Reynolds - 2015-10-14

    Bruce,
    Awesome, thanks for this.

     

Log in to post a comment.