View previous topic :: View next topic |
Author |
Message |
Ameen Beginner
Joined: 22 Dec 2004 Posts: 4 Topics: 2
|
Posted: Wed Dec 22, 2004 12:48 am Post subject: Redefines Clause |
|
|
Hi,
I have a doubt in Redefining a variable.
05 Var1 PICTURE X(6).
05 Var2 REDEFINES Var1.
10 V1 PICTURE X(2).
10 V2 PICTURE 9(4).
Var1 contains "Ashoka"
Var2 redefines Var1.
What will happen, when i display V2?
-Ameen |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Wed Dec 22, 2004 5:18 am Post subject: |
|
|
Ameen,
Did you try testing? V2 will contain "hoka" upon display
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Wed Dec 22, 2004 5:26 am Post subject: |
|
|
Kolusu,
I have a basic question here. I tested the code today morning and as I expected it had 'hoka'. But I thought the job will abend in SOC7, when I use the variable v2 in an arithmetic expression (ADD +1 to V2). But I ended up with an RC of 0. When I displayed the value I got "8622" (Add +1 to HOKA).
Now why didn't I get a SOC7 ? Is it dependant on compiler options.
PS: I compiled my cobol program using SCALES compiler with the following compiler options:
Code: |
PP 5668-958 IBM VS COBOL II Release 4.0 09/15/92
Invocation parameters:
ADV,DYNAM
Options in effect:
ADV
APOST
NOAWO
BUFSIZE(4096)
NOCMPR2
COMPILE
DATA(31)
NODBCS
NODECK
NODUMP
DYNAM
NOEXIT
FASTSRT
NOFDUMP
FLAG(W,W)
NOFLAGMIG
NOFLAGSAA
NOFLAGSTD
LANGUAGE(EN)
LIB
LINECOUNT(60)
NOLIST
MAP
NONAME
NONUMBER
NUMPROC(NOPFD)
OBJECT
OFFSET
OPTIMIZE
OUTDD(SYSOUT)
RENT
RESIDENT
SEQUENCE
SIZE(MAX)
SOURCE
SPACE(1)
NOSSRANGE
NOTERM
NOTEST
TRUNC(OPT)
VBREF
NOWORD
XREF(FULL)
ZWB
|
Thanks,
Phantom |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12377 Topics: 75 Location: San Jose
|
Posted: Wed Dec 22, 2004 5:46 am Post subject: |
|
|
phantom,
Note that v2 is defined as 9(4) instead of S9(4), so the value is treated as if it were X'F8F6F2F1'. With display numeric fields the compiler will see it anything in it as a valid numeric until proven otherwise through an arithmetic operation, where conversion would take place.
So adding 1 to v2 will not cause an s0c7 abend.
Change the definition of v2 to comp-3 format and re-run the job.
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Wed Dec 22, 2004 6:09 am Post subject: |
|
|
Oh Okay....Now I understand. Thanks for the clarification.
Phantom |
|
Back to top |
|
 |
Ameen Beginner
Joined: 22 Dec 2004 Posts: 4 Topics: 2
|
Posted: Sun Dec 26, 2004 11:32 am Post subject: |
|
|
Kolusu,
Here 9(4) is a numeric, how it can hold alphabets.
Please clarify. |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Mon Dec 27, 2004 1:19 am Post subject: |
|
|
Ameen,
Yes, 9(4) cannot hold alphabets. If you try to move a alpha-numeric literal to a numeric variable, the compiler itself will throw u an error. But in this example, the numeric variable is SHARING the same memory location of an alphanumeric variable and the value is actually moved to the alpha-numeric variable and not directly to the numeric variable.
So, now when u display the numeric variable, it refers to the memory location where the alphabetic value is stored and picks up whatever value is stored there and displays it.
Hope I'm clear,
Thanks,
Phantom |
|
Back to top |
|
 |
|
|