Clean Control Language Source Code
For CLLE and CLP programs this basically means that we can use the CLNCLSRC command to look through our Control Language Source code and spiff up the source layout by doing things like –
- switching all the code to lower case
- or (of course) switching it to upper case
- re-parsing each command line and making it cleaner to read
- indent all DO/ENDO loops
- tell us if we have any missing ENDO statements
Here is a quick example of some code before and after cleaning:
UGLY CODE
/* this is an ugly example of some dodgy CL Code */
PGM PARM(&curhotfix &library &linefailed)
COPyRiGhT text('| HOTFIX733 2017.07.31')
DCL VAR(&CURHOTFIX) +
TYPE(*CHAR) +
LEN(10)
dcl var(&library) type(*char) len(10)
dcl var(&linefailed) type(*lgl) len(1)
MONMSG MSGID(CPF0000) +
EXEC(GOTO CMDLBL(UNMONERROR))
CHGVAR VAR(&LINEFAILED) VALUE('0')
CHKOBJ OBJ(&LIBRARY/RLL11) +
OBJTYPE(*FILE)
monmsg cpf0000 +
exec(do)
CRTDUPOBJ OBJ(RLL11) +
FROMLIB(&curhotfix) +
OBJTYPE(*FILE) +
TOLIB(&library) TRG(*NO)
enddo
call pgm(tmovrll11) +
parm(&curhotfix &library)
return
unmonerror: +
chgvar var(&linefailed) value('1')
endpgm
Run the CLEAN CL SRC (CLNCLSRC) command
CLNCLSRC SRCMBR(MBR)
SRCFILE(QCLLESRC)
CVTCASE(*LOWER)
INDCMTS(*NO)
OUTPUT(*SRCMBR)
ARCHIVE(*NO)
STRCOL(13)
INDCOL(3)
INDCONT(3)
and end up with:
CLEANED CL CODE
Or more accurately – it’s still UGLY but at least its CLEAN CODE
/* this is an ugly example of some dodgy CL Code */
pgm parm(&curhotfix &library &linefailed)
copyright text('| HOTFIX733 2017.07.31')
dcl var(&curhotfix) type(*char) len(10)
dcl var(&library) type(*char) len(10)
dcl var(&linefailed) type(*lgl) len(1)
monmsg msgid(cpf0000) exec(goto cmdlbl(unmonerror))
chgvar var(&linefailed) value('0')
chkobj obj(&library/rll11) objtype(*file)
monmsg cpf0000 exec(do)
crtdupobj obj(rll11) fromlib(&curhotfix) objtype(*file) +
tolib(&library) trg(*no)
enddo
call pgm(tmovrll11) parm(&curhotfix &library)
return
unmonerror: +
chgvar var(&linefailed) value('1')
endpgm
Cleaner and more readable!

