Sunteți pe pagina 1din 28

Introduction to CL Programming

Mike Pavlak Solutions Consultant Zend Technologies, Inc. Week Two

Survey 2...

What version of i5/OS are you running?


Beta tester for V6R1 V5R4 (More new and changed) V5R3 (57 new and 147 changed) V5R2 V5R1 Don't ask

Review Week 1

CL History Command construction Parameters, keywords and values Edited Source in SEU Created first CL program

This week

Variables! Monitor Message More involved CL programs Real homework!

Reminder:Where to go for support...

Infocenter

http://www.ibm.com/systemi
Support ==>Infocenter

Text books

Complete CL Fourth edition (Complete to V5R3) CL Programming for the AS/400 (V4R5)

Email me at mpavlak@tripplite.com

CL manual...

PDF format on Infocenter

http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp

Books

17 Volumes 9,322 pages Average per volume ==> 583 pages Bring lots of paper!

Variables...

Before V5R3...Variables supported Character *CHAR Decimal *DEC Logical *LGL

Variables (cont.)...

V5R3 introduced 2 more... Integer *INT Unsigned Integer *UINT V5R4 introduced n more... Pointer variables *PTR Paved way to API processing...

Variables in action

Created by using the DCL command First instruction after the PGM command Last for the length of the procedure Can be passed into and out of program Used to store temporary data Begins with an & Examples

DCL VAR(&NAME) TYPE(*CHAR) LEN(20) VALUE('MIKE') DCL VAR(&INVOICE) TYPE(*INT) LEN(2) VALUE(8576112) DCL VAR(&PRICE) TYPE(*DEC) LEN(10 2) VALUE(1500.50)

Variables in action (cont...)


Can be created via file reference Cannot be defined on the fly like RPG Used to populate command values To control program flow Great for communicating with API's Other friends:

Special values Constants

Character Variables

Type *CHAR Max length at V5R4 is 32,767 bytes Minimum 1byte Default 32 bytes Examples

Decimal Variables

Type *DEC Max length at V5R4 is 15,9 Default is 15, 5 Examples

Integer Variables

Type *INT , *UINT Max length at V5R4 is 4 Minimum length is 2 (-32,768 to 32,767) Default is 4 (-2,147,483,648 to 2,147,483,647) Examples

Logical Variables

Type *LGL Max length is 1 Very much like an indicator Boolean '1'=True, '0' = False Examples

Parameters on DCL...old & new

Original (and still there...)


VAR TYPE LEN VALUE

Variable Name Variable Type(*CHAR, *DEC, etc.) Length Default Value Storage type (Used for pointers) Based on pointer Defined on Variable (Think DS) Address offset (Think API)

New with V5R4


STG BASPTR DEFVAR ADDRESS

CL Command Environment

Dependent

Run on command line or program, not both Examples


PGM, DCL, ENDPGM

Independent

Can run either way


DSPUSRPRF WRKOBJ

CHGVAR Change Variable


CL command that explicitly alters variable Key to programming in CL Can manipulate ANY variable type Parameters:

VAR Variable Named in previous DCL VALUE Value to be placed in VAR

Example

CHGVAR VAR(&FIELD1) VALUE('MIKE')

CHGVAR Continued

Used to perform mathematical functions Substrings All variable manipulation Example

DMPCLPGM Command...

Great for debugging Dumps current content of variables to SPLF May be declared more than once No parameters Dependent CL command

Show me some math...


Simple mathematical functions Use algebraic order of evaluation... Use signs: +, -, *, /, etc.

Show me some string...


Simple string functions May concatenate use: *CAT, *TCAT, *BCAT Substring: BIF %SST

QTEMP

Special library Exists only in memory Great for storing temporary objects Destroyed with job cleanup i5/OS uses it a LOT!

Error Handling

Escape message, (GSOD) Not quite, only at the job level Use Monitor Message command to control Can accept an error condition and direct flow Used heavily in professional CL programming Has 3 parameters

MSGID CMPDTA (Optional) EXEC (Optional)

Error messages for CRTDTAARA

MONMSG

Can code specific (CPF1008) Can code group (CPD1000) Can code program level (At top of program)

MONMSG Practical use


Check for existence of object If the object does not exist (CPF9801) Then create it...

Homework...

Write and run some CL programs Assignment on website Will not be collected Can forward copies with question via email

Q&A

Think of some things you would like us to cover...

S-ar putea să vă placă și