ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

VARLEN in DDS defined file

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

  • VARLEN in DDS defined file

    OK. What if I have no idea how long the field will be... Like an open ended reason textbox. In this example, I use VARLEN, but when I do an SQL I see 1000 characters, no less no more. Is there no way to say "1000 characters but maybe a lot more".


    PHP Code:
    R RETURNRC                                                 
      CUSTNO          40          TEXT
    ('CUST NUMBER')                  
      
    TRANSANO       40          TEXT('TRANSACTIO NO')                  
      
    COMMENTS    1000A         TEXT('COMMENTS')              
                                
    VARLEN 
    VARLEN (Variable-Length Field) keyword for physical and logical files
    Use this field-level keyword to define this field as a variable-length field. Variable-length fields are useful for improving storage when the data for the field typically fits within a certain length, but can occasionally be longer. Specify the maximum length of the field in positions 30 to 34. You can specify the allocated length (or typical length) in the parameter.

    The format of the keyword is:

    VARLEN[(allocated-length)]

    The allocated-length parameter is optional. Use it to specify the number of bytes (two byte characters in the case of graphic fields) allocated for the field in the fixed portion of the file. If you do not specify the allocated-length parameter, the data for this field is stored in the variable length portion of the file.

    Valid values for the allocated-length parameter are 1 to the maximum length of the field specified in positions 30 to 34.

    The VARLEN keyword has no parameters for a logical file.

    The VARLEN keyword is valid only on character fields and graphic fields.

    When you specify the VARLEN keyword, the maximum length you can specify in positions 30 to 34 is 32 740 (32 739 if the field allows the null value). If the field is a graphic field, the maximum length you can specify is 16 370.

    If you specify the DFT keyword for a variable-length field, the length of the default value must be less than or equal to the allocated length for the field. If the default value is longer than the allocated length, an error message is issued when the file is created.

    If you specify a hexadecimal value as the default value for a variable-length field, the number of hexadecimal characters must be equal to two times the allocated length for the field.

    The DFT keyword is not allowed on the same field as a VARLEN keyword unless you specify a value for the allocated-length parameter.

    Do not specify the VARLEN keyword on a date, time, or timestamp field (L, T, or Z in position 35).

    Example:

    The following example shows how to specify the VARLEN keyword for a physical file.

    |...+....1....+....2....+....3....+....4....+....5 ....+....6....+....7....+....8
    00010A R RECORD1
    00020A FIELD1 100A VARLEN(30)
    00030A FIELD2 200A VARLEN
    A

    FIELD1 is defined as a variable-length field with a maximum length of 100 and an allocated length of 30. FIELD2 is defined as a variable-length field with a maximum length of 200 and no allocated length.
    __________________
    Thanks,
    Giri
    Last edited by itp; January 19, 2007, 10:40 AM.

  • #2
    Re: VARLEN in DDS defined file

    Originally posted by itp View Post
    OK. What if I have no idea how long the field will be... Like an open ended reason textbox. In this example, I use VARLEN, but when I do an SQL I see 1000 characters, no less no more. Is there no way to say "1000 characters but maybe a lot more".


    PHP Code:
    R RETURNRC                                                 
      CUSTNO          40          TEXT
    ('CUST NUMBER')                  
      
    TRANSANO       40          TEXT('TRANSACTIO NO')                  
      
    COMMENTS    1000A         TEXT('COMMENTS')              
                                
    VARLEN 
    There always has to be a limit ... it may be huge but there is still a limit somewhere. In this case I would decide what the practical maximum is (is anybody _really_ going to write a 20,000 character entry?) and then set that as the field length. Then determine what length will contain (say) 95% of all entries and specify that as the parm to VARLEN to conserve storage. Maybe 500 is good enough? In which case specify VARLEN(500). When you process the field in RPG it will always be padded out to the full length - but the compiler generated code will only ever use the correct length.

    Comment


    • #3
      Re: VARLEN in DDS defined file

      Hi,

      there are also some other restrictions:
      1. The maximum length of a field with varying length is 32,740 Bytes
      2. The row length cannot exeed 32,740 Bytes, too

      If you really need longer fields, you have to define your physical files with SQL and use character large objects (CLOB) to hold your data.

      Birgitta

      Comment

      Working...
      X