Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Redefining an COMP variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Redefining an COMP variable
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Fri Jan 03, 2014 2:16 pm    Post subject: Reply to: Redefining an COMP variable
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    Post subject: Reply to: Redefining an COMP variable
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

Active Member


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

PostPosted: Wed Jan 08, 2014 12:44 am    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Wed Jan 08, 2014 10:47 pm    Post subject: Reply to: Redefining an COMP variable
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Fri Jan 10, 2014 2:24 am    Post subject: Reply to: Redefining an COMP variable
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us