Menu

#18 Length of the field is trimmed when doing "asString()"

v1.0_(example)
open
1
2021-09-09
2021-07-14
Anonymous
No
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

Discussion

  • Bruce Martin

    Bruce Martin - 2021-07-14
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,11 +1,12 @@
    -> 000900          03  KCODE-STORE-KEY.                                      
    +~~~cobol
    +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.               
    -
    +~~~
    
     > package com.example.jrecord;
    
     
  • Bruce Martin

    Bruce Martin - 2021-07-14
    • 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

     
  • Anonymous

    Anonymous - 2021-07-15

    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

     
    • Bruce Martin

      Bruce Martin - 2021-07-16

      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 the output
      • Create a second copybook with out comp fields and do a field by field copy. You could create the output-Copybook either manually or in your program. If done manually you use the CobolCopy program in JReecord.

      Pad Output

      You can do some thing like:

             IFieldValue fieldValue = line.getFieldValue(dtar020.keycodeNo);
             IFieldDetail fieldDetail = fieldValue.getFieldDetail();
             int len = fieldDetail.getCobolItem().getDisplayLength();
             if (fieldValue.isNumeric()) {
      
             } else {
      
             }
      

      Update copybook

      There is several way to go

      • Use a Text editor
      • Do it in a Java program
      • Update cb2xml/JRecord internal classes
       
  • Bruce Martin

    Bruce Martin - 2021-07-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,37 +8,38 @@
     001500          03  SALE-PRICE         PIC S9(9)V99 COMP-3.               
     ~~~
    
    -> package com.example.jrecord;
    +~~~ 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()
    ->       );
    ->     }
    ->   }
    -> }
    -
    + 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
    
     
  • Bruce Martin

    Bruce Martin - 2021-07-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -8,7 +8,8 @@
     001500          03  SALE-PRICE         PIC S9(9)V99 COMP-3.               
     ~~~
    
    -~~~ java
    +java program
    +~~~java
      package com.example.jrecord;
    
      import java.io.IOException;
    
     
  • Bruce Martin

    Bruce Martin - 2021-07-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -9,6 +9,7 @@
     ~~~
    
     java program
    +
     ~~~java
      package com.example.jrecord;
    
     
  • Anonymous

    Anonymous - 2021-08-12

    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

     
  • Bruce Martin

    Bruce Martin - 2021-08-12

    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:

    ICobolIOBuilder iobuilder = JRecordInterface1.COBOL
                        .newIOBuilder(copybookName)
                            .setFont("cp037")                                   // US EBCDIC
                            .setFileOrganization(Constants.IO_VB);
                 AbstractLineWriter writer = iobuilder.newWriter("filename");
    

    I should have more time to look at things on Saturday

     
  • Anonymous

    Anonymous - 2021-09-09

    This code actually worked, thanks @bruce_a_martin

     
  • Anonymous

    Anonymous - 2021-09-09

    Also we were able to successfully load it into mainframe

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.