What’s New In CL Programming

Slides:



Advertisements
Similar presentations
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Advertisements

CL programming (with Display Files). Review Display Files Constants Input/Output fields Attributes Activating Function keys.
Macro Processor.
CL Programming with Database Files Updated Fall 2010.
Programming Logic and Design, Third Edition Comprehensive
1 Kevin Forsythe DMC Consulting What’s New In CL Programming.
Chapter 10.
VBA Modules, Functions, Variables, and Constants
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
Adding Automated Functionality to Office Applications.
CHP - 9 File Structures. INTRODUCTION In some of the previous chapters, we have discussed representations of and operations on data structures. These.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Set path vs current schema. Set Current Schema ‘The CURRENT SCHEMA special register specifies a VARCHAR(128) value that identifies the schema name used.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
IBC233 Calling Programs Updated Summer Agenda Assignments are mandatory Assignment 2 due on July 13, 2007 Display files – lower case Display files.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
DBT544. DB2/400 Advanced Features Level Check Considerations Database Constraints File Overrides Object and Record Locks Trigger Programs.
Week 4 presentation! This week we will cover editing and the use of the on-board tools provided, SEU and PDM.
IBC233 Lecture 2 Updated Summer 2006 Agenda Review What’s ODIN doing? Library List Websphere –Filters.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 11: Pointers.
C Part 1 Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens A History Lesson Development of language by Dennis Ritchie at Bell.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Batch Files Flow of Control to Strengthen Copyright © by Curt Hill.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
1 Week # 5 Agenda CL Programming CL Commands Job Logs Review for test # 1.
NXT File System Just like we’re able to store multiple programs and sound files to the NXT, we can store text files that contain information we specify.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Secure Coding Rules for C++ Copyright © 2016 Curt Hill
User-Written Functions
How’s assignment 1 coming? Winter 2007
CHP - 9 File Structures.
The Data Types and Data Structures
A bit of C programming Lecture 3 Uli Raich.
Java Primer 1: Types, Classes and Operators
System Programming and administration
C Programming Tutorial – Part I
Why exception handling in C++?
A First Book of ANSI C Fourth Edition
Scripts & Functions Scripts and functions are contained in .m-files
Secure Coding Rules for C++ Copyright © Curt Hill
Array.
MATLAB: Structures and File I/O
Arrays, For loop While loop Do while loop
Object Oriented Programming COP3330 / CGS5409
Bases and Representations, Memory, Pointers, Arrays, For-Loops
Week 4 Updated Winter 2011.
Java Programming Arrays
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Overloading functions
Methods.
ECE 352 Digital System Fundamentals
9-10 Classes: A Deeper Look.
Programming Logic and Design Fifth Edition, Comprehensive
Course Overview PART I: overview material PART II: inside a compiler
Arrays.
Testing & Security Dr. X.
21st-Century CL Ted Holt Senior Software Developer, Profound Logic Software Senior Technical Editor, The Four Hundred
9-10 Classes: A Deeper Look.
CL programming (with Display Files)
Presentation transcript:

What’s New In CL Programming Kevin Forsythe DMC Consulting kevin.forsythe@dmcconsulting.com

What’s New In CL Programming In the last two releases, IBM has made huge and unprecedented changes in the CL programming language. Until V5R3 and V5R4, CL had seemed about as dormant as DOS! But now we can all thank IBM for beefing up this language and providing us with a number of great features. These enhancements improve CL program’s ability to interoperate with other languages, and generally make it easier and more productive to work with.

What’s New In CL Programming Included in the recent enhancements are: Support for Integer and Unsigned Integer data types Support for Pointer Data Types Select DoUntil Loop DoWhile Loop DoFor Loop Subroutines Support for processing up to five files

What’s New In CL Programming Integers and Unsigned Integers These new data types provide an efficient method of storing certain numeric data. Obviously if the data contains decimal values then these two data types are inappropriate, but otherwise it provides an even more compact form than the traditional packed (*DEC) format. The following chart illustrates the maximum values expressed by *INT, *UINT, and *DEC formats (for comparison).

What’s New In CL Programming Data Type Size in Bytes Maximum value *INT 2 32K *UINT 2 64K *DEC 2 999 *INT 4 2 Bil. *UINT 4 4 Bil. *DEC 4 9,999,999

What’s New In CL Programming A simple example of when to use one of these is any time that you need a “counter” or “index” variable. In the following example, the program receives a file name as a parameter; it attempts to create an achieved copy of the object and then deletes the original. If it fails to get a lock, it retries up to 3 times before giving up.

What’s New In CL Programming PGM PARM(&FILE &LIB) DCL &FILE *CHAR (10) DCL &LIB *CHAR (10) DCL &X *UINT (2) CRTDUPOBJ OBJ(&FILE) FROMLIB(&LIB) OBJTYPE(*FILE) + TOLIB(ARCHIVE) DATA(*YES) MONMSG MSGID(CPF0000) EXEC(DO) DLTF ARCHIVE/&FILE CRTDUPOBJ OBJ(&FILE) FROMLIB(&LIB) + OBJTYPE(*FILE) TOLIB(ARCHIVE) DATA(*YES) ENDDO

What’s New In CL Programming DLT: DLTF &LIB/&FILE MONMSG MSGID(CPF0000) EXEC(DO) CHGVAR &X (&X +1) IF COND(&X >= 3) THEN(DO) SNDUSRMSG MSG('File' *BCAT &FILE *BCAT + 'in library' *BCAT &LIB *BCAT 'Was not destroyed.') + MSGTYPE(*INFO) TOUSR(*REQUESTER) GOTO END ENDDO GOTO DLT

What’s New In CL Programming SNDUSRMSG MSG('File' *BCAT &FILE + *BCAT 'in library ' *BCAT &LIB *BCAT + 'destroyed.') MSGTYPE(*INFO) + TOUSR(*REQUESTER) END: ENDPGM

What’s New In CL Programming Pointers Pointers are fairly new for most RPG programmers, but they have been around a long time, and are commonly used in other languages such as C. Unlike most other data types, pointers do not contain data. Instead, they contain the memory address for a piece of data. Each pointer is 16 bytes long, which corresponds to the size of a memory address.

What’s New In CL Programming These sophisticated variables might seem out of place in CL programs, which are typically fairly simple programs. However, for greater interoperability with other languages and API’s, pointers provide much needed flexibility. The following example shows how to use pointers to scan through a large text field holding the current user portion of the library list and searching for a specific library.

What’s New In CL Programming PGM DCL &LIBL *CHAR (2750) DCL &PTR *PTR ADDRESS(&LIBL) DCL &LIB *CHAR (10) STG(*BASED) + BASPTR(&PTR) RTVJOBA USRLIBL(&LIBL)

What’s New In CL Programming CHECK: IF COND(&LIB = 'EUREKA') THEN(DO) SNDUSRMSG MSG('I Found it!') + MSGTYPE(*INFO) + TOUSR(*REQUESTER) GOTO END ENDDO CHGVAR VAR(%OFS(&PTR)) + VALUE(%OFS(&PTR) + 11) GOTO CHECK END: ENDPGM

What’s New In CL Programming The field &PTR is defined as a *PTR data type and initialized with the address of &LIBL. The variable &LIB is “based” on &PTR. This means that it does not have its own location in storage (memory). Rather, it moves to the location given in &PTR. When this program loads, &LIB initially overlays the first 10 bytes of &LIBL. Each time the program loops, the pointer moves 11 characters further down the &LIBL field.

What’s New In CL Programming The offset function (%OFS) allows the CL program to easily adjust the location of the pointer by simply adding or subtracting a number of bytes. The program uses an increment of 11 because there is one byte of blank data between each library name in the list, and each library name is 10 characters long, so the total is 11.

What’s New In CL Programming PGM DCL &LIBL *CHAR (2750) DCL &FIRSTLIB *CHAR(10) + STG(*DEFINED) DEFVAR(&LIBL 1) Variables may be defined as being sub-fields of other variables. This is similar to a data structure in RPG.

What’s New In CL Programming SELECT Statement The select statement is nothing more than a specialized “IF” structure. It defines a set of mutually exclusive tests. Each test has a corresponding command to execute upon a successful test. As soon as that command is complete, control passes to the statement after the ENDSELECT. This may not present any truly new ability, it does however, provide a much easier to read and understand logical control for CL Programs. The following example illustrates the use of the select statement by sending users to a different menu based upon their user class.

What’s New In CL Programming PGM DCL &CLASS *CHAR (10) RTVUSRPRF USRCLS(&CLASS)

What’s New In CL Programming SELECT WHEN COND(&CLASS = '*SECOFR') THEN( + GO UBERLEET) WHEN COND(&CLASS = '*SECADM') THEN( + GO NOTSOUBER) WHEN COND(&CLASS = '*SYSOPR') THEN( + GO REALWORK) WHEN COND(&CLASS = '*PGMR') THEN( + GO GEEKDOM) OTHERWISE CMD(GOTO LOCKDOWN) ENDSELECT END: ENDPGM

What’s New In CL Programming DOUNTIL Statement The DOUNTIL command provides a nice and easy to use tool for looping until some event happens. The following example shows how to use DOUNTIL to force a program to loop continuously until the job, subsystem or the system itself is shut down.

What’s New In CL Programming PGM DCL &ENDJOB *LGL DOUNTIL COND(&ENDJOB) CALL PGM1 CALL PGM2 CALL PGM3 RTVJOBA ENDSTS(&ENDJOB) ENDDO END: ENDPGM

What’s New In CL Programming Its important to note that DOUNTIL does not test the value of &ENDJOB until after the code inside the loop has processed once. The test is performed when control of the program reaches the ENDDO for the loop.

What’s New In CL Programming DOWHILE Statement If DOUNTIL’s test at the end of the loop bugs you, you could use DOWHILE instead. It is very similar in function. However, it loops while the condition is true, and exits the loop when it is not true. And the test is performed at the beginning of the loop, so there is no guarantee that the code inside the loop will ever execute.

What’s New In CL Programming PGM DCL &ENDJOB *LGL RTVJOBA ENDSTS(&ENDJOB) DOWHILE COND(*NOT &ENDJOB) CALL PGM1 CALL PGM2 CALL PGM3 RTVJOBA ENDSTS(&ENDJOB ENDDO END: ENDPGM

What’s New In CL Programming DOFOR Statement If you have a loop that executes a specific number of times, DOFOR will come in handy. The following example illustrates a modified version of an earlier example.

What’s New In CL Programming PGM PARM(&FILE &LIB) DCL &FILE *CHAR (10) DCL &LIB *CHAR (10) DCL &X *INT (2) DCL &ERR *LGL

What’s New In CL Programming CRTDUPOBJ OBJ(&FILE) FROMLIB(&LIB) + OBJTYPE(*FILE) + TOLIB(ARCHIVE) DATA(*YES) MONMSG MSGID(CPF0000) EXEC(DO) DLTF ARCHIVE/&FILE CRTDUPOBJ OBJ(&FILE) FROMLIB(&LIB) + OBJTYPE(*FILE) + ENDDO

What’s New In CL Programming CHGVAR VAR(&ERR) VALUE(‘1’) DOFOR VAR(&X) FROM(1) TO(3) BY(1) DLTF &LIB/&FILE MONMSG MSGID(CPF0000) EXEC(ITERATE) CHGVAR VAR(&ERR) VALUE(‘0’) LEAVE ENDDO

What’s New In CL Programming IF COND(&ERR) THEN( + SNDUSRMSG MSG('File' *BCAT &FILE + *BCAT 'in library‘ *BCAT &LIB + *BCAT 'Was not destroyed.') + MSGTYPE(*INFO) TOUSR(*REQUESTER)) ELSE CMD( + SNDUSRMSG MSG('File' *BCAT &FILE + *BCAT 'in library ' + *BCAT &LIB *BCAT 'destroyed.') + END: ENDPGM

What’s New In CL Programming Subroutines Okay, is it just me, or is it incredible that IBM has added subroutine support to CL programs? While its true a lot of CL programs are far too simple to benefit the use subroutines. There are plenty of places where it is very useful. The following example shows the code for a program that calls several programs and monitors for errors in each one. A subroutine provides common error handling for the program.

What’s New In CL Programming PGM DCL &MSG *CHAR (80) DCL &ANS *CHAR (1) DCL &X *INT (2) DOUNTIL (&X = 1) CHGVAR &X 1 CALL PGM1 MONMSG MSGID(CPF0000) EXEC(CALLSUBR ERR) ENDDO

What’s New In CL Programming DOUNTIL (&X = 2) CHGVAR &X 2 CALL PGM2 MONMSG MSGID(CPF0000) EXEC(CALLSUBR ERR) ENDDO DOUNTIL (&X = 3) CHGVAR &X 3 CALL PGM3

What’s New In CL Programming SUBR SUBR(ERR) RCVMSG MSG(&MSG) SNDUSRMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&MSG) + VALUES(C I D R) DFT(R) + TOMSGQ(*SYSOPR) + MSGRPY(&ANS)

What’s New In CL Programming SELECT WHEN (&ANS = C) THEN(+ SNDPGMMSG MSGID(CPF9897) + MSGF(QCPFMSG) MSGDTA(&MSG) + MSGTYPE(*ESCAPE)) WHEN (&ANS = R) THEN(+ CHGVAR &X 0)

What’s New In CL Programming WHEN (&ANS = D) THEN(DO) DUMPCLPGM SNDPGMMSG MSGID(CPF9897) + MSGF(QCPFMSG) MSGDTA(&MSG) + MSGTYPE(*ESCAPE)) ENDDO ENDSELECT ENDSUBR END: ENDPGM

What’s New In CL Programming Notice that the calls to PGM1, PGM2, and PGM3 are all wrapped up in a do loop. That loop allows the retry function of the error handling sub routine to work. If an error occurs and the user takes an “R” to retry, &X is set to 0 and the loop will continue calling the program again. If no error occurs or if a different option is taken, &X will be unchanged ending the loop.

What’s New In CL Programming Multiple Files Another great and recent addition to CL is the ability to handle more than one file in a single program. Sure, the CL language is not intended for intensive I/O handling programs. However, there are still times when it is very convenient to read two or more files in the same program. The following example shows a CL program that searches a list of libraries for source physical files and then performs a FNDSTRPDM command against each of these files, looking for a specified string.

What’s New In CL Programming PGM PARM(&TEXT) DCLF FILE(APPLIBS) OPNID(LIBS) DCLF FILE(QAFDBASI) OPNID(FILES) DCL VAR(&TEXT) TYPE(*CHAR) LEN(40) /* LOOP THROUGH EACH LIBRARY */ /* IN THE APPLIBS FILE */ /* AND ADD ALL OF FILES */ /* IN EACH TO QGPL/FILES */

What’s New In CL Programming DOWHILE COND(1 = 1) RCVF OPNID(LIBS) MONMSG MSGID(CPF0864) EXEC(LEAVE) DSPFD FILE(&LIBS_LIBNAME/*ALL) + TYPE(*BASATR) + OUTPUT(*OUTFILE) + OUTFILE(QTEMP/FILES) + OUTMBR(*FIRST *ADD) ENDDO

What’s New In CL Programming /* READ EACH FILE IN QGPL/FILES */ /* AND PERFORM A FNDSTRPDM */ /* AGAINST IT. SEARCHING FOR */ /* THE PARM &TEXT */ OVRDBF FILE(QAFDBASI) + TOFILE(QTEMP/FILES) DOWHILE COND(1 = 1) RCVF OPNID(FILES) MONMSG MSGID(CPF0864) EXEC(LEAVE)

What’s New In CL Programming IF (&FILES_ATDTAT = 'S' *AND + &FILES_ATFTYP = 'P') THEN(DO) FNDSTRPDM STRING(&TEXT) + FILE(&FILES_ATLIB/&FILES_ATFILE) + MBR(*ALL) OPTION(*NONE) PRTMBRLIST(*YES) + PRTRCDS(*NONE) MONMSG MSGID(PDM0000) ENDDO DLTOVR FILE(QAFDBASI) ENDPGM

What’s New In CL Programming Each of the declare files have an OPNID parameter (LIBS and FILES respectively) which provides a unique identifier for the files. The RCV command should reference the appropriate file ID to ensure reading the next record from the appropriate file.

What’s New In CL Programming Each of the fields from the files must also use the open ID as a prefix to the field name, such as &FILES_ATFILE. The field name is ATFILE, the open ID is FILES, and so the variable name in the CL program is &FILES_ATFILE. If you are only using one file in the CL program, you can omit the open ID from the RCV command and the field names.

What’s New In CL Programming Use Procedure calls to integrate more tightly with ILE applications. This also allows us to create more practical and functional tools.

What’s New In CL Programming CALLPRC PRC(‘RUNSQL') + PARM((&SQLSTMT *BYVAL)) + RTNVAL(&SQLCODE)

Possible Future Changes CLOSE command (read file more than once) INCLUDE command (like /COPY in RPG) Modify CVTDAT to support larger year range Compiler option to keep unreferenced CL variables Show DO/SELECT levels on compiler listing Support *BYREF/*BYVAL for ILE CL procedures Increased variable sizes Support for Arrays

What would you like… What changes/enhancements would you like to see?

Any Questions ?????

What’s New In CL Programming While it is doubtful that many shops will jump to V5R4 just to get these new features in CL, its still true that most shops will be happy to take advantage of these enhancements as they move up to the current release. The enhancements to CL in the last two releases also leave us wondering what pleasant surprises might be in store for the next release…