IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to write in a PS in comma separated form


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
masterlock

New User


Joined: 16 Mar 2007
Posts: 6
Location: India

PostPosted: Fri Mar 16, 2007 10:35 am
Reply with quote

Hi,

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.
Back to top
View user's profile Send private message
saiprasadh

Active User


Joined: 20 Sep 2006
Posts: 154
Location: US

PostPosted: Fri Mar 16, 2007 12:01 pm
Reply with quote

Hi

can you give an example how your input file look's like



Sai
Back to top
View user's profile Send private message
masterlock

New User


Joined: 16 Mar 2007
Posts: 6
Location: India

PostPosted: Fri Mar 16, 2007 6:12 pm
Reply with quote

Hi Sai,

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.

Thanks,
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Mar 17, 2007 4:24 pm
Reply with quote

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
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Mar 17, 2007 8:30 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Sat Mar 17, 2007 11:05 pm
Reply with quote

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.

Input:AAAABBBBCCCC11112222.
Output:AAAA,BBBB,CCCC,1111,2222

Code:
outrec fields=(1,4,c',',5,4,c',',9,4,c',',12,4,c',',16,4)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Mar 17, 2007 11:16 pm
Reply with quote

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.

FWIW. . .
Back to top
View user's profile Send private message
masterlock

New User


Joined: 16 Mar 2007
Posts: 6
Location: India

PostPosted: Tue Mar 20, 2007 7:58 pm
Reply with quote

Hi all,

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Write line by line from two files DFSORT/ICETOOL 7
This topic is locked: you cannot edit posts or make replies. How To Write, Compile and Execute Cob... COBOL Programming 5
No new posts Compare two files with a key and writ... SYNCSORT 3
No new posts JCL to write the log on to a PDS file JCL & VSAM 10
Search our Forums:

Back to Top