Release the NEW Power of CL

Release the NEW Power of CL

Name:

Email:

Profile Manager

Stop spending time and money reinstating user profiles!

Try Profile Manager Today!

30 DAY FREE TRIAL

Learn More

Programming Services

Do you need a program written?

Bruce Vining Services can provide highly experienced IBM i developers to supplement your staff with short term contracts. If you are looking for custom solutions involving system functions such as communications, database, security, encryption, print, and work management you will find your answers at Bruce Vining Services.

PDF Print E-mail

Set Variable Field Length (SETVFLCLF)

Where allowed to run:
  • Batch program (*BPGM)
  • Interactive program (*IPGM)
Threadsafe: Yes
Parameters
Examples
Error messages

The Set Variable Field Length (SETVFLCLF) command is used in a CL program to set the character length of a variable-length field.

This command never runs in the traditional sense and will return an error if an attempt is made to run the command. The CLF precompilers, when they encounter this command in a CL source program, replace the command and generate CL instructions directly into the compiled CL program.

Restrictions:

  • This function can only be used in a CL program that is created using a CLF precompiler command. The CLF precompiler commands are CRTBNDCLF, CRTCLFMOD, and CRTCLFPGM.
  • The file containing the variable-length field must be declared in the CL program using the DCLFCLF command with VFLSPT(*VARLEN).
Top

Parameters

KeywordDescriptionChoicesNotes
VAR CL variable name CL variable name Optional, Positional 1
VARLEN Field length Integer, *TRIM Optional, Positional 2
TRMCHR Character to trim Character value, *BLANKS Optional
Top

CL variable name (VAR)

Specifies the name of a variable-length field.

This is a required parameter.

CL-variable-name
Specify the CL variable name that you want to set the length of.
Top

Field length (VARLEN)

Specifies the number of characters with the variable-length field identifed by the VAR parameter.

*TRIM
The length of the variable-length field is to be set to the length of the field after trimming the trailing character specified by the TRMCHR keyword.
integer
Specify the CL variable name or a numeric constant whose value is used to set the length. The value must be greater than or equal to 0 and less than or equal to the maximum number of characters defined for the field. The value must be specified with no decimal points.

If the CL variable used is declared as numeric the value of the CL variable will be used to set the character length of the variable-length field.

If the CL variable used is declared as a fixed-length character field the maximum size, in bytes, of the CL variable will be used to set the character length of the variable-length field

If the CL variable used is declared as a variable-length character field the number of characters of the CL variable will be used to set the character length of the variable-length field identified by the VAR keyword.

Top

Character to trim (TRMCHR)

Specifies the trailing character to be trimmed when determining the character length of the variable-length field identified by the VAR keywork.

*BLANKS
The length of the variable-length field is set after trimming any trailing EBCDIC blanks.
character-value
Specify the trailing character value to be trimmed when determining the length of the variable-length field. The character value can be specified as one or two bytes. If two bytes are specified trimming is done on the basis of a two byte Graphic or UCS2/UTF16 field.

For the trimming of lowercase alphabetic characters enclose the value in single quotes.

Top

Examples for SETVFLCLF

Example 1: Set Length to a Variable Value

 

    SetVFLCLF  Var(&DptName) VarLen(&Size)

 

This command sets the length of the variable-length field &DPTNAME to the value of variable &SIZE. &SIZE is declared as a numeric variable within the program.

Example 2: Set Length to a Blank Trimmed Value

 

    SetVFLCLF  Var(&DptName)

 

This command sets the length of the variable-length field &DPTNAME to the blank trimmed length of &DPTNAME.

Example 3: Set Length after Trimming any Asterisks

 

    SetVFLCLF  Var(&DptName) TrmChr(*)

 

This command sets the length of the variable-length field &DPTNAME to the asterisk trimmed length of &DPTNAME.

Example 4: Set Length after Trimming ASCII Blanks

 

    SetVFLCLF  Var(&DptName) TrmChr(x'20')

 

This command sets the length of the variable-length field &DPTNAME to the ASCII blank trimmed length of &DPTNAME.

Example 5: Setting the Variable Length

 

/**********************************************************/
/*                                                        */
/* This program is defined with one required and one      */
/* optional parameter. The required parameter is the      */
/* department ID that is to be read and possibly changed. */
/* The program will display the departname name using     */
/* the length found in the database record. Department    */
/* name (&DPTNAME) is defined as a variable-length field. */
/*                                                        */
/* The optional parameter is the new length of the        */
/* department name for the department identified by the   */
/* first parameter. If the second parameter is not        */
/* specified, the length of the deparment name is not     */
/* changed. If the second parameter is specified, the     */
/* length of the department name is set to this length.   */
/*                                                        */
/**********************************************************/
    Pgm        Parm(&DptID_In &Size_In)
    Dcl        Var(&DptID_In) Type(*Char) Len(2)
    Dcl        Var(&Size_In)  Type(*Dec)
    /******************************************************/
    /* Declare work variables:                            */
    /*   &SIZE  - will hold the current length of a       */
    /*            department name read from the VC2DPTVAR */
    /*            file                                    */
    /*   &CHG_Y - a flag to indicate that the length of   */
    /*            the current department name should be   */
    /*            changed                                 */
    /******************************************************/
    Dcl        Var(&Size)  Type(*Int)  Len(2)
    Dcl        Var(&Chg_Y) Type(*Lgl)  Value('1')
    /******************************************************/
    /* Declare the file VC2DPTVAR and CLF indicators      */
    /******************************************************/
    DclFCLF    FileID(VC2DPTVAR)
    DclIndCLF  CLFInd(*Yes)
    /******************************************************/
    /* Test if department ID parameter was passed         */
    /******************************************************/
    ChgVar     Var(&DptID) Value(&DptID_In)
    MonMsg     MsgID(MCH3601) Exec(Do)
               RmvMsg Clear(*All)
               SndPgmMsg  Msg( +
                 'Department ID is a required parameter')
               Return
               EndDo
    /******************************************************/
    /* Test if &Size_In parameter was passed              */
    /******************************************************/
    ChgVar     Var(&Size_In) Value(&Size_In)
    MonMsg     MsgID(MCH3601) Exec(Do)
               RmvMsg Clear(*All)
               ChgVar Var(&Chg_Y) Value('0')
               EndDo
    /******************************************************/
    /* Open VC2DPTVAR for reading by key and update       */
    /******************************************************/
    OpnFCLF    FileID(VC2DPTVAR) Usage(*Both) +
                 AccMth(*Key)
    /******************************************************/
    /* Read the requested department record               */
    /******************************************************/
    ReadRcdCLF FileID(VC2DPTVAR) Type(*Key) KeyRel(*EQ) +
                 KeyList(&DptID) RcdNotFnd(&RNF)
    If         Cond(&RNF) Then( +
               SndPgmMsg Msg('Department' *BCat +
                 &DptID *BCat 'not found.'))
    Else       Cmd(Do)
               /*******************************************/
               /* Get current length of &DPTNAME          */
               /* and display the name                    */
               /*******************************************/
               RtvVFLCLF Var(&DptName) VarLen(&Size)
               If Cond(&Size *GT 0) Then( +
                  SndPgmMsg Msg(%sst(&DptName 1 &Size)))
               Else Cmd( +
                  SndPgmMsg Msg( +
                    'No department name for' *BCat &DptID))
               /*******************************************/
               /* If length is to be changed then make    */
               /* the change, update the database, and    */
               /* display the new department name         */
               /*******************************************/
               If Cond(&Chg_Y) Then(Do)
                  SetVFLCLF Var(&DptName) VarLen(&Size_In)
                  MonMsg MsgID(VC25077) Exec(Do)
                         SndPgmMsg Msg( +
                           'No Change due to size too large')
                         GoTo CmdLbl(NoUpdate)
                         EndDo
                  UpdRcdCLF FileID(VC2DPTVAR)
                  If Cond(&Size_In *GT 0) Then( +
                     SndPgmMsg Msg( +
                       %sst(&DptName 1 &Size_In)))
                  Else Cmd( +
                     SndPgmMsg Msg( +
                       'Department name is now 0 length'))
                  EndDo
 NoUpdate:     EndDo
    /******************************************************/
    /* Close the file and end the program                 */
    /******************************************************/
    CloFCLF    FileID(VC2DPTVAR)
    EndPgm

 

The source for the example program can be found in member DEV_VARLEN of source file VC2CLSRC in library VC2CLF. The source for file VC2DPTVAR can be found in member VC2DPTVAR of source file QDDSSRC in library VC2CLF.

To compile example DEV_VARLEN use either Create Bound CLF Program (CRTBNDCLF) or Create CLF Program (CRTCLFPGM). You will need to create, and load records into, the VC2DPTVAR file before compiling and running the DEV_VARLEN example program.

To create the VC2DPTVAR file into QTEMP you can use the command

 

    CrtPF File(QTEMP/VC2DPTVAR) SrcFile(VC2CLF/QDDSSRC)

 

To load records into VC2DPTVAR you

 

    CrtBndCLF Pgm(QTEMP/DEV_LOADVL) SrcFile(VC2CLF/VC2CLSRC)
    Call Pgm(QTEMP/DEV_LOADVL)

 

To create the DEV_VARLEN program into QTEMP you can use the command

 

    CrtBndCLF Pgm(QTEMP/DEV_VARLEN) SrcFile(VC2CLF/VC2CLSRC)

 

After creating DEV_VARLEN you may want to try a few test cases such as:

 

    CALL DEV_VARLEN A1
    CALL DEV_VARLEN (A1 4)
    CALL DEV_VARLEN (A1 50)

 

The first test should show the department name 'Corporate Management'. The second test should show the new department name of 'Corp'. The third test case should show the message 'No Change due to size too large'. This is because &DPTNAME has a maximum size of 30 characters while the third test case requested that the length of the field value be set to 50 characters. The message is displayed due to the MONMSG for VC25077.

Top

Error messages for SETVFLCLF

*ESCAPE Messages

VC25057
The &1 command is intended only for CLF precompiler support.
VC25077
Specified VARLEN for &&1 is greater than maximum size of field.
Top
 
Joomla 1.5 Templates by Joomlashack