Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REDEFINES usage

Status
Not open for further replies.

VictorBme

Programmer
Mar 17, 2001
1
US
I'm a programming student (cobol) looking for examples of the REDEFINES statement. My program takes an input salesfile and makes a general report, and some of the data that's supposed to be numeric is not numeric. This data is sent to a "error-report", but the pic field needs REDEFINED. Any help would be greatly appreciated.
VictorBme
 
01 SOME-RECORD.
03 PERHAPS-NUMERIC PIC 9(5).
03 PERHAPS-NUMERIC-ALF REDEFINES
PERHAPS-NUMERIC PIC X(5).
....

IF PERHAPS-NUMERIC NOT NUMERIC
MOVE PERHAPS-NUMERIC-ALF TO REPORT-PERHAPS-NUMERIC
....

I hope this is helpful
 
I prefer not to redefine fields unless necessary.

My preferred technique for the examples shown is like this:

05 SOME-DISPLAY-ITEM.
10 SOME-DISPLAY-ITEM-N PIC 9(6).

Group items are always DISPLAY (i.e. PIC X...)

Perhaps a more realistic example would be something like:

05 WS-GROSS-AMT PIC S9(7)V99.
05 WS-GROSS-PERCENT PIC S9(5)V9999
REDEFINES WS-GROSS-AMT.
 
All,

using a group item as an implicit redefinition is fine in most cases. There are however some differences between the characteristics of a group item and that of an identifier which is explicitly defined as PIC X ... (check your COBOL reference to find out which :) ) A group item won't do as a DB2 host variable, either. Also, explicitly redefining an identifier might in some cases be a little clearer.

"... and that's all i have to say about thát !"
 

The REDEFINES allows you to provide a redefinition of a name, redefinition of the PIC clause for the name or both.

05 ONE-TYPE-DATA PIC 9(5).
05 TWO-TYPE-DATA REDEFINES ONE-TYPE-DATA PIC 9(4).

05 ONE-NAME PIC X(3).
05 TWO-NAME REDEFINES ONE-NAME.

Note that the second example doesn't redefine the PIC clause, just redefines the name. (The original name will still work of course;just gives it a second name which that is used sometimes for internal tables)

How you use a REDEFINED name in a program is simply by referring to that name, so you can use it in both INPUT and OUTPUT.

Recently I used a REDEFINES statement in INPUT where one field of data could be a Sales figure, an hourly wage rate or a fixed salary rate (sales figure was 9(5), the hourly was 9(2)V99 and the salary was 9(3)V99).

Another good mention is the original definition must be the LARGEST PIC clause, redefines can't be any larger in size than the original statement.

BTW I'm a COBOL student too :) Chris Green
Computer Information Systems Student
Cayuga Community College -- Fulton
 
GC1CEO,

i consider it a good practice to make the redefining identifier exactly the same size (bytewise) as the redefined identifier. That way, you avoid different compilers gettting stomach aches and it's clearer what is happening. For example: say you have a PIC X(8) identifier, you redefine it PIC 9(7), and manipulate the - numeric -redefinition; what happens to that one byte that differs ... and which one is it ?

Good luck !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top