Introduction to CL program

CL programming language:
 
In this blog post, I will make you understand, what is CL and what can and cannot be done by using the CL language.
  • CL is a control language that contains a set of AS/400 commands which execute in a sequence to control the flow of an application.
  • It is used for job controlling just like JCL in the mainframe.
  • So to understand the CL program, we should be knowing all CL commands
Where CL is used / what can be done using CL
 
Using the CL language, we can perform the below

  • Schedule and submit jobs.
  • Setup environment required for running programs.
  • Creating an Interface with other systems.
  • Reading a database file.
  • Work with simple display screens.
Drawbacks in CL / what cannot be done using CL
  • We can't create/Generate a report using CL language.
  • Updating/writing database files is not possible.
CL Commands:
 
As we all know CL program is a set of AS/400 commands that can be executed in a sequence to control the flow of an application. We should be knowing CL commands in order to write a CL program.
  • The general structure of command is
Command Name
Command
parameter
  • Parameters of a CL command could be a value or a variable or also a keyword.
  • Parameters provide specific values and control the functions of the command.
  • Type of Parameters
    • Required
    • Optional
Now we will write our first CL program
 
Step 1 - Create a new source physical file for the CL program.
  • To write a CL program, we need a source physical file that will act as a folder in which the CL program is an object/member.
  • Universally the source physical file for the CL program would be named QCLSRC or QCLLESRC.
  • Use the CRTSRCPF command (create source physical file), to create a source file in your own library (Here I'm using 'Jass1601' as the library name since I created a library in the name of jass1601)
CRTSRCPF command
  • The source physical file QCLSRC is created in library Jass1601 but it is empty because we didn't start writing any physical member in our source physical file.
Source physical file - QCLSRC
 
Step 2 - Add physical member into the source file QCLSRC
  • We will code the CL program in a new member of the source physical file.
  • To create the physical member take option F6 function key in PDM screen or use command ADDPFM to add a member.
  • The most preferred way is to press the F6 key. The below screenshot gives a better idea.
Physical member adding using F6function key
  • The source type is CLP/CLLE for CL. We will discuss this later.
  • Now the member is added. we are going to write our logic inside the member.
Physical member inside source physical file
 
Step 3 - Writing logic inside the physical member
  • This is an important phase, the reason is here we going to write the business logic. As of now, for understanding CL, I will write a simple 'Send program message'. The structure of the CL program will be explained in the next post.
  • Open the physical member using the edit option, write the following inside member
Basic CL program structure
  • Type  'file' in the SEU line to save and exit.
Step 4 - Compile and run the logic
  • Once the CL source is coded in the new member, Compile the source to create a program object.
  • To compile take option 14. If our code is error-free, then the program object will be created successfully. In the below screenshot, the display message is shown as "Program FIRST_CL created in the library jass1601"
Compile option
  • Now we are going to test our CL program by running it. To run the CL program, we need to call the program by either using the CALL command or simply putting 'C' before the member.
Calling CL program
  • Output for our CL program is
The output of the CL program
 
That's it, we have done our first CL. We covered just how to create a Source physical file, physical member, writing logic inside physical member, compile and then run.
 
The general program structure of CL will be explained in the next post.
 
Thanks, everyone... 

No comments:

Post a Comment