Joined: 14 Jan 2008 Posts: 2504 Location: Atlanta, Georgia, USA
Yes, your syntax is correct. But I'd like to make two suggestions.
First, as a failsafe, you can programmatically calculate the max-occurs definition. You've already defined variable INDX (hopefully, as a binary-fullword), then define INDX-MAX (also as a binary-fullword) and issue at program start -
03 INDX-MAX PIC 9(08) COMP.
DIVIDE LENGTH OF NPUT-ARRAY BY LENGTH OF IA-RECORD (1) GIVING INDX-MAX.
After which, INDX-MAX will equal 400. If someone comes along and increases or decreases the OCCURS, your calculation will always be correct. You can also avoid looking through the code for the hard-coded max of the ARRAY OCCURS and there's always a chance you'll miss one or two.
Second (IMHO), it's always good programming practice (sometimes for syntax but always for readability) to issue your compares as -
IF (IA-REC300 (INDX) (50:3) = 'ABC'
OR IA-REC300 (INDX) (50:3) = 'EFG'
OR IA-REC300 (INDX) (50:3) = 'GHI')
Inasmuch as it may seem redundant, it shows the exact intent of your compare, so that the next person will understand your code and that's the most important part of programming.
But also, you should replace the subscripts with INDEX as they are the more efficient method of array-element addressing.
Calculating a max-index is the same as described above for the max-subscript. The only difference is to define two indices to the array, with one being used to represent the MAX value and after the above calculation, you set this MAX index value to the binary-fullword.
One other point. Try to avoid naming a WS variable which includes the word INDEX (such as WS-INDEX) or something similar (such as INDX) as others may formulate this as an INDEX, when it really isn't.
I was GOING to suggest that an EVALUATE structure like this:
EVALUATE IA-REC300 (INDX) (50:3)
do something different (or just CONTINUE)
would be more efficient than the IF construct Bill suggested, assuming that the computation of the identifier's (subscripted,reference-modified) address would only occur ONCE for an EVALUATE construct rather than three times for the IF construct.
BUT, when I ran test compiles in which I included both constructs, I found that both resulted in the generation of identical code.
When the NOOPTIMIZE option was specified, BOTH constructs generated three address computations - one preceding each compare/branch. When the OPTIMIZE(STD) option was specified, both constructs generated only one computation of address followed by three compares/branches.