Menu

Number Field Help

Help
2015-11-08
2015-11-08
  • richard bradwell

    Hi,

    As a java developer I'm new to mainframes and the use of jrecord.

    I have been given a cobol file that I need to parse with a given copybook. In general it is working great however I am having problems with numeric fields.

    I know that the first 4 characters of the file I need to parse should hold the number 48 in binary format. When I read in the file, before parsing against the copybook, I see the first four bytes as 0,0,0,48. I declare the field in the copybook as

    PICTURE S9(4)

    (I have also tried variants of COMP)

    When I parse it against the copybook, using jrecord, I get a value of zero.

    It's the same when I write out my own file. The documents I have say that I need a length field that is a 4 byte binary field however when I to write the copybook format I don't get 0,0,0,48 written to the file.

    For the writing part I thought I would try

        ByteBuffer bbuf = ByteBuffer.allocate(4) ;
        bbuf.putInt(48) ;
        byte[] arr = bbuf.array() ;
    

    then
    recird.getFieldValue(...).set(arr) ;

    However that seem to fall over complaining about it wanting a number.

    Any thoughts?

    Thanks in advance.

     

    Last edit: richard bradwell 2015-11-08
  • Brian Reynolds

    Brian Reynolds - 2015-11-08

    sounds like you have a packed decimal (e.g. S9(6) COMP-3) in little endian format (FMT_INTEL)

    E.g

               05 TEST01.
                06 STR1 PIC X(2).
                06 VAL1 PIC S9(6) COMP-3.
                06 STR2 PIC X(2). 
    

    data (hex values)

    41 42 00 00 00 48 58 59  
    

    Output:

    <CobolData>
            <TEST01>
                <STR1>AB</STR1>
                <VAL1>48</VAL1>
                <STR2>XY</STR2>
            </TEST01>
        </CobolData>
    

    Does that clarify?

     

    Last edit: Brian Reynolds 2015-11-08
  • Bruce Martin

    Bruce Martin - 2015-11-08

    Try

          Pic s9(9) comp.
    

    in cobol you are specifing the number of decimal digits and not the number of bytes. The comp gives you big-endian binary integer. so

          pic s9(4)   -  2 byte binary integer (short java)
          pic s9(9)   -  4 byte binary integer (int   java)
          pic s9(18)  -  8 byte binary integer (long  java)
    

    The alternative is to use the RecordEditor Xml file schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <RECORD RECORDNAME="DTAR1000 VB" COPYBOOK="DTAR1000" DELIMITER="&lt;Tab&gt;" DESCRIPTION="Stores File VB" FONTNAME="CP037" FILESTRUCTURE="Mainframe_VB" STYLE="0" RECORDTYPE="BinaryRecord" LIST="Y" QUOTE="" RecSep="default" SYSTEMNAME="Mainframe" LINE_NO_FIELD_NAMES="1">
        <FIELDS>
            <FIELD NAME="STORE-NO" POSITION="1" LENGTH="2" TYPE="Binary Integer Big Endian (Mainframe?)"/>
            <FIELD NAME="REGION-NO" POSITION="3" LENGTH="2" TYPE="Binary Integer Big Endian (Mainframe?)"/>
            <FIELD NAME="STORE-NAME" POSITION="5" LENGTH="50" TYPE="Char"/>
    
     

Log in to post a comment.