Page 1 of 2

Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 6:48 pm
by tivrfoa
Hello,

I'm getting data from DB2 and saving it in a file. I store the values in COMP variables because the table conversion between SQL and COBOL.
But then the data is unreadable in the file. :/

FILE SECTION.
FD FFFF055S
    BLOCK  CONTAINS 000 RECORDS
    RECORD CONTAINS 021 CHARACTERS
    RECORDING F.
01 FFFF055S-REG.
       05 T-TPO            PIC  X(004).
       05 T-CLS            PIC  X(004).
       05 T-SCL            PIC  X(004).
       05 T-SEQ            PIC  X(009).

01 FFFF055S-AREA.
   05 TPO                PIC S9(004) COMP.
   05 CLS                PIC S9(004) COMP.
   05 SCL                PIC S9(004) COMP.
   05 SEQ                PIC S9(009) COMP.

WRITE FFFF055S-REG FROM FFFF055S-AREA.


Do you know what can I do, so the data will be in a readable formart in the file?

Thank you.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 7:00 pm
by BillyBoyo
It is not clear from your explanation why you are storing in COMP and what you expect the fields to contain. Please explain more fully.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 7:00 pm
by Robert Sample
Change your code:
       05 T-TPO            PIC  9(004).
       05 T-CLS            PIC  9(004).
       05 T-SCL            PIC  9(004).
       05 T-SEQ            PIC  9(009).

The data in the file IS readable, you just have to use HEX mode in ISPF/EDIT and understand how COMP values are stored to be able to read them.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 7:25 pm
by tivrfoa
BillyBoyo wrote:It is not clear from your explanation why you are storing in COMP and what you expect the fields to contain. Please explain more fully.

Hi,

It's because:
smallint -> PIC S9(004) COMP.
integer -> PIC S9(009) COMP.

Robert Sample wrote:Change your code: ...
The data in the file IS readable, you just have to use HEX mode in ISPF/EDIT and understand how COMP values are stored to be able to read them.

Is there a difference in the output if I change as you said? I used SET HEX and the result seems to be the same. :roll:
But how to change from hex to a "friendly" readable format? :D
You know, like a report that you need to give to someone.

Kind Regards,
Leandro.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 7:36 pm
by BillyBoyo
For a report, use a numeric-edited field


a-nice-name PIC Z(9)9-


There are many possible varieties. Just MOVE you COMP field to one of those, and it'll be how you want.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 7:50 pm
by Robert Sample
Is there a difference in the output if I change as you said?
Absolutely there will be a difference. COBOL moves COMP variables to a PIC X variable with no conversion or other modification of the data. 1234 in a PIC S9(04) COMP varialbe is X'04D2', which would be moved to a PIC X(04) variable as X'04D24040' (assuming space is the filler character). COBOL moves COMP varaibles to a PIC 9 variable by converting the value to a decimal number so it becomes readable by a human with no interpreation required. 1234 moved to a PIC 9(04) variable becomes X'F1F2F3F4' or 1234 displayed.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 8:45 pm
by tivrfoa
I changed the variables type in the FILE SECTION to PIC Z …, but the result is still in HEX.
Then I tried MOVE before WRITE, but the result is the same.
I’ll reply if I find a solution.
Thank you very much.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 8:52 pm
by dick scherrer
Hello,

Please post a few of the values using HEX ON so we can see your actual data.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 8:55 pm
by BillyBoyo
Can you show your code and your definitions please?

You can still store in the file in binary, and then use the numeric-edited if you want to actually print. If you store it as a numeric-edited, you make it more complicated to do anything with it (like add it up, for instance) except print it.

Re: Convert PIC S9(004) COMP to character

PostPosted: Wed Aug 22, 2012 9:07 pm
by Robert Sample
Move the individual variables, NOT the group level. Moving the group level will NOT convert the binary data. Your WRITE FROM is a group-level move, hence the binary data will not be converted to display format.