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: 7232

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: 961
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: 7232

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: 7232

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 Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am
No new posts OPC JCL Variable passion_sujesh IBM Tools 5 Fri Jul 01, 2016 4:21 am


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