How to create CSV in COBOL



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to create CSV in COBOL

Postby bond_ajay » Wed May 14, 2008 1:16 pm

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
bond_ajay
 
Posts: 11
Joined: Wed Apr 02, 2008 9:53 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to create CSV in COBOL

 

Re: How to create CSV in COBOL

Postby dick scherrer » Wed May 14, 2008 9:25 pm

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: How to create CSV in COBOL

Postby CICS Guy » Wed May 14, 2008 9:56 pm

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......
CICS Guy
 
Posts: 255
Joined: Wed Jun 20, 2007 4:08 am
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post