Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve only certain lines from dataset using REXX

Status
Not open for further replies.

Cweinber21

Technical User
Sep 13, 2018
6
0
0
US
Hello,
I was wondering if anyone could assist me in some REXX coding. Here is the scenario, I'm using JCL to dump SAR information into a dataset and then I'm wanting to grab only certain information from the dataset. There is a particular beginning word that I know is in the dataset which is on line 255, so I'm doing a select statement with a when pos('BEGIN',in.i) > 0. I'm at the beginning of the line I would like to output the information from to another dataset. How do I output this line and the next 10? I figured I would need a counter of some sort but I haven't been able to figure this one out. Is there a way to delete all lines before 255 and all lines after 234? Any help would be greatly appreciated. Thanks, Chris
 
If you do not know how to use a counter then you have a problem!

Basic outline:
Code:
Using EXECIO read the first 250 lines
Read 1 record using EXECIO
Do While RC = 0
   Select
      When Pos('BEGIN',in.1) > 0
      Then Do
         Do i = 1 To 11
            Use EXECIO to write the record
            Read 1 record using EXECIO
         End
         Signal eoj
      End
      OTHERWISE
            Read 1 record using EXECIO
   End
End
eoj: Exit

However - will that required line always be the 255th line? Will there always be 11 lines to write out?


Nic
 
Hello Nic,
I have been using a counter just not receiving the correct information. I've been parsing the data and then queuing it then running the execio at the end of the code. To answer your question, yes, the same data will always been in line 255 with 11 rows needed captured. It'll only have different processing data information in those lines
 
Have you tried with a trace? I would set it in the WHEN. If running interactively start with '?R'.


Nic
 
A solution using OORexx
Code:
/*-------------------------------------------------------------------*/
/*                                                                   */
/* Program : tek-tips-extract.rex                                    */
/*                                                                   */
/* Function: Extract records 255 to 265 inclusive from a file.       */
/*                                                                   */
/* Usage   : rexx tek-tips-extract                                   */
/*                                                                   */
/*-------------------------------------------------------------------*/
Trace 'O'
infile = '"300records.txt"'		/* Input                     */
extract = '"11extracted.txt"'	        /* Extract 		     */
exit_msg = "Program ended OK"           /* Default exit message      */
rows_extracted = 0			/* Count of rows extracted   */
/*----------------------*/
/* Mainline starts here */
/*----------------------*/
	
	/* Skip 254 records */
	Address HOSTEMU "EXECIO 254 DISKR "infile" (STEM not_needed."
	If rc <> 0
	Then Do
		exit_msg = "Failed reading 254 records. Code:"rc
		Signal door
	End
	Drop not_needed.
	
	/* Read 11 records */
	Address HOSTEMU "EXECIO 11 DISKR "infile" (STEM needed."
	If rc <> 0
	Then Do
		exit_msg = "Failed reading 11 records. Code:"rc
		Signal door
	End
	
	/* Write 11 records */
	Address HOSTEMU "EXECIO "needed.0" DISKw "extract" (STEM needed."
	If rc <> 0
	Then Do
		exit_msg = "Failed writing 11 records. Code:"rc
		Signal door
	End

/* Done */
door:
	Say exit_msg

Exit
/*===================================================================*/
::requires "hostemu" library


Nic
 
Appreciate the information. I ended up going another route and just using an IF statement and pulling 3 lines instead of the 11. These 3 lines had the information the support team needed. I was able to parse out the information and send the support team an email whenever the job failed. Thanks again for the time and information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top