Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 1349
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: 1349
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
doug smith082

New User


Joined: 20 Jan 2016
Posts: 1
Location: USA

PostPosted: Thu Apr 23, 2020 11:26 pm    Post subject: Reply to: Defining a two variables with same name
Reply with quote

The same does Not seem to be true for indexes .. You get error
IGYPS2180-S An index-name was qualified .... The statement was discarded.
Is there a way around that problem. And why is that true ?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8547
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 23, 2020 11:45 pm    Post subject: Reply to: Defining a two variables with same name
Reply with quote

No, there is no way around this -- index names CANNOT be qualified. If you think about what qualification means, you will understand why. A qualified data name in COBOL is a reference to a variable IN (or OF) a group variable. Since an 01 level cannot be part of a group variable, it cannot be qualified. And since an index does not have a group variable, it cannot be qualified either.
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 Not able to view the values of variab... sattar_engg CA Products 1 Thu Jan 23, 2020 12:32 pm
No new posts Comparison of numeric edited variables Nileshkul COBOL Programming 4 Sat Mar 16, 2019 1:18 am
No new posts Calling and updating SAS Macro variab... Yogesh Jaiswal All Other Mainframe Topics 7 Thu Oct 11, 2018 12:37 pm
No new posts How to remove spaces between variable... Selvarajars DFSORT/ICETOOL 7 Fri Jul 27, 2018 3:58 pm
No new posts Defining SYSLIB to USS c++ (cxx) comp... Harold Barnes All Other Mainframe Topics 2 Sat Apr 07, 2018 5:06 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us