MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to read a file using a key in a REXX program

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
Jamylady
Beginner


Joined: 04 Nov 2004
Posts: 68
Topics: 22

PostPosted: Wed Apr 11, 2007 12:26 pm    Post subject: How to read a file using a key in a REXX program Reply with quote

Hi,
I am writting a Rexx program which uses two files as input. I am reading one file and based on the key value from that file, I need to look up in the second file and get some values and update the first file. But I am not sure how can I read the second file using a key value!

Could any one help?
Thanks
JA
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Wed Apr 11, 2007 1:12 pm    Post subject: Reply with quote

If the files are not very large, you can read the 2nd file first, saving each line as a stem variable with the key as the tail. Then, when you read the 1st file, extract the key from the line you read, and use that key as the tail on the stem variable.
Code:

/* pseudocode!! */
'execio DISKR * file2 (stem file2. finis'
stem. = ''
do i = 1 to file2.0
  key = substr(file2.i,1,8)
  stem.key = file2.i
end
drop file2.
/* now read file1 */
'execio * diskr file1 (stem file1. finis'
do i = 1 to file1.0
  key = substr(file1.i,30,8)
  stuffFromFile2 = stem.key
  if stuffFromFile2 <> '' then
    Do
       ...
    end
end
drop file1.

Of course you could optimize this to use less storage by saving indices into file2. instead if copying whole lines, but the code is easier to understand this way.
Back to top
View user's profile Send private message Visit poster's website
expat
Intermediate


Joined: 01 Mar 2007
Posts: 475
Topics: 9
Location: Welsh Wales

PostPosted: Thu Apr 12, 2007 1:52 am    Post subject: Reply with quote

Here's a bit of REXX that I've used to sole another problem for someone - they read a flatfile and get a key value from the file and then wnat to update the flatfile if one of two VSAM files has a record of the same key.
Code:

CARD1 = " REPRO IFILE(IDD) OFILE(ODD) - "
CARD2 = "   FROMKEY(         )        - "
CARD3 = "     TOKEY(         )          "

"EXECIO 1 DISKRU FLATFILE"
PARSE VAR FLATFILE    1 KEY    10 DATA      99 .

"EXECIO 0 DISKW SYSIN ( FINIS" /* ALLOCATED BY JCL - AS IS ODD DD */
QUEUE CARD1
QUEUE OVERLAY(KEY,CARD2,12)
QUEUE OVERLAY(KEY,CARD3,12)
"EXECIO" QUEUED() "DISKW SYSIN ( FINIS"
"FREE  FI(IDD)"
"ALLOC FI(IDD) DA('"VSAM FILE 1 NAME"') SHR"
"IDCAMS"
IF RC = 0 THEN DO   /* KEY MATCH VSAM FILE 1 */
 ********************
 UPDATE FLATFILE HERE
 ********************
END
ELSE DO
  "FREE  FI(IDD)"
  "ALLOC FI(IDD) DA('"VSAM FILE 2 NAME"') SHR"
  "IDCAMS"
  IF RC = 0 THEN DO   /* KEY MATCH VSAM FILE 2 */
    ********************
    UPDATE FLATFILE HERE
    ********************
  END
END
GO BACK AND GET NEXT FLATFILE RECORD

_________________
If it's true that we are here to help others,
then what exactly are the others here for ?
Back to top
View user's profile Send private message
Jamylady
Beginner


Joined: 04 Nov 2004
Posts: 68
Topics: 22

PostPosted: Thu Apr 12, 2007 3:47 am    Post subject: Reply with quote

Thanks a million

JA
Back to top
View user's profile Send private message
shash_modi
Beginner


Joined: 22 Apr 2008
Posts: 26
Topics: 9
Location: Mumbai

PostPosted: Mon May 12, 2008 11:45 pm    Post subject: Reply with quote

Hi Jamylady,

Did your REXX working fine? If so could you please help me know how it looks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group