Home > AS/400 Tips > iSeries programmer tips > Take command of your commands
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Take command of your commands


John Kohan, Search400.com expert
01.15.2003
Rating: -3.22- (out of 5)


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



[TABLE]

User-defined commands are one of the most under utilized objects in OS/400. The way they are defined, created and used is often misunderstood, so programmers stay away from them. Once they're mastered, however, they become a great tool to have in your toolbox.

Not only do they allow you to reduce the amount of code needed, but they also allow you to place them on a job scheduler so you don't need a user to actually enter the data. You can think of it as "pre-requesting" the report.

How easy are user-defined commands? Let's take a look at an example:

To create a report to display the current status of a customer's orders, you need a printer file, a High Level Language (HLL) program such as RPG or Cobol, and you need to ask the user for the customer's number. If you create a screen and a CL program to invoke the report, the process can run only in an interactive mode using a traditional interface such as CA400. The display file would contain about 10 lines of source, and the CL program would contain about the same.

But if you create a user-defined function, the screen and program would contain three lines of source code total. The screen would also look like a traditional iSeries command and would be used as such. The process could be called interactively, placed on the job scheduler or called from a Web interface such as net.data.

Below is a simple command:

When you compile your command (CRTCMD), set the "PGM" parameter to the name of the HLL program you want to receive the user's request. When the user presses enter, the program you entered on the PGM parameter will get called and passed these values.

Commands may be as simple or as complex as we need them. They can have default parameters so the user does not need to remember them. They can have special values that convert the parameters from one the user would understand to one the program can use. They can have qu


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


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
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Running PHP open source applications: NOBODY needs authority
Programming for the Web on the IBM i, what is possible
Using geocoding on AS/400 to enhance your Web presence
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
Documenting nested program structures on the AS/400
What is an integrated database?
An automated CL method of moving a query from AS/400 to Excel

Application Development
iSeries calling an .exe
Top 10 programmer tips
Formatted work job scheduler
Convert system date and time
Mixing free format code with embedded SQL
SQL update a field in one file from a field in another file
Webcasts for iSeries programmers
Programming advice from the pros
Easy code copying via the drag and drop method
Setting FTP time-outs

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


alified parameters so if the user selects a value that requires more information, the command will automatically ask for it.

Commands may also validate values so you can make sure the user inputs values you control. They may also have multiple values for the same field so the user may ask for many selections at once.

User-defined commands may seem complex, but their total lines of source code is usually fewer than 10. So even a complex command will require less coding than one simple screen, and it will increase functionality and flexibility many times over.

There are six statements (or OPCODE for RPG programmers) in command definition:
CMD (command)
DEP (dependent)
ELEM (element)
PARM (Parameter)
PMTCTL (Prompt Control)
QUAL (Qualifier) statement

You only need to use the "CMD" statement and the "PARM" statement to create your own commands.

Visit the iSeries information center to review the command syntax.

-----------------------------------------
About the author: John Kohan is a senior programmer analyst at CT Codeworks.

==================================
MORE INFORMATION
==================================

  • User-defined commands to the rescue
    Search400.com member Eitan Rosenberg shows you a technique for submitting a report using a homegrown command.
  • User-defined options make it easier to work with source objects
    If you're like progbrammer Richard Cranston, you often work within pdm working with source members. Richard added two 'User Defined Options' that call his utility programs, which will issue "CHGOBJOWN" or "EDTOBJAUT" commands on the source objects. The "CHGOBJOWN" program will prompt the command automatically so the new owner information can be entered.
  • Use FNDMSG command to maintain and manage error messages
    Using external message files is a great way to keep your error messages external to your program visible and easy to maintain. But this file can get out of control if messages are continually added. You can end up with duplicate or similar error messages. And if you're trying to maintain any consistency with your error messages, you'll have a problem. To solve that problem, site expert Tim Granatir created the FNDMSG command.


      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