Home > AS/400 Tips > iSeries programmer tips > Yet another SQL program
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Yet another SQL program


Herb Bujak
01.09.2003
Rating: -4.07- (out of 5) Hall of fame tip of the month winner


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


You've probably seen several utilities which offer a way to execute SQL via a standard command interface but here's one more.

This is a command/program set that I've been using since V3R2. The features I like (and which make it different from the other utilities I've seen) are ...

1. Optional printed log
2. Interactive warning if no WHERE clause (update/delete)
3. Ability to syntax check (no execution)

The command consists of the following objects:

1) ZRUNSQL command
2) ZRUNSQL CL program
3) RUNSQL.EXE C program

The ZRUNSQL command and CL programs are pretty straight forward, just go ahead and use CRTCMD and CRTCLPGM to compile them. RUNSQL.EXE is a SQLC program and you will need to have SQL in order to compile it (use the CRSQLCI) command. If you don't own SQL then get a good buddy to compile it and send you the *PGM object! Once all this is done you're off and running.

A brief description of the ZRUNSQL parms:

SQLSTMT
---------------
Specify a SQL statement up to 3000 bytes in length. Inside a CL program, normal character string concatenation rules apply. (Note: if you're ambitious and just want to call the C program directly, you can pass up to 10,000 bytes ... wouldn't want to work with your DB if you need this capability!)

LOG
-------
Optionally, print a log (*YES/*NO). Default is *NO. If you specify *YES, an 80 byte wide printed log file is produced. It shows the SQL statement, any errors, start/end times and elapsed time.

PRTDEV
-------------
Where the LOG file goes.

USRDTA
-------------
Attaches the specifed data to the LOG spool file.

ALLROWWRN
----------------------
Warn if all rows are to be updated/deleted (*YES/*NO). Default is *YES. If you're running interactively, will pop up a window warning if you have specified an UPDATE or DELETE statement without a WHERE clause. This is similar to the way interactive SQL (STRSQL) works. Notice the use of DSM (Dynamic Screen Manager) API calls to produce the window without having a DSPF.

BORDCOL
---------------
Popup window border color .... I was bored, OK?

TEXTCOL
---------------
Popup window text color .... still bored.

MODE
----------
Execute or just syntax check (*EXEC/*CHECK). Default is *EXEC. If *CHECK is specified RUNSQL.EXE will stop after the PREPARE statement. An *ESCAPE message is sent if the SQL statement contains errors.

Usage notes ...

1) SQL errors are sent back as escape messages so you can monitor for them.
2) Successful executions send back completion messages.
3) Press F12 on the warning screen to halt processing, ENTER to continue.
4) Successful *CHECK returns SQL7967 COMP message with "PREPARE of statement S1 completed" as text.
5) This command won't run a SELECT statement to produce a report (sub-SELECTs are OK).

Click here to view the code.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


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

iSeries ILE programming
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
How to use an embedded SQL statement and display the result in a subfile
Eight steps for creating program documentation using AS/400 utilities
Searching fields for values
Searching part of a name or address in AS/400
Top 10 programmer tips YTD
How to use the binder language to manage service programs -- Part 3: Examples and pitfalls
Top 10 programmer tips of 2005
Understanding the binder language on 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

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