Menu

#21 ASCII to EBCDIC conversion -- JRecord

v1.0_(example)
open
None
1
2024-07-15
2022-01-14
Anonymous
No

Hi Bruce, Could you please provide a reference or document where we can convert ASCII file to EBCDIC. The attached is the sample ASCII file consisting of multiple layout records that needs to be converted into EBCDIC and transmitted to MainFrame. Do we need to have a layout/copybook of the data?

1 Attachments

Discussion

  • Bruce Martin

    Bruce Martin - 2022-01-14

    By the looks like a Text file, if so the Mainframe file transfer program can convert the file from ASCII to EBCDIC.

    If you use JRecord, you will need a layout/copybook. You only need JRecord if

    • it is a binary file (Cobol Comp* fields)
    • You need some sort of translation e.g. changing Zoned-Decimal fields from one Cobol dialect to another, Converting readable numerics to cobols Zoned-Decimal or assumed decimal places
     
  • Anonymous

    Anonymous - 2022-01-18

    Hi Bruce, thank you, could you please provide some code examples related to the second point (you need some sort of translation....).

    And attached is the copy book and a sample ASCII file, and I would like to convert that file to EBCDIC. could you please assist on that.

     
  • Bruce Martin

    Bruce Martin - 2022-01-19

    Again the mainframe-file transfer program should be able to convert the file to from ascii to a mainframe file.

    Attached are 2 example programs:

    • ReadSaloSalxFileStructure.java using standard JRecord. It is also listed below

    • ReadSaloSalxFileStructure2.java is another way to do the conversion (with out using much of JRecord)

            AbstractLine line;
            int lineNum = 0;
    
            try {
                ICobolIOBuilder iob = JRecordInterface1.COBOL
                                    .newIOBuilder(copybookName)
                                       //.setFont("") // Think about specifying an encoding !!!
                                       .setFileOrganization(Constants.IO_BIN_TEXT)
                                       .setSplitCopybook(CopybookLoader.SPLIT_NONE);
               ICobolIOBuilder iobOutput = JRecordInterface1.COBOL
                                       .newIOBuilder(copybookName)
                                          .setFileOrganization(Constants.IO_FIXED_LENGTH)
                                          .setSplitCopybook(CopybookLoader.SPLIT_NONE)
                                          .setFont("cp037")
                                          ;  
    
    
                AbstractLineReader reader = iob.newReader(dataFile);
                AbstractLineWriter writer = iobOutput.newWriter(outputFile);
                LayoutDetail layout = iob.getLayout();
    
                while ((line = reader.read()) != null) {
                    lineNum += 1;
                    AbstractLine newLine = iobOutput.newLine();
                    for (int i = 0; i < layout.getRecord(0).getFieldCount(); i++) {
                        newLine.getFieldValue(0, i).set(line.getFieldValue(0, i).asString());
                    }
                    writer.write(newLine);
                }
    
                reader.close();
                writer.close();
            } catch (Exception e) {
                System.out.println("~~> " + lineNum + " " + e);
                System.out.println();
    
                e.printStackTrace();
            }
    
     
  • Anonymous

    Anonymous - 2022-01-19

    Thank you Bruce, will give a try.

     
  • Anonymous

    Anonymous - 2022-06-23

    Hi Bruce, will this also take the packed decimal conversion into account?

     
    • Bruce Martin

      Bruce Martin - 2024-07-15

      yes

       

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB