I recently saw a request for a For Loop executed with plain old SQL so I decided to create my own version.
The report you see was built by running the code once for each character in the name.
This required four queries: one to set it up, and one to end it. The other two are the actual code, and then one to decide whether to loop or not.
(If you want to see everything behind the scenes, set OnOff in SetUpLoop to 'On'. This will turn on feedback, verify, echo and the terminal wherever those statements are found.)
SetUpLoop creates a temp table to hold the Counter and then calls the query that determines where we are in the loop.
SetUpLoop.SQL |
---|
Define OnOff = Off |
Looper uses case statements to set two amper-variables. They are both used with the '@' sign to first either run the code or, at the end drop the temp table. The second tells the system to call this same query again, or just drop out.
The terminal is turned off unless debugging so the output from this query is not shown to the user.
Looper.SQL |
---|
Set Term &OnOff |
Code is the actual code that we want to run multiple times. It runs the query and then updates the Counter in the temp table.
Code.SQL |
---|
Column Character Format A9 |
EndLoop is just a little clean-up.
EndLoop.SQL |
---|
Truncate Table GTT_CountHolder ; |
No comments:
Post a Comment