Download presentation
Presentation is loading. Please wait.
Published byDouglas Robinson Modified over 9 years ago
1
1 Week # 5 Agenda CL Programming CL Commands Job Logs Review for test # 1
2
2 CL Programming Difference between a command and a program Why write a CL program (convenience/repetitious tasks or commands) Characteristics of a CL program (use the CALL command/compiled object/conditioning/operational logic) Retrieving Source Code
3
3 CL programming The Use of Variables Storing temporary information Retrieve system information Exchange information between programs Send information between users and programs
4
4 CL Programming (Walk-thru) Walk-thru of 2 sample programs
5
5 CL Commands Walk-thru of 1 sample command
6
6 Job Logs What is a Job Log Walk-thru of how to access a Job Log
7
7 Week # 5 CL Review OS/400 Control Language (CL) provides a single, consistent, and flexible interface to many different system functions. Individual CL commands can be provided to certain classes of users and restricted from others based on their needs, by assigning users to a user-profile class and further restricting use through command object authority and authorization lists.
8
8 Week # 5 CL Review (Continued) To summarize, CL: Uses a single, consistent syntax Can be entered from the command line, placed in CL programs, or included as part of a batch job A CL command name usually consists of a verb that identifies the action, a noun that specifies the object of the action, and, optionally, a modifier that limits or narrows the range of the command.
9
9 Week # 5 CL Review (Continued) Command: DSPFD FILE(CATPF) CL syntax notation: LabelApplies to VerbDSP ModifierF NounD KeywordFILE ValueCATPF
10
10 Week # 5 CL Review (Continued) The operating system helps with the preparation and use of CL commands by providing: Prompting support for all commands Default values for most parameters Validity checking to ensure correct entry Extensive online Help for explanations of commands and parameters Selective authorization by user, user class, and group profile
11
11 Week # 5 CL Program Uses Most programs fall into one of three categories: User interface -- CL programs can help give non- technical users an interactive interface that is simple and easy to use. Such an interface lets users request application functions and control application flow while insulating them from command-line access. With such a user interface, users do not require knowledge of CL or operating-system functions, and they can work with greater efficiency and less chance of error.
12
12 Week # 5 CL Program Uses (Continued) Operations -- Specific operational procedures are always required on any system. When you can write these regularly needed operational procedures in CL programs, they can then be tested and stored in an efficient form that requires only a single command or menu choice for consistent, error-free execution. Applications might range from procedures that select records from database files to be input to batch report programs, to procedures that selectively save objects or libraries to backup media at a certain time every night.
13
13 Week # 5 CL Program Uses (Continued) Job attributes -- Technical users and programmers may need to work in one of several different job environments that may require changes to job attributes. A user might need a special work screen after signing on. Use a CL program as the initial program to automatically tailor the environment after sign-on. This initial program can execute appropriate CL commands based on the user’s choice from a menu- like display screen. CL programs often manage “flow control” -- the sequencing, setup procedures, and error handling of related high-level language (HLL) programs in a multi-job-step application process.
14
14 Week # 5 Advantages of CL Programs A CL program (an object of type *PGM) exists as an independent entity. Just like a compiled RPG or Cobol program, a CL program is in a “machine language” or a lower-level form that can be immediately executed.
15
15 Week # 5 Advantages of CL Programs (Continued) Additional advantages include the following: Some CL commands are available only from within a CL program. These include selection and iteration commands (e.g., IF-THEN, GOTO), error-testing commands (e.g., MONMSG), and file-processing commands (e.g., SNDRCVF). CL programs let you declare and work with variables and retrieve values (e.g., system values, job attributes, object descriptions) that will be used as variables in a program.
16
16 Week # 5 Advantages of CL Programs (Continued) Additional advantages include the following (continued): You can test and debug CL programs just as you can HLL programs. Once checked out, CL programs always provide consistent, error-free execution because the sequence of commands and the logic become part of the actual program. If factors outside the program require the program to be changed, you can modify and re- compile the source CL program.
17
17 Week # 5 Advantages of CL Programs (Continued) Additional advantages include the following (continued): CL programs can pass parameters to programs they call, and they can receive parameters passed from higher-level programs. This ability to pass and receive parameters makes CL programs very flexible and lets a single CL program meet the needs of different applications.
18
18 Week # 5 Entering CL Source You enter CL programs as source members of source physical file QCLSRC using Source Entry Utility (SEU). When creating a new member (F6 from Work with Members Using PDM for QCLSRC), it is important to correctly specify the source type on the Start Source Entry Utility (STRSEU) screen.
19
19 Week # 5 Entering CL Source (Continued) The source type for CL programs that we will be looking at is CLP -- the source type that is commonly used to create a *PGM object from each source member. (For CL programs designed to function in the Integrated Language Environment, or ILE, you use source type CLLE.)
20
20 Week # 5 Entering CL Source (Continued) Once you are in SEU edit mode, entering each command is a little different than describing a ‘PF’ member in QDDSSRC. Because each CL command has its own unique prompt screen, the SEU line command IP for a CLP type is meaningless; if you enter it, SEU takes you to the Major Command Groups menu, just as if you had pressed F4 on a blank command line.
21
21 Week # 5 Entering CL Source (Continued) Enter I to Insert a new line. Then type the command name (e.g., PGM) and press F4 if you need prompting -- this will take you to the command prompt screen for that command. There, you can fill out the parameter values. All commands have a Label parameter as the first parameter in the list, and this parameter lets you attach a tag or label to any command so you can refer to it as the object of a GOTO command from another location in the program. (Using the GOTO command along with the IF command is the only way to accomplish iteration control, or looping, in a CL program.)
22
22 Week # 5 Entering CL Source (Continued) When you have finished with the command prompt screen, pressing Enter adds the command (in keyword notation) to your SEU work screen and inserts another line for you. If the command and its parameters won’t fit on a single line, SEU inserts the continuation character (+) after a parameter and continues the command on the next line.
23
23 Week # 5 CL Program Structure Depending on their function, CL programs can take many different forms, but a few general rules and guidelines apply. (See example showing the general structure of a CL program). The program ID is not formalized in a CL program and must be entered using comments. Comments are any text on a line bracketed by a beginning /* and an ending */. The program ID should at least identify the program by name, briefly state the program’s purpose or function, and identify the program’s author.
24
24 Week # 5 CL Program Structure (Continued) The PGM statement (when needed) must be the first statement in the CL program, as it is required to list all CL variable names used to reference parameters passed to the program. When the program receives no parameters, the PGM statement is optional, but it is usually used anyway. When parameters are passed, the parameter-list variables in the called program must match the calling program’s parameter list positionally.
25
25 Week # 5 CL Program Structure (Continued) Each variable in the PGM parameter list of the called program must be identical to the calling program’s corresponding parameter in size and type. The DCLF statement, if present, declares a file to be accessed by the CL program. Only one file, regardless of type, can be accessed by a single CL program. It can be a display file or a database file.
26
26 Week # 5 CL Program Structure (Continued) DCL statements are used to declare variables needed by the CL program. Variables serve the same purposes in a CL program that they do in an HLL program -- counters, accumulators, indicators, or character strings. You can declare any number of variables in a single CL program. DCLF and DCL statements, when present, must immediately follow the PGM statement and precede any other statements in the program.
27
27 Week # 5 CL Program Structure (Continued) Sequence operations are implemented by one CL command following another. Practically any CL command can be executed in any required order, but there are certain restrictions. For example, you cannot include commands that require an interactive environment in a program that will be run in batch.
28
28 Week # 5 CL Program Structure (Continued) When multiple statements must be executed for a certain selection result, the statements must be blocked within a DO-ENDDO group structure. Iteration (loop control) is limited to the branching statement GOTO, when it is executed from within an IF statement. Specify the command label of the statement to which control passes after the GOTO command.
29
29 Week # 5 CL Program Structure (Continued) The ENDPGM statement, which is optional, marks the end of the CL program. When the program encounters this command, control returns to the calling program (or interactive job).
30
30 Week # 5 Designing a CL Program (Walk through the Sample programs at this point).
31
31 Week # 5 Declaring Variables Variables are explicitly declared in a CL program by the DCL (Declare) command. All variable names begin with the ampersand character (it is not necessary to declare variables made available through a file). Five types of CL variables exist: (Prior to V5R3 we had 3 types) Decimal (*DEC) for numeric packed-decimal variables Character (*CHAR) for character or string variables Logical (*LGL) for indicators that function as switches (on or off, true or false) Integer (*INT) An integer variable that contains a signed binary value. Unsigned Integer (*UINT) An integer variable that contains a unsigned binary value.
32
32 Week # 5 Declaring Variables (Continued) Logical variables can have only the value '1' for on/true or '0' for off/false. When a variable is declared, only its name and type are required, but, except for *LGL variables, it is a good idea to explicitly include the length. Depending on the variable’s type, if you do not declare the variable’s length and value, they will default.
33
33 Week # 5 Declaring Variables (Continued) Character variables default to a length of 32 and a value of spaces. Logical variables can have a length of only 1, so there’s no need to declare a LEN attribute for a logical variable. Variables are used in CL programs much the same as they are used in HLL programs -- to reference data items or as indicators, counters, accumulators, and working-storage items used for data manipulation, intermediate arithmetic results, type conversion, substring, or concatenation operations.
34
34 Week # 5 Changing the Value of a Variable When a variable must be changed to a value other than its initial value or incremented by some arithmetic expression, you need the CHGVAR (Change Variable) command. The CHGVAR command has two required parameters: VAR (Variable) parameter, which names the variable to be changed VALUE parameter, which specifies the new value that the variable will assume. The value can be expressed as a constant, another variable, or an arithmetic or logical expression.
35
35 Week # 5 Changing the Value of a Variable (Continued) When you use an expression as the value, you must enclose it in parentheses. You can use the CHGVAR command to convert from decimal to character types or, with caution, from character to decimal. A common reason for this type of conversion is to be able to display as part of a message a decimal variable value used as a counter or accumulator.
36
36 Week # 5 Changing the Value of a Variable (Continued) CHGVAR &CNTR (&CNTR + 1) If the variable &CNTR, shown above had been used to count the objects deleted in a certain library and you wanted to display that information as a message to the interactive job calling the program, you would first need to convert the information to character type.
37
37 Week # 5 Changing the Value of a Variable (Continued) If &CNTR were declared as a four-digit integer, you could declare a new variable as follows: DCL &ACNTR *CHAR 4 And after the count was completed, you could convert the numeric &CNTR to a character variable by coding CHGVAR &ACNTR &CNTR This command would place the character equivalent of the packed-decimal value in &CNTR into the character variable &ACNTR.
38
38 Week # 5 Changing the Value of a Variable (Continued) The value could then be concatenated to a message and sent to a message queue or job, using a command such as SNDPGMMSG MSG(&ACNTR *BCAT 'objects have been deleted')
39
39 Week # 5 Selection and Iteration To implement selection in CL programs, use the IF statement. The syntax of a simple IF statement is: IF (condition) THEN(command) The condition can be a simple relational or logical expression, a negated expression using the logical operator *NOT, or a combined expression using the logical operators *AND and *OR.
40
40 Week # 5 File I/O in CL Programs CL programs can access two types of files: display files and database files, both physical and logical. A single CL program can declare only one file, and that file must exist at the time the CL program is compiled. When the program is compiled, data fields from the file are made available to the program as variables.
41
41 Week # 5 Sending Messages A message is a communication sent from a program or a user to a message queue. A message queue functions like a mail box to hold the incoming message until it can be handled. Every user on the system has a message queue identified by the same name as the user ID, and when you sign on and start an interactive job, your workstation message queue also becomes available.
42
42 Week # 5 Sending Messages (Continued) These are permanent message queues that continue to exist after you sign off and when the terminal is not in use; if you return to examine these message queues from a later session, they will still be there, and the old messages will still be available (unless they were deleted). In addition to these message queues, every running program has a program message queue that is created when the program starts and is deleted when the program ends.
43
43 Week # 5 Sending Messages (Continued) Every job has an external message queue that is created when the job starts and is available during the life of the job. An external message queue is often used to display an inquiry message (one requiring a reply) when a CL or HLL program experiences a severe runtime error during testing.
44
44 Week # 5 Sending Messages (Continued) Several types of messages exist, but we mention only two here: informational and inquiry. Informational messages are just that -- they inform the recipient of some condition or convey the results of a process. They are not usually used for error messages and do not require a response. On the other hand, inquiry messages request a response and are often used to display error messages that require a reply.
45
45 Week # 5 Sending Messages (Continued) You can use several commands to send messages. Here are four of them: SNDMSG (Send Message) -- You can use the SNDMSG command interactively or from within a CL program. SNDMSG works only with messages whose text is included within the MSG (Message text) parameter of the command. It can deliver the message to a named message queue or to a user.
46
46 Week # 5 Sending Messages (Continued) SNDBRKMSG (Send Break Message) -- The SNDBRKMSG command delivers messages only to a workstation message queue. If the workstation is active at the time of delivery, the command interrupts the job and displays the message. If the message is an inquiry message, you can specify a message queue for the response. As with the SNDMSG command, you can use the SNDBRKMSG command interactively or from a CL program, and the message text is part of the command.
47
47 Week # 5 Sending Messages (Continued) SNDPGMMSG (Send Program Message) -- You can use the SNDPGMMSG command only from within a CL program. You can define the message text within the MSG parameter, or you can use a predefined message that exists in a message file and that has a unique message identifier. The command can deliver its message to any type of message queue, including program and external message queues. For messages requiring a response, you can designate a reply message queue. This command is especially useful when a running program needs to send a message back to the program that called it.
48
48 Week # 5 Sending Messages (Continued) SNDUSRMSG (Send User Message) -- The SNDUSRMSG command also delivers messages only to a workstation message queue. If the workstation is active at the time of delivery, the command interrupts the job and displays the message.
49
49 Week # 5 Using Concatenation Concatenation is the joining of two character variables or constants. In CL programs, programmers often use concatenation to form messages by combining several character variables and string constants to be assigned to a single variable or to be used as a single message-text value. In fact, concatenation is very often used when a CL program needs to communicate with its user or to send a message to a message queue.
50
50 Week # 5 Creating a CL Program In general, the source code for each CL program is maintained as a member of a source physical file (QCLSRC). Before you can begin coding a source CL program, you need to have created QCLSRC in your library using the CRTSRCPF (Create Source Physical File) command.
51
51 Week # 5 Creating a CL Program (Continued) When you have completed the CL source code, you use the CRTCLPGM (Create CL Program) command to create the *PGM type object. You can key this command on the command line and prompt or, more conveniently, invoke the command from the Work with Members Using PDM screen by taking option 14 on the CLP source member. When the CRTCLPGM command is executed successfully, a new object of type *PGM is created in your library.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.