Compiling CL

209 Views


Compiling CL source program

A CL source program must be compiled before it can be run.

  • CRTCLPGM or CRTBNDCL: To create a CL program in one step, you can use the Create CL Program (CRTCLPGM) command or the Create Bound Control Language Program (CRTBNDCL) command, which create a bound program with one module.
  • CRTCLMOD & CRTPGM or CRTCLMOD & CRTSRVPGM: You can also create a CL module with the Create Control Language Module (CRTCLMOD) command. The module must then be bound into a program or service program using the Create Program (CRTPGM) or Create Service Program (CRTSRVPGM) command.
  • You can use the Include CL Source (INCLUDE) command to embed another source file during compilation.

The following example creates the module ORD040C and places it in library DSTPRODLB:

CRTCLMOD MODULE(DSTPRODLB/ORD040C) SRCFILE(QCLSRC) TEXT('Order dept general menu program')

The source commands for ORD040C are in the source file QCLSRC, and the source member name is ORD040C.

An other example creates the program IFSTEST and places it in library QGPL from an IFS stream source file:

CRTBNDCL PGM(QGPL/IFSTEST) SRCSTMF('/home/ifstest/ifstest.clp')

The source commands for IFSTEST are in the IFS stream source file /home/ifstest/ifstest.clp. By default, a compiler listing is created.

 

Setting create options in the CL source program

With the Declare Processing Options (DCLPRCOPT) command, you can set many of the same create option parameters that are on the CL compiler commands.

The CL compiler commands include Create CL Program (CRTCLPGM), Create CL Module (CRTCLMOD), and Create Bound CL Program (CRTBNDCL).

Values specified on the DCLPRCOPT command take precedence over any values specified on the CL compiler commands.

In addition, the DCLPRCOPT command supports the Binding directory (BNDDIR) and Binding service program (BNDSRVPGM) parameters that can be used when running the CRTBNDCL command.

The following examples show how the DCLPRCOPT command can be used:

Example: Declaring compiler options to override CRTCLPGM

DCLPRCOPT ALWRTVSRC(*NO) USRPRF(*OWNER)

This command overrides the Allow RTVCLSRC (ALWRTVSRC) and User profile (USRPRF) parameter values that are specified on the CRTCLPGM command. The resulting CL program does not allow the CL source code to be retrieved from the *PGM object. When the program object is called, it adopts the authorities of the user profile that owns the *PGM object.

Example: Declaring compiler options to override CRTCLMOD

DCLPRCOPT LOG(*NO) AUT(*USE)

This command overrides the Log commands (LOG) and Authority (AUT) parameter values that are specified on the CRTCLMOD command. When the resulting ILE CL module is bound into an ILE program or service program and the ILE CL procedure is called, CL commands that run from this procedure are not logged in the job log. The public authority for the *MODULE object that is created by the CRTCLMOD command is *USE.

Example: Declaring compiler options to override CRTBNDCL

DCLPRCOPT ALWRTVSRC(*NO) DFTACTGRP(*NO) ACTGRP(MYAPP) +
 BNDDIR(MYAPPLIB/MYBNDDIR)

This command overrides the Allow RTVCLSRC (ALWRTVSRC), Default activation group (DFTACTGRP), Activation group (ACTGRP), and Binding directory (BNDDIR) parameter values that are specified on the CRTBNDCL command. The resulting ILE CL program does not contain CL source that can be retrieved using the RTVCLSRC command. The program runs in the activation group named MYAPP. When the CRTPGM command is used to create the bound CL program, the CRTBNDCL command adds binding directory MYBNDDIR in library MYAPPLIB to the Binding directory (BNDDIR) parameter. In this way, the service programs and ILE modules that are referenced by that binding directory can be used to resolve ILE procedures used in the ILE CL program.

Examples:

0030.00              DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(QILE) 

      
0013.00              DCLPRCOPT  DFTACTGRP(*NO)  ACTGRP(*CALLER) 


0009.00              PGM        PARM(&LIB &FIL &MBR)          
0010.00              DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(*CALLER) 

   
0012.00              PGM                                           
0013.00              DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(QILE)        

 

Embedding CL commands from another source member

You can use the Include CL Source (INCLUDE) command to split your CL source code, so that the CL source code can be compiled across multiple source file members.

The CL source to be embedded can be located in another member of the same source file that is identified on the Source file (SRCFILE) parameter of the CL compiler commands or a different source file

0077.00              DCL        VAR(&DATET) TYPE(*CHAR) LEN(20)                      
0078.00 /* Include File Check Variables                                      */       
0079.00              INCLUDE    SRCMBR(TESTSRCMBR) SRCFILE(*LIBL/QCLSRC)               
0080.00                                                                               
0081.00              DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(QILE)                           
0082.00              RTVJOBA    TYPE(&JOBTYPE) DATETIME(&DATET)                      
0074.00 /* Include File Check Variables                                      */ 
0075.00              INCLUDE    SRCMBR(TESTVARMBR) SRCFILE(*LIBL/QCLSRC)         
0360.21 /* File Integrity check                                              */ 
0360.22              INCLUDE    SRCMBR(TESTFILE) SRCFILE(*LIBL/QCLSRC)        
0360.15              CALL   PGM(TESTPHM)               
0360.17              IF  COND(&OUTPVAL *NE ' ')  THEN(DO)                           
0360.18                  CHGVAR  VAR(&SNDEMAILF) VALUE(&OUTPVAL)                    
0360.19              ENDDO                                                          
0360.20                                                                             
0360.21 /* File Integrity check                                              */     
0360.22              INCLUDE    SRCMBR(TESTFILCHK) SRCFILE(*LIBL/QCLSRC)            
0360.23              GOTO       CMDLBL(ENDPGM)                                      
0360.56                                                                             
0360.57              INCLUDE    SRCMBR(TESTFILCH2) SRCFILE(*LIBL/QCLSRC)            
0360.58                                                                             
0360.59  ENDPGM:     ENDPGM                                                         

 

Logging CL program or procedure commands

You can specify that most CL commands that are run in a CL program or procedure be written (logged) to the job log.

To log CL commands, specify one of the following values on the LOG parameter on the Create Control Language Module (CRTCLMOD) command or the Create Bound Control Language Program (CRTBNDCL) command when the CL source program is compiled:

*JOB This default value indicates that logging is to occur when the job's logging option is on.

*YES This value indicates that logging is to occur each time the CL program or procedure is run. 

*NO This value indicates that no logging is to occur. 

If the CL program or procedure is running interactively, and the message level on the job's LOG parameter is set to 4, you can press F10 (Display detail messages) to view the logging of all commands.

Here we can see the loggings of all CL commands executed.

 

Retrieving CL source code

Depending on the CL compiler options used, you can retrieve the CL source code from a CL program or CL module object.

The CL program or CL module must have been created specifying *YES for the Allow RTVCLSRC (ALWRTVSRC) parameter.

The ability to retrieve the CL source from a CL program or CL module can make it easier to diagnose and fix problems in CL code on systems where the original CL source code is not available.

Retrieving CL source from a module in an ILE CL program

RTVCLSRC PGM(MYCLPGM) MODULE(MOD1) SRCFILE(MYLIB/QCLSRC)

This command retrieves the CL source from module MOD1 in ILE program MYCLPGM. The retrieved CL source is stored in member MOD1 of the source physical file QCLSRC located in library MYLIB.

CL module compiler listings

When you create a CL module, you can create various types of listings using the OPTION and OUTPUT parameters on the Create Control Language Module (CRTCLMOD) command.

The OPTION parameter values and their meanings are:

*GEN or *NOGEN Whether a module is to be created (*GEN is the default).

*XREF or *NOXREF Whether a listing of cross-references to variables and data references in the source input is to be produced (*XREF is the default).

The OUTPUT parameter values and their meanings are:

*PRINT - print listing

*NONE - no compiler listing

1 2 3
5722SS1 V5R3M0 041231 Control Language MYLIB/DUMPER SYSNAME 05/06/00 11:12:55 Page 1
Module . . . . . . . . . . . . . . . . . . . . : DUMPERR
Library . . . . . . . . . . . . . . . . . . : MYLIB
Source file . . . . . . . . . . . . . . . . . : QCLSRC
Library . . . . . . . . . . . . . . . . . . : MYLIB
Source member name . . . . . . . . . . . . . : DUMPERR 05/06/94 10:42:26 4
Source printing options . . . . . . . . . . . : *XREF *NOSECLVL *NOEVENTF
Module logging . . . . . . . . . . . . . . . : *JOB
Replace module object . . . . . . . . . . . . : *YES
Target release . . . . . . . . . . . . . . . : V5R3M0
Authority . . . . . . . . . . . . . . . . . . : *LIBCRTAUT
Sort sequence . . . . . . . . . . . . . . . . : *HEX
Language identifier . . . . . . . . . . . . . : *JOBRUN
Text . . . . . . . . . . . . . . . . . . . . : Test program
Optimization . . . . . . . . . . . . . . . . : *NONE
Debugging view . . . . . . . . . . . . . . . : *STMT
Enable performance collection . . . . . . . . : *PEP
Compiler . . . . . . . . . . . . . . . . . . : IBM i5/OS Control Language Compiler 5
6 Control Language Source
SEQNBR *...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8 ...+... 9 ...+. DATE 8
100- PGM 05/06/94
200- DCL &ABC *CHAR 10 VALUE(’THIS’) 05/06/94
300- DCL &XYZ *CHAR 10 VALUE(’THAT’) 7 05/06/94
400- DCL &MNO *CHAR 10 VALUE(’OTHER’) 05/06/94
500- CRTLIB LB(LARRY) 05/06/94
* CPD0043 30 Keyword LB not valid for this command. 9
600- DLTLIB LIB(MOE 05/06/94
* CPD0013 30 A matching parenthesis not found.
700- MONMSG CPF0000 EXEC(GOTO ERR) 05/06/94
800- ERROR: 05/06/94
900- CHGVAR &ABC ’ONE’ 05/06/94
1000- CHGVAR &XYZ ’TWO’ 05/06/94
1100- CHGVAR &MNO ’THREE’ 05/06/94
1200- DMPCLPGM 05/06/94
1300- ENDPGM 05/06/94
* * * * * E N D O F S O U R C E * * * * *
5722SS1 V5R3M0 040201 Control Language MYLIB/DUMPER SYSNAME 05/06/00 11:12:55 Page 2
Cross Reference
Declared Variables
Name Defined Type Length References
&ABC 200 *CHAR 10 900
&MNO 400 *CHAR 10 1100
10
&XYZ 300 *CHAR 10 1000
Defined Labels
Label Defined References 11
ERR ****** 700
* CPD0715 30 Label ’ERR ’ does not exist.
ERROR 800
* * * * * E N D O F C R O S S R E F E R E N C E * * * * *
5722SS1 V5R3M0 040201 Control Language MYLIB/DUMPER SYSNAME 05/06/04 11:12:55 Page 3
Message Summary
Severity
Total 0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80-89 90-99 12
3 0 0 0 3 0 0 0 0 0 0
Module DUMPERR not created in library MYLIB. Maximum error severity 30. 13
* * * * * E N D O F M E S S A G E S U M M A R Y * * * *

 

Common compilation errors

The types of errors that are detected at compile time include syntax errors, references to variables and labels not defined, and missing statements.

The following types of errors stop the program or module from being created (severity codes are ignored):

  • Value errors
  • Syntax errors
  • Errors related to dependencies between parameters within a command
  • Errors detected during validity checking

Even after an error that stops the program or procedure from being created is encountered, the compiler continues to check the source for errors. This lets you see and correct as many errors as possible before you try to create the module or program again.

Obtaining a CL dump

You can obtain a CL program or CL procedure dump while the CL program or CL procedure is running.

The CL dump consists of a listing of all messages on the program’s or procedure's message queue and the values of all variables used in the program or procedure. 

To obtain a CL dump, complete one of the following tasks:

. Run the Dump CL Program (DMPCLPGM) command. This command can only be used in a CL program or CL procedure and does not end the CL program or CL procedure

 

Displaying module attributes

Use the Display Module (DSPMOD) command to display the attributes of any module object, including a RPGILE, CL module.

DSPMOD TESTDA1

Displaying program attributes

To display the attributes of any program object, including a CL program, use the Display Program (DSPPGM) command.

DSPPGM TEST

Return code summary

A return code can be returned using the Return code (RTNCDE) parameter on the Retrieve Job Attributes (RTVJOBA) command.

The return code is a 5-digit decimal value with no decimal positions (12345. for example).

CL programs do not set the return code.

However, you can retrieve the current value of the return code as set by another program in a CL program. You can do this by using the RTNCDE parameter of the Retrieve Job Attributes (RTVJOBA) command.

 

Compiling source programs for a previous release

The CL compiler commands allow you to compile CL source programs to use on a previous release by using the Target release (TGTRLS) parameter.

The TGTRLS parameter specifies on which release of the IBM i operating system the CL program will be run.

You can specify *CURRENT, *PRV, or a specific release level.

A CL source program compiled with TGTRLS(*CURRENT) runs only on the current release or later releases of the operating system.

A CL source program compiled with a specified TGTRLS value other than *CURRENT can run on the specified release value and on later releases.

Post Comments