Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Defining a two variables with same name

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
kchand
Currently Banned

New User


Joined: 05 Sep 2008
Posts: 10
Location: Bangalore

PostPosted: Tue Sep 23, 2008 6:46 pm    Post subject: Defining a two variables with same name
Reply with quote

Can we define variable with having same name in a single program twice.
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Sep 23, 2008 6:49 pm    Post subject:
Reply with quote

01 ws-name pic x(12)
01 ws-name pic x(10) is not allowed....
but

01 ws-1.
05 ws-name pic x(12)

01 ws-2.
05 ws-name pic x(10) is allowed.....
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Tue Sep 23, 2008 6:53 pm    Post subject:
Reply with quote

Yes, COBOL allows that.
In order to reference the variables, they must have a parent level with different names:
Code:
01  SAMPLE-VARS.
    03 INPUT-FIELDS.
       05 INVOICE-DATE     PIC X(10).
       05 INVOICE-NBR      PIC S9(8)   COMP-3.
    03 OUTPUT-FIELDS.
       05 INVOICE-DATE     PIC X(10).
       05 INVOICE-NBR      PIC S9(8)   COMP-3.
.
.
    MOVE INVOICE-DATE OF INPUT-FIELDS TO INVOICE-DATE OF OUTPUT-FIELDS
Back to top
View user's profile Send private message
kchand
Currently Banned

New User


Joined: 05 Sep 2008
Posts: 10
Location: Bangalore

PostPosted: Tue Sep 23, 2008 8:29 pm    Post subject:
Reply with quote

Thanks for clarification
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Tue Sep 23, 2008 8:39 pm    Post subject: Reply to: Defining a two variables with same name
Reply with quote

Duplicated names can be also useful when used with MOVE CORRESPONDING:

Code:
01  DATE-DMY.
    03 DD      PIC XX.
    03 FILLER  PIC X.
    03 MM      PIC XX.
    03 FILLER  PIC X.
    03 YY      PIC X(4).

01  DATE-YMD.
    03 YY      PIC X(4).
    03 MM      PIC XX.
    03 DD      PIC XX.
.
.
MOVE CORR DATE-DMY TO DATE-YMD

this will move DD to DD, MM to MM and YY to YY.
All FILLERs (input and output) are ignored.
Back to top
View user's profile Send private message
Cary

New User


Joined: 23 Sep 2008
Posts: 3
Location: China

PostPosted: Wed Sep 24, 2008 7:17 am    Post subject:
Reply with quote

01's name can not repeat, they must be unique.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts Is it possible to pass variables of s... Csongor CLIST & REXX 2 Fri Jun 10, 2016 7:33 pm
No new posts TWS 'global' or 'local' variables Steve Coalbran IBM Tools 2 Thu Mar 17, 2016 7:40 pm
No new posts Using different values for Skeleton d... venksiv CLIST & REXX 8 Thu Sep 03, 2015 5:28 pm
No new posts Types of variables REXX tvinodkumar7 TSO/ISPF 2 Wed Aug 26, 2015 6:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us