Home > AS/400 Tips > iSeries programmer tips > There is very little RPG on System i can't do: From RPG nay to RPG yay!
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

There is very little RPG on System i can't do: From RPG nay to RPG yay!


Aaron Bartell, Contributor
06.13.2008
Rating: -4.41- (out of 5)


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


If you think that RPG on the System i is good for little more than green screen coding, think again. Here, RPG on i believer Aaron Bartell shares his RPG Chart Engine tool to create graphical charts on the iSeries.

I have a new goal in life. Well at least I have a new goal as it relates to my job. I am a firm believer in RPG's ability to meet current day business needs. This also means I am a firm believer in not jumping ship to platforms like Microsoft/.NET just because they have more out-of-the-box glitter. After all, most shops have invested millions in hardware, software and personnel in and around the iSeries -- it would make sense to expend a reasonable amount of effort to not only make the platform survive, but also thrive.

Some would say that they're skeptical of RPG's ability to do much outside of a green screen. But I say there is very little RPG can't do. To back up my statement, I am going to show how to create graphical pie, bar and line charts with RPG. Now, I could create the necessary code from scratch, but that just wouldn't make sense because there are free code-sets out there that allow me to completely bypass that portion. I will be making use of JFreeChart to build the charts and simply put an RPG facade over their API's to make the creation of charts seamless.

Now you might say "why is Java OK and Microsoft/.NET gets a bad rap?" Good question. It is because I am a proponent of using Java around the fringe edges of your main RPG application suite. Also, because .NET doesn't natively run on the iSeries, I rule it out pretty fast. I have found that a healthy balance of RPG and Java on the iSeries provides me with many opportunities to retain investment in the platform. IMO, a healthy balance of Java for an RPG shop would be a ratio of around 1% to 99%. Ok, enough preaching to the choir.

The tool I am describing in this text is called the "RPG Chart Engine" and is used to produce charts like the following shown in Figure 1. RPG Char


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


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

RPG iSeries programming
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
How to: Create an RPGLE array
How to use an embedded SQL statement and display the result in a subfile

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


t Engine is a free and open source tool I wrote and make available via my personal website, www.mowyourlawn.com.

[IMAGE]

By simply making some straightforward calls to the RPG Chart Engine service program you can accomplish charts like the above and more (see notes at bottom for links to more examples). Below is the RPG code to produce the pie chart in Figure 1. Yes, that's right, only three easy-to-use API calls are required! Of course the values in this example program are hard coded for brevity sake and normally data would be pulled from your DB2 files.

Let me explain the above code a little so it is understood what's happening. Starting at the top you can see a binding directory of RCEBND used to aid in finding the RCESV service program at compile time. Next RCECp is copied in which contains the necessary prototypes and variables to accomplish the various calls to the RPG Chart Engine. It should be noted there are two DB2 tables that receive data from the RPG Chart Engine sub procedures behind the scenes and they are called RCEHDRPF and RCEDTAPF. Each of these tables have their records made unique by specifying an integer column with a number that is pulled from a data area. A unique integer is returned when RCE_newPieChart is called and is stored in variable UID. The variable UID then needs to be specified on all subsequent calls to RCE_addPieChartData so the pie chart data can be matched up with the record in RCEHDRPF. Next make multiple calls to RCE_addPieChartData specifying the UID of this chart along with the actual data this chart should be based on (e.g. Janauary, 3100.50). A question I get asked a lot at this point is "could I wrap a DOW loop around the call to RCE_addPieChartData so that I can specify DB columns as parameters?" The answer is yes!

There are three types of charts that can currently be created with RPG Chart Engine -- pie, bar and x/y line charts. Above the pie chart creation process was described, and the bar and x/y line charts are pretty much the same, just a few different parameters. Take a look at program T_RCE (Test RPG Chart Engine) to see an example of creating all three types of charts.

Once you have executed RCE_newPieChart to set header level data and executed RCE_addPieChartData to enter all detail level data you are ready to execute the RCE_run sub procedure. This does a whole bunch of work behind the scenes. Basically, the RCE_run sub procedure is going to send a message to keyed data queue DQRCE. Listening for input entries on DQRCE is the Java side of RPG Chart Engine. When the Java receives an entry it uses the unique id of the DB2 records to obtain access to all the necessary information used to build the graphical chart. After it has created the jpg file it will write a data queue entry back into DQRCE that the RPG Chart Engine service program is listening/waiting for, and once received will return control to your calling program.

The "big picture" of how all the pieces fit together is detailed in Figure 2.

[IMAGE]

The numbered steps in Figure 2 are:

Crazy! That process may seem kind of complicated, but the best part about it is that you don't need to care about those details. Instead you just need to install RPG Chart Engine and run a prompt-able command to start the Java that waits for messages on the data queue! Note the below STRRCE only needs to be started once and will service all users/jobs on your iSeries. In this way each user will not incur the JVM startup costs of invoking Java.

Here is a sample of the necessary information to specify on the STRRCE (Start RPG Chart Engine) command:

Here is the result:

Command STRRCE calls CL program STRRCEC which submits a RUNJVA job to QBATCH. This initializes the Java process and starts it waiting on data queue DQRCE. For an example of how this is done:

Now that you know how the tool works the next step would be to install it on your iSeries. This is a two part process as there is both RPG and Java included in the zip download. Detailed instructions are included in the download readme.txt, but in general what needs to happen is upload a *SAVF to QGPL/RCE.SAVF and then upload the Java jar files to /java/rce in the IFS. Go here and click on the RPG Chart Engine link to download.

The RPG Chart Engine is in it's first version and as mentioned earlier it only supports three charts -- RCE_newPieChart, RCE_newBarChart, RCE_newXYLineChart. New charts can be added fairly easily by adding a new sub procedure to the RCEFN program and modifying the RPGChartEngine.java source file (included in download). I built the underlying DB2 tables, RCEHDRPF and RCEDTAPF, to facilitate holding data for any of the other charts supported (in theory). The vast array of other charts can be seen at www.jfree.org -- select the "JFreeChartDemo (web start)" link to get the full picture of different charts. Please feel free to contact me if you have a particular chart need and would like help creating it.

That's it for now. Stay tuned for more open source tooling from www.mowyourlawn.com before years end!

ABOUT THE AUTHOR: Aaron Bartell is a RPG and Java developer for Krengeltech.com. He is also the lead developer of the popular RPG-XML Suite, which aids RPG programmers in getting up to speed fast with xml web services on the iSeries with zero Java involved. Aaron can be contacted at aaronbartell@mowyourlawn.com.

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