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

What is the output of this code?


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

New User


Joined: 22 Nov 2007
Posts: 13
Location: Noida

PostPosted: Fri Jan 08, 2010 12:01 pm
Reply with quote

I have the following varibles in the working storage.

01 WS-A PIC X(30) VALUE 'ABCDEFGHIJKLMNOPQRESTUVWXYZ ' .

01 WS-B REDEFINES WS-A.
10 WS-B1 PIC X(10).
10 WS-B2 PIC 9(10).
10 WS-B3 PIC X(10).

If I display B1, B2 and B3 respectively, what is the value displayed in B2? Will it throw any error as WS-B2 is a numeric field?
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Jan 08, 2010 12:10 pm
Reply with quote

Quote:
What is the output of this code?

I don't know.... You tell us.
It would be a very simple test and you'll see the results in seconds....
Back to top
View user's profile Send private message
kshirabdhi

New User


Joined: 22 Nov 2007
Posts: 13
Location: Noida

PostPosted: Fri Jan 08, 2010 12:14 pm
Reply with quote

If I had mainframe connection, I would have seen the results in seconds and would not have posted it here.

I can not test as I have no resource icon_sad.gif
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Jan 08, 2010 12:47 pm
Reply with quote

It will not through any error if you just display it. Numeric variable will get populated with character value (KLMNOPQRSH).
Back to top
View user's profile Send private message
kshirabdhi

New User


Joined: 22 Nov 2007
Posts: 13
Location: Noida

PostPosted: Fri Jan 08, 2010 12:51 pm
Reply with quote

Thank you Sambhaji.
One more query ... If we move alphabets to numberic field, it throws error; but in this case wile displaying characters through a numeric field it works fine. How?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Jan 08, 2010 12:56 pm
Reply with quote

Can't feed more...

Get the COBOL compiler from
Mainframe Software Downloads

And try on yourself.
Let us know if you are facing any problem.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 08, 2010 5:07 pm
Reply with quote

kshirabdhi, there is a link to manuals at the top of the page. Click on it, find the COBOL Language Reference and Programming Guide manuals, and read them -- cover to cover. You will learn much from doing this and be able to answer many questions on your own.

While you cannot move 'ABC' to a numeric DISPLAY variable, if you set up a PIC X variable and move 'ABC' to it, you can then move that variable to the numeric DISPLAY variable with no problems.

Quote:
If we move alphabets to numberic field, it throws error
No, it does not. JAVA throws errors, COBOL does not. COBOL abends but it does not "throw" things -- ever. Getting the terminology right is a repeated request by the moderators on this forum since if you cannot get the terminology right you cannot get the concepts right. And so far your terminology is not right.
Back to top
View user's profile Send private message
l.nethaji

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Fri Jan 08, 2010 10:54 pm
Reply with quote

The main use of redefines is like it can be used for avoiding SOC7 error.

Only when we do arithmatic operation i.e moving X(3) to 9(3) soc7 occurs.

But in redefines we just override it on the same memory location.

Thats y we wont face error in redefines.

Hope this helps
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jan 08, 2010 11:11 pm
Reply with quote

Quote:
The main use of redefines is like it can be used for avoiding SOC7 error.


not true.
main use of redefines is to have different definitions of same area.

Quote:
Only when we do arithmatic operation i.e moving X(3) to 9(3) soc7 occurs.


not true
1. a move is not an arithmetic operation.
2. you won't get a SOC7 because of receiving field. it is due to bad data in sending field.

actually, nothing you said helps, other than as a good example of a bad example.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Jan 08, 2010 11:15 pm
Reply with quote

l.nethaji wrote:
Only when we do arithmatic operation i.e moving X(3) to 9(3) soc7 occurs.


Not exactly correct.
According to the COBOL Language Reference Manual:

When the category of the sending item is alphanumeric, alphanumeric-edited, national, or national-edited, the data is moved as if the sending item were described as an unsigned integer."

So... Moving a field defined as PIC X(3) to one defined as PIC 9(3) won't result in a S0C7 if the value of the X(3) field is, for example, '123', or '987'. It will only result in a S0C7 if the value of the X(3) field does not qualify as a valid unsigned integer - e.g. 'XYZ'.
Back to top
View user's profile Send private message
l.nethaji

New User


Joined: 16 Mar 2008
Posts: 90
Location: tamil nadu

PostPosted: Sat Jan 09, 2010 12:00 am
Reply with quote

Hi,

Its true


" a good example of a bad example."
_________________


I learnt a lot from mine .

thanks
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
Search our Forums:

Back to Top