View previous topic :: View next topic |
Author |
Message |
Jamylady Beginner
Joined: 04 Nov 2004 Posts: 68 Topics: 22
|
Posted: Wed Apr 11, 2007 12:26 pm Post subject: How to read a file using a key in a REXX program |
|
|
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 |
|
|
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Wed Apr 11, 2007 1:12 pm Post subject: |
|
|
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 |
|
|
expat Intermediate
Joined: 01 Mar 2007 Posts: 475 Topics: 9 Location: Welsh Wales
|
Posted: Thu Apr 12, 2007 1:52 am Post subject: |
|
|
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 |
|
|
Jamylady Beginner
Joined: 04 Nov 2004 Posts: 68 Topics: 22
|
Posted: Thu Apr 12, 2007 3:47 am Post subject: |
|
|
Thanks a million
JA |
|
Back to top |
|
|
shash_modi Beginner
Joined: 22 Apr 2008 Posts: 26 Topics: 9 Location: Mumbai
|
Posted: Mon May 12, 2008 11:45 pm Post subject: |
|
|
Hi Jamylady,
Did your REXX working fine? If so could you please help me know how it looks. |
|
Back to top |
|
|
|
|