View previous topic :: View next topic
|
Author |
Message |
raveendra_ibm Currently Banned New User
Joined: 07 Jan 2006 Posts: 31
|
|
|
|
Hi All,
Can anyone please explain if the following code for initializing a
group variable containing a comp variable allowed ?
01 GRP1.
02 MEM1 PIC X(2).
02 MEM2 PIC 9(2).
02 MEM3 PIC S9(4) COMP.
02 MEM4 PIC S9(8) COMP-3.
.
.
.
INITIALIZE GRP1.
ADD 10 TO MEM3.
ADD 20 TO MEM4.
Would this lead to an ABEND ?
Thanks and Regards,
Raveendra. |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi,
I think it will abend. I need to try it out.
Correct me if I am wrong. |
|
Back to top |
|
|
raveendra_ibm Currently Banned New User
Joined: 07 Jan 2006 Posts: 31
|
|
|
|
Hi iKnow !!!
Thanks for such a prompt reply to my query.
It actually did not ABEND ? It initialized those variables to 0.
I am working on IBM Mainframes COBOL ?
Thanks n Regards,
Raveendra. |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi Raveendra,
Thanks a lot for correcting me. |
|
Back to top |
|
|
raveendra_ibm Currently Banned New User
Joined: 07 Jan 2006 Posts: 31
|
|
|
|
Hi iKnow,
Actually I was expecting an ABEND as well ?
But to my wonder it turned out error free ?
Could please check the same on your compiler, because it might not be the same on all compilers.
Thanks & Regards,
Raveendra. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
In addition, it will also init an array if it were in the 01 level.
One problem w/init is that it's not very efficient, so if you are initing in a loop it can be costly.
What some do is init the field outside the loop; move it to a hold field then move the hold field back to the original as part of the loop process. |
|
Back to top |
|
|
raveendra_ibm Currently Banned New User
Joined: 07 Jan 2006 Posts: 31
|
|
|
|
Hi mmwife,
I was expecting the comp variables to be initialized to spaces and thereby
any arithmetic operation on them further would lead to an abend.
I just wanted a clarification on whether the comp variables like the usual
numeric variables are initialized to zero or not .....
Thanks and Regards,
Raveendra. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Raveendra,
You can use init to init variables to any values consistant with their data types. The defaults are spaces for alpha/AN types; zeros for numeric types. The zeros will be consistant with the numeric type being inited. For ex. a 2 byte field:
comp signed and unsigned will get X'0000'
comp-3 unsigned will get X'000F' (pic 9 comp-3)
comp-3 signed will get X'000C' (pic S9 comp-3)
display unsigned will get X'F0F0' (pic 9)
display signed will get X'F0C0' (pic S9)
HTH |
|
Back to top |
|
|
|