-4

i'm trying to re-define the a variable in Cobol working-storage. Please see if below id possible: Can I re-define a variable with PIC clause 9(2).9(3) to this PIC clause -(2).9(3)

Sunitha S
  • 1
  • 1
  • 3
  • 4
    Why not just try it? Your compiler is never wrong, and it doesn't waste time waiting for possibly incorrect answers on the Internet. – user207421 Jun 12 '17 at 05:34
  • Welcome to stackoverflow.com. Please take some time to read the [help pages](https://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](https://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](https://stackoverflow.com/help/dont-ask). Also please take the [tour](https://stackoverflow.com/tour) and read about [how to ask good questions](https://stackoverflow.com/help/how-to-ask). Lastly please learn how to create a [Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve). – cschneid Jun 12 '17 at 14:18

1 Answers1

0

Redefining fields in COBOL is simply that, redefining. All it means is, you're just breaking down the bytes that will be stored in that respective field into smaller segments/bytes.

For example, say if you're working with an expiry date which could be applied on many common things, such as a credit card. The initial working storage field/variable in COBOL would be:

05 EXPIRATION-DATE          PIC X(8).

So now, let's redefine those 8 bytes into smaller bytes. That way, for example, I could pull out only the year, only the months, or only the days of the expiration date.

So it becomes:

05 EXPIRATION-DATE          PIC X(8). ---> 20170623 (data stored in field)
05 EXPIRATION-DATE-NEW REDEFINES EXPIRATION-DATE.
   10  EXPIRATION-YEAR      PIC 9(4). ---> 2017
   10  EXPIRATION-MONTH     PIC 9(2). ---> 06
   10  EXPIRATION-DAY       PIC 9(2). ---> 23

So the main field will store the date, however, by redefining it you could now work with just the year, month, or day, depending on what you're trying to do in the program.

Hope this helps.

Jabgan
  • 31
  • 1
  • 3
  • 8