Posted: Thu Aug 05, 2004 6:10 am Post subject: Rexx help for a beginner
I am new to rexx..
I have a requirement..
There are two datasets(PS), one is the input(ds1) and the other is the output(ds2)
I have to open a ds1, read the first row and check the tag( tag can be add, del, update,display)
if add tag in ds1 then add all the recordss to ds2 till the tag ends(addend)
if the tag is del in ds1 then delete all the records from ds2 which are same as in ds1 and clode the file
i am getting confused...
can anybody help m eon this
DS1 format
<sam1>
aaaaaaaaaa
cccccccccc
dddddddddd
</sam1>
or
<sam2>
aaaaaaaaaa
cccccccccc
dddddddddd
</sam2>
open DS1
read DS1
if sam1 then
open DS2 in write
write all the records between <sam1> to </sam1> to DS2
if sam2 then
delete all the records from DS2,by comparing the records from DS1 till the end of sam2.
(compare the record in DS1 with DS2, if present in DS2, then delete that)
Whew! This one turned out to be a little more complex that I originally thought it would be. For my solution, I wanted to keep the code 100% REXX, so that's what I did. There are no external functions, programs, or TSO commands anywhere.
sam1 = 0 /* Initialize Action Flag */
sam2 = 0 /* Initialize Action Flag */
id = 0 /* Initialize Action Flag */
Do Forever
"EXECIO 1 DISKR DS1" /* Read 1 Record from DS1 */
If rc <> 0 Then Leave /* Check for EOF */
Parse Pull rec /* Retrieve record to stack */
If Left(rec,6) = '<sam1>' Then
Do
sam1 = 1 /* Turn ON 'sam1' Action Flag */
sam2 = 0 /* Turn OFF 'sam2' Action Flag */
id = 1 /* Turn ON 'id' Action Flag */
End
Else If Left(rec,6) = '<sam2>' Then
Do
sam1 = 0 /* Turn OFF 'sam1' Action Flag */
sam2 = 1 /* Turn ON 'sam2' Action Flag */
id = 1 /* Turn ON 'id' Action Flag */
End
Else If Left(rec,7) = '</sam1>' Then
Do
"EXECIO 0 DISKW DS2 (FINIS"
sam1 = 0 /* Turn OFF 'sam1' Action Flag */
sam2 = 0 /* Turn OFF 'sam2' Action Flag */
id = 1 /* Turn ON 'id' Action Flag */
End
Else If Left(rec,7) = '</sam2>' Then
Do
"EXECIO 0 DISKW DS3 (FINIS"
sam1 = 0 /* Turn OFF 'sam1' Action Flag */
sam2 = 0 /* Turn OFF 'sam2' Action Flag */
id = 1 /* Turn ON 'id' Action Flag */
End
Else id = 0 /* Turn OFF 'id' Action Flag */
If (sam1 &
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
Posted: Mon Aug 09, 2004 3:38 pm Post subject:
Sam,
This solution uses DFSORT/ICETOOL. With this job, you can implement all the operations of ADD, DELete, UPDate and DISplay. For the following tagged dataset,
Code:
----+----1----+----2----+-
<add>
REC1 added from IN01
REC2 added from IN01
REC3 added from IN01
REC4 added from IN01
</add>
<del>
REC5
REC6
REC7
</del>
<upd>
REC8 updated from IN01
REC9 updated from IN01
RECA updated from IN01
</upd>
<dis>
RECB
RECC
</dis>
I got the following dataset with add, delete and update operations done in this order.
Spool output shifted right by 1 byte.
Code:
---+----1----+----2----+-
RECA updated from IN01
REC8 updated from IN01
REC9 updated from IN01
REC1 added from IN01
REC2 added from IN01
REC3 added from IN01
REC4 added from IN01
The first pass gets the starting and ending record numbers for each tag. The next pass generates cards to get the records between the pair of tags. The dataset Z4 will have the <dis> and </dis> records. The next three passes are for ADD, DEL and UPD functions. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
Posted: Mon Aug 09, 2004 3:41 pm Post subject:
What happens when a given pair is not present in IN01? I get a JCL ERROR as one Zx datasets do not exist. The solution would be to use cataloged datasets for Zx by using IEFBR14 steps before to catalog and after to delete.
For the following input in IN01,
Code:
----+----1----+----2----+-
<del>
REC5
REC6
REC7
</del>
<upd>
REC8 updated from IN01
REC9 updated from IN01
RECA updated from IN01
</upd>
<dis>
RECB
RECC
</dis>
I get OUT as
Code:
---+----1----+----2----+-
RECA updated from IN01
REC8 updated from IN01
REC9 updated from IN01
_________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
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