View Full Version : How to Read 1 Byte Packed Data
G.Gaunt
01-07-2004, 05:49 AM
<pre> D X S 3U 0 inz( x'16' ) D Y S 2S 0 /free Y = %div(X:16)*10 + %rem(X:16);</pre>
R.Cozzi
01-07-2004, 06:07 AM
What do you want the data to be? Is it 16 or is it X'16'? The term "packed" has special meaning to AS/400 so I would have choosen a different term, not sure what though? :)
dacust
01-07-2004, 08:31 AM
It's called "un-signed packed".
Guest.Visitor
01-08-2004, 05:45 AM
The value in the “un-signed” packed field can be different every time (not always 16). So, how can I extract the value of a variable in a similar manner as below? The value that I need is 16 as opposed to X’16’. Ps. Thanks for everyone’s quick responses yesterday!
G.Gaunt
01-08-2004, 06:01 AM
Declare the variable as a one-byte unsigned binary value. <ul> Divide the binary value by 16, discard the remainder. Multiply by 10. Add the remainder of the binary value divided by 16. [/list] In pseudo RPG:<pre>PACKED = %div(UBIN1:16)*10 + %REM(UBIN1:16); </pre>
dacust
01-08-2004, 06:02 AM
Try this. Some people more familiar with BIFs could probably find cleaner way, but this will work. It includes code for converting both directions using the same data structure. I posted this before seeing Gene's post. His is cleaner looking, but if you're doing millions of records, the data structure method will probably be more efficient (only one DIV operation). But experiment with both. <hr width=50 align=left>Code ('http://www.mcpressonline.com/mc/showcode@@.6ae8eed1/5')
Guest.Visitor
01-08-2004, 02:18 PM
Melanie Thomas wrote: > The value in the "un-signed" packed field can be different every time > (not always 16). So, how can I extract the value of a variable in a > similar manner as below? The value that I need is 16 as opposed to > X'16'. Melanie, How about something like this: D ds D cInput 1 D xZeroF 1 Inz(x'0F') D nOutput 1 2p 1 C* C Eval cInput = x'16' C Eval cInput = x'99' C* C Eval *InLR = *On This puts your one byte at the head of a 3.1 packed decimal field. Displaying the values of nOutput after the execution of these two instructions show values of 16.0 and 99.0 . Bill
Guest.Visitor
01-13-2004, 05:11 AM
Thanks everyone for your help. You solved the problem!
Guest.Visitor
03-28-2004, 12:34 PM
Another alternative is to use the function to convert to an hexa string: cvthc (see C MI reference). Each half byte contains 0-9, so this would give x'F0'-x'F9' that you could use as a 'Signed' number. Something like the following: <hr width=50 align=left>Code ('http://www.mcpressonline.com/mc/showcode@@.6ae8eed1/8')
Guest.Visitor
04-19-2004, 03:42 AM
We receive a file from a mainframe that packs 2 bytes of data into 1 byte. When I try to access the data on the AS400, I receive a decimal data error. When I view the file using DSPPFM and then switch to hexadecimal, I can see the two numbers that are packed into the 1 byte. How can I access the value of this field? <hr width=50 align=left>Code ('http://www.mcpressonline.com/mc/showcode@@.6ae8eed1')
Guest.Visitor
04-19-2004, 03:42 AM
I am a COBOL programmer. Here's how to do it in COBOL. First create a 99v9 comp-3 work field (wrkfld). Move your 1 byte field into the first position of the work field. Now do whatever you want with the work field (contains 16.0). Michael Dratwa
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.