我之前用SAS程序在大型机上写了一个文件(按列)。我希望与Java类似。
SAS计划:
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;
基本上,我的问题是:
将ascii
值转换为ebcdic
和s370fpd
格式。 (据我所知,s370fpd与COMP3相同)
直接在大型机服务器上编写文件而不将其创建到本地服务器。我可以跳过此问题,即使我们首先在本地创建一个文件,其中包含ascii
到ebcidic
所需的编码,并将decimal
和ftp
打包到大型机 - 我很好
答案 0 :(得分:0)
在JRecord中,您可以定义Fields&记录布局:
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";
}
}
然后写文件
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();