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

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

When prompted for a workspace enter C:\SUMMER2009. Buck CL and The Integrated Language Enviroment Lab.doc .Starting Rational Developer for IBM I (RDi) or select RDi from the start menu at the following Start RDi by clicking on the desktop icon location – Start > Programs > IBM Software Delivery Platform > IBM Rational Developer for i > Rational Developer for i. 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.

Create A Connection: Close the Welcome window by clicking on the X in the Tab at the top left of the window. Buck CL and The Integrated Language Enviroment Lab. The Connection name can be anything but I usually make it descriptive for the server that I’m connecting to. The default perspective for RDi is the Remote System Explorer and your screen should look like the one below. In this example.” 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. the Host name is the one from Gateway Technical College. For this lab you should use ____________________. Notice the Window named “IBM i Remote System Explorer Getting Started. Page 4 of 16 © Copyright 2009 – James E.doc .

Expand the Library list icon as shown on the right. Enter the profile IBMCLLABXX (Where XX is the number given to you for this lab). The password is SUMMER09. Expand the Objects icon on the connection we just created as shown in the graphic on the right.doc . The login window will be displayed as shown in the graphic a right. Page 5 of 16 © Copyright 2009 – James E.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. 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. Buck CL and The Integrated Language Enviroment Lab. QCLLESRC – CL Source members that you will work on in this lab. QCMDSRC . Expand QDDSSRC and Right-Click the LISTGTCSTP source member as shown and select CRTPRTF. QRPGLESRC – RPG Source members that you will work on in this lab. expand the icon Library list and your remote Systems view should look like the graphic on the right. QCLLESRCC – Completed CL source code. GTCSTP – Physical file used by the RPG programs in this Lab. QRPGLESRCC – Completed RPG source code. You will need to compile this member. Below is an explanation of the contents of the IBMCLLABXX Library (XX should correspond to the number assigned to you). Page 6 of 16 © Copyright 2009 – James E. QDDSSRC – Print file source code for the RPG programs in this lab. QCMDSRCC – Completed source code.CMD Source members that you will work on in this lab. Compile the Print file for this Lab Create the Print file used by the RPG programs in this lab.

Select rename and rename the member SA2250 as shown.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. Buck CL and The Integrated Language Enviroment Lab. Copy the RPG program Right-Click and copy the program SA2205OPM as shown in the graphic on the right. You will see a window similar to the window below. Right-Click the QRPGLESRC library as show in the graphic on the right and click Paste.doc . Page 7 of 16 © Copyright 2009 – James E.

Procedure interface and the Procedure Boundary Specifications.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. Buck CL and The Integrated Language Enviroment Lab. Page 8 of 16 © Copyright 2009 – James E.doc .

doc . 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. Buck CL and The Integrated Language Enviroment Lab.Delete the Old PLIST Code Navigate to the code shown below and highlight it. Review the New Prototype and interface Code Page 9 of 16 © Copyright 2009 – James E.

H-Spec – Add H nomain 2. If it is open it. 3.Similar to the Prototype but actually defines the variables used in the procedure. 5. Add the code to check and see if the output file is closed. F4 will give you a format line as shown in the second graphic. Since this module will not have a main. There are a number of areas we need to add code and each area is described below. Page 10 of 16 © Copyright 2009 – James E. we will add the H-Spec shown below.doc . Buck CL and The Integrated Language Enviroment Lab. Comment out the LR indicator and add the Close statement. Procedure boundary Specification – This is used to define the start and end of the program. 1. If you have problems adding the code. Prototype – This is used in by the compiler to insure that the correct program is called and the correct parameters are passed. Procedure Interface . 4.Add the Prototype and Interface Code We will need to add the code shown on the previous page to this member.

Page 11 of 16 © Copyright 2009 – James E.We also don’t need the *inlr = *on.doc . but we do need to manually close the output file. Buck CL and The Integrated Language Enviroment Lab. Save the revised source member Click on the Save icon on the top left corner of the IDE (or do a Ctrl+S). At the bottom of the source member. add the ending Procedure Boundary Specification as shown below.

Notice that the message Module SA2205 was successfully created in library IBMCLLAB… is displayed. Buck CL and The Integrated Language Enviroment Lab. Check the results of the Compile Check Command Log window shown below. 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. Page 12 of 16 © Copyright 2009 – James E.Compile the revised source member as a MODULE.doc .

doc . Buck CL and The Integrated Language Enviroment Lab. Page 13 of 16 © Copyright 2009 – James E. 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.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.

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. Page 14 of 16 © Copyright 2009 – James E. It is often a good idea to Right-Click the library and select Refresh.doc . The first step is to navigate back to the Remote System window as shown in the graphic below. This will refresh the contents of the window. Buck CL and The Integrated Language Enviroment Lab. Select and Right-Click the CL module that you have created and select Create > program as shown in the graphic below.

Page 15 of 16 © Copyright 2009 – James E.doc . Buck CL and The Integrated Language Enviroment Lab. 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.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.

Page 16 of 16 © Copyright 2009 – James E. Buck CL and The Integrated Language Enviroment Lab. 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.RUN the CL Program You can now login to the system and run the CL program as shown below.doc .

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 Gateway Technical College Creating Commands. Buck Creating Commands CPPs & VCPs Lab.IBM Summer School 2009 IBM Power Systems: IBM i and AIX Presented By James E.doc .

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

Starting Rational Developer for IBM I (RDi) or select RDi from the start menu at the following Start RDi by clicking on the desktop icon location – Start > Programs > IBM Software Delivery Platform > IBM Rational Developer for i > Rational Developer for i. You will see the screen below next – If you haven’t taken the time to explore this screen you should! Remember. When prompted for a workspace enter C:\SUMMER2009.doc . Buck Creating Commands CPPs & VCPs Lab. 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.

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. In this example. Buck Creating Commands CPPs & VCPs Lab. The Connection name can be anything but I usually make it descriptive for the server that I’m connecting to. Right click the IBM i icon and you will be able to create a new connection as shown below. Page 4 of 16 © Copyright 2009 – James E.doc .Create A Connection: Close the Welcome window by clicking on the X in the Tab at the top left of the window. the Host name is the one from Gateway Technical College.” 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. For this lab you should use ____________________.

Page 5 of 16 © Copyright 2009 – James E. Enter the profile IBMCLLABXX (Where XX is the number given to you for this lab). The login window will be displayed as shown in the graphic a right. Expand the Library list icon as shown on the right.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. Buck Creating Commands CPPs & VCPs Lab. The password is SUMMER09. Expand the Objects icon on the connection we just created as shown in the graphic on the right.doc .

QRPGLESRC – RPG Source members that you will work on in this lab. Page 6 of 16 © Copyright 2009 – James E. expand the icon Library list and your remote Systems view should look like the graphic on the right. QRPGLESRCC – Completed RPG source code. QCMDSRC . 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. Compile the Print file and the RPG Program required for this lab.CMD Source members that you will work on in this lab. Expand QRPGLESRC and Right-Click SA2305RPT select Compile > CRTSQLRPGI. QCLLESRC – CL Source members that you will work on in this lab. QDDSSRC – Print file for the RPG programs in this lab.doc . Expand QDDSSRC and Right-Click LISTGTCSTP then select Compile > CRTPRTF. QCLLESRCC – Completed CL source code. You will need to compile this member.Check the contents of your Library Note: Your library will be IBMCLLABXX where XX is the number assigned to you! After you login. QCMDSRCC – Completed source code. Buck Creating Commands CPPs & VCPs Lab.

RSTD restricts the values entered to the values listed in the VALUES keyword.Code the Command The first step is to create the command. TYPE is a character field.doc . TYPE is a character field. Open the source member SA2305CMD in the source file QCMDSRC and key in the following code. /* 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. Page 7 of 16 © Copyright 2009 – James E. you can always press F4 to have RDi prompt the statement. Save the source member by clicking on the Save icon on the top left corner of the IDE (or do a Ctrl+S). Remember. TYPE is a character field. Buck Creating Commands CPPs & VCPs Lab. DFT sets the default value and PROMPT describes the prompt displayed. /* Displays the Command Heading */ CMD PROMPT('Customer Pay Date Report') The following KWD names the parameter. /* 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. LEN(1) sets the length to one. /* 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. MIN makes is a required field and PROMPT describes the prompt displayed. MIN makes is a required field and PROMPT describes the prompt displayed.

Change the command name to RUNPDATRPT and click OK. You will see the window shown below. Page 8 of 16 © Copyright 2009 – James E.doc . Buck Creating Commands CPPs & VCPs Lab.Create the Command Create the command using Compile [Prompt] as shown in the graphic below.

/* 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. Add the code below to the member. Run the command from the 5250command line.Check the results of the CRTCMD in the Commands Log window. This code checks the &BATCH parameter and either runs the program SA2305RPT interactively or submits it to batch. Code the Command Processing Program (CPP) Open the member SA2305CPP in the source file QCLLESRC as shown in the graphic below.doc . The command will execute but you will receive an error that it couldn’t find the CPP.

The completed code should look similar to the code below. Do not forget to check the outcome of the compile in the Commands Log window. Buck Creating Commands CPPs & VCPs Lab. Page 10 of 16 © Copyright 2009 – James E.doc . Create the Command Processing Program (CPP) Create the CPP as shown below.

Make the changes shown and click OK. Run the command from the 5250 command line. Do not forget to check the outcome of the compile in the Commands Log window. Buck Creating Commands CPPs & VCPs Lab. Did you get a report? What happens to the report if you enter an invalid date? Page 11 of 16 © Copyright 2009 – James E. This time we will include the 2305CPP program.Recreate the RUNPDATRPT command.doc .

Compile the CL program SA2305VCP Compile the program as shown in the graphic below. The MONMSG command checks for all of the possible errors and goes to a standard error handling routine. Buck Creating Commands CPPs & VCPs Lab. Review the code in the current SA2305VCP The current program has to CVTDAT commands and a MONMSG for each command.Review and Test the Validity Checking Program (VCP) Open the member SA2305VCP in the source file QCLLESRC as shown in the graphic below. This routine sends a message in the event of an error.doc . Page 12 of 16 © Copyright 2009 – James E.

Change the RUNPDATRPT command You can also change a command that you have already created. The graphic below shows the CHGCMD and all of the changes you can make.doc . Page 13 of 16 © Copyright 2009 – James E. Right-Click the command from the Remote Systems Explorer window and select Change as shown in the graphic on the right. Buck Creating Commands CPPs & VCPs Lab. Add the SA2305VCP program you recently compiled and click OK.

We’ll fix this in the next few pages. Buck Creating Commands CPPs & VCPs Lab.Run the RUNPDATRPT command From the 5250 command line run the command and use an invalid date as shown below. Page 14 of 16 © Copyright 2009 – James E. What Happened? The program ABENDS with a CPF0555 Function check. This wouldn’t be good for an interactive program.doc .

The error flag &errflg will tell us where the error occurred. For this to work the error message (MSGDTA) must be preceded by four character type zero’s ‘0000’ and the SNDPGMMSG CPF0002 is required. /* 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. Add the code in RED to the Declarations section of the member SA2305VCP. Change the Error Handling Segment so that the code matched the code below. This will allow the user to change invalid input without exiting the command.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. DCL DCL DCL &msgdta *CHAR 100 &errflg *CHAR 5 /* Used to decide what error occured */ VAR(&startdate) TYPE(*CHAR) LEN(8) Add the code in RED to the Procedure section of the member SA2305VCP. /* ----------------------------------.doc . Buck Creating Commands CPPs & VCPs Lab.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.

doc . Be sure to check the Commands Log for the results of the compile. The VCP is called each time the user hits the enter key. Page 16 of 16 © Copyright 2009 – James E. You will not need to change the command it will run the NEW version of the Validity Checking Program.Compile the CL program SA2305VCP This was shown previously. 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. Buck Creating Commands CPPs & VCPs Lab.