Home > AS/400 Tips > iSeries programmer tips > Taking advantage of CL advancements, starting with V5R3
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Taking advantage of CL advancements, starting with V5R3


Andrew Borts, Contributor
09.15.2009
Rating: -4.69- (out of 5)


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



[IMAGE]
[IMAGE][IMAGE]
Andrew Borts [IMAGE]
[IMAGE]

When was the last time you wanted to write a subroutine in your CL program to cut down the amount of code you're writing? Or use a logic more complex then "" within your CL program? When was the last time you wanted to loop through something without the use of 's and 's in the clunkiest use of code you've seen in a while. For me, it's daily. Who wants to clean up some code so our business rules and our code look related?

Starting in V5R3, there were significant changes to the organization of CL programming languages:

  • New looping methods
    • Until loop – DOUNTIL (ENDDO)
    • For loop – DOFOR (ENDDO)
    • While Loop – DOWHILE (ENDDO)
  • Logical end and restart of loops
    • ITERATE (same as RPG ITER)
    • LEAVE – (same as RPG LEAVE)
  • Multiple file declaration (V5R3)
    • RCVF for up to five files
    • Flow changes
    • SELECT when
  • Subroutines (V5R4)
    • SUBR./ENDSUBR

DO/ENDDO vs DOUNTIL
Let me show you what you've been missing. In our old routines, we needed to group commands together using DO/ENDDO Again:

In a word: Yuck. What if this looked like this?

Program flow is cleaned up. checks the logic after the first iteration so we'll try and read the file, and leave the loo...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
iSeries CL programming
Checking in on your IBM i authorization lists
Running PHP open source applications: NOBODY needs authority
Simplify the process of converting a spool file from iSeries into an Excel spreadsheet
CL program for daily backups
An automated CL method of moving a query from AS/400 to Excel
Changing user password expiration
Eight steps for creating program documentation using AS/400 utilities
DAYSPAST CLLE program for AS/400: Compares object creation date with today's date
Advanced Job Scheduler help
How do I retrieve the source for an output queue description to put in to a CL program?

iSeries programmer tips
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Implementing a browser interface in COBOL: Displaying database fields
TAATOOL: Useful tools for programmers on IBM i
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
Making the most of RPG data handling on IBM i
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?

iSeries programming commands
TAATOOL: Useful tools for programmers on IBM i
Date calculation commands for AS/400
Monitoring escape messages and using RCVMSG for diagnostic messages
iSeries application display subfiles with other program windows
Creating a user profile from a file
DSPPGMREF (Display Program Reference)
DSPPGM (Display Program)
DSPFD (Display File Description)
DSPPTF (Display PTF)
Top 10 iSeries commands
iSeries programming commands Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Quiz: iSeries (AS/400) Commands  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


p when the file is completed.

Controlling patterns using DOWHILE
You can control the patterns of your CL programs using as follows:

I'm never going to perform the loop unless JHANCOCK is found. Once I reach the end of file in all of these examples, I leave the loop. I can pop back up to the top of the loop if my logic requires me to start with, for example, the next record in the file.

Setting the number of loops
is for looping a set amount of times, then falling out of the loop. Say if you need to do something 15 times:

The static values can be substituted for field names – from to is a valid loop as well.

The examples I gave above also show how to uniquely identify up to five files – display or database files.

Using SELECT/WHEN/END/SELECT to clean up programs
So how many of our programs look like this?

A little ugly. So we can clean it up:

The grouping of code above may be a bit exaggerated. But, you can see that using the your code looks so much easier to understand.

Using CL subroutines
Subroutines clean up the code even more.

You see that subroutine is called AAA is in the prefix of the field &FILENM. (%SST is the substring command.)

Using this technique, your code will clean up, and you'll be writing shorter and shorter CL programs in no time.

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts