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

Redefining 9(Numeric) to X(Alphanumeric) and again to 9


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

New User


Joined: 04 Apr 2005
Posts: 15

PostPosted: Fri Apr 08, 2005 10:47 pm
Reply with quote

01 ws-def
05 ws-a pic x(20)
05 ws-b pic x(50)
05 ws-c pic x(5)
05 ws-d pic x(5)
01 ws-trf redefine ws-def
05 ws-tra pic 9(80)
01 ws-shed redefine ws-def
05 ws-shda pic x(10)
05 ws-shdb pic x(70)
is this a valid redefine operation? if valid what ll happen when i initialize a data item which is alphanumeric redeifned from numeric
Back to top
View user's profile Send private message
bsng_surru

New User


Joined: 07 Mar 2005
Posts: 16

PostPosted: Sat Apr 09, 2005 12:19 am
Reply with quote

you cant give 9(80)
compile error maxcc=12
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Apr 09, 2005 8:24 pm
Reply with quote

The reason is that there is an 18 digit limit for numeric items (31 if you use ARITH(EXTEND) in the latest compiler versions.)
Back to top
View user's profile Send private message
cmohanraj

New User


Joined: 04 Apr 2005
Posts: 15

PostPosted: Mon Apr 11, 2005 2:15 pm
Reply with quote

thankyou now i have changed this code. explain me about the redefines function.
01 ws-def
05 ws-a pic x(20)
05 ws-b pic x(50)
05 ws-c pic x(5)
05 ws-d pic x(5)
01 ws-trf redefine ws-def
05 ws-tra pic 9(10)
05 ws-trb pic 9(10)
05 ws-trc pic 9(10)
05 ws-trd pic 9(10)
05 ws-tra1 pic 9(10)
05 ws-trb2pic 9(10)
05 ws-trc3 pic 9(10)
05 ws-trd4 pic 9(10)
01 ws-shed redefine ws-def
05 ws-shda pic x(10)
05 ws-shdb pic x(70)
is this a valid redefine operation? if valid what ll happen when i initialize a data item which is alphanumeric redeifned from numeric
Back to top
View user's profile Send private message
David P

Active User


Joined: 11 Apr 2005
Posts: 106
Location: Cincinnati Ohio

PostPosted: Tue Apr 12, 2005 4:28 pm
Reply with quote

This is a valid definition. You won't get any compilation errors on this.
But when you execute the same its going to ABEND throwing a data execption.

regards,
david
Back to top
View user's profile Send private message
rsshanmugam

New User


Joined: 08 Mar 2005
Posts: 62
Location: Basildon

PostPosted: Tue Apr 12, 2005 6:49 pm
Reply with quote

i think this not a valid redefine since ws-def is already redefined with ws-trf u cant redefine ws-def once again, the redefining variable must immediatly follow the redefining variable.
Back to top
View user's profile Send private message
anuradha

Active User


Joined: 06 Jan 2004
Posts: 247
Location: Hyderabad

PostPosted: Tue Apr 12, 2005 11:53 pm
Reply with quote

Hi rsshanmugam,

I am wondering why we can't redefine a data area more than once. The redefines structure is a valid one only. Even i doubt that initialize may cause data exception.
Back to top
View user's profile Send private message
David P

Active User


Joined: 11 Apr 2005
Posts: 106
Location: Cincinnati Ohio

PostPosted: Wed Apr 13, 2005 9:07 am
Reply with quote

Hi Anu,
Why I am saying that its going to cause a data execption is because the variable definition is of numeric type but redefinition is alphanumneric and since the memory is been assigned to numeric data type and when we try to initialize the redefined alphanumeric variable (trying to move spaces to numeric tada field in memory) it should throw a data exception.

regards,
David.
Back to top
View user's profile Send private message
sribks2005

New User


Joined: 04 Apr 2005
Posts: 20
Location: Mysore

PostPosted: Wed Apr 13, 2005 10:25 am
Reply with quote

hi David,

i tried with the small example regarding this issue.
I have given a part of that program.
i could compile and run it successfully. Why it did not throw exeption or abend while executing the program?
==============================================
WORKING-STORAGE SECTION.
01 data1.
02 data4 pic 9(2) value 45.
01 data2 redefines data1.
02 data3 pic x(2).

PROCEDURE DIVISION.
MAIN-PARA.
move spaces to data2.
if data4 = spaces
display "numeric item contained spaces"
end-if.
display "alphanumeric data2=" data2.
Stop run.
==============================================

please let us know the correct answer.
Thank you
Back to top
View user's profile Send private message
Niteshs

New User


Joined: 24 Mar 2005
Posts: 6

PostPosted: Wed Apr 13, 2005 11:15 am
Reply with quote

Can you tell what was result of this.

if data4 = spaces
display "numeric item contained spaces"
end-if.
display "alphanumeric data2=" data2.
Tx
Back to top
View user's profile Send private message
sribks2005

New User


Joined: 04 Apr 2005
Posts: 20
Location: Mysore

PostPosted: Wed Apr 13, 2005 11:57 am
Reply with quote

hi,

The result was

======================
numeric item contained spaces
alphanumeric data2="
======================

thank you
Back to top
View user's profile Send private message
sribks2005

New User


Joined: 04 Apr 2005
Posts: 20
Location: Mysore

PostPosted: Wed Apr 13, 2005 11:59 am
Reply with quote

please ignore my previous reply

hi,

The result was

======================
numeric item contained spaces
alphanumeric data2=
======================

thank you
Back to top
View user's profile Send private message
Niteshs

New User


Joined: 24 Mar 2005
Posts: 6

PostPosted: Wed Apr 13, 2005 12:09 pm
Reply with quote

can you put display as DISPLAY ""Numeric data4=" data4.
Back to top
View user's profile Send private message
sribks2005

New User


Joined: 04 Apr 2005
Posts: 20
Location: Mysore

PostPosted: Wed Apr 13, 2005 6:23 pm
Reply with quote

hi Niteshs,

yes i could run the program successfully after putting
[b]DISPLAY ""Numeric data4=" data4[/b] also.

It is showing spaces.

thanks
Back to top
View user's profile Send private message
anuradha

Active User


Joined: 06 Jan 2004
Posts: 247
Location: Hyderabad

PostPosted: Thu Apr 14, 2005 1:19 pm
Reply with quote

Hi David!

Quote:
Why I am saying that its going to cause a data execption is because the variable definition is of numeric type but redefinition is alphanumneric and since the memory is been assigned to numeric data type and when we try to initialize the redefined alphanumeric variable (trying to move spaces to numeric tada field in memory) it should throw a data exception.

I mean to say even i agree with you. Am sorry, my sentence is giving different meaning there. But after seeing the test results of sribks2005, iam getting curious to test myself again. AFAIK it should give data exception. let me try at my end too regarding this.

sribks2005-- Thats a very good try. But i dont know why it is not giving data exception over there. Try to keep initialize statement instead of moving spaces to data2. Let us see what happens..
Back to top
View user's profile Send private message
David P

Active User


Joined: 11 Apr 2005
Posts: 106
Location: Cincinnati Ohio

PostPosted: Thu Apr 14, 2005 2:03 pm
Reply with quote

Hi Anu,
The reason you are not getting data exception is because both the variables data1 and data2 are of alphanumeric data type. (both being group items). If you define data1 as a numeric item and redefine the same by alphanumeric (only 2 variables instead of 4) then the same run would throw a data exception.

please feel free to add your views.
david.
Back to top
View user's profile Send private message
kanak

Moderator


Joined: 12 Mar 2005
Posts: 252
Location: India

PostPosted: Thu Apr 14, 2005 3:53 pm
Reply with quote

i think numeric field can contain spaces, but if u define the numeric field field as comp then u will get data exception while executing the program, at the time of compilation it won't show any error. and if the numeric field is defined just as 9(tt)...tt is any numeric value then even at the execution time it won't give abend.Just check this link...probably it will help

www.ibmmainframes.com/viewtopic.php?t=1968&highlight=

though example mention here is for comp-3 but it will be same for comp even.
Back to top
View user's profile Send private message
sribks2005

New User


Joined: 04 Apr 2005
Posts: 20
Location: Mysore

PostPosted: Thu Apr 14, 2005 4:34 pm
Reply with quote

Quote:
sribks2005-- Thats a very good try. But i dont know why it is giving data exception over there. Try to keep initialize statement instead of moving spaces to data2. Let us see what happens..

hi Anu,

I tried with initialize statement also.
=================================
initialize data2.
if data4 = spaces
display "numeric item contained spaces"
end-if.
display "alphanumeric data2=" data2.
==================================

but again it ran succesfully with data2 holding spaces.

Thanks,
Saraswathi
Back to top
View user's profile Send private message
raaga21

New User


Joined: 25 Mar 2005
Posts: 3

PostPosted: Fri Apr 15, 2005 1:39 pm
Reply with quote

hi anu,
i think that spaces also of alphanumeric type, while so it produces the same result. Lets check it out.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts Handling the numeric data in unstring... COBOL Programming 18
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top