02
Sat, Nov
2 New Articles

HOT TIPS: CL (8 Tips)

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

CL

Decompile CL Programs

If you inadvertently delete the source code of a compiled CL Program, you can retrieve the source (minus comments) with the Retrieve CL Source (RTVCLSRC) command, instead of restoring the member from a backup. Remember, there may be no backup if this program was new. The command's format is:

RTVCLSRC PGM(library/compiled program name) + SRCFILE(library/QCLSRC) + SRCMBR(source program name)

The ALWRTVSRC parameter of the CL program must have a value of '*YES'. This is the default value for the CRTCLPGM command.

- Richard A. Phifer

OPNQRYF and MDY Dates

You can use date selection in reports even when the dates are in *MDY format in the database by using mapped fields on an OPNQRYF command. For example, the following command selects only records whose LRDAT field (which is a packed date in *MDY format) falls within 1992:

OPNQRYF FILE(LRDS) + QRYSLT('yymmdd = %RANGE(''920101'' ''921231'')') + MAPFLD((DATE1 LRDAT *ZONED 6 0) (DATE2 DATE1 *CHAR 6) + (YYMMDD '(%SST(DATE2 5 2) *CAT %SST(DATE2 1 4))' + *CHAR 6))

Note that if the date is already in zoned or character format, the first or first and second mapped field specifications can be eliminated respectively. This still allows updates and deletes of the data.

You can sort by date this way by adding a mapped field specification to map the new date back to another field in the file that you specify on the KEYFLD parameter. The field must be one that you don't need for that application. Data will not be affected; however, you cannot update the file when this map is added.

- Bryan Leaman

Re-use File After OPNQRYF

Here's a way that I re-cycle the OPNQRYF command in the same CL program:

OVRDBF FILE(FILENAME) SHARE(*YES).... OPNQRYF ... OPNID(FILE1) CALL PGM(PGMA) POSDBF OPNID(FILE1) POSITION(*START) CALL PGM(PGMB) CLOF OPNID(FILE1) DLTOVR FILE(FILENAME)

I also use this technique frequently when I want to view the records/sequence that my OPNQRYF is producing. I issue the OPNQRYF command, then do a CPYFRMQRYF to a test file, then issue the POSDBF command and then call my program. It's a nice feature.

- Cynthy Johnson

CL Gotcha

In CL, the CLOF command will not close a file declared in the CLP. The only way to close the file is to end the program, transfer control to another program, or reach the end of file. If the end of file is reached, the file is closed and CPF0864 is issued. The file cannot be opened again in the same execution of the program.

If end of file is not reached, the CL program cannot close the file and hence cannot perform certain operations like CLRPFM or DLTF.

- Douglas Handy

Date Validation in CL

The easiest way to validate dates in CL is to use the CVTDAT command. You do not actually need to convert the date to another format. For example:

CVTDAT DATE(&DATE) TOVAR(&DATE) FROMFMT(*MDY) + TOFMT(*MDY) TOSEP(*NONE) MONMSG MSGID(CPF0000) EXEC(DO) CHGVAR VAR(&IN70) VALUE('1') /* Error indicator */ GOTO CMDLBL(SCREEN) /* Redisplay */ ENDDO

In this case the from-format and to-format are the same, so no conversion actually takes place. However, an exception message will be sent if the variable &DATE does not contain a valid date.

- Bryan Leaman

Beware of Changed Commands-Part I

This tip is for consultants and software developers who have to write CL programs that must run on someone else's (your customer's) machine.

An interesting feature of S/38 and AS/400 CL procedures is that, even though they are compiled, each command is interpreted when run, and the current default values for that command are substituted into the command. This can lead to unexpected errors if someone changes any of the defaults for any of the IBM-supplied commands using the CHGCMDDFT command.

To avoid this pitfall, when creating CL procedures that must run at other sites, prompt each command in SEU by pressing F4=Prompt with the cursor on that line; then, press F10=Additional Parameters. Then, type over the first character of each default value with the same character. This causes the "modified data tag" for that field to be turned on, and so when you press Enter, that "key-word(value)" will be included in the statement.

What this technique does, in effect, is allow you to supply all of the "defaults" with the default values used at your site. Hence, at run-time, the values are already supplied at the user's site, so there are no defaults to be plugged in-no more nasty surprises!

- Mark Waterbury

Beware of Changed Commands-Part II

This tip is for consultants and software developers who have to write CL programs that must run on someone else's (your customer's) machine.

If you distribute compiled CL procedures to other AS/400 sites, either utilities or tools, or as part of a software product, consider the following:

If a customer wants to, he can change the default values or even replace certain IBM commands in QSYS directly. This is, of course, not recommended and ill-advised.

However, when you ship your program, you probably want to use the "real" IBM supplied versions of IBM commands. The following technique will ensure that when the CL procedure runs at the customer's site, it will use the same defaults and the same version of the command definition object used at your site when you compiled the procedure. This can be very useful for critical procedures that must not fail.

1. Copy each of the *CMD command definition objects from QSYS into your product library, using CRTDUPOBJ. (NOTE: if you need to support a user running a previous release of OS/400, duplicate the commands from QSYSPRV rather than QSYS, and be sure to specify TGTRLS(*PRV) on the CRTCLPGM command.)

2. Qualify all of the commands in your CL program to use the copies in the product library. For example:

MYLIB/DSPFFD FILE(&LIB/&FILE) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/DSPFFD)

3. Save the entire library MYLIB on your distribution tape. This saves everything in your product library, including the duplicated command definition objects (*CMD) needed to run the CL procedures correctly. (NOTE: specify TGTRLS(*PRV) on the SAVLIB command to support users running the previous release of OS/400.)

4. The first step of your printed installation documentation should instruct the user to restore the product library (e.g. MYLIB). For example:

RSTLIB SAVLIB(MYLIB) DEV(TAP01)

- Mark Waterbury

A Permanent Solution to Temporary Work Files

There are times when you need to create work files for jobs-normally batch type. Occasionally, the jobs that use these work files either get canceled or end abnormally and you end up with a file needlessly taking up space on your system. Not only is this wasting space, but there is the chance that one of your programs may end up referencing the wrong version of the file.

A good solution to this problem is to create the work file(s) in the appropriate production library and leave them there empty, permanently.

Whenever you need to use the work file, use the RTVOBJD command to retrieve the name of the library where the work file resides. Then, use the Create Duplicate Object (CRTDUPOBJ) command to create a duplicate of the work file from the production library to library QTEMP. (If the job is interactive and the file already exists in QTEMP, clear it [CLRPFM] instead of creating the duplicate object.) Override the file (OVRDBF) to the copy in QTEMP before using it.

If the job gets canceled or terminates abnormally and it's a batch job, the work file goes away since it is in QTEMP. If the job is interactive, the work file will go away at sign-off or it will be cleared if used again before sign- off.

- Robin Klima

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: