You are on page 1of 34

LAB: CL Track

Exercises

Tuesday, July 28
IBM Summer School 2009
IBM Power Systems: IBM i and AIX

Presented By James E. Buck


Gateway Technical College

CL and the Integrated Language Environment

User Profile IBMCLLABxx________ XX being your assigned number

Password __summer09________
Host Name _________________ This is written on the Board

Page 1 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Table of Contents
IBM Summer School 2009 ....................................................................................................................... 1
Starting Rational Developer for IBM I (RDi)........................................................................................... 3
Welcome Window .................................................................................................................................... 3
Create A Connection: ............................................................................................................................... 4
Connect to the IBM i system .................................................................................................................... 5
Check the contents of your Library .......................................................................................................... 6
Compile the Print file for this Lab............................................................................................................ 6
Convert RPG program to a RPG ILE Module.......................................................................................... 7
Copy the RPG program--------------------------------------------------------------------------7
Open the RPG Member SA2205 .............................................................................................................. 8
Delete the Old PLIST Code ---------------------------------------------------------------------9
Review the New Prototype and interface Code -----------------------------------------------9
Add the Prototype and Interface Code------------------------------------------------------- 10
Save the revised source member-------------------------------------------------------------- 11
Compile the revised source member as a MODULE.-------------------------------------- 12
Check the results of the Compile ------------------------------------------------------------- 12
Convert the CL program to a CL Module .............................................................................................. 13
Change the CALL to CALLPRC -------------------------------------------------------------- 13
Create the program object from the two modules .................................................................................. 14
Check the results of the Compile ------------------------------------------------------------- 15
RUN the CL Program ............................................................................................................................. 16

Page 2 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Starting Rational Developer for IBM I (RDi)

Start RDi by clicking on the desktop icon or select RDi from the start menu at the following
location – Start > Programs > IBM Software Delivery Platform > IBM Rational Developer for i >
Rational Developer for i.

When prompted for a workspace enter C:\SUMMER2009.

You will see the screen below next – If you haven’t taken the time to explore this screen you should!
Remember, this screen can always be seen by clicking on it from the “Help” entry on the toolbar.

Welcome Window

Page 3 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Create A Connection:
Close the Welcome window by clicking on the X in the Tab at the top left of the window.

The default perspective for RDi is the Remote System Explorer and your screen should look like the
one below. Notice the Window named “IBM i Remote System Explorer Getting Started.” This is an
invaluable resource for new users of RDi and you can restore this by clicking on “IBM i RSE Getting
Started” from the “Help” entry on the toolbar.

Right click the IBM i icon and you will be able to create a new connection as shown below.

In this example, the Host name is the one from Gateway


Technical College. For this lab you should use
____________________.

The Connection name can be anything but I usually make it


descriptive for the server that I’m connecting to.

Page 4 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Connect to the IBM i system
We have now created a connection and we need to login and set our Library list for this lab.

Expand the Objects icon on the connection we just created as


shown in the graphic on the right.

Expand the Library list icon as shown on the right. The login
window will be displayed as shown in the graphic a right. Enter
the profile IBMCLLABXX (Where XX is the number given to
you for this lab). The password is SUMMER09.

Page 5 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Check the contents of your Library
Note: Your library will be IBMCLLABXX where XX is the number assigned to you!

After you login, expand the icon Library list and your remote
Systems view should look like the graphic on the right. Below is
an explanation of the contents of the IBMCLLABXX Library
(XX should correspond to the number assigned to you).

GTCSTP – Physical file used by the RPG programs in this Lab.

QCLLESRC – CL Source members that you will work on in


this lab.

QCLLESRCC – Completed CL source code.

QCMDSRC - CMD Source members that you will work on in


this lab.

QCMDSRCC – Completed source code.

QDDSSRC – Print file source code for the RPG programs in this
lab. You will need to compile this member.

QRPGLESRC – RPG Source members that you will work on in


this lab.

QRPGLESRCC – Completed RPG source code.

Compile the Print file for this Lab


Create the Print file used by the RPG programs in this lab. Expand QDDSSRC and Right-Click the
LISTGTCSTP source member as shown and select CRTPRTF.

Page 6 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Convert RPG program to a RPG ILE Module
The program SA2205OPM is a report program that uses a PLIST to accept a fifteen character
parameter (LastNameParm) and then uses SQL to produce a report. This section of the lab will show
you how to change the PLIST to a Prototype to accept the LastNameParm parameter and then make
the needed changes to change the program to a module with one callable procedure for the CL
program.

Copy the RPG program


Right-Click and copy the program SA2205OPM as shown in the
graphic on the right.

Right-Click the QRPGLESRC library as show in the graphic on the


right and click Paste.

You will see a window similar to the window below. Select rename and rename the member SA2250
as shown.

Page 7 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Finally you will see the window below. Click OK and you have created a copy of the original member.

Open the RPG Member SA2205


Right-Click the member SA2205 and open it as shown in the graphic below.

Now we will add the Prototype, Procedure interface and the Procedure Boundary Specifications.

Page 8 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Delete the Old PLIST Code
Navigate to the code shown below and highlight it. You can cut the code like you would if you were
using Word or you could delete the block of code using the traditional SEU commands – DD.

Review the New Prototype and interface Code

Page 9 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Add the Prototype and Interface Code
We will need to add the code shown on the previous page to this member. There are a number of areas
we need to add code and each area is described below. If you have problems adding the code; F4 will
give you a format line as shown in the second graphic.

1. H-Spec – Add H nomain


2. Prototype – This is used in by the compiler to insure that the correct program is called and the
correct parameters are passed.
3. Procedure boundary Specification – This is used to define the start and end of the program.
4. Procedure Interface - Similar to the Prototype but actually defines the variables used in the
procedure.
5. Comment out the LR indicator and add the Close statement.

Since this module will not have a main; we will add the H-Spec shown below.

Add the code to check and see if the output file is closed. If it is open it.

Page 10 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
We also don’t need the *inlr = *on, but we do need to manually close the output file.

At the bottom of the source member, add the ending Procedure Boundary Specification as shown
below.

Save the revised source member


Click on the Save icon on the top left corner of the IDE (or do a Ctrl+S).

Page 11 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Compile the revised source member as a MODULE.
Right-Click the member in the Remote Explorer Window and select Compile [Prompt]

The window shown below will open – In the dropdown box select “Compile Type” = *Module and
then click OK.

Check the results of the Compile


Check Command Log window shown below. Notice that the message Module SA2205 was
successfully created in library IBMCLLAB… is displayed.
Page 12 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Convert the CL program to a CL Module
We need to change the code that called the old RPG program from a CALL to a CALLPRC.

Change the CALL to CALLPRC

/* Call the Listing program and pass the Last name parameter */
CALL PGM(SA2205) PARM(&lastname)
to this

/* Call the call The RPG Procedure */


CALLPRC PRC('ListGTCSTPPgm') PARM(&lastname)

Save the source member by clicking on the Save icon on the top left corner of the IDE (or do a Ctrl+S).
Right-Click the member in the Remote Explorer Window and select Compile (CRTCLMOD) as shown
below.

Page 13 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
Create the program object from the two modules
You have now created the CL and the RPG modules; the next step is to Bind them into an executable
program object.

The first step is to navigate back to the Remote System window as shown in the graphic below. It is
often a good idea to Right-Click the library and select Refresh. This will refresh the contents of the
window.

Select and Right-Click the CL module that you have created and select Create > program as shown in
the graphic below.

Page 14 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
You will be presented with the window shown below. This is the step where you bind the two modules
together and create an executable program.

Check the results of the Compile


You can check to see that the program was created by looking at the Command Log window as shown
below.

Page 15 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
RUN the CL Program
You can now login to the system and run the CL program as shown below. Note to have the report
show any records you need JOHNSON in caps.

The output from your completed program should look like the screen below.

Page 16 of 16
© Copyright 2009 – James E. Buck
CL and The Integrated Language Enviroment Lab.doc
IBM Summer School 2009
IBM Power Systems: IBM i and AIX

Presented By James E. Buck


Gateway Technical College

Creating Commands, CPP’s and VCP’s Lab

User Profile IBMCLLABxx________ XX being your assigned number

Password __summer09________
Host Name _________________ This is written on the Board

Page 1 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Table of Contents
IBM Summer School 2009 ....................................................................................................................... 1
Starting Rational Developer for IBM I (RDi)........................................................................................... 3
Welcome Window .................................................................................................................................... 3
Create A Connection: ............................................................................................................................... 4
Connect to the IBM i system .................................................................................................................... 5
Check the contents of your Library .......................................................................................................... 6
Compile the Print file and the RPG Program required for this lab. -----------------------6
Code the Command .................................................................................................................................. 7
Create the Command-----------------------------------------------------------------------------8
Check the results of the CRTCMD in the Commands Log window. -----------------------9
Run the command from the 5250command line.----------------------------------------------9
Code the Command Processing Program (CPP) ...................................................................................... 9
Create the Command Processing Program (CPP)----------------------------------------- 10
Recreate the RUNPDATRPT command.----------------------------------------------------- 11
Review and Test the Validity Checking Program (VCP)....................................................................... 12
Review the code in the current SA2305VCP ------------------------------------------------ 12
Compile the CL program SA2305VCP ------------------------------------------------------ 12
Change the RUNPDATRPT command------------------------------------------------------- 13
Run the RUNPDATRPT command ----------------------------------------------------------- 14
Change the SA2305VCP CL program.................................................................................................... 15
Change the Error Handling Segment -------------------------------------------------------- 15
Compile the CL program SA2305VCP ------------------------------------------------------ 16
Run the RUNPDATRPT command with the new VCP ------------------------------------- 16

Page 2 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Starting Rational Developer for IBM I (RDi)

Start RDi by clicking on the desktop icon or select RDi from the start menu at the following
location – Start > Programs > IBM Software Delivery Platform > IBM Rational Developer for i >
Rational Developer for i.

When prompted for a workspace enter C:\SUMMER2009.

You will see the screen below next – If you haven’t taken the time to explore this screen you should!
Remember, this screen can always be seen by clicking on it from the “Help” entry on the toolbar.

Welcome Window

Page 3 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Create A Connection:
Close the Welcome window by clicking on the X in the Tab at the top left of the window.

The default perspective for RDi is the Remote System Explorer and your screen should look like the
one below. Notice the Window named “IBM i Remote System Explorer Getting Started.” This is an
invaluable resource for new users of RDi and you can restore this by clicking on “IBM i RSE Getting
Started” from the “Help” entry on the toolbar.

Right click the IBM i icon and you will be able to create a new connection as shown below.

In this example, the Host name is the one from Gateway


Technical College. For this lab you should use
____________________.

The Connection name can be anything but I usually make


it descriptive for the server that I’m connecting to.

Page 4 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Connect to the IBM i system
We have now created a connection and we need to login and set our Library list for this lab.

Expand the Objects icon on the connection we just created as


shown in the graphic on the right.

Expand the Library list icon as shown on the right. The login
window will be displayed as shown in the graphic a right. Enter
the profile IBMCLLABXX (Where XX is the number given to
you for this lab). The password is SUMMER09.

Page 5 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Check the contents of your Library
Note: Your library will be IBMCLLABXX where XX is the number assigned to you!

After you login, expand the icon Library list and your
remote Systems view should look like the graphic on
the right. Below id an explanation of the contents of
the IBMCLLABXX Library (XX should correspond to
the number assigned to you).

GTCSTP – Physical file used by the RPG programs in


this Lab.

QCLLESRC – CL Source members that you will


work on in this lab.

QCLLESRCC – Completed CL source code.

QCMDSRC - CMD Source members that you will


work on in this lab.

QCMDSRCC – Completed source code.

QDDSSRC – Print file for the RPG programs in this


lab. You will need to compile this member.

QRPGLESRC – RPG Source members that you will


work on in this lab.

QRPGLESRCC – Completed RPG source code.

Compile the Print file and the RPG Program required for this lab.

Expand QDDSSRC and Right-Click LISTGTCSTP then select Compile > CRTPRTF.

Expand QRPGLESRC and Right-Click SA2305RPT select Compile > CRTSQLRPGI.

Page 6 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Code the Command
The first step is to create the command. Open the source member SA2305CMD in the source file
QCMDSRC and key in the following code. Remember, you can always press F4 to have RDi prompt
the statement.

/* Displays the Command Heading */


CMD PROMPT('Customer Pay Date Report')

The following KWD names the parameter, TYPE is a character field, MIN makes is a required field
and PROMPT describes the prompt displayed.

/* Prompts for the First Date */


PARM KWD(SDATE) TYPE(*char) LEN(8) MIN(1) +
PROMPT('Enter Start Date YYYYMMDD')

The following KWD names the parameter, TYPE is a character field, MIN makes is a required field
and PROMPT describes the prompt displayed.
/* Prompts for the Second Date */
PARM KWD(eDATE) TYPE(*CHAR) LEN(8) MIN(1) PROMPT('Enter +
End Date YYYYMMDD')

The following KWD names the parameter, TYPE is a character field, LEN(1) sets the length to one,
RSTD restricts the values entered to the values listed in the VALUES keyword, DFT sets the default
value and PROMPT describes the prompt displayed.
/* Prompts and Validates the Batch Variable */
PARM KWD(BATCH) TYPE(*CHAR) LEN(1) RSTD(*YES) DFT(Y) +
VALUES(Y N) PROMPT('Submit to Batch (Y/N)')

Your final code should look similar to the graphic below.

Save the source member by clicking on the Save icon on the top left corner of the IDE (or do a Ctrl+S).
Page 7 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Create the Command
Create the command using Compile [Prompt] as shown in the graphic below.

You will see the window shown below. Change the command name to RUNPDATRPT and click OK.

Page 8 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Check the results of the CRTCMD in the Commands Log window.

Run the command from the 5250command line.


The command will execute but you will receive an error that it couldn’t find the CPP.

Code the Command Processing Program (CPP)


Open the member SA2305CPP in the source file QCLLESRC as shown in the graphic below.

Add the code below to the member. This code checks the &BATCH parameter and either runs the
program SA2305RPT interactively or submits it to batch.

/* Check to see if they want to run it in batch */


IF COND(&BATCH *EQ 'Y') THEN(DO)
SBMJOB CMD(CALL PGM(*LIBL/SA2305RPT) PARM(&STARTDATE &ENDDATE))
ENDDO
ELSE CMD(CALL (*LIBL/SA2305RPT) PARM(&STARTDATE &ENDDATE))

Page 9 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
The completed code should look similar to the code below.

Create the Command Processing Program (CPP)


Create the CPP as shown below.

Do not forget to check the outcome of the compile in the Commands Log window.

Page 10 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Recreate the RUNPDATRPT command.
This time we will include the 2305CPP program. Make the changes shown and click OK. Do not
forget to check the outcome of the compile in the Commands Log window.

Run the command from the 5250 command line. Did you get a report? What happens to the report if
you enter an invalid date?

Page 11 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Review and Test the Validity Checking Program (VCP)
Open the member SA2305VCP in the source file QCLLESRC as shown in the graphic below.

Review the code in the current SA2305VCP


The current program has to CVTDAT commands and a MONMSG for each command. The
MONMSG command checks for all of the possible errors and goes to a standard error handling
routine. This routine sends a message in the event of an error.

Compile the CL program SA2305VCP


Compile the program as shown in the graphic below.

Page 12 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Change the RUNPDATRPT command
You can also change a command that you have
already created. Right-Click the command from the
Remote Systems Explorer window and select Change
as shown in the graphic on the right.

The graphic below shows the CHGCMD and all of the changes you can make. Add the SA2305VCP
program you recently compiled and click OK.

Page 13 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Run the RUNPDATRPT command
From the 5250 command line run the command and use an invalid date as shown below.

What Happened? The program ABENDS with a CPF0555 Function check. This wouldn’t be good for
an interactive program. We’ll fix this in the next few pages.

Page 14 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Change the SA2305VCP CL program
Modify the Error Handling Segment to send a message to the users screen without ending the
command that is running. This will allow the user to change invalid input without exiting the
command.

The error flag &errflg will tell us where the error occurred.

Add the code in RED to the Declarations section of the member SA2305VCP.

DCL &msgdta *CHAR 100


DCL &errflg *CHAR 5 /* Used to decide what error occured */
DCL VAR(&startdate) TYPE(*CHAR) LEN(8)

Add the code in RED to the Procedure section of the member SA2305VCP.

/* Check the Start Date */


CHGVAR &errflg 'start'
CVTDAT DATE(&STARTDATE) TOVAR(&STARTCVT) FROMFMT(*YYMD) +

/* Check the end date */


CHGVAR &errflg 'end '
CVTDAT DATE(&ENDDATE) TOVAR(&ENDCVT) FROMFMT(*YYMD) +

Change the Error Handling Segment


The new code will check to see which conversion failed and send the appropriate message to the users
screen. Change the Error Handling Segment so that the code matched the code below. For this to work
the error message (MSGDTA) must be preceded by four character type zero’s ‘0000’ and the
SNDPGMMSG CPF0002 is required.

/* ----------------------------------- Error Handling Segment */


ERROR: RCVMSG MSGTYPE(*LAST) MSGDTA(&msgdta) MSGID(&msgid) MSGF(&msgf) +
SNDMSGFLIB(&msgflib)
SELECT
WHEN (&errflg *eq 'start') SNDPGMMSG MSGID(CPD0006) MSGF(&msgflib/&msgf) +
MSGDTA('0000 Start Date Invalid') MSGTYPE(*DIAG)
WHEN (&errflg *eq 'end ') SNDPGMMSG MSGID(CPD0006) MSGF(&msgflib/&msgf) +
MSGDTA('0000 End Date Invalid') MSGTYPE(*DIAG)
ENDSELECT
/* Send a CPF0002 to the calling command */
SNDPGMMSG MSGID(CPF0002) MSGF(&msgflib/&msgf) MSGDTA(&msgdta) MSGTYPE(*ESCAPE)

END: ENDPGM

Page 15 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc
Compile the CL program SA2305VCP
This was shown previously. Be sure to check the Commands Log for the results of the compile.

You will not need to change the command it will run the NEW version of the Validity Checking
Program.

Run the RUNPDATRPT command with the new VCP

Notice that the Message “Start Date Invalid” now shows the field in error and the program will not
continue till the problem is resolved. The VCP is called each time the user hits the enter key.

Page 16 of 16
© Copyright 2009 – James E. Buck
Creating Commands CPPs & VCPs Lab.doc

You might also like