Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

How to Read 1 Byte Packed Data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Read 1 Byte Packed Data

     D X S 3U 0 inz( x'16' ) D Y S 2S 0 /free Y = %div(X:16)*10 + %rem(X:16);

  • #2
    How to Read 1 Byte Packed Data

    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?

    Comment


    • #3
      How to Read 1 Byte Packed Data

      It's called "un-signed packed".

      Comment


      • #4
        How to Read 1 Byte Packed Data

        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!

        Comment


        • #5
          How to Read 1 Byte Packed Data

          Declare the variable as a one-byte unsigned binary value.
            [*]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:
            PACKED = %div(UBIN1:16)*10 + %REM(UBIN1:16); 

          Comment


          • #6
            How to Read 1 Byte Packed Data

            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.
            Code

            Comment


            • #7
              How to Read 1 Byte Packed Data

              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

              Comment


              • #8
                How to Read 1 Byte Packed Data

                Thanks everyone for your help. You solved the problem!

                Comment


                • #9
                  How to Read 1 Byte Packed Data

                  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:
                  Code

                  Comment


                  • #10
                    How to Read 1 Byte Packed Data

                    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?
                    Code

                    Comment


                    • #11
                      How to Read 1 Byte Packed Data

                      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

                      Comment

                      Working...
                      X