Menu

Writing of FMT_MAINFRAME adds 2 bytes (0x0d0x25) to every line

2016-11-17
2016-11-17
  • dirk jaeckel

    dirk jaeckel - 2016-11-17

    Hello Bruce,
    first at all: thank you for the great work you are doing here!

    I try to write a file with the following code(dont wonder about the fully qualified names, its nessecary in talend):

    net.sf.JRecord.Details.LayoutDetail schema = net.sf.JRecord.utilityClasses.SchemaLoader.loadSchema(     "V:/paketierung/A244_WPL/01_Dokumentation/02_Datenmodell/Copybooks/cobol/ACTIVITY-TAB",
        net.sf.JRecord.External.CopybookLoader.SPLIT_NONE, 
        "cp1141", 
        net.sf.JRecord.Numeric.ICopybookDialects.FMT_MAINFRAME).asLayoutDetail();
        //
        int recordIdx = 0;  // since there is only one record type, the record index must be zero
                             // If there where more than one record, you could use:
                             //    schema.getRecordIndex("COMPANY-RECORD");
    
            net.sf.JRecord.IO.AbstractLineWriter  writer = net.sf.JRecord.IO.LineIOProvider
                            .getInstance().getLineWriter(schema);
    
            writer.open(context.file);
            net.sf.JRecord.Details.AbstractLine line = new net.sf.JRecord.Details.Line(schema);
    
            String[] fieldNames = line.getLayout().getFieldDescriptions(0,0);
            System.err.println(java.util.Arrays.deepToString(fieldNames));
    
            // Retrieve the Record-Definition
            net.sf.JRecord.Details.RecordDetail  record = schema.getRecord(recordIdx);
            System.err.println("Schemainfos:");
            System.err.println("schema.getFileStructure "+ schema.getFileStructure());
            System.err.println("schema.getFontName "+schema.getFontName());
            System.err.println("schema.isBinary "+ schema.isBinary());
    

    for creating the file
    Output:
    -------------------------------------------------------
    Warning there was no "cb2xml.properties" file,
    using the default Cobol columns of 6 to 72
    -------------------------------------------------------
    *** using start column = 6, end column = 72
    Schemainfos:
    schema.getFileStructure 1
    schema.getFontName cp1141
    schema.isBinary false

    then i fill 61 lines and write them :

    // this codepice is triggerd 61 times
    if (record.getFieldCount()==row2.alles.getColumnCount() -1) {
        // row2.alles is a dynamic structure with an additional linenumber in pos 0
        for (int idx = 1, count = row2.alles.getColumnCount(); idx < count; ++idx) {
                line.getFieldValue(record.getField(idx-1)).set(row2.alles.getColumnValue(idx));
        }
        System.out.println("|"+line.getFullLine()+"|");
        writer.write(line);
    }  else {
        throw new Exception("Spaltendefinition zwischen Tabelle und Copybook unterschiedlich");// diffrence in definitions detected
    
    }
    

    The system out println of getFullLine gives me 100% what i expect !
    After closing the file

    // end of the component, outside/closing the loop
        writer.close();  
    

    i load the file with Recordeditor and the same Copybook, i find between the records: 0d25

    What am i doing wrong ?

    Regards
    Dirk

     
  • dirk jaeckel

    dirk jaeckel - 2016-11-17

    Hi again, sorry for posting in the wrong section, anyway, the library version i use is:
    JRecord_Version_0.81.4
    which includes:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.8.4
    Created-By: 1.7.0_79-b15 (Oracle Corporation)
    Main-Class: net.sf.cb2xml.Cb2Xml
    Implementation-Version: 0.95.8
    Built-Date: 2016-11-05 16:43:51

     
  • dirk jaeckel

    dirk jaeckel - 2016-11-17

    I found the error: i used a line writer:

    net.sf.JRecord.IO.LineIOProvide.getInstance().getLineWriter(schema);
    

    should have done this:

       ISchemaIOBuilder cobolBuilder = JRecordInterface1.COBOL
               .newIOBuilder(context.copybook)
                .setFileOrganization(net.sf.JRecord.Common.Constants.IO_FIXED_LENGTH)
                .setDialect(net.sf.JRecord.Numeric.ICopybookDialects.FMT_MAINFRAME);
    
        AbstractLineWriter writer =  cobolBuilder.newWriter(context.file);
        LayoutDetail  schema = cobolBuilder.getLayout();
    

    a little confusing the start with only javadoc in hand, but really great work from your side :)

     

    Last edit: Bruce Martin 2016-11-17
  • Bruce Martin

    Bruce Martin - 2016-11-17

    Good point, I will update JavaDoc to reference JRecordInterface1.

    In the JRecord source directory there is JRecord_IO_Builder_Examples which holds examples of using JRecord.

    Also in the RecordEditor, the Generate >>> Java JRecord Code for Cobol option will generate basic example JRecord code from a Cobol copybook (and optionally data file). See file:///F:/Work/JRecord/Versions/Version_0.81/Docs/RecordEditorGenerate.htm#HDRJRECGEN for details.

    If you are editing a CSV file in the RecordEditor, you can use the Generate option to generate JRecord code to read / write the CSV file. I plan to add these options to ReCsvEditor as well.

     

Log in to post a comment.