If then do loop



IBM's Command List programming language & Restructured Extended Executor

If then do loop

Postby JRIVERA » Thu Jun 25, 2009 9:13 pm

Im trying to pull 2 diffrent records but only code runs but shows data for DEL only and then stays in a loop. Can anyone help.

                                                                   
DONE = 'NO'                                                         
LINENO = 0                                                           
                                                                     
DO WHILE DONE = 'NO'                                                 
  "EXECIO 1 DISKR DATA"                                             
                                                                     
  IF RC = 0 THEN                              /*  RECORD WAS READ */
     DO                                                             
       PULL RECORD                                                   
       LINENO = LINENO + 1                  /*  COUNT THE RECORD */ 
       IF INDEX(RECORD,'RPL') \= 0 THEN                             
       PULL RECORD                                                   
       LINENO = LINENO + 1                  /*  COUNT THE RECORD */ 
       IF INDEX(RECORD,'DEL') \= 0 THEN                             
         DO                                                         
           SAY 'FOUND IN RECORD' LINENO                             
           SAY 'RECORD = ' RECORD   
         END       
         END       
       ELSE NOP     
     END           
  ELSE             
 DONE = 'YES'       
END                 
EXIT 0
Jrivera:

Thanks for your help and suggestions.
JRIVERA
 
Posts: 16
Joined: Thu Jun 04, 2009 12:57 am
Has thanked: 0 time
Been thanked: 0 time

Re: If then do loop

 

Re: If then do loop

Postby MrSpock » Thu Jun 25, 2009 10:26 pm

Whoa! Hold on a sec!

First of all, are you missing a "DO" somewhere? You seem to have an extra "END" coded? Use the HILITE DO ISPF Edit command instead of the usual HILITE REXX to see if there's an unmatchd DO/END pair.

Also, you've only read 1 record into the data stack. You can't read 1 record and then issue 2 pull commands.
User avatar
MrSpock
Global moderator
 
Posts: 810
Joined: Wed Jun 06, 2007 9:37 pm
Location: Raleigh NC USA
Has thanked: 0 time
Been thanked: 2 times

Re: If then do loop

Postby JRIVERA » Thu Jun 25, 2009 11:45 pm

ok removed the 2nd pull and end statement so now the 2nd if statement executes and not the first and return code is zero. would like it to find both strings... sorry im new to programming and if then statement still confuse me
Jrivera:

Thanks for your help and suggestions.
JRIVERA
 
Posts: 16
Joined: Thu Jun 04, 2009 12:57 am
Has thanked: 0 time
Been thanked: 0 time

Re: If then do loop

Postby senthil » Tue Jun 30, 2009 9:20 am

hi,
from your piece of code what i understood is you are trying to display a record which has 'DEL' in it.
in that case try the following code.
"EXECIO 1 DISKR DATA(FINIS STEM REC."        /* after allocating a file you put records into stem var say rec.*/
DO I = 1 TO REC.0                                        /*REC.0 indicates end of file    */
      IF POS('DEL',REC.I) > 0 THEN
           DO
              SAY 'DEL IS PRESENT IN RECORD NUMBER ' I   /* will display the record number*/
              SAY 'RECORD IS ' REC.I                                 /* will display the record */
           END
END

if you want to display records with REPL you can have another IF THEN within this loop.
hope this might solve your problem.
Thanks
Senthil Kumar
senthil
 
Posts: 12
Joined: Mon Jun 01, 2009 3:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: If then do loop

Postby senthil » Tue Jun 30, 2009 9:33 am

"EXECIO 1 DISKR DATA(FINIS STEM REC."        /* after allocating a file you put records into stem var say rec.*/
DO I = 1 TO REC.0                                        /*REC.0 indicates end of file    */
      IF POS('DEL',REC.I) > 0 | POS('REPL',REC.I) > 0 THEN
           DO
              SAY 'DEL IS PRESENT IN RECORD NUMBER ' I   /* will display the record number*/
              SAY 'RECORD IS ' REC.I                                 /* will display the record */
           END
END



I hope this will do...........
Thanks
Senthil Kumar
senthil
 
Posts: 12
Joined: Mon Jun 01, 2009 3:23 pm
Has thanked: 0 time
Been thanked: 0 time

Re: If then do loop

Postby JRIVERA » Wed Jul 08, 2009 8:36 pm

sorry didnt respond back but thanks did help and was bale to make my if block work.
Jrivera:

Thanks for your help and suggestions.
JRIVERA
 
Posts: 16
Joined: Thu Jun 04, 2009 12:57 am
Has thanked: 0 time
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post