Four Hundred Guru- -V5. R4 CL Enhancements, Revealed and Detailed. V5. R4 CL Enhancements, Revealed and Detailed. Published: February 8, 2. Ted Holt. . Version 5 Release 4 of i.
OS continues the tradition that V5. R3 began- -that is, making a liar of me. Before V5. R3, I would have bet my last Federal Reserve Note that IBM would never enhance the i. Series Control Language (cleverly known by its acronym, CL), and I would have lost the bet. Like V5. R3, V5. R4 introduces several new CL features. I would like to thank Guy Vig of IBM for telling me about them. Now I'd like to share them with you.
Call a Subroutine from a different Module in VBA. Access a variable of a module in another module after running the program which calls that module?
Let's learn more about them. Keep in mind that I have not tested any of the code in this article, since I don't have access to a machine that is running the new release. I expect to use subroutines primarily to divide a CL procedure (a program or a module) into tasks of logically related code.
The second way I plan to use subroutines is to avoid the duplication of code within a CL procedure. No need to add a GOTO or RETURN command before the first subroutine, the CL compiler inserts an implicit RETURN for you.
The IBM i Control Language (CL). At its most basic a command names a single program to call. Subjects like program are always PGM, user is USR, module. 08.Abap Dialog Programming Overview. How To Create an ASP.NET HTTP Module Using Visual C#.NET. BeginRequest: Call this event to notify a module that new request is beginning. The ability of a module to call another module is an interesting component. By changing the original program from a CALL opcode to a.
Here is the general outline CL procedures follow. The name of a subroutine goes in the SUBR command's only parameter, also named SUBR. If you place a label on the SUBR command, or precede the SUBR command with a labeled null command, you may use GOTO within the subroutine to return to the first executable command within the subroutine. In the following example, branching to the Again label continues execution with the first CHGVAR command. In the following example, three END labels exist- -one in the main routine and two in subroutines Validate and Next. File. The compiler won't allow it.
One way you might use this feature is to provide a return status, which would indicate whether the subroutine completed normally or abnormally. You might use zero, the default value, to indicate that the subroutine completed normally, and non- zero values to indicate errors. The caller can test the return value and proceed accordingly. RTNSUBR has the same optional RTNVAL parameter that ENDSUBR has.
CALLSUBR has two parameters. SUBR indicates the name of the subroutine to be called, while RTNVAL may contain the name of a four- byte integer variable to receive the subroutine's return code. If PGM1 creates the report, then programs PGM2, PGM3, and PGM4 should also run. But if PGM1 does not build the report, the job is complete. Subroutine Rtv. Splf. Nbr uses the QSPRILSP API to retrieve the number of the last spool file that was created in the job.
Call Module Cl Programming
I used the RTNVAL parameter of the ENDSUBR command to load the retrieved spool file number into the & SPLFNBR1 and & SPLFNBR2 variables. Calling the subroutine immediately before and after calling PGM1 provides two spool file numbers. If they are the same, PGM1 did not create a spool file.
If the CALL command is issued by a CL program or ILE CL procedure, each parameter value passed to the called program can be a character string constant. Contact Center Agent Development Program. Module 4: Controlling the Call; Module 5: Presenting the Solution. The IBM i Control Language (CL). At its most basic a command names a single program to call. etc. Subjects like program are always PGM, user is USR, module. May have to use the Create CL Module. Calling a procedure from CL.
However, subroutines can call other subroutines. In fact, a subroutine can call itself. Each invocation of a subroutine pushes an entry onto a stack that by default can go 9. An entry is popped off the subroutine stack when the subroutine returns so, as far as I'm concerned, 9. However, you can use the new Declare Processing Options (DCLPRCOPT) command to change the depth of the subroutine stack to any value from 2. The following command allows 1.
In V5. R4, DCL gets four new parameters and a new data type to boot! CL will never be the same. Let's look at overlaying data first.
The first ten characters are the object name. The last ten characters are the library name. Prior to V5. R4, you must use the substring function to extract the object and library names to variables of their own. STG(*DEFINED) tells the compiler that a variable overlays all or part of another variable. You'll also need to use the DEFVAR (defined on variable) keyword to tell which variable this new variable is part of. DEFVAR takes two values- -the name of the variable that is overlaid and the starting position for the overlay. The default starting position is one.
Under V5. R4, you may define the object and library variables to be substrings of the parameter. This means that you no longer need the substring operations. Compare the following code to the pre- V5. R4 code of the previous example. In the pre- V5. R4 version, changing & File or & Lib does not change & Qual.
File, and changing & Qual. File does not change & File and & Lib.
In the V5. R4 version, changing & File or & Lib does change & Qual. File, and changing & Qual. File does change & File and & Lib. The real power of this feature is when data of one type is contained within a variable of another type. For example, let's say you have written a CL command that defines a list of packed decimal parameters.
The first two bytes contain the number of entries in the list in binary format. Each group of four bytes thereafter holds a packed decimal number. Now, how does your CL program extract the decimal values from that big ol' character string? In fact, your CL program can't do it. It has to call a program in some other language (e.
RPG or COBOL) to get the job done. Here's some code from the command- processing program. This gives me a way to access each customer account number as a decimal value. The first two bytes of the & LIST parameter contain the number of list entries as a binary number.
I have defined & NBROFLISTE to contain that number. In V5. R3 and earlier, I have to use the %binary (or %bin) built- in function to extract the number of list entries. I first learned how to use pointers eons ago when I learned Pascal. I found them very useful for linked lists and other data structures that I had to master in order to get my computer science degree. While I enjoy programming with pointers for fun, I haven't found pointers to be of much help in shipping product out the factory doors.
On one hand, if CL is to fully participate as an ILE language, it probably makes sense to add pointer support to CL. On the other hand, CL is fundamentally a job control language. Does a job control language really need to do the sorts of things that RPG, C, COBOL, and Java do so much more easily? For example, V5. R4 allows you to bind CL to the C record I/O routines (the ones whose names begin .
Why not use RPG for database processing instead? To assign a memory address to it, use the new %ADDRESS built- in function. The following example shows how pointer & List. Addr is set to point to character variable & List. List. 2. The pointer on which a based variable is based must be set to the address of another variable before the based variable can be used. Look at the following variable declarations. The STG(*BASED) parameter means that the compiler is not to allocate storage.
The BASPTR parameter says that the pointer variable & Ptr. Text has the address of the memory that & Text should reference. In the following example, & Name is assigned to the first 2.
Data variable. The new %OFFSET (or %OFS) built- in function can be used to store the offset portion of a pointer or, when used on the VAR parameter of a CHGVAR command, to change the offset in a pointer variable. Suppose there are four identically defined variables that must be processed in the same way. You could duplicate the processing code, once for each variable, but wouldn't it be nice to write one subroutine that can handle one variable and use the subroutine four times? The following example does just that.
It references the & Text variable. To make Process carry out its mission for any of the procedure's parameters is a simple matter of setting & ptr.
Text to the address of that parameter. That is, while & ptr.
Text is set to the address of & Text. Text are really changes to & Text. I was hoping for source code inclusion directives, like /COPY in RPG, COPY in COBOL, and #include in C.
Nevertheless, I'm glad to see the compiler enhanced again after so many years. I'll hope for compiler directives in a future release.