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

INITIALIZE Comp Variables ?


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

New User


Joined: 07 Jan 2006
Posts: 31

PostPosted: Mon Jan 09, 2006 7:04 pm
Reply with quote

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

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Mon Jan 09, 2006 7:10 pm
Reply with quote

Hi,

I think it will abend. I need to try it out.

Correct me if I am wrong.
Back to top
View user's profile Send private message
raveendra_ibm
Currently Banned

New User


Joined: 07 Jan 2006
Posts: 31

PostPosted: Mon Jan 09, 2006 7:21 pm
Reply with quote

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

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Mon Jan 09, 2006 7:32 pm
Reply with quote

Hi Raveendra,

Thanks a lot for correcting me.
Back to top
View user's profile Send private message
raveendra_ibm
Currently Banned

New User


Joined: 07 Jan 2006
Posts: 31

PostPosted: Mon Jan 09, 2006 7:40 pm
Reply with quote

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

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Jan 10, 2006 7:05 am
Reply with quote

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

New User


Joined: 07 Jan 2006
Posts: 31

PostPosted: Tue Jan 10, 2006 9:39 am
Reply with quote

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

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Jan 11, 2006 6:27 am
Reply with quote

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
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts JCL with variables JCL & VSAM 1
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts JCL Variables JCL & VSAM 1
Search our Forums:

Back to Top