Page 1 of 1

If then do loop

PostPosted: Thu Jun 25, 2009 9:13 pm
by JRIVERA
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

Re: If then do loop

PostPosted: Thu Jun 25, 2009 10:26 pm
by MrSpock
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.

Re: If then do loop

PostPosted: Thu Jun 25, 2009 11:45 pm
by JRIVERA
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

Re: If then do loop

PostPosted: Tue Jun 30, 2009 9:20 am
by senthil
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.

Re: If then do loop

PostPosted: Tue Jun 30, 2009 9:33 am
by senthil
"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...........

Re: If then do loop

PostPosted: Wed Jul 08, 2009 8:36 pm
by JRIVERA
sorry didnt respond back but thanks did help and was bale to make my if block work.