0

I have a requirement where I take a SUBSTR (e.g st_detail = "%BOM0007992739871P", st_digit = SUBSTR(st_detail, 8, 10) ). I have to do some validations on the st_digit and if it is valid change "%BOM0002562186P" to "%BOM0002562186C". My code works fine upto this. But I was asked to increment st_digit (I used st_digit = st_digit + 1 ) and print 100 valid st_digits and append it with C. so I put the code in a loop and display st_detail. But when i ran it i got "%BOM0007.99273987E+9C" after first increment. Please help on how to display "%BOM0007992739872C"? (NOTE: this is a reference only and I can't display the validation logic here and my code works fine. The extra code i added was the code I used here)

out_ctr = 1
DO while out_ctr < 101
   /* validations */
   IF valid THEN
     say st_digit " is valid"
   ELSE
     say st_digit " is invalid"
   st_digit = st_digit + 1
   out_ctr = out_ctr + 1
END
  • Please submit your trace (relevant part only). As shown your code is valid although I would code it as Do out_ctr = 1 To 100. You also appear to be incrementing st_digit whether it is valid or invalid. You should also, whilst trying to figure out what is wrong, show the value of st_digit before and after increment. But I suspect the error is elsewhere. – NicC Oct 12 '20 at 09:52
  • You could also split st_detail into three parts - the first 8 bytes, st_digits and the trailing character. Then increment the digits and finally concatenate all parts back into one : st_detail = part1||part2||part3 – NicC Oct 12 '20 at 11:24
  • *-* st_digit = st_digits + 1 >V> "7992739871" >L> "1" >O> "7.99273987E+9" – Vinay Paladi Oct 12 '20 at 11:31
  • I suspect the problem arises after assignment. You advised to split, I already did it, and it still shows the same. – Vinay Paladi Oct 12 '20 at 11:35
  • @VinayPaladi You're right to suspect that, and if you run your code with `Trace I` as NicC suggests, you'd know it for sure. That's the very first thing any Rexx programmer will do to debug a misbehavior. – Ross Patterson Oct 19 '20 at 14:27

1 Answers1

2

It seems the NUMERIC setting was " 9 0 SCIENTIFIC ". I changed it to NUMERIC DIGITS 12, So, now it works.

parse numeric my_numeric_settings
say my_numeric_settings   /* 9 0 SCIENTIFIC */
NUMERIC DIGITS 16
parse numeric my_numeric_settings
say my_numeric_settings  /* 16 0 SCIENTIFIC */

It's because I used SUBSTR(st_detail, 8, 10),So, st_digit is of length 10, which is greater than the DEFAULT setting of "9 0 SCIENTIFIC", So by changing it to either "NUMERIC DIGITS 10" or "NUMERIC DIGITS 12" the code worked.