Page 1 of 1

How to create CSV in COBOL

PostPosted: Wed May 14, 2008 1:16 pm
by bond_ajay
hi,

Can someone please help me with creating a comma separated file in COBOL.

In the program we have the following layout of the record that needs to be converted to comma separated file before being written to the output file.

Copybook Layout:
01 record
05 var1 pic x(5)
05 var2 pic X(9)
05 var3 pic 9(5)
05 var4 pic 9(9)
05 var5 pic x(5)
05 var6 pic X(1)

So say we have the record data as: abcd(1 space)(9 spaces)(2 spaces)123(9 0's)(5 spaces)(1 space)

This will look like: abcd xyz 123000000000

We need to remove all spaces and 0's. Also the last byte - Var6 must be spaces. Since we need a comma separated file in the output file, the record should appear as shown below in the output file;
abcd,,123,,,

Please let me know how best this can be achieved in a cobol program.

Thanks,
Ajay

Re: How to create CSV in COBOL

PostPosted: Wed May 14, 2008 9:25 pm
by dick scherrer
Hello Ajay,

There is another, current topic on creating a csv file. http://www.ibmmainframeforum.com/all-other-mainframe-topics/topic600.html

Please look at that topic and see if that helps you.

Re: How to create CSV in COBOL

PostPosted: Wed May 14, 2008 9:56 pm
by CICS Guy
01 record
   05 var1 pic x(5) 'abcd '
   05 var2 pic X(9) '         '
   05 var3 pic 9(5) '  123'
   05 var4 pic 9(9) '000000000'
   05 var5 pic x(5) '     '
   05 var6 pic X(1) ' '

From 'abcd            123000000000      '
To 'abcd,,123,,,'

      STRING var1 ','
             var2 ','
             var3 ','
             var4 ','
             var5 ','
             var6
        delimited by size
        into temp.                             
      move 1 to out
      move 1 to in
      move spaces to outrec
      Perform until in > length of record + 5
        if temp(in:1) = space or zero
          add +1 to in
        else
          move temp(in:1) to outrec(out:1)
          add +1 to in
          add +1 to out
        end-if
      end-perform.


Not tested, but should be close......