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

Redefining an COMP variable


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

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Fri Jan 03, 2014 2:08 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jan 03, 2014 2:16 pm
Reply with quote

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
View user's profile Send private message
saurabh39
Warnings : 1

Active User


Joined: 11 Apr 2008
Posts: 144
Location: Jamshedpur

PostPosted: Fri Jan 03, 2014 2:31 pm
Reply with quote

@Bill - Thanks for reply.

reading you reply now the question feel stupid icon_redface.gif , but thanks it cleared some of the lingering doubt on redefine and edited pic clause.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Jan 08, 2014 12:44 am
Reply with quote

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

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Wed Jan 08, 2014 8:57 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jan 08, 2014 10:47 pm
Reply with quote

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

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Thu Jan 09, 2014 9:55 pm
Reply with quote

Wow...OK...

When we tested it, it left it spaces.

IBM mainframe.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Jan 10, 2014 2:24 am
Reply with quote

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

Active Member


Joined: 08 Jun 2011
Posts: 556
Location: USA

PostPosted: Fri Jan 10, 2014 2:51 am
Reply with quote

Aha! I see.
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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
Search our Forums:

Back to Top