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

internal table in cobol


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

New User


Joined: 05 Jun 2007
Posts: 24
Location: kerala

PostPosted: Fri Dec 18, 2009 10:10 am
Reply with quote

I have an internal table in cobol declared as follows

01 ws-inter-table
03 ws-table-struct occurs 100 times.

I have moved values into this table. And suppose I am accessing the ws-table-struct[0] what would be it contain? Can I refer table elements like this.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Dec 18, 2009 10:16 am
Reply with quote

Hello,

It is not clear what you are asking. . .

"ws-table-struct[0]" is invalid.

You can use a numeric literal for a subscript but you would use "ws-table-struct(n)" and n should be > zero and < 101.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Dec 18, 2009 10:16 am
Reply with quote

I suggest spend some time in reading manuals for this

publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGYPG204/1.4?DT=19990113230517

OR
try yourself and let us know if you are not clear with anything...
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Dec 18, 2009 4:03 pm
Reply with quote

The answer to your question is ... it depends.

If the compiler option SSRANGE was set when the program is compiled, COBOL checks for and does not allow any reference to an element of the table outside the defined range (1 to 100 in your case). If you attempt to do so, you get an error message.

If this compiler option was not set, then accessing a table element outside the defined range may -- and may not -- access data within your program or other memory locations. Typically such memory access is not good, may cause abends, but is not prevented by the system.
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Sat Dec 19, 2009 8:07 am
Reply with quote

As Mr. Sample has stated -- you would be able to access the space that preceeds the table by using a SUBSCRIPT with a value of ZERO.

Example: 01 WS-HOLD-AREA PIC X(02) VALUE SPACES.
01 WS-SUB1 PIC 9(04) COMP VALUE ZERO.
01 WS-TEST-FIELD PIC X(05) VALUE 'ABCDE'.
01 WS-TABLE.
05 WS-TBL-ENTRIES OCCUR 20 TIMES.
10 WS-TBL-FLD1 PIC X(03).
10 WS-TBL-FLD2 PIC X(02).

MOVE WS-TBL-FLD2 (WS-SUB1) TO WS-HOLD-AREA.
>>>>> WS-HOLD-AREA WOULD NOW CONTAIN 'DE'
>>>>> YOU HAVE MOVED 2 BYTES THAT PRECEED THE TABLE TO
WS-HOLD-AREA
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Dec 19, 2009 8:33 am
Reply with quote

Hello,

Quote:
>>>>> WS-HOLD-AREA WOULD NOW CONTAIN 'DE'
Did you test this?

While the code may not abend, WS-HOLD-AREA may also not have DE (unless the compiler has been changed and i didn't get the memo icon_smile.gif )
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Dec 19, 2009 10:10 am
Reply with quote

Quote:
WS-HOLD-AREA WOULD NOW CONTAIN 'DE'

As Dick indicates, if the 2 bytes before the start of WS-TABLE contain 'DE' after the MOVE, it would be a miraculous coincidence. For one thing, since 01 levels are double word aligned, there are 3 bytes of data that occur after 'ABCDE' that probably contain X'000000' with the Enterprise compiler, but there's no guarantee of that. For another, there's no guarantee that WS-TABLE immediately follows the 8 bytes where WS-TEST-FIELD begins. This information is available in the COBOL Language Reference manual.
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 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
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top