Home > AS/400 Tips > iSeries programmer tips > Enhancing RPG with external SQL stored procedures
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Enhancing RPG with external SQL stored procedures


Andrew Borts, Contributor
10.30.2009
Rating: -3.73- (out of 5)


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


Some of the important tools that you may not be aware of are actually external SQL stored procedures. A slew of these helper objects can only be created in RPG; requiring far too many JOIN statements, logical operators and SELECT/OMIT statements for logical files otherwise. Years ago, we used RPG primarily to gather information that otherwise required some fancy footwork to retrieve, and what remains powerful about RPG is its ability to position in a specific location within our databases and read before or after to receive the necessary business-related results.

These results were used in countless reports, subfile screens and many green screen-related programs. But now, with so many Web programs and interfaces with other systems, what can we do?

Returning data sets using RPG
RPG doesn't understand sets, but SQL and all the external systems in the world do. What if, then, we could return a set of data that represents our business needs from an RPG program? First, let's look at the many ways to declare this procedure.

  • External programs such as iSeries Navigator
  • SQLRPGLE programs
  • SQL licensed programs

What makes this procedure so powerful is that it opens your internal RPG programs up to the world. Using a DB2 database that needs to call an RPG program to return one value, can take ten files to get or return a result set. With SQL, it all can be done within RPG. Let's look at some examples.

To register an external SQL stored procedure, select the schema of your choice and select the "External" option:

[IMAGE]
Figure 1:Selecting the 'External option.

Once there, enter the information pertaining to your external procedure -- the parameters you're using, the result sets being returned and the type of parameters being used to send information to that program.

[IMAGE]
Figure 2:Enter the necessary information for your exter...


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



RELATED CONTENT
iSeries programmer tips
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
EGL Rich UI on IBM i: Do you Dojo?

RPG iSeries programming
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
How to: Sort arrays using RPGIV

iSeries SQL commands and statements
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
SQL server error message -321
Convert a numeric physical file to a character in SQL without leading zeros
Inserting data from a CTE into a file in SQL
iSeries SQL commands and statements Research

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


nal procedure.

You might be asking yourself, "Will this Contain SQL?" Or, "How will it be used within the program, and how do I commit the data changes, if any?" Don't worry, it's not as scary as it sounds.

In the 'Parameters' tab, 'Simple - no Nulls' is how most of your parameters will be passed. In the 'External Program' tab, you'll enter the program name, which is Schema(i.e., Library) and select RPGLE.

In SQL, the command would look as follows:

LIBUWANT contains the schema/library where the stored procedure will reside, LIB4RPGPGM is where the RPGLE program you are calling exists and the parameters have been defined.

So now that we are set up, the question remains: "How can we return data?" Our choices are:

  • Returned in the parameters (the fields defined as 'OUT')
  • Returned as data sets
  • Passing back a multiple-occurrence data structure (only recommended to those handy with RPG)

In my RPG program, to return the cursor, I use the following code:

As you define your fetches, along with deciding how you'll perform the selected operations, you can pass that information to the external called procedure. But there is another method. In my definition specification, I have defined a multiple-occurrence data structure for this:

Click here for the code (PDF)

You've now returned the values to the stored procedure called earlier. To then call this from SQL, you'd use the the following code:

Click here for the code (PDF)

Presto! You have a program usable with anything SQL-compatible. Return the data to the external system, and your RPG system has just become SQL-friendly.

The lesson here is that stored procedures have the power to open your RPG programs up to a world they haven't yet encountered.

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