Home > AS/400 Tips > iSeries programmer tips > Programming in CL? Check out these five tips
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Programming in CL? Check out these five tips


Search400.com site experts
08.31.2004
Rating: -3.48- (out of 5)


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


Don't let CL programs trip you up. These tips show you how to do the following:

  • Retrieve the system date in a CL program
  • Retrieve the width value in a file
  • Use a CL program to obtain IP addresses for all printers
  • Determine if a file is empty in a CL program
  • Call a CL program from a VB program

  • 1. Retrieving the system date in a CL program

    [ Return to top of page ]

    You've retrieved the system date (QDATE) using RTVSYSVAL in my CL program and now you need to advance the date by one. How can you do this within the CL program?

    Search400.com expert Tim Granatir says, you would have to use the convert date to convert your date to Julian, add 1 to it, check for leap year and make adjustments and then convert it back. A good example of this technique used to be found in the old TAATools in the ADDDAT command. Here is that example. This command has a six-character, date but that can easily be changed with a very slight modification.

    2. Retrieving the width value in a file

    [ Return to top of page ]

    According to site expert Tim Granatir, a quick way to retrieve the width value in the printer file is to make up a small CL program and pass it the file name and library of your print file. In that CL program, execute the following command on your print file. Read that file in your CL program, and then return the values that you want to your calling program.

    DSPFD FILE(QSYSPRT) TYPE(*ATR) OUTPUT(*OUTFILE) FILEATR(*PRTF) OUTFILE(...


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



    RELATED CONTENT
    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

    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

    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 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


    QTEMP/QAFDPRT)

    3. CL program to obtain IP addresses for all printers

    [ Return to top of page ]

    A user needed to write a CL program to obtain the IP addresses for all printers (LAN & RMTOUTQ) that they have on their system. The only OS command he could find was WRKOUTQD, but that does not allow output to *file and only one can be specified. He wondered if there is an API that he can call that does that?

    Site expert Glen Bunnell says there is a process that you can go through to create this information. Below is an example CL that will create an external file with all the information that's required. You will need to write an RPG program or query to retrieve the desired information. The following are the steps that you need to do in order to make the CL work properly:

    1. Create an externally described physical file for use by the CL. Below are the field specifications that will be needed:

    2. Execute the following command:

    DSPOBJD OBJ(QSYS/QGPL) OBJTYPE(*LIB) OUTPUT(*OUTFILE) OUTFILE(XXXX/DSPOBJ (Replace the XXXX with the library that you want the information stored into.)

    3. Create the following CL:

    Replace the XXXX with the library name of where the object was created. Replace the HHHHHH with the name of the file that was created in step one.

    4. Run the CL.

    5. With the file created in step one, you can use an RPG program, iSeries query or even download the file and get all the necessary information that you need.

    4. Determine if a file is empty or not in a CL program (READ FEEDBACK TO THIS TIP)

    [ Return to top of page ]

    Do you need to know if a file is empty or not in a CL program? Site expert Jim Mason says he isn't aware of any command that returns the number of records in a file, but you could easily create one with these steps.

    CHKF (Check file command) to create:

    CHKF FILE(MYLIB/MYFILE) NBRRCDS(&NBR)

    The second parm in this command definition is a return variable type to return the record number to the caller. Running interactively, this should take about one or two seconds to complete on an iSeries.

    In the CL program for your command:

    1. DSPFD FILE(&FILENAME) TYPE(*MBRLIST) OUTPUT(*OUTFILE) OUTFILE(QTEMP/FD)

    2. In a CALLED CL PGM, open the file QTEMP/FD.

    3. Do RCVF cmd on QTEMP/FD. This reads in the first record for the first member in the file. It has a record format (QWHFDML) and 2 fields: MLFILE (filename) and MLNRCD (number of records). You now have the record count of the first member.

    4. CHGVAR to set the return CL PGM VAR (&NBRRCDS) from the MLNRCD variable you accessed.

    5. Calling a CL program from a VB program

    [ Return to top of page ]

    Calling a CL program from a Visual Basic program is essentially the same as if you were calling a COBOL or RPG program, according to Search400.com expert Shahar Mor. That means you can call it from VB using the program call object or the QCMDEXC stored procedure. Some good examples can be found here.

    And since OLE database is thread-safe, you can run it on the server. That means that you can use the OLE database provider to call the CL program from your asp pages.



    User Feedback to "Determine if a file is empty or not in a CL program"

    Several Search400.com members wrote to say that you can use the RTVMBRD command to determine the number or records in a file. Here are few code examples:

    From Karen Hodge --


    From Kathy Adams --


    From Bob Abbott --


    From Warren Schultz --


    From Domenico Finucci --


    From Marilyn Spicer --


    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.


    Submit a Tip




    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