Today I needed to write a CL program to check if names of save files are in the patter of Qxxxxxxxxx, where ‘xxxxxxxxx’ are 9 digits. I thought at first that I need to get each byte from position 2 and check if it is between ‘0’ and ‘9’. But fortunately I found a build in function %CHECK, which is used to qualify each character in a string, very fit for my problem!
So I wrote this.
IF COND(%CHECK(’0123456789′ &ODOBNM 2) *NE 0) THEN(GOTO LOOPER1)
If there are other characters than ‘0’ – ‘9’, it will be skipped. When I compile it on 6.1, I run into an error. The error is: CPD0056 30 Built-in function %CHECK not valid. Why?
Then I found the infocenter I checked in 7.1. Checking 6.1 infocenter, there is no %CHECK, so it is a new one introduces in 7.1.
How can I do it on 6.1 and previous?
This works.
IF COND((%SST(&ODOBNM 2 1) *LT ’0′) *OR (%SST(&ODOBNM 2 1) *GT ’9′) *OR +
(%SST(&ODOBNM 3 1) *LT ’0′) *OR (%SST(&ODOBNM 3 1) *GT ’9′) *OR +
(%SST(&ODOBNM 4 1) *LT ’0′) *OR (%SST(&ODOBNM 4 1) *GT ’9′) *OR +
(%SST(&ODOBNM 5 1) *LT ’0′) *OR (%SST(&ODOBNM 5 1) *GT ’9′) *OR +
(%SST(&ODOBNM 6 1) *LT ’0′) *OR (%SST(&ODOBNM 6 1) *GT ’9′) *OR +
(%SST(&ODOBNM 7 1) *LT ’0′) *OR (%SST(&ODOBNM 7 1) *GT ’9′) *OR +
(%SST(&ODOBNM 8 1) *LT ’0′) *OR (%SST(&ODOBNM 8 1) *GT ’9′) *OR +
(%SST(&ODOBNM 9 1) *LT ’0′) *OR (%SST(&ODOBNM 9 1) *GT ’9′) *OR +
(%SST(&ODOBNM 10 1) *LT ’0′) *OR (%SST(&ODOBNM 10 1) *GT ’9′)) +
THEN(GOTO LOOPER1)
You probably think this is not elegant and want to use a loop and then only one line of check. You could do that. But actually you have to declare a variable and then call DO…CHECK…TALLY…ENDO, it is also several line of code and not as easy to read as this one. Anyway, this is only 9 repeats, so does not matter much.
Of course, %CHECK is better than any one of this. So I will use %CHECK on 7.1 and above. As it is always be, life is better as we progress.