0

I'm trying to put together some REXX code to achieve the following.

  1. Check given input(0007145547162165876, 0002734752467588968, 555729879318548867, 5559871342286434816)for a given condition (first 3 characters are 000). If so, perform some computation on that input (as below).

    b. If condition not met (i.e first 3 characters not 000 ), perform a different computation on that input.

  2. Printout the results of both computations in one file.

Below is the code I have for the first if conditional statement and it works as desired. Problem is implementing the second condition. How do I achieve this?

 if substr(rec.i,3,3) == '000'                             
      then do                                                
   sum = d1+d2+d5+d6+d7+d8+d9+d10+d11+d12+d13+d14+d15+d16    
   sum = sum * 9                                             
   chksum = substr(sum,2,2)                                  
   chk    = d3||d4                                           
   if chksum = chk                                           
      then do                       
            say 'valid check sum' chksum 'in' rec.i          
            out.1=rec.i                                      
            "EXECIO 1 DISKW DATA       (stem out."           
           end                                               
      else do                                                
            say '*** invalid check sum' chk 'in' rec.i       
            say '*** check sum should be' chksum 'in' rec.i  
            out.1=rec.i                                      
            "EXECIO 1 DISKW OUTFILE (stem out."              
           end                                               
   end                                                       
   end                                                       
Walter
  • 43
  • 1
  • 2
  • 6
  • Rexx has `else`. You've even used it in your code. What is your actual problem? You're not looking at the first three characters of a record, by the way. – Bill Woodger Jun 02 '15 at 10:45
  • Really? What's the right way of going about it? Maybe that's why it doesn't work in the first place. Please help. I edited the question to try and make the problem more clear. – Walter Jun 02 '15 at 15:30
  • Change this, `substr(rec.i,3,3)`, to this `substr(rec.i,1,3)`. In the code you have shown you have an unmatched `end`. You have unnecessary use of a stem variable for your EXECIOs for the output, although it should work. Basically, your first IF was failing, and you thought it wasn't, so couldn't work out why the else was not at least getting actioned. So basically it is a typo getting in the way of your progress. – Bill Woodger Jun 02 '15 at 16:15
  • Just a tip, `I1il`. Those are all fairly similar at a glance. I avoid using single-character variables. Each time you "saw" i,3,3 I think you read the i as a 1. – Bill Woodger Jun 02 '15 at 16:25

1 Answers1

0

You can look at the SELECT...WHEN...OTHERWISE clause to see if that helps you any. I've used it to simplify some complex code where I may want to check for several different flavours of input.

Note, It's not a direct replacement for IF...THEN...ELSE logic.