Menu

Hyphen in COBOL field name

2020-03-13
2020-03-16
  • Gabor Markon

    Gabor Markon - 2020-03-13

    Dear Support,

    I've tried to run a sample application to read a (downloaded) mainframe file by using a COBOL data structure definition, something like this:

               01  TCQ76B-DATEN.                                           
                   05 TCQ76B-SORT.                                             
                        10 TCQ76BXWK            PIC X(004).                  
                        10 TCQ76B-FT            PIC X(024).                   
                        10 TCQ76B-POS           PIC X(004).                       
    

    It seems the Java application does not interpret the hyphen "-" as a part of the field name. Rather the name will be cut at "-" and only the part after ("FT", "POS"...) will be delivered by the code line "entry.getKey()".

    Another issue is: the field names will be not delivered in the loop in the sequence defined in the copybook (here the corresponding part of my code).

    AbstractLineReader reader = ioProvider.getLineReader(
        fileStructure, Convert.FMT_MAINFRAME,
        CopybookLoader.SPLIT_NONE, copybookName, salesFile
    );
    
    AbstractLineWriter writer = ioProvider.getLineWriter(fileStructure, salesFileOut);
    
    while ((saleRecord = reader.read()) != null) {
        lineNum += 1;
        Map mymap = new HashMap();
        mymap = saleRecord.getLayout().getFieldNameMap();
    
        Set set = mymap.entrySet(); //Converting to Set so that we can traverse  
        Iterator itr = set.iterator();
        while (itr.hasNext()) {
            //Converting to Map.Entry so that we can get key and value separately  
            Map.Entry entry = (Map.Entry) itr.next();
          **  System.out.println("field...:" + entry.getKey() + " **" + entry.getValue().toString());
        }
        ...
    }
    

    And a last question. Is JRecord runnable on a mainframe (perhaps using JZOS to read the mainframe files)?

    Best regards,
    Gabor

     

    Last edit: Bruce Martin 2020-03-13
  • Bruce Martin

    Bruce Martin - 2020-03-13

    Firstly it would be better to use the JRecordInterface1.COBOL.newIOBuilder(>>) interface.

    It seems the Java application does not interpret the hyphen "-" as a part of the field name. Rather the name will be cut at "-" and only the part after ("FT", "POS"...) will be delivered by the code line "entry.getKey()".

    • Depends on what attributes are set. The setDropCopybookNameFromFields(boolean)
      of the Iobuilder controls wether the Copybook name is dropped from the front of
      field-names.
           ICobolIOBuilder iob = JRecordInterface1.COBOL
                .newIOBuilder("G:/Users/Bruce01/RecordEditor_HSQL/CopyBook/Cobol/DTAR020.cbl")
                     .setDropCopybookNameFromFields(false)
                     .setFont("cp037");
    

    Another issue is: the field names will be not delivered in the loop in the sequence defined in the copybook (here the corresponding part of my code).

    • The getFieldNameMap() returns a hashmap. The getFieldIterator method is what you want
                final FieldIterator iter = saleRecord.getFieldIterator(0);
                while (iter.hasNext()) {
                    final AbstractFieldValue field = iter.next();
                    System.out.print("|" + field.getFieldDetail().getName() + "=" + field.asString());
                }
    

    And a last question. Is JRecord runnable on a mainframe (perhaps using JZOS to read the mainframe files)?

    • I have not tried, probably. It should be possible use JZOS to read/write files
      but you will need to write some interface code.

    in JRecord you can use the IByteRecordReader, IByteRecordWriter interfaces with
    newLineReader / newLineWriter methods.

    To read a file using JZOS, You would need to create a class that implements IByteRecordReader
    that uses JZOS to read the file and returns an array of bytes

         reader = iobuilder.newLineReader(IByteRecordReader byteReader);
    

    The IByteRecordReader interface:

    public interface IByteRecordReader {
    
        /**
         * Read one line from the input file as an array of bytes
         *
         * @return line read in
         *
         * @throws IOException io error
         */
        byte[] read() throws IOException;
    
        /**
         * Closes the file
         *
         * @throws IOException io error
         */
        void close() throws IOException;
    }
    
     
    • Gabor Markon

      Gabor Markon - 2020-03-13

      Hello Bruce,

      thanks for the prompt answer, I will try asap, and let you know.

      Regards
      Gabor

      Am Fr., 13. März 2020 um 14:35 Uhr schrieb Bruce Martin bruce_a_martin@users.sourceforge.net:

      Firstly it would be better to use the
      JRecordInterface1.COBOL.newIOBuilder(>>) interface.

      It seems the Java application does not interpret the hyphen "-" as a part
      of the field name. Rather the name will be cut at "-" and only the part
      after ("FT", "POS"...) will be delivered by the code line "entry.getKey()".

      • Depends on what attributes are set. The
        setDropCopybookNameFromFields(boolean)
        of the Iobuilder controls wether the Copybook name is dropped from the
        front of
        field-names.

        ICobolIOBuilder iob = JRecordInterface1.COBOL
        .newIOBuilder("G:/Users/Bruce01/RecordEditor_HSQL/CopyBook/Cobol/DTAR020.cbl")
        .setDropCopybookNameFromFields(false)
        .setFont("cp037");

      Another issue is: the field names will be not delivered in the loop in the
      sequence defined in the copybook (here the corresponding part of my code).

      • The getFieldNameMap() returns a hashmap. The getFieldIterator
        method is what you want
            final FieldIterator iter = saleRecord.getFieldIterator(0);
            while (iter.hasNext()) {
                final AbstractFieldValue field = iter.next();
                System.out.print("|" + field.getFieldDetail().getName() + "=" + field.asString());
            }
        

      And a last question. Is JRecord runnable on a mainframe (perhaps using
      JZOS to read the mainframe files)?

      • I have not tried, probably. It should be possible use JZOS to
        read/write files
        but you will need to write some interface code.

      in JRecord you can use the IByteRecordReader, IByteRecordWriter interfaces
      with
      newLineReader / newLineWriter methods.

      To read a file using JZOS, You would need to create a class that
      implements IByteRecordReader
      that uses JZOS to read the file and returns an array of bytes

       reader = iobuilder.newLineReader(IByteRecordReader byteReader);
      

      The IByteRecordReader interface:

      public interface IByteRecordReader {

      /**     * Read one line from the input file as an array of bytes     *     * @return line read in     *     * @throws IOException io error     */
      byte[] read() throws IOException;
      
      /**     * Closes the file     *     * @throws IOException io error     */
      void close() throws IOException;}
      

      Hyphen in COBOL field name
      https://sourceforge.net/p/jrecord/discussion/678633/thread/b5a81928ae/?limit=25#5032


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/jrecord/discussion/678633/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
  • Gabor Markon

    Gabor Markon - 2020-03-16

    Hello Bruce,

    issues 1. (Java application does not interpret the hyphen "-" as a part
    of the field name) and 2. (field names will be not delivered in the loop in the
    sequence defined in the copybook ) are clear now, thanks.

    As for JZOS: I'll try to implement your suggestion in the next time.

    Regards
    Gabor

     

Log in to post a comment.