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

Add statement, what is the value of A


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

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:13 pm
Reply with quote

i have one doubt in add statement
for example


01 a pic 9


add -2 to a.
add -4 to a.
add -6 to a.


i want to know what is the value of A right now


thanks
raj
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:17 pm
Reply with quote

What do you think it is?
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:21 pm
Reply with quote

my interviewer asked this question
but i didnt try this example
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:22 pm
Reply with quote

In my view -6 will be added to the old value of a and stored in a.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:23 pm
Reply with quote

well, just for fun, give it a try, and explain to me how you arrived at your answer.... icon_biggrin.gif
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:26 pm
Reply with quote

If we have not mentioned any initial value for a then I think some garbage value will be there and -6 will be added to that.

Please give me correct answer.

I am curious to know it...................... icon_lol.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:31 pm
Reply with quote

well, for the sake of argument, assume that it was initialized to zero, what is its value after the adds?
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:34 pm
Reply with quote

i told just 6 only
because if we specify sign we will see -6
but in this example we didnt specify any sign
so what is the value of a
by
raj
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:35 pm
Reply with quote

see it the initial value is 0 then in first operation value of a will be -2 then -6 and finally -12.
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:38 pm
Reply with quote

I think I am wrong because a is specified as PIC 9 so how can -12 be stored.
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:38 pm
Reply with quote

i accept that answer but can we see the minus sign
by
raj
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:38 pm
Reply with quote

I think that:
0+-2=-2 but there is no sign so now a=2
2+-4=-2 but there is no sign so now a=2
2+-6=-4 but there is no sign so now a=4

final answer? 4
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:40 pm
Reply with quote

thanks for ur reply
raj
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Dec 19, 2006 9:42 pm
Reply with quote

Hello,

The code as shown may very well get a S0C7. "a" doesn't have an initial numeric value. You may get strange results if there happens to already be some number at that location.

If you use the following code:

01 A PIC 9 VALUE 0.
01 B PIC S9 VALUE 0.

DISPLAY A.
ADD -2 TO A.
DISPLAY A.
ADD -4 TO A.
DISPLAY A.
ADD -6 TO A.
DISPLAY A.
DISPLAY ' '.
DISPLAY B.
ADD -2 TO B.
DISPLAY B.
ADD -4 TO B.
DISPLAY B.
ADD -6 TO B.
DISPLAY B.
DISPLAY ' '.

you get:
0
2
2
4

{
K
O
K

The second set of "answers" is due to the sign The { is a signed zero the letters are negative numbers K=-2, O=-6, etc.

Code:
Code:
Code:
Code:
Code:
Back to top
View user's profile Send private message
rajrohith

New User


Joined: 15 Apr 2005
Posts: 54
Location: chennai

PostPosted: Tue Dec 19, 2006 9:43 pm
Reply with quote

what is difference between working storage copy book
and procedure division copy book
by
raj
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 9:45 pm
Reply with quote

raj, use a new topic when you change it..

One copys data division statements while the other copys procedure division statements.
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 9:49 pm
Reply with quote

William what I have read is::
The operational sign is not stored as a separate character. the operational sign is stored as the zone bits of the rightmost digit position of the data item.

i.e A = +1
B = +2 ................... I = +9

J = -1
K = -2
............. R = -9
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 10:01 pm
Reply with quote

Yes, but since the pic did not specify the sign, when COBOL stored the result of the add back it made sure there was no sign.

If there had been a sign, what would the results been then?
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 10:40 pm
Reply with quote

If PIC S9 was mentioned then in my opinion the answer would be:

Suppose 0 is teh initial value in a

add -2 to a ----------> a = -2 (k)

add -4 to a -----------> a = -6 (o)

add -6 to a -----------> a = -12 (internally it would be stored as k, 1 will be truncated)


What do you say William ?
Correct me if I am wrong.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 10:45 pm
Reply with quote

ya got it. icon_biggrin.gif
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 JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
No new posts SYNCSORT/ICETOOL JOINKEYS SORT Statem... DFSORT/ICETOOL 13
No new posts DFDSS COPY using Filter REFDT statement JCL & VSAM 2
Search our Forums:

Back to Top