sponsored links



No announcement yet.

dcl-ds varname LEN(X) end-ds;

  • Filter
  • Time
  • Show
Clear All
new posts

  • dcl-ds varname LEN(X) end-ds;

    Hi guys. Im struggling to understand what the LEN keyword does on a data structure and more importantly -- why I would ever use it?

    I'm looking over http://www.omniuser.org/downloads/om...PGFreeForm.pdf these slides (slide number 31)

    PHP Code:
    //Only character keys supported for program- described

    //For other types, use a data structure

    dcl-f generic disk(2000keyed(*CHAR:7);

    dcl-ds key len(7qualified;
    item_num packed(12);

    key.item_num 14;
    chain key generic
    I looked in the rpgle reference manual and all it says is "The LEN keyword is used to define the length in characters of a Data Structure or character, UCS-2 or graphic definition"

    So does that mean this data structure is supposed to be 7 bytes long? (Assuming a character is 1 byte). However in this example there is a subfield that is packed(12). It seems like the subfield isn't going to fit properly (I say that variables will lose 5 bytes of data). If that is true was this intended to truncate data?

    Why would I want to use LEN Keyword on a Data Structure when you can automatically declare subfields and let the compiler generate the byte-length needed for the ds?

    Thanks for any insight or help you can provide.

  • #2
    An example could be if you call a program (myProg) using the data structure as a parameter.
    This program could return some information in the data structure.

    If you define it for example with a length of 2000 bytes and only in the beginning
    use 100 bytes of them then you can modify the called program to return further information
    without having to compile all programs calling myProg because there is already reserved 2000
    bytes of memory.
    If you don't reserve the 2000 bytes and only use the length of 100 then you have to compile all
    programs that calls myProg in order to avoid violation of the memory.



    • #3
      You may want the DS to use a specific amount of bytes that is larger than the subfields, so you have room to expand it in the further without increasing its actual size. This might be useful if you are passing it through some kind of interface. But generally, no, you won't need a fixed size.

      I do not know what happens when the DS length is smaller than its subfields. I'd be surprised if the compiler allows it.

      In your example though I don't think packed(12) is longer than len(7). Packed uses a half-byte per digit and a half-byte for sign, rounded up so there is a full number of bytes. So packed(12) will be 6 bytes for the digits + a half byte for the sign, rounded up = 7 bytes.


      • #4
        Hey guys great information, thanks for your feedback. I didn't realize that about Packed fields using half a byte. That's totally cool.