13
Wed, Nov
5 New Articles

Moving to ILE CL

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
I'm often asked what the differences are between regular CL and ILE CL and how to convert CL to ILE CL.

The CL for OS/400 is often called "command language" but its official name, perhaps showing its age, is "control language." It is, however, unlike any job control language of those legacy operating systems. CL was developed long after JCL and OCL and is a compiled language with program variables, error messages, and limited structured programming constructs, such as IF/THEN/ELSE and DO. Soon, IBM will introduce an incredible number of long overdue enhancements to CL.

CL has been around so long that most AS/400 and iSeries programmers know it like the back of their hand. So when IBM quietly introduced ILE CL six or seven years ago, most developers easily overlooked it. ILE CL--or more properly, CL for ILE--is simply a version of the CL compiler that targets the Integrated Language Environment.

Few enhancements were incorporated into the language in conjunction with the new compiler. IBM did the minimum necessary to get the compiler to be compatible. Even then, however, a few minor enhancements were required. It is these enhancements that allow CL for ILE to work effectively with your RPG IV and COBOL programs for ILE.

ILE Program Model

The CL compiler supports the ILE program model. This means that the CL compiler is a two-phase compiler (just like RPG IV). Phase I compiles the CL code, producing a *MODULE object. Phase II binds the CL module (possibly with other modules) and generates a *PGM object. Like RPG, COBOL, and CL, there is also a one-step compiler command (CRTBNDCL) that compiles the source into a *MODULE, storing it in QTEMP, then binds the module, producing a *PGM program--all by using option 14 on the PDM menu.

As with other ILE languages, a CL *MODULE object may be bound together with other non-CL ILE modules to create a program. For example, if an RPG IV program needs to run a few CL commands, just create an ILE CL source member that runs those CL commands, compile the CL source into a *MODULE, then bind that module with the RPG IV *MODULE object, creating a single program object.

Converting to ILE CL

As with most ILE languages, a new SEU attribute or source type has been introduced with CL for ILE. It is "CLLE." In fact, changing the old CLP source type to CLLE is all you need to do to convert an existing CL source member into an ILE CL source member.

The CL Compilers

And, as with the other ILE languages, PDM options 14 and 15 recognize this source type and evoke the necessary compilers. If PDM option 14 is selected on a source member whose source type is CLLE, the CRTBNDCL command is evoked, whereas a source type of CLP evokes the CRTCLPGM command. If PDM option 15 is selected for a source type of CLLE, the CRTCLMOD command is evoked. Option 15 is not allowed for source members with a source type of CLP.

The CRTCLMOD command compiles the CLLE source code and generates a *MODULE object. *MODULE objects, as you may know, cannot be called, but are used as input by the second phase of the compiler to produce program or service program objects.

The CRTPGM command uses one or more *MODULE objects and generates a *PGM program. The *MODULE objects may be from any ILE programming language: CLLE, RPGLE, C, etc.

The CRTSRVPGM command also uses one or more *MODULE objects as input but generates a *SRVPGM object. Although there is nothing wrong with doing so, it is rare that you use CL in a service program.

The CRTBNDCL command simplifies the CL program creation process by allowing a CLLE source member to be compiled to a *MODULE object then bound into a *PGM object. This one-step compiler command is tied into PDM option 14. This command, along with CRTBNDRPG, CRTBNDC, and CRTBNDCBL were created to provide a level of compatibility with the original CRTxxxPGM compiler (one source member to one program) commands.

So the steps in compiling a CL "program" can be as easy as PDM option 14 or as complex as the following:

CRTCLMOD MODULE(MYCLMOD1) SRCFILE(QCLSRC) DBGVIEW(*SOURCE) 
CRTCLMOD MODULE(MYCLMOD2) SRCFILE(QCLSRC) DBGVIEW(*SOURCE)
CRTRPGMOD MODULE(MYRPGMOD3) SRCFILE(QRPGLESRC) DBGVIEW(*SOURCE)
CRTPGM PGM(MYPGM) MODULE(MYCLMOD1 MYCLMOD2 MYRPGMOD3) ACTGRP(QILE)

CL "programs" may be made up of modules from any ILE-based language; therefore, a program is really an ILE program, not a CL program. In the example above, I'm creating a *PGM object from two CL *MODULE objects and one RPG *MODULE object.

Language Syntax

The CL for ILE language syntax included few enhancements from the original CL compiler language. The most notable is the addition of the CALLPRC (call procedure) statement. CALLPRC allows you to call a procedure written in any ILE language. This means that any procedure written in RPG IV (or C for that matter) may be called using the CALLPRC statement.

The CALLPRC command is used just like the original CALL command; however, only bound-in procedures may be called with CALLPRC. In addition, CALLPRC includes the RTNVAL parameter. This parameter receives the return value from a procedure.

Unfortunately, CL for ILE does not include any additional data types. So character, decimal, and logical are the only data types that may be used. This can present a problem when calling procedures. If a procedure expects a parameter value in integer format ('I' data type in RPG IV), it must be passed as a character value and wrapped in the %BIN built-in function. For example:

0001         DCL        VAR(&COUNT) TYPE(*DEC) LEN(10) VALUE(6)
0002         DCL        VAR(&COUNTB) TYPE(*CHAR) LEN(4)
0003         CHARVAR    VAR(%BIN(COUNTB)) VALUE(&COUNT)
0004         CALLPRC    PRC(MYPROC) PARM(%BIN(&COUNTB))

On lines 1 and 2, two CL variables are declared. The first one is &COUNT, which is a 10-digit numeric value. The second one is &COUNTB, which is a 4-position character field. In order to copy the numeric value from &COUNT into &COUNTB as an integer value, the %BIN built-in function is used (line 3) with the CHGVAR command. If %BIN were not used, then the value of &COUNT would be copied into &COUNTB as a character value. So without %BIN, the value X'F0F0F0F6' would be copied to &COUNTB--instead of X'00000006', which is what is needed to represent the integer value.

Line 4 is the procedure call. Here, the &COUNTB variable is passed to the MYPROC procedure. Note that even though %BIN is used on line 3, it is again required on line 4 to represent the value in &COUNTB as a binary value.

The data types, *CHAR and *DEC, may be passed normally. Remember that *DEC is packed decimal format, not zoned numeric.

A Simple Example

I want to illustrate how to mix RPG IV and CL together to enhance CL with RPG-like functions. The example I chose answers a question I get a lot: "How do I get the day of the week from a CL date?" Answer: Use RPG IV.

Listed below, in Figure 1, is the CLLE source code for a CL module named MDTEST1.

0001 MDTEST1:     PGM
0002              DCL        VAR(&JOBDATE) TYPE(*CHAR) LEN(7)
0003              DCL        VAR(&ISODATE) TYPE(*CHAR) LEN(10)
0004              DCL        VAR(&DAYOFWEEK) TYPE(*DEC) LEN(3 0)
0005              DCL        VAR(&FAKEBIN) TYPE(*CHAR) LEN(2) VALUE(X'0000')
0006              DCL        VAR(&DAY) TYPE(*CHAR) LEN(1)

0007              RTVJOBA    CYMDDATE(&JOBDATE)
0008              CVTDAT     DATE(&JOBDATE) TOVAR(&ISODATE) +
0009                           FROMFMT(*CYMD) TOFMT(*ISO) TOSEP('-')
0010              CALLPRC    PRC(GETDAYOFWEEK) PARM(&JOBDATE) +
0011                           RTNVAL(%BIN(&FAKEBIN))
0012              CHGVAR     VAR(&DAYOFWEEK) VALUE(%BIN(&FAKEBIN))
0013              CHGVAR     VAR(&DAY) VALUE(&DAYOFWEEK)
0014              SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) +
0015                           MSGDTA('Date:' *BCAT &ISODATE *BCAT +
0016                           'is day' *BCAT &Day) MSGTYPE(*COMP)
0017  ENDPGM:     ENDPGM

Figure 1: CLLE Source Calling a Procedure (MDTEST1)

The CL source member listed in Figure 1 has one goal in life: to retrieve the job date and then calculate the day of the week. To do this, it retrieves the current job date, using RTVJOBA (line 7). Then, the job date is converted from *CYMD format to *ISO format (lines 8 and 9). This *ISO date is used to format a status message that is sent to the end user on lines 14 to 16.

To calculate the day of the week, rather than build a CL routine or call a command that I may not know about, I chose (for example purposes) to call a procedure written in RPG IV. The GetDayOfWeek procedure is called on lines 10 and 11. It accepts a character input value in *CYMD format. *CYMD, in case you haven't used it before, is the CL date format used in CL commands when sending date values to CL and RPG programs.

On line 11 the RTNVAL keyword is used to accept the integer return value. This value will represent the day of the week as a number. Since the return value is a "short" integer value, it is 2 bytes in length. Using %BIN(&COUNTB) ensures that the return value will be stored as a properly formatted "binary" value in the &COUNTB field.

On line 12, the returned value is converted into a decimal value by copying it with the CHGVAR command, again using %BIN in the VALUE parameter. In this case, the target variable is the decimal variable named &DAYOFWEEK.

Since we want to send a completion message to the end user, we need to use the day of the week in a concatenated string. Therefore, we cannot use it in numeric form. So on line 13, we convert the decimal value to character. Then finally, on lines 14 to 16, we build and send a completion messages to the end user.

The source for the GETDAYOFWEEK procedure is listed Figure 2.

     H NOMAIN
      ** Calculate day of week from a CL format date
     D GetDayOfWeek    PR             5I 0
     D   cymdDate                     7A   CONST

     P GetDayOfWeek    B                   Export
      ** GETDAYOFWEEK
     D GetDayOfWeek    PI             5I 0
     D   cymdDate                     7A   CONST
     D BaseDate        S               D   DATFMT(*ISO) INZ(D'1582-10-14')
     D Days            S             10I 0
     D DayofWeek       S             10I 0
     D InputDate       S               D   DATFMT(*ISO)
     C     *CYMD0        TEST(DE)                cymdDate
     C                   If        %ERROR
     C                   return    0
     C                   endif
     C     *CYMD0        MOVE      cymdDate      InputDate
     C     Inputdate     SubDur    BaseDate      Days:*Days
     C                   CALLB     'CEEDYWK'
     C                   PARM                    Days
     C                   PARM                    DayofWeek
     C                   Return    DayOfWeek
     P GetDayOfWeek    E

Figure 2: RPG IV Procedure Source Called from CL

Note that there is only one procedure in the RPG IV source member and that its procedure is exported.

To compile the CL source in Figure 1 and the RPG IV source from Figure 2, use the following commands:

CRTCLMOD MODULE(MDTEST1) SRCFILE(QCLSRC) DBGVIEW(*SOURCE) 
CRTRPGMOD MODULE(MDTEST2) SRCFILE(QRPGLESRC) DBGVIEW(*SOURCE)
CRTPGM PGM(MDTEST) MODULE(MDTEST1 MDTEST2) ACTGRP(QILE)

Note that since we didn't use the ENTMOD (entry module) keyword on the CRTPGM command, it defaulted to MDTEST1--that is, ENTMOD(*FIRST). That way, the CL module is what is loaded when the program is called.

I hope this helps clear up migration to ILE CL from traditional CL programs. Moving to ILE CL is important for file overrides and scoping. To use the advanced features in RPG IV (such as procedures), you need to compile RPG source members such that they do not run in the default activation group. Consequently, you also need to move any supporting CL programs to CL for ILE. Otherwise, all kinds of override issues and scoping problems could arise.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: