Moving COMP-3 to PIC X



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Moving COMP-3 to PIC X

Postby jellypuno » Thu Jun 14, 2012 2:12 pm

Hi,

I need your assistance regarding COMP-3.

I need to move my computed date to an output file defined as PIC 9(08) comp-3. But for some reason it is converted to PIC X.

The program processing is as follows:

1. I will compute the date and move it in a format of PIC 9(08).
2. After a successful computation, I will move the computed date to a copybook with a format of PIC 9(08) comp-3.
3. After #2, I will move the whole copybook to the output file. I will move the 01level of the copybook to the 01 level of the output file.

The format of the output files is defined as

01 W-OUTPUT-FILE.
05 FILLER PIC X(24)
05 W-OUTPUT-FILE-DATE PIC 9(08) COMP-3
05 FILLER PIC X(105)

The problem I am having is that after step 3 the date is converted to PIC X. I don't know why the values are not in COMP-3. I checked the amounts and they are in comp-3 but for some reason the date is not.
I displayed all the variables from the computed date to the output file. They are all in comp-3 but if you view the file, they are converted to PIC X. Please help.
jellypuno
 
Posts: 5
Joined: Wed Jun 13, 2012 4:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving COMP-3 to PIC X

Postby Robert Sample » Thu Jun 14, 2012 2:33 pm

Your terminology is so far from standard that it is not possible to determine what you need help with. For example, what does this mean?
I need to move my computed date to an output file defined as PIC 9(08) comp-3. But for some reason it is converted to PIC X.
You need to show us some values in hexadecimal -- using the Code tag to preserve spacing -- so we can understand. A COBOL PIC X variable is alphanumeric, and hence ANYTHING is valid as PIC X. Saying data is PIC X is not saying anything about the data. Furthermore, numeric data is USAGE DISPLAY, USAGE COMP, USAGE COMP-1, USAGE COMP-2, USAGE COMP-3, or edited numeric -- which of these do you mean when you say "PIC X"?

And this
2. After a successful computation, I will move the computed date to a copybook with a format of PIC 9(08) comp-3.
is complete and utter garbage. A copy book is code -- data definitions or procedure division statements -- that are copied into a program using a COPY statement. Once the program is compiled, you cannot move anything to a copybook -- only to a variable -- since the copybook no longer exists as far as the program goes. And since the copied statements become part of the program, talking about a copy book separate from the program is nonsense; the copy book code is incorporated during the compile into the program and they are compiled as one program, not multiple programs.

So start fresh and post some examples of the data that you see (in hexadecimal so we can see the full value, and using the Code button to preserve formatting) and what you think each value should be. Only then will we be able to start to make sense of your terminology.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Moving COMP-3 to PIC X

Postby jellypuno » Thu Jun 14, 2012 3:08 pm

Hi,

Your right. I will just put the code here so we would be on the same page.

These are the variables for my input and output file.

INPUT FILE:
01 W-INPUT-RECORD-LAYOUT.
05 W-INPUT-REC-KEY PIC X(24).
05 W-INPUT-DATE PIC 9(06) COMP-3.
05 W-INPUT-OTHER-DATE PIC X(90).

Temporary Working Storage:
01 W-TEMP-STORAGE-DATE PIC 9(08).

OUTPUT FILE
01 W-OUTPUT-RECORD-LAYOUT.
05 W-OUTPUT-REC-KEY PIC X(24).
05 W-OUTPUT-DATE PIC 9(08) COMP-3.
05 W-OUTPUT-OTHER-DATE PIC X(90).

Using W-INPUT-DATE I will move it to W-TEMP-STORAGE-DATE(3:6) and add the century on the first 2 digits. After this process, I will move W-TEMP-STORAGE-DATE to W-OUTPUT-DATE and write the output file.

I am expecting the date to be in a comp-3 format but for some odd reason it's not. The result is this:

5021114000000000000028  20020 99995         
FFFFFFFFFFFFFFFFFFFFFF44FFFFF0FFFFF0000000400
50211140000000000000280020020099995000001400C
Code'd
The date is turned to 20020. (The date should be 20020521 in comp-3 format)

I was thinking maybe my variable definition is wrong but the amount 104400.00 is written correctly.

Do you have any idea how to fix this error?
jellypuno
 
Posts: 5
Joined: Wed Jun 13, 2012 4:35 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving COMP-3 to PIC X

Postby Robert Sample » Thu Jun 14, 2012 5:09 pm

When you are using reference modification -- the (3 : 6) in your post -- you are implicitly making the variable PIC X, no matter what it really is. This is why your data is not COMP-3 -- YOU told the compiler that it is not. You are making things more complicated than they should be. What you should have is something like this COMPUTE statement (or a MOVE and ADD):
       77  WS-INPUT-DATE               PIC 9(06) COMP-3.
       77  WS-TEMP-STORAGE-DATE        PIC 9(08).
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE 120614                 TO  WS-INPUT-DATE.
           COMPUTE WS-TEMP-STORAGE-DATE =
                   WS-INPUT-DATE + 20000000.
           DISPLAY 'INPUT  <' WS-INPUT-DATE '>'.
           DISPLAY 'TEMP   <' WS-TEMP-STORAGE-DATE '>'.
which produces output of
 INPUT  <120614>
 TEMP   <20120614>
And note the use of the Code button here -- code and data is MUCH more understandable when you use it.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post