View previous topic :: View next topic
|
Author |
Message |
krunalbafna Warnings : 1 Active User
Joined: 18 Jan 2010 Posts: 143 Location: Pune
|
|
|
|
Hi,
Following is my table defination:
05 NPUT-ARRAY.
10 IA-RECORD OCCURS 400 TIMES.
15 IA-REC PIC X(004).
15 IA-REC300 PIC X(300).
I have defined a subscript variable indx.
I want to use coloum 50 to 52 of IA-REC-300
Is the following formation correct:
IF ( IA-REC300(indx)(50:3) = 'abc','efg',ghi') |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 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 -
Code: |
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 -
Code: |
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.
It's all how you name it....
Bill |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
FYI,
I was GOING to suggest that an EVALUATE structure like this:
Code: |
EVALUATE IA-REC300 (INDX) (50:3)
WHEN 'abc'
WHEN 'efg'
WHEN 'ghi'
do something
WHEN OTHER
do something different (or just CONTINUE)
END-EVALUATE |
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.
Live and learn. |
|
Back to top |
|
|
krunalbafna Warnings : 1 Active User
Joined: 18 Jan 2010 Posts: 143 Location: Pune
|
|
|
|
Hi,
if i want update only coloumn 54 t0 58 of the variable mentioned above.
will moving the value result in deletion of value from other bytes. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
As long as you specify the correct length in your REFERENCE MODIFICATION (54:5), it will work.
If you omit the length (54:) then all bytes, beginning at position 54 to the end, will be cleared.
Bill |
|
Back to top |
|
|
|