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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing variable using redefines clause in COBOL

Status
Not open for further replies.

startup

Technical User
May 22, 2002
42
0
0
US
Please, can anyone help with this beginner's question:

01...
03 v_parameter_1.
05 v_archive_numb pic 9(4).
03 v_archive_char redefines v_parameter_1.
05 filler pic x(4).

When moving spaces to v_archive_char, the v_archive_numb is initialized to 00. This happens even using the Initialize verb.
How can v_archive_numb be initialized to be null.
 
Hi,

I don't understand the example, because when you move space to v-archive-char, the v-archive-num is not numeric anymore, so why would it be zero? On the mainframe the use of this numeric field without the right value will cause a dump.

If you mean x'00' / low-values by null, than you can move low-values to v-parameter-1. But why would you want to do this?

Does this answers your question?
 
I agree with 'Croxie'. Furthermore, why are you redefining? I can see no benefit. The 03 level (v_parameter_1) will give you alphanumeric access to your 05 level numeric(v_archive_num). Furthermore, I always retain an element of the original field in the redefinition name (eg v_parameter_1_red instead of v_archive_char). It will help whoever has to read your code after you've been knocked down by a bus :)
 
You don't mention what COBOL you're on, but I'm sure it's a factor. Some COBOLs, including many PC COBOLs, think they are doing you a favor and treat a numeric PIC item as if it had zeros in it when it actually has a value of spaces. Thus any reference to V_ARCHIVE_CHAR after the MOVE would yield SPACES, but a reference to V_ARCHIVE_NUMB would yield ZEROS. If you want to see the SPACES in such a COBOL, you have to refer to the V_ARCHIVE_CHAR field. If you just want the field to be blank in a print line, you might try adding the BLANK WHEN ZERO clause after the PIC clause and then move ZEROS to the field, or just use a PIC Z(4), if zero suppressing everything is acceptable. Betty Scherber
Brainbench MVP for COBOL II
 
Startup,

to add to kfmason's reaction, your definition could look something like this:

01 ...
03 v_parameter_1.
05 v_archive_numb pic 9(4).

v_archive_numb implicitly redefines v_parameter_1, which is alpanumeric by definition.
If you do need to redefine it explicitly (it happens ...), do it directly:

01 ...
03 v_parameter_1 pic x(4).
03 v_archive_numb pic 9(4) redefines v_parameter_1.

This might not solve your initialisation problems, as BettyScherber pointed out, but at least it's simple and legible.

Good luck !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top