COBOL Code DT041410



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

COBOL Code DT041410

Postby tanmaypotdar » Wed Apr 14, 2010 12:36 pm

Hi,

Kindly lemme knw the output of below COBOL code;

01 A PIC 9 (10).
01 B REDEFINES A PIC X (10).

INITIALIZE A B.
MOVE 'TANMAY' TO B.
COMPUTE A = A + 1.
DISPLAY 'A = ' A.
DISPLAY 'B = ' B.
EXIT.
tanmaypotdar
 
Posts: 3
Joined: Wed Apr 14, 2010 12:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Code DT041410

Postby Robert Sample » Wed Apr 14, 2010 5:11 pm

Why don't you run it yourself?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: COBOL Code DT041410

Postby tanmaypotdar » Thu Apr 15, 2010 12:03 pm

I ran it got abend with SOC7.
My question was;
1. Can we redefine variables with different data types?
2. If yes then why can't we perform computation on it?
tanmaypotdar
 
Posts: 3
Joined: Wed Apr 14, 2010 12:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Code DT041410

Postby Robert Sample » Thu Apr 15, 2010 5:20 pm

1. You can redefine any type of variable as any other type of variable, and so long as the lengths match COBOL won't give you problems.
2. You need to read up in the COBOL Language Reference and Programming Guide manuals until you understand exactly what the internal formats are used by COBOL to store USAGE DISPLAY, USAGE COMP, USAGE COMP-3 data. While you can, for example, define a 4-byte USAGE DISPLAY numeric field as PIC S9(04) and then redefine a USAGE COMP-3 PIC S9(07) field on that variable (both are 4-byte fields), the fact that the internal formats are incompatible means you will almost certainly get a S0C7 abend when attempting to use the COMP-3 variable.

COBOL allows you to do things that will cause abends -- it does not protect the programmer from their own mistakes. And unless you understand the formats used by COBOL to store data, you absolutely will make mistakes.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: COBOL Code DT041410

Postby dick scherrer » Fri Apr 16, 2010 12:23 am

Hello and welcome to the forum,

Just curious. . .

Why would you believe that a redefinition of some PIC X field as a PIC 9 field would transform the alphanumeric value to something usable as a numeric?

Something very basic has been completely overlooked. . .

1. Can we redefine variables with different data types?
2. If yes then why can't we perform computation on it?
1. Yes, but should only do so when a data item has multiple definitions/uses. . .
2. Because computations require valid numeric values. . .

The manuals can surely help, but you would benefit by doing some basic review with your seniors or whoever was the COBOL instructor.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: COBOL Code DT041410

Postby tanmaypotdar » Fri Apr 16, 2010 1:10 pm

Hi,

Thanks for your prompt reply. I would definitely look for more information in manuals.
tanmaypotdar
 
Posts: 3
Joined: Wed Apr 14, 2010 12:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: COBOL Code DT041410

Postby dick scherrer » Sat Apr 17, 2010 2:26 am

Hello,

If you find something in a manual that is not clear, post what you found and your doubt about it. Someone will be able to clarify.

Good luck :)

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post