2

I have earlier written a file (column-wise) on mainframe with SAS program. I want to achieve similar with Java.

SAS program:

FILENAME fileReference ftp "'ThreadNum.ThreadType.NEW.AplicationFlag.J&feed_dt.'"
          RCMD='SITE TR PRI=20 SEC=20 RECFM=F LRECL=84'  HOST='host'
          USER="&user."  PASS="&pass."
          ;

  DATA _null_;
         SET MyDataSet ;
         name=0;
         pro='000';
         format custid 05. ;
         action='A ';
         flagcnt='01';
         FILE  fileReference LRECL=84 RECFM=f;
         PUT @01 num13    s370fpd07.
             @08 names    370fpd05.
             @13 pro      $ebcdic03.
             @16 action   $ebcdic02.
             @18 flag     $ebcdic02.
             @56 flagcnt  $ebcdic02.
             @70 num15    s370ff015.
         ;
       RUN;

So basically, my problems are:

  1. Converting ascii value to ebcdic and s370fpd format. ( I understand, s370fpd is same as COMP3)

  2. Writing a file on mainframe server directly without creating it to local server. I can skip this problem and even if we first create a file on local with desired encoding of ascii to ebcidic and packed decimal and ftp it to mainframe - I am good.

dimo414
  • 47,227
  • 18
  • 148
  • 244
Piyush Baijal
  • 281
  • 4
  • 13
  • Maybe http://stackoverflow.com/questions/368603/convert-string-from-ascii-to-ebcdic-in-java –  Jun 27 '16 at 05:16
  • "JAVA" isn't an acronym. It's just "Java". – dimo414 Jun 27 '16 at 05:50
  • Looks to me as though your your "directly on the Mainframe" is not what you think. Ftp. Also, have you confirmed with the Mainframe people whether or not your dataset on the Mainframe (your file) is "blocked"? Unblocked 84-byte records are not going to perform well, and it will be noticeable if you have any quantity of them. – Bill Woodger Jun 27 '16 at 16:23
  • @BillWoodger: Dataset isn't blocked and I am the only user who will write to it. LRECL=84 is recomended by Maniframe users and I am not really concerned about it. – Piyush Baijal Jun 28 '16 at 06:59
  • Ok, it can't be large. I don't think you know what blocked is in this context. If you do use large amounts of data you will come to know. – Bill Woodger Jun 28 '16 at 13:38

1 Answers1

0
  1. IBM have packages for handling Mainframe data see IBM Documentation, not sure if it is free or not.
  2. Look at my project JRecord. You can define mainframe Records in
    • Cobol Copybook
    • Xml File description
    • Java Code.

In JRecord you can define Fields & record layout:

public class FieldNamesDtar020 {

    public static final RecordDtar020 RECORD_DTAR020 = new RecordDtar020();



    public static IFixedWidthIOBuilder newIoBuilder() {
        RecordDtar020 r = RECORD_DTAR020;
        return JRecordInterface1.FIXED_WIDTH.newIOBuilder()
                            .setFont("CP037")
                            .setFileOrganization(Constants.IO_FIXED_LENGTH)                        
                            .defineFieldsByLength()
                                .addFieldByLength(r.keycodeNo, Type.ftChar, 8, 0)
                                .addFieldByLength(r.storeNo, Type.ftPackedDecimal, 2, 0)
                                .addFieldByLength(r.date, Type.ftPackedDecimal, 4, 0)
                                .addFieldByLength(r.deptNo, Type.ftPackedDecimal, 2, 0)
                                .addFieldByLength(r.qtySold, Type.ftPackedDecimal, 5, 0)
                                .addFieldByLength(r.salePrice, Type.ftPackedDecimal, 6, 2)
                            .endOfRecord();    
}    

    public static class RecordDtar020 {
       public final String keycodeNo = "KEYCODE-NO";
       public final String storeNo = "STORE-NO";
       public final String date = "DATE";
       public final String deptNo = "DEPT-NO";
       public final String qtySold = "QTY-SOLD";
       public final String salePrice = "SALE-PRICE";

    }  
}

Then to write the file

        IIOBuilder iob = FieldNamesDtar020.newIoBuilder();
        AbstractLineWriter writer = iob.newWriter(filename);
        AbstractLine line = iob.newLine();

        writer.write(line);
        line.getFieldValue(rDtar020.keycodeNo).set("123");
        line.getFieldValue(rDtar020.storeNo).set(111);
          ...
        line.getFieldValue(rDtar020.salePrice).set)222);

        writer.close();
Bruce Martin
  • 10,358
  • 1
  • 27
  • 38