Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

REDEFINE CLAUSE : GROUP ITEM WITH ARRAY

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
priyanshupathak

New User


Joined: 25 May 2006
Posts: 8
Location: india

PostPosted: Thu Aug 13, 2009 2:17 pm    Post subject: REDEFINE CLAUSE : GROUP ITEM WITH ARRAY
Reply with quote

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

Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Aug 13, 2009 2:40 pm    Post subject:
Reply with quote

Hi Priya..

First of all there is some serious declaration problem. Is this the actual code ? icon_neutral.gif
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.. icon_wink.gif

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
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Thu Aug 13, 2009 3:10 pm    Post subject:
Reply with quote

Hi.

If you are not sure about your array range...y dont you use SSRANGE...
Back to top
View user's profile Send private message
priyanshupathak

New User


Joined: 25 May 2006
Posts: 8
Location: india

PostPosted: Thu Aug 13, 2009 3:24 pm    Post subject: Reply to: REDEFINE CLAUSE : GROUP ITEM WITH ARRAY
Reply with quote

Sorry, made typying mistake. WS-A is 502 bytes.

Thanks for the replies. Problem got resolved, silly to raise this query at first place icon_redface.gif ....may be I need a break icon_biggrin.gif
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Aug 13, 2009 3:28 pm    Post subject:
Reply with quote

Hi Priyanshu,

Nice to know the issue got resolved.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Aug 13, 2009 3:33 pm    Post subject:
Reply with quote

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... icon_redface.gif ... Seeing it now only... WS-A is 502 bytes.
Back to top
View user's profile Send private message
priyanshupathak

New User


Joined: 25 May 2006
Posts: 8
Location: india

PostPosted: Thu Aug 13, 2009 3:34 pm    Post subject: Reply to: REDEFINE CLAUSE : GROUP ITEM WITH ARRAY
Reply with quote

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
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Thu Aug 13, 2009 3:50 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


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

PostPosted: Thu Aug 13, 2009 8:01 pm    Post subject:
Reply with quote

Priya,
Please use BBCode (see FAQ) next time for readability.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Thu Aug 13, 2009 9:14 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Fri Aug 14, 2009 9:35 am    Post subject:
Reply with quote

Hi Robert , Priyanshu and others....

My most sincere apologies for my post... icon_redface.gif icon_redface.gif
Guess.. I had a pretty bad day yday... icon_redface.gif

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... icon_redface.gif ... I guessed it would give me a runtime error without actually running the code. My apologies once again.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Fri Aug 14, 2009 4:49 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Fri Aug 14, 2009 7:59 pm    Post subject:
Reply with quote

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 icon_cool.gif
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 abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts Compiler option for override the exte... muralikrishnan_new COBOL Programming 9 Fri Jul 08, 2016 12:09 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us