View previous topic :: View next topic
|
Author |
Message |
kchand Currently Banned New User
Joined: 05 Sep 2008 Posts: 10 Location: Bangalore
|
|
|
|
Can we define variable with having same name in a single program twice. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
kchand Currently Banned New User
Joined: 05 Sep 2008 Posts: 10 Location: Bangalore
|
|
|
|
Thanks for clarification |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
Cary
New User
Joined: 23 Sep 2008 Posts: 3 Location: China
|
|
|
|
01's name can not repeat, they must be unique. |
|
Back to top |
|
|
doug smith082
New User
Joined: 20 Jan 2016 Posts: 1 Location: USA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|