000900 03 KCODE-STORE-KEY. 001000 05 KEYCODE-NO PIC X(08). 001100 05 STORE-NO PIC S9(03) COMP-3. 001200 03 THE-DATE PIC S9(07) COMP-3. 001300 03 DEPT-NO PIC S9(03) COMP-3. 001400 03 QTY-SOLD PIC S9(9) COMP-3. 001500 03 SALE-PRICE PIC S9(9)V99 COMP-3.
java program
~~~java
package com.example.jrecord;
import java.io.IOException;
import net.sf.JRecord.Common.Constants;
import net.sf.JRecord.Details.AbstractLine;
import net.sf.JRecord.External.CopybookLoader;
import net.sf.JRecord.IO.AbstractLineReader;
import net.sf.JRecord.JRecordInterface1;
import net.sf.JRecord.def.IO.builders.ICobolIOBuilder;
public class Sample {
public static void main(String[] args) throws IOException {
ICobolIOBuilder ioBldrReader = JRecordInterface1.COBOL
.newIOBuilder("DTAR020.cbl").setFont("cp037")
.setFileOrganization(Constants.IO_FIXED_LENGTH)
.setSplitCopybook(CopybookLoader.SPLIT_NONE);
AbstractLineReader reader = ioBldrReader.newReader("DTAR020.bin");
AbstractLine readLine;
while ((readLine = reader.read()) != null) {
System.out.println(
readLine.getFieldValue("KEYCODE-NO").asString()
+ " " + readLine.getFieldValue("STORE-NO").asString()
+ " " + readLine.getFieldValue("THE-DATE").asString()
+ " " + readLine.getFieldValue("DEPT-NO").asString()
+ " " + readLine.getFieldValue("QTY-SOLD").asString()
+ " " + readLine.getFieldValue("SALE-PRICE").asString()
);
}
}
}
~~~
When we try to convert everything according to fields is converting but trailing and leading spaces and zeros are trimmed, when we tried to convert full line from a file comp3 values are not converting properly. Are we missing something, please help
Anonymous
Diff:
When we try to convert everything according to fields is converting but trailing and leading spaces and zeros are trimmed - That is how asString method works, why do you want the leading zero's / trailing spaces ??? The idea is convert Cobol data to java. Normally Java Strings do not have trailing spaces.
when we tried to convert full line from a file comp3 values are not converting properly. - the getFullLine() does not do any conversion Cobol conversion, it converts the data line to Text and is not useful for binary files.
What are you trying to do, why do you want padding / leading zero's
Thanks for the response @bruce_a_martin
Our use case to process the records line by line which contains some fillers, we are not sure about comp3 values in fillers, so we thought of taking field by field and do a string concatenation but that is not maintaining the line record length
eg: our record length is 100 when we do asString the length is reduced and when we do getFullLine comp3 is tampered, basically we want the full line converted without changing the length
can we do something about this
In JRecord to retain cobol FILLER you need to use IOBuilder setKeepFillers method
i.e
ioBldrReader.setKeepFillers(true);
For Comp-3 conversion, JRecord uses the field definition. Only fields that are defined as Comp-3 get comp-3 conversion.
There is 2 basic approaches:
Pad Output
You can do some thing like:
Update copybook
There is several way to go
Diff:
Diff:
Diff:
Thanks for the response @bruce_a_martin we were able to make good progress in our project, all thanks to your jRecord. Now we are stuck at writing a variable block file with RDW.
So the scenario is we have a VB file we were to able to read it with jrecord and do all types of operation when we try to write it back the RDWs are gone.
Kindly respond
Thank You
I really need to see your code to understand what you are doing. While JRecord can create a VB file, transporting it to a mainframe might be a problem. If you are running on the mainframe , let me know
Any way this should create a VB writer:
I should have more time to look at things on Saturday
This code actually worked, thanks @bruce_a_martin
Also we were able to successfully load it into mainframe