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 

Rexx help for a beginner

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


Joined: 05 Aug 2004
Posts: 2
Topics: 1

PostPosted: Thu Aug 05, 2004 6:10 am    Post subject: Rexx help for a beginner Reply with quote

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

Thanks in advance
Sam
Back to top
View user's profile Send private message
superk
Advanced


Joined: 19 Dec 2002
Posts: 684
Topics: 5

PostPosted: Thu Aug 05, 2004 7:09 am    Post subject: Reply with quote

Seems like a relatively easy process. I might be able to assist if you can provide:

1. A sample of the input data with the tag(s).
2. A layout of your logic up to this point, either in REXX or in Pseudo-code.
Back to top
View user's profile Send private message
sam20097
Beginner


Joined: 05 Aug 2004
Posts: 2
Topics: 1

PostPosted: Thu Aug 05, 2004 9:39 am    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
superk
Advanced


Joined: 19 Dec 2002
Posts: 684
Topics: 5

PostPosted: Mon Aug 09, 2004 1:12 pm    Post subject: Reply with quote

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.

Here is the job:
[code:1:627a72eb24]
//*
//STEP0001 EXEC PGM=IEFBR14
//DS2 DD DSN=&SYSUID..DS2,DISP=(MOD,DELETE,DELETE),
// UNIT=(SYSDA),SPACE=(TRK,(1,1),RLSE),
// RECFM=FB,LRECL=80
//*
//STEP0002 EXEC PGM=IRXJCL,PARM='TEST67'
//SYSEXEC DD DISP=SHR,DSN=&SYSUID..REXX
//DS1 DD DATA
<sam1>
aaaaaaaaaa
bbbbbbbbbb
cccccccccc
dddddddddd
eeeeeeeeee
</sam1>
<sam2>
aaaaaaaaaa
cccccccccc
dddddddddd
</sam2>
/*
//DS2 DD DSN=&SYSUID..DS2,DISP=(,CATLG,DELETE),
// UNIT=(SYSDA),SPACE=(TRK,(1,1),RLSE),
// RECFM=FB,LRECL=80
//DS3 DD DSN=&&T1,DISP=(NEW,PASS),
// UNIT=(SYSDA),SPACE=(TRK,(1,1),RLSE),
// RECFM=FB,LRECL=80
//SYSTSPRT DD SYSOUT=*
//*

And here is the EXEC:

/* REXX */

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 &
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Mon Aug 09, 2004 3:38 pm    Post subject: Reply with quote

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>                   


and the second dataset,
Code:

----+----1----+----2----+-
REC5                     
REC6                     
REC7                     
REC8                     
REC9                     
RECA                     


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   


These are the records displayed:
Code:

---+----1----+----2----+-
RECB                     
RECC                     


Here is the ICETOOL job used:
Code:

//STEP     EXEC PGM=ICETOOL                               
//TOOLIN   DD *                                           
*Get record numbers between tags                           
 COPY FROM(IN01)          USING(CPY1)                     
*Generate cards                                           
 SORT FROM(CON0)          USING(SRT1)                     
*Split file into records for specific operation           
 COPY FROM(IN01)          USING(CPY2)                     
*Add records to IN02                                       
 COPY FROM(CON1)   TO(OT1)                                 
*Delete records                                           
 SELECT FROM(CON2) TO(OT2) ON(1,4,CH) NODUPS  USING(SEL1) 
*Update records                                           
 SELECT FROM(CON3) TO(OT3) ON(1,4,CH) ALLDUPS USING(SEL2) -
              DISCARD(OT4)                                 
*Final                                                     
 COPY FROM(CON4)   TO(OUT)                                 
/*                                                         
//IN01     DD *                                           
<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>                               
/*                                   
//IN02     DD *               
REC5                         
REC6                         
REC7                         
REC8                         
REC9                         
RECA                         
/*                           
//T1       DD DSN=&&TEMP0001,
//            DISP=(,PASS)   
//T2       DD DSN=&&TEMP0002,
//            DISP=(,PASS)   
//T3       DD DSN=&&TEMP0003,
//            DISP=(,PASS)   
//T4       DD DSN=&&TEMP0004,
//            DISP=(,PASS)   
//T5       DD DSN=&&TEMP0005,
//            DISP=(,PASS)   
//T6       DD DSN=&&TEMP0006,
//            DISP=(,PASS)   
//T7       DD DSN=&&TEMP0007,
//            DISP=(,PASS)   
//T8       DD DSN=&&TEMP0008,
//            DISP=(,PASS)   
//CON0     DD DSN=&&TEMP0001,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T1   
//         DD DSN=&&TEMP0002,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T2   
//         DD DSN=&&TEMP0003,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T3   
//         DD DSN=&&TEMP0004,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T4   
//         DD DSN=&&TEMP0005,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T5   
//         DD DSN=&&TEMP0006,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T6   
//         DD DSN=&&TEMP0007,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T7   
//         DD DSN=&&TEMP0008,
//            DISP=(SHR,KEEP),
//            VOL=REF=*.T8   
//TA       DD DSN=&&TEMP000A,
//            DISP=(,PASS)   
//TB       DD DSN=&&TEMP000B,
//            DISP=(,PASS)   
//TC       DD DSN=&&TEMP000C,
//            DISP=(,PASS)   
//TD       DD DSN=&&TEMP000D,
//            DISP=(,PASS)   
//Z1       DD DSN=&&TEMP00Z1,
//            DISP=(,PASS)   
//Z2       DD DSN=&&TEMP00Z2,
//            DISP=(,PASS)   
//Z3       DD DSN=&&TEMP00Z3,
//            DISP=(,PASS)   
//Z4       DD SYSOUT=*       
//CON1     DD *               
REC5                           
REC6                           
REC7                           
REC8                           
REC9                           
RECA                           
/*                             
//         DD DSN=&&TEMP00Z1, 
//            DISP=(SHR,KEEP),
//            VOL=REF=*.Z1     
//OT1      DD DSN=&&TEMP0OT1, 
//            DISP=(,PASS)     
//CON2     DD DSN=&&TEMP0OT1, 
//            DISP=(SHR,KEEP),
//            VOL=REF=*.OT1   
//         DD DSN=&&TEMP00Z2, 
//            DISP=(SHR,KEEP),
//            VOL=REF=*.Z2     
//OT2      DD DSN=&&TEMP0OT2, 
//            DISP=(,PASS)     
//CON3     DD DSN=&&TEMP0OT2, 
//            DISP=(SHR,KEEP),       
//            VOL=REF=*.OT2           
//         DD DSN=&&TEMP00Z3,         
//            DISP=(SHR,KEEP),       
//            VOL=REF=*.Z3           
//OT3      DD DSN=&&TEMP0OT3,         
//            DISP=(,PASS)           
//OT4      DD DSN=&&TEMP0OT4,         
//            DISP=(,PASS)           
//CON4     DD DSN=&&TEMP0OT3,         
//            DISP=(SHR,KEEP),       
//            VOL=REF=*.OT3           
//         DD DSN=&&TEMP0OT4,         
//            DISP=(SHR,KEEP),       
//            VOL=REF=*.OT4           
//OUT      DD SYSOUT=*               
//CPY1CNTL DD *                       
 INREC  FIELDS=(1,80,SEQNUM,8,ZD)     
 OUTFIL FNAMES=T1,                   
        INCLUDE=(1,6,CH,EQ,C'<add>'),
        OUTREC=(C'A',81,8,8X'F0',80:X)
 OUTFIL FNAMES=T2,                   
        INCLUDE=(1,6,CH,EQ,C'</add>'),
        OUTREC=(C'A',8X'F0',81,8,80:X)
 OUTFIL FNAMES=T3,                   
        INCLUDE=(1,6,CH,EQ,C'<del>'),
        OUTREC=(C'D',81,8,8X'F0',80:X)
 OUTFIL FNAMES=T4,                   
        INCLUDE=(1,6,CH,EQ,C'</del>'),
        OUTREC=(C'D',8X'F0',81,8,80:X)
 OUTFIL FNAMES=T5,                   
        INCLUDE=(1,6,CH,EQ,C'<upd>'),
        OUTREC=(C'U',81,8,8X'F0',80:X)
 OUTFIL FNAMES=T6,                   
        INCLUDE=(1,6,CH,EQ,C'</upd>'),
        OUTREC=(C'U',8X'F0',81,8,80:X)
 OUTFIL FNAMES=T7,                   
        INCLUDE=(1,6,CH,EQ,C'<dis>'),
        OUTREC=(C'S',81,8,8X'F0',80:X)
 OUTFIL FNAMES=T8,                   
        INCLUDE=(1,6,CH,EQ,C'</dis>'),
        OUTREC=(C'S',8X'F0',81,8,80:X)
/*                                   
//SRT1CNTL DD *                                                 
 OPTION ZDPRINT                                                 
 SORT   FIELDS=(1,1,CH,A)                                       
 SUM    FIELDS=(2,8,ZD,10,8,ZD)                                 
 OUTFIL FNAMES=TA,                                               
        INCLUDE=(1,1,CH,EQ,C'A'),                               
        OUTREC=(X,C' OUTFIL FNAMES=Z1,',/,                       
                X,C'        INCLUDE=(81,8,ZD,GT,',02,8,C',&,',/,
                X,C'                 81,8,ZD,LT,',10,8,C'),',/, 
                X,C'        OUTREC=(1,80)',80:X)                 
 OUTFIL FNAMES=TB,                                               
        INCLUDE=(1,1,CH,EQ,C'D'),                               
        OUTREC=(X,C' OUTFIL FNAMES=Z2,',/,                       
                X,C'        INCLUDE=(81,8,ZD,GT,',02,8,C',&,',/,
                X,C'                 81,8,ZD,LT,',10,8,C'),',/, 
                X,C'        OUTREC=(1,80)',80:X)                 
 OUTFIL FNAMES=TC,                                               
        INCLUDE=(1,1,CH,EQ,C'U'),                               
        OUTREC=(X,C' OUTFIL FNAMES=Z3,',/,                       
                X,C'        INCLUDE=(81,8,ZD,GT,',02,8,C',&,',/,
                X,C'                 81,8,ZD,LT,',10,8,C'),',/, 
         X,C'        OUTREC=(1,80,C',X'7D',C'U2',X'7D',C')',80:X)
 OUTFIL FNAMES=TD,                                               
        INCLUDE=(1,1,CH,EQ,C'S'),                               
        OUTREC=(X,C' OUTFIL FNAMES=Z4,',/,                       
                X,C'        INCLUDE=(81,8,ZD,GT,',02,8,C',&,',/,
                X,C'                 81,8,ZD,LT,',10,8,C'),',/, 
                X,C'        OUTREC=(1,80)',80:X)                 
/*                                                               
//CPY2CNTL DD *                                                 
 INREC FIELDS=(1,80,SEQNUM,8,ZD)                                 
/*                                                               
//         DD DSN=&&TEMP000A,                                   
//            DISP=(SHR,KEEP),                                   
//            VOL=REF=*.TA                                       
//         DD DSN=&&TEMP000B,                                   
//            DISP=(SHR,KEEP),                                   
//            VOL=REF=*.TB                                       
//         DD DSN=&&TEMP000C,                                   
//            DISP=(SHR,KEEP),                                   
//            VOL=REF=*.TC                                       
//         DD DSN=&&TEMP000D,                                   
//            DISP=(SHR,KEEP),                                   
//            VOL=REF=*.TD         
//SEL1CNTL DD *                     
 OUTFIL FNAMES=OT2,                 
        OUTREC=(1,80,C'U1')         
/*                                 
//SEL2CNTL DD *                     
 OUTFIL FNAMES=OT3,                 
        INCLUDE=(81,2,CH,EQ,C'U2'),
        OUTREC=(1,80)               
 OUTFIL FNAMES=OT4,                 
        OUTREC=(1,80)               
/*                                 
//DFSMSG   DD SYSOUT=*             
//TOOLMSG  DD SYSOUT=*             


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.
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Mon Aug 09, 2004 3:41 pm    Post subject: Reply with quote

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.
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