1

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

dvhouten
  • 55
  • 5
  • If you could create a table in one of the databases that holds the old code and the new code combinations, you could then use a load-lookup to pull in the information. It would be far fewer lines of code in the SQR. – Bob Sep 24 '20 at 17:10
  • That would be my first choice, and we even have some "translator" tables in the source db, but for some reason they don't want to go that route. Mongo only pawn. . . Thanks, David – dvhouten Sep 25 '20 at 11:41

1 Answers1

1

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.

cardmagik
  • 1,698
  • 19
  • 17
  • 1
    I appreciate you getting back to me. When I need this it's usually 20-150 replacements, so at least I could save 30% of the lines. Thanks, David – dvhouten Sep 24 '20 at 10:59
  • 1
    I see where EVALUATE is used in my program, but they have a "BREAK" on each WHEN LET. Do I need that? Does it save processing time to use the BREAK? Thanks, David – dvhouten Sep 24 '20 at 12:14
  • The BREAK is optional - I'm pretty sure anyways. Try it and test it without and if it doesn't fill your needs, then add the BREAK – cardmagik Sep 24 '20 at 14:03