Developer > RPG

Developer

Using the RPG Graphical Chart Engine to Create Graphs

RPG - Using the RPG Graphical Chart Engine to Create Graphs

Bookmark and Share Print Email

Certain personalities, sometimes my own included, need to visually see pictures of numbers to make sense of data vs. taking a gander at green-bar paper with the same information. What's even funnier is how a Web site that contains tons of solid functionality can be considered a complete failure if eye candy isn't present. So, in the interests of keeping our dying breed alive (that dying breed being RPG-burger-flippin' programmers), I have developed an engine of sorts that will allow RPG programmers to generate eye-catching jaw-dropping graphs that can show customers and higher ups that RPG and the System i platform (coupled with some open-source Java) still has what it takes to thrive in the next generation of computing and presentation.

Anyway, enough preaching to the choir. The tool, the "RPG Chart Engine," produces charts like the one shown in Figure 1.

By simply making some straight-forward calls to the RPG Chart Engine service program you can accomplish charts like Figure 1 and more (see notes at bottom for links to more examples). Below is the RPG code to produce the pie chart in Figure 1. Of course the values in this example program are hard-coded for brevity sake and normally data would be pulled from your DB2 files.

H dftactgrp(*no) bnddir('RCEBND')

/copy qsource,RCECp

D uid             s             15p 0
/free
 uid =
  RCE_newPieChart(
   'Quarterly Sales':
   *on: *on: *on: '/home/aaron/pie123.jpg': 700: 300);

RCE_addPieChartData(uid: 'January': 3100.50);
RCE_addPieChartData(uid: 'February': 5100.50);
RCE_addPieChartData(uid: 'March': 7100.50);
RCE_addPieChartData(uid: 'April': 1100.50);

RCE_run(uid: gError);

*inlr = *on;

/end-free

Let me explain the above code a little. 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 into the program via "/copy," which contains the necessary prototypes and variables to accomplish the various calls to the RPG Chart Engine. It should be noted that two DB2 tables--RCEHDRPF and RCEDTAPF--receive data from the RPG Chart Engine sub procedures behind the scenes. Each of these tables has its records made unique by specifying an integer column with a number that's pulled from a data queue. Because that's in the guts of service program RCESV you really only need to know a unique integer is returned when RCE_newPieChart is called and the returned value is stored in variable uid. The variable uid then must 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 report along with the actual data this report should be based on (e.g., January, 3100.50).

Once you've executed RCE_newPieChart to set header-level data and executed RCE_addPieChartData to enter all detail-level data, you're ready to execute the RCE_run sub procedure. Here's where a whole bunch of work is done for you behind the scenes. Basically the RCE_run sub procedure sends a message to keyed data queue DQRCE. Listening for input entries on DQRCE is the Java side of RPG Chart Engine. When Java receives an entry, it uses the DB2 records' unique IDs to obtain access to all of 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. Once received control returns to your calling program. The best part is 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 System i platform. In this way each user doesn't incur the JVM startup costs of invoking Java.

Next page: >>

Page 1 2

Aaron Bartell is an RPG and Java developer for www.krengeltech.com. Aaron can be reached at aaronbartell@mowyourlawn.com.

Advertisement



Buyers Guide

Browse products and services for Developer.



Advertisement