MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Redefines Clause

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Ameen
Beginner


Joined: 22 Dec 2004
Posts: 4
Topics: 2

PostPosted: Wed Dec 22, 2004 12:48 am    Post subject: Redefines Clause Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Wed Dec 22, 2004 5:18 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 22, 2004 5:26 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Wed Dec 22, 2004 5:46 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Wed Dec 22, 2004 6:09 am    Post subject: Reply with quote

Oh Okay....Now I understand. Thanks for the clarification.

Phantom
Back to top
View user's profile Send private message
Ameen
Beginner


Joined: 22 Dec 2004
Posts: 4
Topics: 2

PostPosted: Sun Dec 26, 2004 11:32 am    Post subject: Reply with quote

Kolusu,

Here 9(4) is a numeric, how it can hold alphabets.

Please clarify.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Mon Dec 27, 2004 1:19 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group