Home > AS/400 Tips > iSeries programmer tips > Automate programming tasks
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Automate programming tasks


Andrew Borts
11.17.2004
Rating: -3.29- (out of 5)


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


One thing I do to make my job easier is create programming tools that I can use to create sections of code for me.

How this works is I have a specific pattern in mind that I need -- say Move's into fields, clearing ALL the fields in a file via Move's or Eval's, or simply inserting a key structure so I can chain to a file. Whatever the mundane programming task, if I can read a file and create the structures or the code automatically, I do it. And that's because, as you know by now, I'm LAZY. But also the results are fantastic. And for files with a large number of fields in them, where you NEED to move data into the fields, this is necessary to get your job done.

I always add to my collection of these tools. In ALL instances, I give my tool the name of the file, and the program responds by writing code that I would use for that particular file. I've been adding to this program for years, so I have sections of this tool that write chunks of Web sites now. But it all started when someone simply said, "Hey, I can't find the source for these files!" So I created the beginnings of my toolbox.

Writing to a Source Physical File
Let's go over the basics of this first. We're writing into a source physical file with the following configuration;

Start   End  K#  Field Name      Len    
    1     6      SRCSEQ      S     6 2  
    7    12      SRCDAT      S     6 0  
   13   114      SRCDTA          102    

Looking at the above, we have a sequence, which because SEU is SUCH a forgiving program, can be filled in with ONE number for all your lines, or add 10 for each sequence in the file you're writing -- It's your choice. You have a date for EACH line number and the code, which will become your new RPG program. One thing I REALLY like doing is creating a list of ALL the KEYS from a file that are available for me. Let's focus on this tool, but you can do MANY variations on this theme. Then I use the following to access the source physical file I'm writing to.

The following CL program is the bread and butter of my program tool. I like calling CR8CSPEC -- or Create C-Specs -- but you can TRULY create ANYTHING you'd like.

Source for CR8CSPEC CL program

What the program does is create the "juice" that my RPG program creation tools will use to output code. Now there's NOTHING sophisticated about this from this point onwards; this is a typical "read a file, and output another file" type of program.

Here's MY program HASTILY WRITTEN to output the C specs for the K lists I have had to cut and paste into thousands of programs over the years.

COMPLETE Source for CR8CSP3

There's NOTHING sophisticated about this program. It's READING the output from the following command from the calling CL program:

             DSPFD      FILE(*LIBL/&FILE) TYPE(*ACCPTH) +                       
                          OUTPUT(*OUTFILE) OUTFILE(QTEMP/RELATE2) +             
                          OUTMBR(*FIRST *REPLACE)                               

This will create the file QAFDACCP. "Hey, where did I figure THAT information out?" Well, I'll SHOW you! On the iSeries, since the V4 days, ALL the hard-to-find reference material -- such as the names of the file names created by CL commands or the CPF error messages that a command may produce -- are built into the help text. So hitting help in SEU, then asking for extended help produces the following text produced for the DSPFFD command:

Clicking fast forward to the File information:

Here's the line I NEEDED blown up:

Here's the Access Path File name -- QAFDACCP. Why do I need that? TO COMPILE IN BATCH!

This is needed for the following line of the RPG program:

     FQAFDACCP  IP   E             DISK                                                               

To ACCESS the file created, I overrode to see the file I created in the CL portion:

             OVRDBF     FILE(QAFDACCP) TOFILE(QTEMP/RELATE2) +                  
                          MBR(*FIRST)                                           
             DSPFD      FILE(*LIBL/&FILE) TYPE(*ACCPTH) +                       
                          OUTPUT(*OUTFILE) OUTFILE(QTEMP/RELATE2) +             
                          OUTMBR(*FIRST *REPLACE)                               

Clear?

Here's a sample of the output from the example program:

      *************************************************************************                                                                                                                                                     
      * Type of file *PHY                                                                                                                                                                                                           
      * Maintenance is Immed                                                                                                                                                                                                        
      * Non-Unique Key                                                                                                                                                                                                              
      * Key for file HTPEOPLEPF                                                                                                                                                                                                     
     C     kyHTPEOPLEPF  Klist                                                                                                                                                                                                      
     C                   KFLD                     HTHPHONE                      
Ascending                                                                                                                                           

So I have everything I need in my program for the KLIST portion -- or wherever I place the KLIST to see what this file is all about -- including if the field is ascending or descending.

Other examples I've written over the years can be found here. These read the DSPFFD output into the file named QADSPFFD:

Again these are examples of what I needed over the years -- I've added tools to this to complete my cache.

Here's something else you might want to play with. Give it a try, and if you have any questions or comments or are confused, e-mail the editor and I'll get right back to you.

Command for CR8CSPEC;
             CMD        PROMPT('Create C Specs')                                                      
             PARM       KWD(FILE_NAME) TYPE(*CHAR) LEN(10) MIN(1) +                                   
                          CHOICE('Valid File Name') PROMPT('Enter a +                                 
                          File for Info')                                                             
             PARM       KWD(DEF_FIELDS) TYPE(*CHAR) LEN(1) +                                          
                          RSTD(*YES) DFT('0') VALUES('1' '0') +                                       
                          CHOICE('1=Yes, 0=No') PROMPT('Provide +                                     
                          definitions?')                                                         

-----------------------------------------
About the author: Andrew Borts is webmaster at United Auto Insurance Group in North Miami, Fla. He is often a frequent speaker at COMMON and is past president of The Southern National Users Group, an iSeries-AS/400 user group based in Deerfield Beach, Fla.


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.




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



RELATED CONTENT
RPG iSeries programming
Enhancing RPG with external SQL stored procedures
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Allow access to data from a stored procedure result set using COBOL or RPG
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
A taste of COMMON: ILE, IBM releases, Web applications and new products
Documenting nested program structures on the AS/400

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
Taking advantage of CL advancements, starting with V5R3
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

iSeries CL programming
Taking advantage of CL advancements, starting with V5R3
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

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Report Program Generator  (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

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