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

How to Redefines a Varible to Edited Class


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ajithkumarsl

New User


Joined: 23 Oct 2006
Posts: 19
Location: Chennai

PostPosted: Wed Jun 11, 2008 3:28 pm
Reply with quote

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
View user's profile Send private message
Manuneedhi K

Active User


Joined: 07 May 2008
Posts: 115
Location: Chennai

PostPosted: Wed Jun 11, 2008 3:49 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 11, 2008 4:32 pm
Reply with quote

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
View user's profile Send private message
Manuneedhi K

Active User


Joined: 07 May 2008
Posts: 115
Location: Chennai

PostPosted: Wed Jun 11, 2008 4:47 pm
Reply with quote

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
View user's profile Send private message
ajithkumarsl

New User


Joined: 23 Oct 2006
Posts: 19
Location: Chennai

PostPosted: Wed Jun 11, 2008 4:50 pm
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Jun 11, 2008 5:32 pm
Reply with quote

Hi,
ajithkumarsl wrote:
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.

Check this link, little different from the current thread but does talk about REDEFINES..

www.ibmmainframes.com/viewtopic.php?t=17836&postdays=0&postorder=asc&start=0
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Jun 11, 2008 5:49 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Jun 11, 2008 6:25 pm
Reply with quote

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
View user's profile Send private message
ajithkumarsl

New User


Joined: 23 Oct 2006
Posts: 19
Location: Chennai

PostPosted: Thu Jun 12, 2008 9:16 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jun 12, 2008 9:46 am
Reply with quote

Hello Ajith,

Quote:
Thanks
You're welcome icon_smile.gif

Thanks for the update.

d
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Jun 12, 2008 11:22 am
Reply with quote

Hi,
ajithkumarsl wrote:
The only need is to suppress the preceding zeros.
Problem is resolved or still there are some problems?
Back to top
View user's profile Send private message
ajithkumarsl

New User


Joined: 23 Oct 2006
Posts: 19
Location: Chennai

PostPosted: Thu Jun 12, 2008 11:58 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jun 12, 2008 12:41 pm
Reply with quote

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
View user's profile Send private message
ajithkumarsl

New User


Joined: 23 Oct 2006
Posts: 19
Location: Chennai

PostPosted: Mon Jun 16, 2008 3:06 pm
Reply with quote

Thanks for your help..
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 building java class with zip4j.jar on... Java & MQSeries 0
No new posts Assembler class assignment: stuck on ... PL/I & Assembler 12
No new posts Getting OUTREC - SHORT REC error for ... DFSORT/ICETOOL 12
No new posts How to determine is PDS member is bei... CLIST & REXX 13
No new posts XML-GENERATE to render edited numeric COBOL Programming 0
Search our Forums:

Back to Top