You are on page 1of 4

DCL(DeclareCLVariable)CommandDescription

Purpose
TheDeclareCLVariable(DCL)commanddefinescontrollanguage(CL)
programvariablesusedinCLprograms.CLvariablesareusedtostoreand
updatedataandtoreceiveparametersfromanotherprogramonacall.CL
variablesareknownbynameonlywithintheprogramthatdeclaresthem.
TheycannotbeusedoutsideaCLprogramexceptwhentheyarereferredto
bysomecommands(suchastheDSPPGMVARcommand)usedfor
debuggingprograms.Ifavariableisdeclared,butnotreferredtobyanother
commandinaCLprogram,thevariableisnotincludedintheprogramwhen
itiscompiled.However,thevalueinthevariablecanbepassedtoanother
programasaparameter.EachDCLcommanddefinestheattributesofone
CLvariableanddeclaresitsnameintheprograminwhichitisused.
EachCLvariableinaprogrammustbeidentifiedbyoneofthetwodeclare
commands.TheDeclareFile(DCLF)commanddeclaresCLvariablesfor
displaydevicefilesanddataareas.TheDCLcommanddeclaresallotherCL
variables.
Restriction:TheDCLcommandisvalidonlywithinaCLprogram.All
declarecommands(COPYRIGHT,DCL,andDCLF)mustfollowthePGM
(Program)commandandmustprecedeallothercommandsintheprogram.
Thethreetypesofdeclarecommandscanbeintermixedinanyorder.
RequiredParameters
VAR
SpecifiesthenameoftheCLvariablebeingdeclaredintheCL
program.Thevariableexistsonlywithintheprograminwhichitis
defined.Itcanbepassedasaparameteronacalltoanotherprogram,
inwhichcaseitcanbeprocessedbythecalledprogram.Thevariable
namemuststartwithanampersand(&).
TYPE
SpecifiesthetypeofvaluecontainedintheCLvariablebeing
declared.Thevalueofthevariablecanbeacharacterconstant,a
decimalconstant,oralogical'1'or'0'.Thevalueforthisparameter
cannotbespecifiedbyaCLvariable.Specifyoneofthefollowing
types:
*DEC:Adecimalvariablethatcontainsapackeddecimalvalue.

*CHAR:Acharactervariablethatcontainsacharacterstringvalue.
*LGL:Alogicalvariablethatcontainsalogicalvalueofeither
'1'or'0'.
OptionalParameters
LEN
SpecifiesthelengthoftheCLvariablebeingdeclared.Ifthevariable
isadecimalvalue,thenumberofdecimaldigitstotherightofthe
decimalpointcanbeoptionallyspecified.ThevalueforthisLEN
parametercannotbespecifiedbyaCLvariable.Themaximum
lengthsandthedefaultsforeachofthethreetypesareshowninTable
1.
length:SpecifythenumberofcharactersthatthevalueinthisCL
variablecanhave.Thelengthcannotbegreaterthanthemaximum
forthistypeofvariable.
decimalpositions:Thisoptionisvalidonlyfordecimalvariables.
Thelengthofthevalueinthevariableincludesthenumberof
decimalpositionsinthevalue.Themaximumlengthofthedecimal
valueis15digits,includingthedigitstotherightofthedecimal
point.Uptoninedecimalpositionscanbespecified.Ifninedecimal
positionsarespecified,thevaluetotheleftofthedecimalpointcan
neverbegreaterthan999,999becauseonly6ofthe15digitsareleft
fortheintegervalue.
Ifalength(indigits)isspecifiedforadecimalvariableandthe
numberofdecimalpositionsisnotspecified,0decimalpositionsis
assumed.
VALUE
SpecifiestheinitialvalueassignedtotheCLvariablewhenitis
declaredintheprogram.Thevaluemustbeofthetypespecifiedby
theTYPEparameter.Ifnovalueisspecified,acharactervariableis
settoblanks,adecimalvariableissettoavalueof0,andalogical
variableissetto'0'.ThevaluefortheVALUEparametercannotbe
specifiedbyaCLvariable.
IfthenameofthedeclaredvariableisspecifiedonthePARM
parameterofthePGMcommandinthesameprograminwhichthe
variableisdeclared,aninitialvaluecannotbespecifiedforthe

variable.Inthatcase,thevariablereceivesitsvaluefromthecalling
program.
Table1.VariableLengths
Type

Maximum DefaultLength1
Length
Decimal 15digits,9 15digits,5decimalpositions
decimal
positions
Character 9999
32characters
characters2
Logical 1character 1character
1

Fordecimalandcharactertypes,thedefaultlengthisthesameasthelengthoftheinitial
value,ifoneisspecifiedintheVALUEparameter.
2

Theinitialvalue(specifiedontheVALUEparameter)ofaCLvariablecanbenogreaterthan
3000characters.

ExamplesforDCL
Example1:SpecifyingtheCLVariableLength
DCL&ABLE*DECLEN(52)

ThiscommanddeclaresaCLvariablenamed&ABLEthatcontainsa
decimalvalue.Thevaluecanneverbegreaterthan999.99becauseLEN
specifiesupto5digits,ofwhichtwoaretotherightofthedecimalpoint.
BecausetheVALUEparameterwasnotspecified,anditisanumericvalue,
&ABLEissettoavalueofzero(000.00).
Example2:SpecifyingaLogicalValue
DCL&SWITCH*LGL

ThiscommanddeclaresaCLvariablenamed&SWITCHtocontaina
logicalvalue.Becausethetypeparameterspecifieslogical,thevariableis
onecharacterlonganditissetto'0'.
Example3:SpecifyingInitialValueofCLVariable
DCL&FILNAM*CHARVALUE(FILEA)

ThiscommanddeclaresaCLvariablenamed&FILNAMwhosevalueis
FILEA.Becausethevaluecontains5charactersandtheLENparameterwas
notspecified,thelengthofthevariableisalso5characters.

ErrormessagesforDCL
None

You might also like