View previous topic :: View next topic
|
Author |
Message |
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
Hi All,
I am trying to redefine a comp variable S9(5) by using an edited pic clause.
Code: |
05 WS-REC-COUNT PIC S9(5) COMP.
05 WS-REC-COUNT-R REDEFINES WS-REC-COUNT.
10 WS-REC-COUNT-ED PIC +ZZ9.
|
If TRUNC(STD) is used, one of the value in WS-REC-COUNT can be +99999. Wont that value get truncated when I use the edited variable to display it.Since I am still trying to remove compilation error and set up data, so I cannot execute the program yet. Moreover, I checked the redefine clause in language reference, no where it mentions any special consideration for redefining COMP variable. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Your code is not going to do what you think.
An edit PICture is only action when the field is that target of a verb, Like MOVE a TO b, where b has an edit pattern in the PICture.
You can't just REDEFINES and assume that when you reference the field it is magically edited. REDEFINES is for another way of looking a piece of storage, which obviously has only one value. If the REDEFINES itself caused the data to change, REDEFINES would be unusable. |
|
Back to top |
|
|
saurabh39 Warnings : 1 Active User
Joined: 11 Apr 2008 Posts: 144 Location: Jamshedpur
|
|
|
|
@Bill - Thanks for reply.
reading you reply now the question feel stupid , but thanks it cleared some of the lingering doubt on redefine and edited pic clause. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
I suggest keeping several small skeleton programs for testing language elements. Then you won't have to compile and run your actual program to see how individual codes work.
By testing and, in this case, finding out that you misunderstood how REDEFINES works, you'll be much smarter than if you just read someone's answer to your question. |
|
Back to top |
|
|
Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA
|
|
|
|
agreed, plus you have a quick way to settle those little disagreements that crop up from time to time about 'how things work.'
My most recent one was that someone said that an INITIALIZE verb put the value clause back into a variable. As in
FIELD1 PIC x(01) VALUE '$'.
would be set to '$' after an INITIALIZE.
Their logic was that the field has spaces in it afterwards, and their value clause was SPACES.
We were setting up a delimited file and needed the pipe character between fields. I had coded a move for each field, and that started it.
There were seriously four senior level developers, who are all smart people and not prone to sillyness, but they really all though the same thing. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Code: |
05 FILLER PIC X(01) VALUE '$'. |
Well, that would be $ after INITIALIZE...
GNU COBOL (formerly OpenCOBOL) has TO VALUE on INITIALIZE. I'm sure some other COBOLs have it as well. We don't :-)
If in a CALLed program, put the thing in the LOCAL-STORAGE SECTION, which will be set to initial values per VALUE clause with each CALL.
Personally I dislike the common usage of INITIALIZE, which is to set all the values in a particular record to zero/space and then immediately MOVE real stuff into them. That tiny fraction of a second when they were zero/space is entirely wasted, scrintillion times a day around the world.
Yes, little programs to try things out are 100% a good idea. |
|
Back to top |
|
|
Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA
|
|
|
|
Wow...OK...
When we tested it, it left it spaces.
IBM mainframe. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I'm not saying what you tested kept the $, Ed. I made a subtle change to the data-name. FILLER fields are not affected by INITIALIZE. |
|
Back to top |
|
|
Ed Goodman
Active Member
Joined: 08 Jun 2011 Posts: 556 Location: USA
|
|
|
|
Aha! I see. |
|
Back to top |
|
|
|