View previous topic :: View next topic
|
Author |
Message |
priyanshupathak
New User
Joined: 25 May 2006 Posts: 8 Location: india
|
|
|
|
Hi,
In one of the application program, found this kind of data definition
Code: |
05 WS-A -------------- 1402 bytes
10 WS-A-E1 PIC X(2).
10 WS-A-E2 OCCURS 100 TIMES
15 WS-A-E2-1 PIC X(1)
15 WS-A-E2-2 PIC X(4)
05 WS-B REDEFINES WS-A --------------- 168 bytes
10 WS-B-E1 OCCURS 12 TIMES
15 WS-B-E1-1 PIC X(1)
15 WS-B-E1-2 PIC X(4)
15 WS-B-E1-3 PIC X(1)
15 WS-B-E1-4 PIC X(8)
01 ws-c pic x(58)
01 ws-d pic x(47) |
Code'd
Now in the application program when following set of MOVE statements are executed :
MOVE value1 TO WS-A-E2-1(WS-A-E1)
MOVE value2 TO WS-A-E2-2(WS-A-E1)
MOVE value3 TO WS-B-E1-3(WS-A-E1) ------ for WS-A-E1 > 12 this statement corrupts area for ws-c, ws-d
Not able to understand why this happens.
Thanks,
Priya |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Priya..
First of all there is some serious declaration problem. Is this the actual code ?
Dont know whether this has anything to do with the COBOL version that you are using... anyways...
If this is not the actual code, I would suggest you to post the actual code as it would certainly make our life easier..
Firstly, WS-A given by you is certainly not 1402 bytes.
Second is WS-B is a larger ( 168 ) item than WS-A ( 152 ) and would have given you a compilation error.
Third, i dont think there is any way you can index an arrary larger than what you have declared. This also would have given you a runtime error. |
|
Back to top |
|
|
bhairon singh rathore
New User
Joined: 19 Jun 2008 Posts: 91 Location: banglore
|
|
|
|
Hi.
If you are not sure about your array range...y dont you use SSRANGE... |
|
Back to top |
|
|
priyanshupathak
New User
Joined: 25 May 2006 Posts: 8 Location: india
|
|
|
|
Sorry, made typying mistake. WS-A is 502 bytes.
Thanks for the replies. Problem got resolved, silly to raise this query at first place ....may be I need a break |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Priyanshu,
Nice to know the issue got resolved. |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Quote: |
Second is WS-B is a larger ( 168 ) item than WS-A ( 152 ) and would have given you a compilation error. |
A Typo error from my part too... ... Seeing it now only... WS-A is 502 bytes. |
|
Back to top |
|
|
priyanshupathak
New User
Joined: 25 May 2006 Posts: 8 Location: india
|
|
|
|
Binop,
Yes this is similar to original code. But the issue is that same code works in Mainframe ( no memory corruption) but in Windows environment it start corrupting the memory area allocated to ws-c after subscript value 36.
Probably this is beacuse of the way Mainframe and Windows allocated memory to the varaibles. |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi,
I am guessing the allocated memory should be same for both. It might have something to do with the COBOL simulator/compiler you are using in Windows.
In windows, when you are referring an array variable, say var1(n), the simulator might be calculating the address
addr = ( <total var size> * ( n - 1 ) ) + offset of var1 in the group
irrespective of whether n takes a value higher than given in the declaration.
In Mainframes, if n takes a value higher than given in the declration, it would give us a runtime error when used as an index for the same array. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Priya,
Please use BBCode (see FAQ) next time for readability. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
In Mainframes, if n takes a value higher than given in the declration, it would give us a runtime error when used as an index for the same array.
|
Oh, really? Without the SSRANGE compile option and run time support?
Test code, which does not have SSRANGE turned on:
Code: |
01 WS-VARIABLES.
05 WS-TABLE-1 OCCURS 50
INDEXED BY WS-T1-IDX.
10 FILLER PIC X(10).
01 WS-FOLLOWING.
05 WS-FIELD-1 PIC X(260) VALUE ALL
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
/
PROCEDURE DIVISION.
S1000-MAIN SECTION.
MOVE SPACES TO WS-VARIABLES.
SET WS-T1-IDX TO 27.
SET WS-T1-IDX UP BY 27.
DISPLAY WS-TABLE-1 (WS-T1-IDX) .
SET WS-T1-IDX UP BY 1.
DISPLAY WS-TABLE-1 (WS-T1-IDX) .
SET WS-T1-IDX UP BY 1.
DISPLAY WS-TABLE-1 (WS-T1-IDX) . |
produces output of
Code: |
ABCDEFGHIJ
KLMNOPQRST
UVWXYZABCD |
I don't see any run time errors being produced; to the contrary:
Code: |
-JOBNAME STEPNAME PROCSTEP RC EXCP CONN TCB SRB CLOCK
-RS0MF093 STEP1 00 14 10 .00 .00 .0 |
Perhaps you ought to re-consider your statement? |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Robert , Priyanshu and others....
My most sincere apologies for my post...
Guess.. I had a pretty bad day yday...
Thanks Robert for pointing out the mistake in my post.
Code: |
01 WS-WORKING-VARIABLES.
05 WS-B.
10 WS-B-E1 OCCURS 12 TIMES
INDEXED BY WS-INDEX.
15 WS-B-E1-1 PIC X(4).
01 WS-C PIC X(40) VALUE ALL 'ABCD'.
01 WS-D PIC X(40) VALUE ALL 'CDEF'.
MOVE SPACES TO WS-B.
DISPLAY WS-B-E1(12).
DISPLAY WS-B-E1(13).
SET WS-INDEX TO 12.
DISPLAY WS-B-E1(WS-INDEX).
SET WS-INDEX UP BY 1.
DISPLAY WS-B-E1(WS-INDEX).
output:
ABCD
|
I had compiled the first part of my code before sending the post. It gave me a return code of 8 with the below message
Code: |
IGYPS2073-E Subscript or index literal "13" exceeded the maximum occurrence value "12" for the table. The maximum occurrence value was assumed. |
In my haste... ... I guessed it would give me a runtime error without actually running the code. My apologies once again. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Binop -- we all make mistakes at times. You definitely cannot use a literal greater than the maximum -- as your (13) showed. However, unless you're using SSRANGE to check for out of bounds indexes or subscripts, there's no run time error generated for out of bounds indexes or subscripts. This has caused many, many abends in programs over the years. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
This has caused many, many abends in programs over the years.
|
When Dame Fortune was smiling on the developer, the abend was immediate. . .
Sometimes the "bad" move did not cause the abend until far later in the run making diagnosis much more difficult |
|
Back to top |
|
|
|