Convert PIC S9(004) COMP to character



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

Convert PIC S9(004) COMP to character

Postby tivrfoa » Wed Aug 22, 2012 6:48 pm

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.
tivrfoa
 
Posts: 84
Joined: Wed Aug 22, 2012 6:35 pm
Has thanked: 60 times
Been thanked: 0 time

Re: Convert PIC S9(004) COMP to character

Postby BillyBoyo » Wed Aug 22, 2012 7:00 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Convert PIC S9(004) COMP to character

Postby Robert Sample » Wed Aug 22, 2012 7:00 pm

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.

These users thanked the author Robert Sample for the post:
tivrfoa (Wed Aug 22, 2012 7:14 pm)
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: Convert PIC S9(004) COMP to character

Postby tivrfoa » Wed Aug 22, 2012 7:25 pm

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.
tivrfoa
 
Posts: 84
Joined: Wed Aug 22, 2012 6:35 pm
Has thanked: 60 times
Been thanked: 0 time

Re: Convert PIC S9(004) COMP to character

Postby BillyBoyo » Wed Aug 22, 2012 7:36 pm

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.

These users thanked the author BillyBoyo for the post:
tivrfoa (Wed Aug 22, 2012 8:31 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Convert PIC S9(004) COMP to character

Postby Robert Sample » Wed Aug 22, 2012 7:50 pm

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.

These users thanked the author Robert Sample for the post:
tivrfoa (Wed Aug 22, 2012 8:31 pm)
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: Convert PIC S9(004) COMP to character

Postby tivrfoa » Wed Aug 22, 2012 8:45 pm

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.
tivrfoa
 
Posts: 84
Joined: Wed Aug 22, 2012 6:35 pm
Has thanked: 60 times
Been thanked: 0 time

Re: Convert PIC S9(004) COMP to character

Postby dick scherrer » Wed Aug 22, 2012 8:52 pm

Hello,

Please post a few of the values using HEX ON so we can see your actual data.
Hope this helps,
d.sch.

These users thanked the author dick scherrer for the post:
tivrfoa (Wed Aug 22, 2012 9:58 pm)
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Convert PIC S9(004) COMP to character

Postby BillyBoyo » Wed Aug 22, 2012 8:55 pm

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.

These users thanked the author BillyBoyo for the post:
tivrfoa (Wed Aug 22, 2012 9:58 pm)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Convert PIC S9(004) COMP to character

Postby Robert Sample » Wed Aug 22, 2012 9:07 pm

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.

These users thanked the author Robert Sample for the post:
tivrfoa (Wed Aug 22, 2012 9:58 pm)
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

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post