IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

COBOL - Use of table variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
krunalbafna
Warnings : 1

Active User


Joined: 18 Jan 2010
Posts: 143
Location: Pune

PostPosted: Sat Nov 20, 2010 8:25 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Sat Nov 20, 2010 9:58 pm
Reply with quote

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.... icon_wink.gif

Bill
Back to top
View user's profile Send private message
Ronald Burr

Active User


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

PostPosted: Sun Nov 21, 2010 1:20 am
Reply with quote

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
View user's profile Send private message
krunalbafna
Warnings : 1

Active User


Joined: 18 Jan 2010
Posts: 143
Location: Pune

PostPosted: Sun Nov 21, 2010 5:20 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Sun Nov 21, 2010 5:28 pm
Reply with quote

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. icon_eek.gif

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Load new table with Old unload - DB2 DB2 6
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top