View previous topic :: View next topic
|
Author |
Message |
luttapi
New User
Joined: 05 Jun 2007 Posts: 24 Location: kerala
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 ) |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
|