How to Pack Char data in cobol



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

How to Pack Char data in cobol

Postby Mann_B » Thu Sep 13, 2012 5:12 pm

Hi All

Can we pack character data ..
If in input we have X(04) fld with data ABCD , i need to pack it to below whose def is X(02).
AC
BD
without changing the value.
Can you please help me out.
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to Pack Char data in cobol

Postby Robert Sample » Thu Sep 13, 2012 5:44 pm

Your "requirement" is not clear -- what do you want to do if the PIC X(4) data is 'WXYZ'? -- which cannot be stored, at all, in a 2-byte variable? For the general case, a 4-byte character field cannot be stored in a 2-byte character field without using some encoding method (Google Huffman coding for one example of how it can be done).

If you are talking about numeric data only (0 to 9 and possibly the hexadecimal values A,B,C,D,E,F), what have you tried and where are you having problems? Have you read the COBOL Language Reference manual (link at the top of this page) on internal representations of data and used that to get an idea how to proceed?
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: How to Pack Char data in cobol

Postby dick scherrer » Thu Sep 13, 2012 11:35 pm

Hello,

This appears to be just a continuation of your other topic about the same situation.

Now, as then, you have not clearly posted what you are tryinig to do.

Show several "input" values and how you want these values stored by your peocess. Explain what should happen if the input data is MNTR.
Hope this helps,
d.sch.
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: How to Pack Char data in cobol

Postby Mann_B » Tue Sep 18, 2012 1:25 pm

HI

My input have characters only from A-F and numebers.
Sample is 7AFB016G.I need to pack this as..
7F06
AB1G
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to Pack Char data in cobol

Postby BillyBoyo » Tue Sep 18, 2012 1:46 pm

Well, you are stuck then. G is not valid as a representation of a value in hexadecimal notation.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: How to Pack Char data in cobol

Postby NicC » Tue Sep 18, 2012 1:53 pm

And G is not in the range A-F (unless someone changed the English alphabet overnight)
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: How to Pack Char data in cobol

Postby Mann_B » Tue Sep 18, 2012 2:11 pm

oops ...I am sorry,Sample is 7AFB016C.
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: How to Pack Char data in cobol

Postby BillyBoyo » Tue Sep 18, 2012 3:31 pm

There is more than one way to do this.

Note that you have 16 values (0-9, A-F). These have a hex representation as characters F0-F9, C1-C6, and also a hex representation when "packed" in a byte - or two, one when on the "left" and one when on the right - ?0-?9, ?A-?F and 0?-9?, A?-F?.

So, at the heart, there can all come down to a simple 1-to-1 relationship.

Then you have some technical stuff, like you can't access a single byte as a binary value in Cobol.

01  a-nice-name COMP-5 PIC 9(4).
01  FILLER REDEFINES a-nice-name,
    05  FILLER PIC X.
    05  another-nice-name-for-this-byte PIC X.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post