I'm new to REXX. I want to write a code which will write the content of one input file to a PS but the fields need to be comma separated. I've no idea how to read a copybook and accordingly separate different fields by comma.
Actually the input file will be a standard master input file where everyfield is mostly contiguous. For ex: AAAABBBBCCCC111112222. Suppose the 1st 4 bytes indicates name, the next 4 bytes location and so on. What I want to make the output look like:AAAA,BBBB,CCCC,1111,2222. Obviously the byte division will be as per the copybook.
here is a quick and dirty sample,
the offsets and the lengths must be hand coded,
( they could be generated by analyzing the copybook, but the task is beyond the scope of this post)
the I/O statements work for a PC REXX environment *tested* on
regina rexx under MAC OS X 10.4.9,
regina rexx under FEDORA CORE 6
to make it running TSO You should substitute linein/lineout the corresponding "EXECIO" constructs
to make it production quality there should be some error and congruence checking
the script is meant to demonstrate the parsing capabilities of REXX
the source code
Code:
#! /usr/bin/rexx
/*REXX */
Trace "O"
parse arg in
parse var in fn "." ft
ou = fn || ".csv" || "." || ft
data = ""
coun = 0
do while ( lines(in) > 0)
data = linein(in)
coun = coun + 1
f1 = substr(data, 1, 4 )
f2 = substr(data, 5, 4 )
f3 = substr(data, 9, 4 )
f4 = substr(data, 13, 5 )
f5 = substr(data, 18, 4 )
/* the following construct is more performing but less intuitive
parse var data f1 +4 f2 +4 f3 +4 f4 +5 f5 +4 .
*/
csv = f1 || "," || ,
f2 || "," || ,
f3 || "," || ,
f4 || "," || ,
f5
call lineout ou, csv
end
say "Processed " coun " records"
exit
the input file
AAAABBBBCCCC111112222
EEEEFFFFGGGG333334444
HHHHIIIIJJJJ555556666
KKKKLLLLMMMM777778888
NNNNPPPPQQQQ999990000
the result
AAAA,BBBB,CCCC,11111,2222
EEEE,FFFF,GGGG,33333,4444
HHHH,IIII,JJJJ,55555,6666
KKKK,LLLL,MMMM,77777,8888
NNNN,PPPP,QQQQ,99999,0000
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
If you have a copybook for the record format and there is no requirement that you must use REXX, you could write a simple program that reads the "plain" input and using STRING you could build a new comma-delimited output.
If this is for learning, great, but if you need to do this quickly, i'd recommend the COBOL code.
Joined: 20 Jan 2007 Posts: 684 Location: Hollywood
If you have copybook then it should be a standard fixed format for which you need CSV format. You can use JCL SORT in the outrec after the field positions put comma character.
This is the quickest method than writing COBOL program.
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
If you must hand key the length and displacement for each field and if the file has a few hundred fields, i believe it will be far faster and less error prone to use the copybook/cobol approach.
Sorry for the delayed reply. I've tried with the REXX code & the jcl, both have worked for a particular copybook which I can get beforehand. I haven't tried with the cobol code yet but will certainly do.
As of now I've been able to generate a REXX program which will store the different PIC values in a stem variable. Now if i become able to join these two codes then I'll get the soln. Now the problem arises in moving the said stem variable in a loop while concatenating. So pls anyone tell me whether the following simple pseudo code works at all.
N.0=","
DO i=1 to m.0
temp=N.(i-1) || N.I
END
where N. is the stem variable mentioned above.
Also expecting any alternate soln of the above problem.