Page 1 of 1

Reading a PS and selecting some part of data

PostPosted: Mon Jul 21, 2008 6:20 pm
by shivendu
I have a requirement like this:
Read a file (actually a text file uploaded to mainframe) line by line and copy next 8 bytes when a particular word is found in the record. E.g., if the input file is like the one below then the REXX code should give next 8 characters whenever say “Program:” is encountered i.e. output file for the below input file should have 2 records- M002233 and M1254789.

Description..
The purpose of this section is to put in ..
Job: J002233
Program:M002233
The purpose of this section..
The purpose of Program:M1254789


Note: position of tag like ‘Program:’ in above sample file is NOT fixed.

How to do this?

Thanks,
Shvndu

Re: Reading a PS and selecting some part of data

PostPosted: Mon Jul 21, 2008 9:28 pm
by MrSpock
I'd use a PARSE statement:

"EXECIO 1 DISKR myindd"
If rc <> 0 Then ...
Parse Pull the_record
Parse Var the_record . the_identifier the_value
If the_identifier = "Program:" Then
  Do
    Push Left(the_value,8)
    "EXECIO 1 DISKW myoutdd"
  End
...

Re: Reading a PS and selecting some part of data

PostPosted: Thu Jul 24, 2008 5:29 pm
by shivendu
Thanks for the reply. I got the desired result though using a bit different code.

done = 'no'                                           
lineno = 0                                           
DO WHILE done = 'no'                                 
"EXECIO 1 DISKR ddin"                                 
If rc = 0 Then                                       
 do                                                   
   Parse Pull the_record                             
   IF INDEX(the_record,'Program:') \= 0 THEN                     
   Do                                                 
     Push Left(the_record,17)                         
     "EXECIO 1 DISKW ddout"                           
   end                                               
 end                                                 
else                                                 
 done = 'yes' 
end