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

Defining a two variables with same name


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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: 1353
Location: Israel

PostPosted: Tue Sep 23, 2008 6:53 pm
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
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Sep 23, 2008 8:39 pm
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
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Apr 23, 2020 11:45 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Defining a struct PL/I & Assembler 3
No new posts JCL with variables JCL & VSAM 1
No new posts JCL Variables JCL & VSAM 1
No new posts reset/clear ALL application profile v... TSO/ISPF 3
No new posts defining a global LUA function in Inf... IBM Tools 1
Search our Forums:

Back to Top