Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
krunalbafna
Warnings : 1

Active User

Joined: 18 Jan 2010
Posts: 143
Location: Pune

 Posted: Sat Nov 20, 2010 8:25 pm    Post subject: COBOL - Use of table variable 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')

Bill O'Boyle

CICS Moderator

Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

Posted: Sat Nov 20, 2010 9:58 pm    Post subject: Reply to: COBOL - Use of table variable

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
Ronald Burr

Active User

Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

Posted: Sun Nov 21, 2010 1:20 am    Post subject:

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.
krunalbafna
Warnings : 1

Active User

Joined: 18 Jan 2010
Posts: 143
Location: Pune

 Posted: Sun Nov 21, 2010 5:20 pm    Post subject: 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.
Bill O'Boyle

CICS Moderator

Joined: 14 Jan 2008
Posts: 2504
Location: Atlanta, Georgia, USA

 Posted: Sun Nov 21, 2010 5:28 pm    Post subject: Reply to: COBOL - Use of table variable 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
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Difference between EQUAL and EQUAL TO... jithinraghavan COBOL Programming 1 Thu Apr 19, 2018 2:22 am Call COBOL or PLI with a click from w... vaibhav gs All Other Mainframe Topics 1 Mon Apr 16, 2018 7:29 pm COBOL MVS options BiswajitDG COBOL Programming 8 Fri Apr 06, 2018 12:35 am Searching a table for the field name? socker_dad COBOL Programming 8 Sat Mar 31, 2018 2:57 am Need inputs on DB2 tablespace/table r... ashek15 DB2 3 Sat Mar 24, 2018 11:49 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us