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.