ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Packed vs Zoned

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

  • Packed vs Zoned

    Ok, this has been bugging me for a long time and I finally decided to ask someone about it. It has to do with numeric field definitions in programs.

    I always try to define my variables based on fields from an external file for the obvious reasons. The problem I am running into is that fields definied as zoned numeric in the file are being defined in the program as packed.

    For example:

    I have a file with two zoned fields.

    Code:
                Data        Field  Buffer    Buffer        Field    Column      
     Field      Type       Length  Length  Position        Usage    Heading     
     CMORD#     ZONED        6  0       6         1        Both     CMORD#      
       Field text  . . . . . . . . . . . . . . . :  Order #                     
     CMSUF#     ZONED        2  0       2         7        Both     CMSUF#      
       Field text  . . . . . . . . . . . . . . . :  Suffix                      
     CMLNUP     ZONED        2  0       2         9        Both     CMLNUP      
       Field text  . . . . . . . . . . . . . . . :  Line-up
    In my program, I want to define the input parameters based on those fields... like so:
    Code:
      *---------------------------------------------------------------
      * Standalone variables.                                         
      *---------------------------------------------------------------
      * Entry parameters.                                             
     D P_Order#        S                          LIKE(CMORD#)        
     D P_Suffix#       S                          LIKE(CMSUF#)
    So I would expect those fields to be zoned as well.

    When I try to call this routine though I get decimal data errors because those fields are actually defined as packed.

    When I look at the compiler listing I see the following:

    Here is the input buffer
    Code:
    000002=I                             S    1    6 0CMORD#                          Order #         
    000003=I                             S    7    8 0CMSUF#                          Suffix
    Everything is zoned. Thats nice.

    Here is the cross reference listing.
    Code:
           CMORD#            P(6,0)                 004400     6000002D     006700      007300 
    ...
           CMSUF#            P(2,0)                 004500     6000003D     006800      007400 
    ...
           P_ORDER#          P(6,0)                 004400D     006300      008200M     012800 
    ...
           P_SUFFIX#         P(2,0)                 004500D     006400      008300M     012900


    Now that I am starting to prototype things this is getting to be a pain in the butt because I declare the prototyping parms as subfields in a data structure so that they can be based upon a file. Like so:

    Code:
     
    *  File definitions used for parm definitions.                 
    D OHFile        E DS                  QUALIFIED EXTNAME(OHP)    
    D O3File        E DS                  QUALIFIED EXTNAME(O3)     
    D O4File        E DS                  QUALIFIED EXTNAME(O4P)    
    D PCFile        E DS                  QUALIFIED EXTNAME(PCP)    
    
    *---------------------------------------------------------------   
    * ChkMfgHold routine.                                              
    *    This routine is used to check if an order is on               
    *    manufacturing hold.                                           
    *                                                                  
    *    Input Parameters:                                             
    *                         Order Number                             
    *    Return Parameter:                                             
    *                         Indicator: *ON:  order is on mfg hold    
    *                                    *OFF: order can be released   
    *---------------------------------------------------------------   
     ChkMfgHold      PR              N                                 
       OrderNumber                             LIKE(OHFile.OHORD#) CONST
    In this case, the LIKE statement works correctly and declares OrderNumber as Zoned. Unfortunately, the field I attempt to do the call with has been incorrectly defined by the compiler as packed.

    As a result, data decimal errors.

    Can anyone explain this to me? Thanks a bunch

  • #2
    Re: Packed vs Zoned

    When the LIKE Keyword Misbehaves by Robert Cozzi Jr.
    "Time passes, but sometimes it beats the <crap> out of you as it goes."

    Comment


    • #3
      Re: Packed vs Zoned

      Exactly what I was looking for. Thanks. That throws a real monkey wrench into things though.

      Comment


      • #4
        Re: Packed vs Zoned

        Just don't shoot the messenger!
        "Time passes, but sometimes it beats the <crap> out of you as it goes."

        Comment


        • #5
          Re: Packed vs Zoned

          Yeah. I ran into this in CALL/PARM. We have mostly RPG-III code here with newer pgms written in RPG-IV. When I call an RPG-IV pgm from RPG-III, if the numerics aren't all packed, I get this error. Debug shows the zoned fields and being passed in packed format, despite both sending and calling pgms define it as zoned. Causing of course, the dec data error.

          I finally resolved this by moving any zoned fields being passed to packed and changing the called pgm to moved packed to zoned.

          Comment


          • #6
            Re: Packed vs Zoned

            Hi,

            I searched on the forum and got to this thread and just decided to use it rather than creating a new one.

            I have been programming in rpg for a while already but still not so clear with the use of zoned and packed fields? When should i use zoned and when should i use packed?

            thanks,
            Greg

            Comment


            • #7
              Re: Packed vs Zoned

              Easy, never use packed. Storage has not been a significant issue in many many years.

              Zoned fields are easier to handle if you ever want to pull the data from a different system.
              Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

              Comment


              • #8
                Re: Packed vs Zoned

                Zoned fields are easier to handle if you ever want to pull the data from a different system.
                Absolutely true. However, if you use a numeric field in CALL/PARM it must be packed or you will get errors. The workaround is to pass a data structure, where the DS is always passed "as is".

                As I understand it, all numeric calcs force zoned fields to be changed to packed, then the operations is performed, then changed back. For this reason (maybe others), if you define a numeric and don't specify zoned, it defaults to packed -- unless its in a data structure.

                As DMW pointed out though, with todays storage and speeds, I doubt you would see any performance difference.

                Comment


                • #9
                  Re: Packed vs Zoned

                  Actually, I still pass stuff as zoned. If I have a field defined as zoned in a file but it is never used for display purposes, the compiler will automatically change it to packed. Therefore, I just create a D spec definition for the field which forces the field to be defined as zoned.

                  The downside is, if the field in the file is ever changed I will have a problem when I recompile the program. For that reason alone, passing it as packed is probably your best bet... as arrow said. I should probably start doing so myself.

                  Comment


                  • #10
                    Re: Packed vs Zoned

                    Thanks guys,

                    @Arrow, you mean when i pass DS as parameters with packed and zoned fields in it, it will not send an error? I will try using DS as parameter (actually have done some modifications with programs using DS as externally described file) and have not found any issue.

                    Thanks,
                    Greg

                    Comment


                    • #11
                      Re: Packed vs Zoned

                      you mean when i pass DS as parameters with packed and zoned fields in it, it will not send an error?
                      That is correct. The DS is passed as a string, then loaded into the DS fields.

                      Comment


                      • #12
                        Re: Packed vs Zoned

                        Thanks. I think with this, i will be resorting to using DS as parameter for program parameters passing. It is but just like coding a plist and
                        no longer be bothered with dec data errors.

                        Comment

                        Working...
                        X