Using Variable Length Fields in LANSA

Date:Archived
Product/Release:LANSA for the AS/400
Abstract:Variable Length Field Support in LANSA
Submitted By:LANSA Technical Support

LANSA allows the use of Variable Length fields providing these steps are followed:

  1. Have the option *OTHER_VARCHAR in the data area DC@OSVEROP to indicate that the conversion option *VARCHAR is to be used when OTHER file I/O modules are compiled. This allows variable length (VARLEN or VARCHAR) fields to be accessible in LANSA.
     
  2. Create a virtual field with the maximum length of the variable. (ie 253). E.g:
    DC@P100102 Display Data Dictionary Field
    Field name : LVCOMV
    Type (A,P,S) / Keybd shift : A /
    Length / total digits : 253
    Number of decimal positions :
    Reference field :
    Description : COMMENT
    Label : LVCOMM Column headings : LVCOMM
    Output attributes list : PBCE
    Input attributes list : FE
    Edit code / Edit word : /
    Default value : *BLANKS
    Optional alias name :
    System field ? NO
    Prompting process/function : /

     
  3. Include the virtual field created into the file needed.
    DC@P201601     Display Virtual Fields in File Definition
    File : COMPLEV IKLIB                      Neller - COMPLEV
    Edit virtual field derivation code . . . . . . YES YES, NO
    Sequence Name      Description PJF
    &&&                PJF's before virtuals derived on input     B
    &&&                Virtual Fields derived after input
    &&&                PJF's after virtuals derived on input      A
    &&&                Virtual Fields derived before output
    &&&                Undefined Virtual Fields                    U
    LVCOMV             COMMENT                                U

     
  4. Type in the RPG derivation code for the Data Structure, After Input and Before Output operations. (Note: Do not forget to include the special VC_USING line which should include the names of all real file fields which are used in the code.)
    DC@P201602 Edit Virtual Field Derivation Code
    File : COMPLEV IKLIB                       Neller - COMPLEV
    Choose section(s) of file I/O module in which virtual
    field derivation code is to be included ....................
    Choose I/O module code section RPGIII type :
    File specifications                          "F" specs
    Array specifications                         "E" specs
    External record format or field renames      "I" specs
    X Data structure specifications              "I" specs
    X Calculations after input from file         "C" specs
    X Calculations before output to file         "C" specs
    Internal subroutines                         "C" specs
    Output specifications                        "O" specs
    Compile time array data                       N/Applicable


    Data Structure

    E.g: SEU==> EDITWORK

    FMT * ..... *. 1 ..+...2 ..+...3 ..+...4 ..+...5 ..+...6 ..+...7
    *************** Beginning of data ******************************
    I*
    I* VC_USING FIELDS(LVCOMV)
    I*
    I         DS
    I                                  1 255 VARFL1
    I                                B 1   20LEN1
    I                                  3 255 FLD1
    ****************** End of data ***********************************

    Calculations after input from file

    E.g: SEU==> EDITWORKFMT

    * ..... *. 1 ..+...2 ..+...3 ..+...4 ..+...5 ..+...6 ..+...7
    *************** Beginning of data *****************************
    C*
    C* VC_USING FIELDS(LVCOMM LVCOMV)
    C*
    C MOVE LVCOMM LVCOMV
    ****************** End of data *********************************

    Calculations before output to file

    E.g: SEU==> EDITWORK FMT * ..... *. 1 ..+...2 ..+...3 ..+...4 ..+...5 ..+...6 ..+...7
    *************** Beginning of data *****************************
    C*
    C* VC_USING FIELDS(LVCOMM LVCOMV)
    C*
    C                        MOVELLVCOMV    FLD1
    C               ' '     CHEKRFLD1     NUM     30
    C                        Z-ADDNUM       LEN1
    C                        MOVE VARFL1   LVCOMM
    ****************** End of data ******************************


    Notes: It is not mandatory to use the CHEKR command to find the length of the string, it can be set to the maximum length of the variable but it is recommended to have the correct length of the data.

  5. Using RPG/IV instead of RPGIII:

    The above example is using RPGIII but RPGIV can be used in the calculations specifications to create the virtual code and allow built-in function %LEN to calculate the length of the data in the variable length field. Option *RPGIV needs to be added to the data area DC@OSVEROP to activate RPGIV. The virtual code must also include the ILE activation option as below and the syntax must be for RPGLE.

    E.g:

    *************** Beginning of data ******************************
    0001.00 C*
    0002.00 C* VC_USING FIELDS(LVCOMM LVCOMV)
    0003.00 C*
    0004.00 C**ILE                 MOVE      LVCOMV          FLD1
    0005.00 C**ILE                  EVAL       LEN1 = %LEN(LVCOMV)
    0006.00 C**ILE                  MOVEL      VARFLD1        LVCOMM
    0007.00 C*
    ****************** End of data ***********************************


  6. In the LANSA for the AS/400 functions or LANSA Open field definitions, use and refer only to the virtual field created.