View previous topic :: View next topic
|
Author |
Message |
ajithkumarsl
New User
Joined: 23 Oct 2006 Posts: 19 Location: Chennai
|
|
|
|
Hello,
In cobol can we use the following variable declaration?
03 VAR-1 PIC 9(4).
03 VAR-2 REDEFINES VAR-1 PIC ZZZ9.
Thanks |
|
Back to top |
|
|
Manuneedhi K
Active User
Joined: 07 May 2008 Posts: 115 Location: Chennai
|
|
|
|
You can redefine 9(4) into ZZZ9.
But you got the syntax wrong. It has to be like this
03 VAR-1 PIC 9(4).
03 VAR-2 REDEFINES VAR-1.
05 VAR-3 PIC ZZZ9. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Manu, the OP's syntax is correct.
Ajith,
I hope you don't think you can move something to var1 and then expect to move an edited var2. though you could move var1 (0099) to var2 and then var2 would contain ' 99'. |
|
Back to top |
|
|
Manuneedhi K
Active User
Joined: 07 May 2008 Posts: 115 Location: Chennai
|
|
|
|
Yes his syntax is right. My bad. I had a different error while trying to test it and thought it had to do with the syntax. |
|
Back to top |
|
|
ajithkumarsl
New User
Joined: 23 Oct 2006 Posts: 19 Location: Chennai
|
|
|
|
Thanks Manu and Dick for your replay.
Dick,
What I felt is - why to take more space for an edited variable.
IF we declare Var1 and Var2 as two variables it will take twice the memory space.
Do any syntax is there that we can refer the same space?
Please correct me if I am wrong.
Thanks |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Ajith,
The danger in doing that is knowing at any point in the code what VAR1/2 contains, e.g.:
line 100 move 99 to VAR2
line 1250 add 1 to VAR1 (this will cause an abend). |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
In cobol can we use the following variable declaration?
03 VAR-1 PIC 9(4).
03 VAR-2 REDEFINES VAR-1 PIC ZZZ9.
|
While this can be done,it should not be done. . . .
To quote an old IBM phrase - "The results may be unpredictable". If those fields are used multiple places in the code, it will be difficult to always know when the numeric definition contains a valid number. |
|
Back to top |
|
|
ajithkumarsl
New User
Joined: 23 Oct 2006 Posts: 19 Location: Chennai
|
|
|
|
Thanks Dick and Anuj.
Dick, I am using the Var1 for populating the page number.
So I am sure that it will always have a valid number.
The only need is to suppress the preceding zeros.
Hope this makes the requirement more clear.
Thanks |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello Ajith,
You're welcome
Thanks for the update.
d |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Hi,
ajithkumarsl wrote: |
The only need is to suppress the preceding zeros.
|
Problem is resolved or still there are some problems? |
|
Back to top |
|
|
ajithkumarsl
New User
Joined: 23 Oct 2006 Posts: 19 Location: Chennai
|
|
|
|
Hi Anuj,
I have declared two variables(Var1 and Var2 Separately) and done that.
But I couldn't redefine and do.
I am asking this because if next time a same case happen I have to be in a position to handle that.
Now the need came for only one Variable of length 4 but if it is more, I feel, it will be more critical to find a solution.
So temporarily the problem is solved.
Thanks |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Now the need came for only one Variable of length 4 but if it is more, I feel, it will be more critical to find a solution. |
I suspect it will never be critical. It is doubtful that you could write enough of these redefines to ever make a difference in the execution of some program.
Your time will be much better invested in making sure the code always works, that the code is maintainable, and the code does not waste cpu time and/or i/o. |
|
Back to top |
|
|
ajithkumarsl
New User
Joined: 23 Oct 2006 Posts: 19 Location: Chennai
|
|
|
|
Thanks for your help.. |
|
Back to top |
|
|
|