SQR replace by position rather than multiple IF LET ENDIF

148 views Asked by At

In translating codes from one database to the next, I have to use an IF LET ENDIF for each code. IF $CODE = 'A11' LET $CODE = 'AAA' END-IF IF $CODE = 'B11' LET $CODE = 'BBB' END-IF IF $CODE = 'C11' LET $CODE = 'CCC' END-IF. . .ad nauseum

Is there a way in SQR to do a positional replace? REPLACE ('A11', 'B11', 'C11') IN ('AAA', 'BBB', 'CCC')

Thanks, David

1

There are 1 answers

3
cardmagik On

Unfortunately, both the REPLACE and TRANSLATE sub-commands of the LET Statement only allow a single transformation.

As an alternative to multiple if-then-else's, you could use the Evaluate statement:

Evaluate $Code
   When = 'A11'
      Let $Code = 'AAA'
   When = 'B11'
      Let $Code = 'BBB'
   When-Other
End-Evaluate

This would make the code easier to review and less verbose.