Friday, September 21, 2007

AS/400 Control Language (CL)



The AS/400 control language (CL) is reminiscent of JCL and consists of an ever expanding set of command AS/400 object|objects (*CMD) used to invoke traditional AS/400 programs and/or get help on what those programs do. CL can also be used to create CL programs (congruent to Shell script|shell scripts) where there are additional commands that provide program-like functionality (GOTO, IF/ELSE, variable declaration, file input, etc.)

The vast majority of AS/400 commands were written by IBM developers to perform system level tasks like compiling programs, backing up data, changing system configurations, displaying system AS/400 object|object details, or deleting them. Commands are not limited to systems level concerns and can be drafted for user applications as well.

Commands and programs

Parameter (computer science)|Parameters (aka arguments) defined in the main procedures of all traditional AS/400 programs are hard coded lists that are be made up of parameters that can be numeric, alphanumeric, boolean, etc and the order in which Parameter (computer science)|parameters are passed is important. This is a stark difference from the Unix & DOS worlds where the parameter list in Unix Shell script|shell scripts and C programming language|C programs is a set or array of character pointers and more often than not the parameters are not positionally dependent.

The AS/400 developer's solution to this problem was the command AS/400 object|object (*CMD). While the parameters on the command can be specified in any order, each parameter is defined to be passed in a specific order to the program. The programmer can also define, among other things, the parameter's data type, unique parameter name, descriptive text (for prompting), default value (used only if the parameter isn't specified during execution), if the values are restricted to a certain set or range, if the data entered should be changed to another value before calling the program, etc.

At its most basic a command names a single program to call when the user types or prompts the command and presses the Enter key. The command takes all of the parameters typed by the user, and those not typed by the user, and builds a parameter list that it passes to the program when it's called.



Sample Code

The following is a sample of CL programming. The program interactively converts dates from julian to mdy and vice versa. Results are displayed on line 24 of the terminal. It accepts two parameters. The &IN parameter which is the date string to be converted. If a julian string it should be in the format yynnn where yy is the year number and nnn is the day number of the year. If a MDY string it must be in the format mmddyy. The second parameter is &TYP which is the type of date to be converted to. It must be 'J' (julian) or 'M' (mdy). For example: the command CALL PGM(ICVTDATC) PARM('04180' 'M') will convert the julian date 04180 to 062804 (June 28, 2004).




PGM PARM(&IN &TYP)

DCL VAR(&IN) TYPE(*CHAR) LEN(6)
DCL VAR(&OUT) TYPE(*CHAR) LEN(8)
DCL VAR(&TYP) TYPE(*CHAR) LEN(1)
DCL VAR(&MSG) TYPE(*CHAR) LEN(80)

IF COND(&TYP = J) THEN(DO)
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*MDY) +
TOFMT(*JUL) TOSEP(*NONE)
ENDDO

IF COND(&TYP = M) THEN(DO)
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*JUL) +
TOFMT(*MDY) TOSEP(*NONE)
ENDDO

CHGVAR VAR(&MSG) VALUE('IN=' || &IN || ' OUT=' || +
&OUT)
SNDPGMMSG MSG(&MSG)

ENDPGM

Retrieved from "http://csiwiki/index.php?title=AS/400_Control_Language"

No comments:

Post a Comment