Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
COBOL - Use of table variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: COBOL - Use of table variable
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Sat Nov 20, 2010 9:58 pm    Post subject: Reply to: COBOL - Use of table variable
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    Post subject:
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    Post subject:
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: 2504
Location: Atlanta, Georgia, USA

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

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us