Menu

Get unpacked length from a COMP-3 field

Help
2016-10-24
2016-10-24
  • Juan Miguel

    Juan Miguel - 2016-10-24

    Hi,

    I have a COMP-3 field defined by this line:

    BIYDCOMI-IMPCOC PIC S9(13)V9(02) COMP-3.

    I want to get the integer part of the unpacked length (13), or at least the total unpacked length (15).

    If i call the getLen() method of FieldDetail i get the packed length (8) instead of the unpacked length.

    How can i get the unpacked length from JRecord?

    Thanks so much in advance,
    Juan Miguel.

     
  • Bruce Martin

    Bruce Martin - 2016-10-24

    Using standard JRecord you can not get the original Cobol length, the cobol details get simplified.
    Longer term I will bring more cobol information through.
    Currently your options are:

    • Calculate it. This will not be completely accurate. For Comp3 it is
      (field.getLen() + 1) * 2 - field.getDecimal()

      The problem is 9(6)  and 9(7) have the
      
    • Use CobolSchemaReader

      ICobolSchemaReader reader = CobolSchemaReader.newCobolSchemaReader("copbook");
      
      CobolSchemaDetails schemaDetails = reader.getCobolSchemaDetails();
      

    The schemaDetails will hold the complete Cobol Item Tree with all the Cobol and JRecord details.

    • schemaDetails.recordItems gets you a list of items, schemaDetails.recordItems.get(i) ~ layout.getRecord(i)
    • schemaDetails.cobolCopybook The complete Cobol Tree
    • schemaDetails.ioBuilder ioBuilder for the copybook

    With CobolSchemaReader you get all the Cobol information:

    01 My-Copybook.
          03 Header-details.
                 05 Field-1                pic 9(6) comp-3.
                 05 Nield-2                pic x(5).
          03 User-Details.
                ...
    

    becomes:

          item {name=My-Copybook}
                Children ={
                    item {name="Header-details"}
                        Children = {
                            item {name=My-Copybook picture="9(6)" usage="computational-3"}
                            item {name="Field-2" ...}
                        }
                     item { name="User-Details" }
    
    • For IItem
      • getDisplayLength() gets the display length
      • For normal fields getFieldDefinition(), the getDecimal() method gets the decimal length
      • For array fields use getArrayDefinition()

    Note: CobolSchemaReader does not support split on redefines.


    The CobolToXml and CobolToJson both extend CobolSchemaReader

     

    Last edit: Bruce Martin 2016-10-24

Log in to post a comment.

MongoDB Logo MongoDB