Bar graphs, pie charts and other business graphics are at your fingertips with standard OS/400 facilities.
Brief: The Graphical Data Display Manager (GDDM) is a standard part of OS/400. If you have the correct device (either a terminal or a printer that can support graphics), GDDM can produce a wide variety of charts and graphics. In this article, we get you started with GDDM basics and a command you can use to create simple bar graphs from data entered as parameters. Although many people may not realize it, the AS/400 has always had the capability of producing graphic images. This capability is provided at no extra cost. No matter which version of OS/400 you are running, you already have the Graphical Data Display Manager (GDDM) built right into the operating system.
You may have heard of a similar product called Business Graphics Utility (BGU). If so, you're probably wondering what the differences are between BGU and GDDM. Well, the main difference is that BGU is a menu-driven software package that lets you interactively design and create business graphics. GDDM, on the other hand, is a series of routines which you call from within an application program.
If you think BGU sounds easier to use, you're probably right. However, you should be aware that you have to purchase BGU separately, whereas GDDM is included free of charge when you purchase OS/400. My guess, however, is that few people take advantage of it. Hopefully, after reading this article and trying the accompanying Create Bar Chart (CRTBARCHT) utility, you will be inspired to take advantage of this powerful feature.
GDDM consists of a set of routines which you call from within an application program. These routines perform a wide variety of graphical tasks. Basic graphics routines are provided, such as those which draw lines and fill areas, as well as much more powerful routines which create presentation graphics. These presentation graphics routines provide you with an easy way to convert numerical data into bar charts, histograms, pie charts, line graphs, scatter plots, surface charts and Venn diagrams. It is these presentation graphics routines that this article focuses on.
Although all AS/400s have the capability of producing graphics, only certain display and printer devices can produce graphic image output. Valid displays are the IBM 5292 model 2 or a PC using the Workstation Function of PC Support configured as graphics capable. To print, you would need one of the following printers:
IBM 4214 Printer IBM 4234 Printer IBM 5224 Printer IBM 5225 Printer
You can also use one of the following printers as long as it is defined as an intelligent printer data stream (IPDS) device (i.e., the device description's TYPE parameter is equal to *IPDS):
IBM 3812 Printer IBM 3816 Printer IBM 4028 Printer IBM 4224 Printer
Even if your printer isn't an IBM product, it may still work-as long as the device description for the printer is defined as one of the printers mentioned above. When you attempt to print the results, you may receive error message CPA3388, "Attributes of file not supported for device." This indicates that either the device description for your printer is defined incorrectly or your printer is not one of those supported by GDDM. If you attempt to display the results to a workstation that doesn't support graphics, you will receive message CPC8601, "Graphics messages signalled during processing."
The Command
The CRTBARCHT utility (1) serves two purposes. First of all, CRTBARCHT serves as an example of the kinds of things GDDM can accomplish. Secondly, it gives you a useful (although somewhat limited) utility that you can start using right away to produce bar charts on your AS/400. Let's take a look.
The CRTBARCHT utility (Figure 1) serves two purposes. First of all, CRTBARCHT serves as an example of the kinds of things GDDM can accomplish. Secondly, it gives you a useful (although somewhat limited) utility that you can start using right away to produce bar charts on your AS/400. Let's take a look.
CRTBARCHT prints a bar chart with up to 12 bars. You supply the labels and values for the bars, the device type of the printer and the heading for the chart. Let's say, for example, that you entered the command shown in 2.
CRTBARCHT prints a bar chart with up to 12 bars. You supply the labels and values for the bars, the device type of the printer and the heading for the chart. Let's say, for example, that you entered the command shown in Figure 2.
When the output of this command is sent to a 4234 printer, you obtain the graph depicted in 3.
When the output of this command is sent to a 4234 printer, you obtain the graph depicted in Figure 3.
Using this utility as an example, you may want to experiment with some of the many other GDDM routines which are available. This particular utility happens to use 11 different GDDM routines. However, there are more than 150 routines from which to choose. When you add to this the fact that many of these routines have multiple options, the number of ways you can combine these routines becomes practically limitless.
Let's take a close look at how this utility works. First of all, the CRTBARCHT command prompts for up to four parameters: BAR, HEADING, OUTDEV and DEVTYPE. The BAR parameter allows a maximum of 12 elements containing two parts-label and value. Each label can contain up to eight characters of text to identify the bar. The value, which can be a number up to 99,999,999, represents the height of the bar. The next parameter, HEADING, consists of up to 50 characters of text to appear at the top of the chart.
The output device parameter allows you to send the output to the display ('*') or to the requesting job's printer (*PRINT). If the output device is *PRINT, the DEVTYPE parameter must be one of the following values: 4214, 4234, 5224, 5225 or IPDS. To determine the correct value, use the Display Device Description (DSPDEVD) command on the printer you want to print the graph on and note the device type.
The CL program BAR001CL (4) calculates how many bars were requested and converts the embedded list into two fields-one for the labels and the other for the values.
The CL program BAR001CL (Figure 4) calculates how many bars were requested and converts the embedded list into two fields-one for the labels and the other for the values.
The RPG program BAR001RG (5) starts out by moving the two fields LABELS and VALUES into arrays. The program then begins calling the GDDM routines. The following is a list of the GDDM routines which are called and a brief explanation of what each one does. For more detailed information, refer to the GDDM Programming Reference (SC33-0537).
The RPG program BAR001RG (Figure 5) starts out by moving the two fields LABELS and VALUES into arrays. The program then begins calling the GDDM routines. The following is a list of the GDDM routines which are called and a brief explanation of what each one does. For more detailed information, refer to the GDDM Programming Reference (SC33-0537).
FSINIT-Initializes graphics processing. This routine must be called before any other GDDM routines.
DSOPEN-Opens the device to be used for graphics. The DEVTYPE parameter from the command is passed into this routine.
DSUSE-Activates the device that has been opened.
CHHEAD-Specifies the chart heading text. The HEADING parameter is passed into this routine.
CHXLAB-Allows the specification of labels. The labels are placed, in sequence, at major scale marks along the X-axis. The label array is passed into this routine.
CHSET-Overrides default chart attributes. For the CRTBARCHT utility, I call this routine three times to set three attributes:
CBAR specifies a composite (stacked) bar chart (colinear bars).
NOLEGEND specifies that a legend is not to be constructed.
VALUES controls the appearance of data values at the ends of bars on bar charts.
The attribute value is passed as the option parameter on each call.
CHPAT-Overrides the default shading pattern value to be used. In this case 15 is chosen for white bars.
CHBAR-Plots one or more bar chart data groups on the currently selected axes.
ASREAD-Performs an output to the display, then unlocks the workstation keyboard and waits for operator acknowledgement (Enter key, Function keys or Clear key).
FSFRCE-Performs all outstanding graphics output.
FSTERM-Terminates graphics processing for the application program and frees all the resources acquired. This routine should always be the last GDDM routine called.
At this point, you may be wondering which routines are required and which ones are optional. Well, let me put it this way. A bare bones GDDM application would need at least six routines, called in this order:
1. FSINIT - Initialize Graphics 2. DSOPEN - Open Device 3. DSUSE - Specify Device Usage (optional routines go here) 4. Choose one of the following:
CHBAR - Bar Charts CHHIST - Histograms CHPIE - Pie Charts CHPLOT - Line Graphs and Scatter Plots CHSURF - Surface Charts CHVENN - Venn Diagrams
5. FSFRCE - Display Outstanding Graphics 6. FSTERM - Terminate Graphics
There are far too many optional routines for me to cover in this article. Refer to the GDDM Programming Reference manual to discover the wealth of graphical functions available through GDDM.
An Important Observation
One final thing I would like to mention is that although this utility includes a command, a CL program and an RPG program, only one RPG program is really necessary to produce a graph. The command and the CL program are provided to make the utility more user friendly.
You can create your own applications, incorporating GDDM routines with a single RPG program. For example, you could read one of your sales history files in an RPG program and load the sales amounts in an array. You could then pass the array directly into one of the appropriate GDDM routines and create a graph all within the same program.
GDDM routines also give you the ability to create an interesting graph from an existing report program. Just add the code which calls the various GDDM routines to produce a graph to the program. When you run this program, you would receive the same report that you got originally; however, it would now be accompanied by a graphed version.
This article gives you one more tool which you can use to view the information you have stored in your database. Whether you use the Create Bar Chart utility or create your own applications using GDDM routines, you now have the ability to turn numbers into graphical images. By experimenting with this technique, you can come up with some exciting new ways to look at your data.
Robin Klima is a senior technical editor at Midrange Computing.
Creating Presentation Graphics with GDDM
Figure 1 CRTBARCHT Command
/*===================================================================*/ /* To compile: */ /* CRTCMD CMD(XXX/CRTBARCHT) PGM(XXX/BAR001CL) + */ /* SRCFILE(XXX/QCMDSRC) ALLOW(*INTERACT + */ /* *IPGM *IREXX) */ /* */ /*===================================================================*/ CRTBARCHT: CMD PROMPT('Create Bar Chart') PARM KWD(BAR) TYPE(ELEM1) MIN(1) MAX(12) + PROMPT('Bar labels and values') PARM KWD(HEADING) TYPE(*CHAR) LEN(50) + PROMPT('Chart heading') PARM KWD(OUTDEV) TYPE(*CHAR) LEN(6) RSTD(*YES) + DFT(*) VALUES(* *PRINT) PROMPT('Output + device') PARM KWD(DEVTYPE) TYPE(*CHAR) LEN(4) RSTD(*YES) + DFT(4214) VALUES(4214 4234 IPDS) + SPCVAL((5224 522X) (5225 522X)) + PMTCTL(PMTCTL1) PROMPT('Device type') ELEM1: ELEM TYPE(*CHAR) LEN(8) PROMPT('Label') ELEM TYPE(*INT4) RANGE(0 99999999) PROMPT('Value') PMTCTL1: PMTCTL CTL(OUTDEV) COND((*EQ '*PRINT'))
Creating Presentation Graphics with GDDM
Figure 2 Sample Submission of CRTBARCHT
CRTBARCHT BAR(('Jan' 181898) ('Feb' 193082) ('Mar' 210365) + ('Apr' 261303) ('May' 269201) ('Jun' 277945) + ('Jul' 366935) ('Aug' 385192) ('Sep' 216270) + ('Oct' 268672) ('Nov' 178373) ('Dec' 147111)) + HEADING('Monthly Sales for 1992') + OUTDEV(*PRINT) DEVTYPE(4234)
Creating Presentation Graphics with GDDM
Figure 3 Sample Bar Chart Output
UNABLE TO REPRODUCE GRAPHICS
Creating Presentation Graphics with GDDM
Figure 4 Command Processing Program BAR001CL
/*===================================================================*/ /* To compile: */ /* CRTCLPGM PGM(XXX/BAR001CL) SRCFILE(XXX/QCLSRC) */ /* */ /*===================================================================*/ BAR001CL: + PGM PARM(&BAR &HEADING &OUTDEV &DEVTYPE) DCL VAR(&BAR) TYPE(*CHAR) LEN(218) DCL VAR(&DEVTYPE) TYPE(*CHAR) LEN(4) DCL VAR(&HEADING) TYPE(*CHAR) LEN(50) DCL VAR(&CNT) TYPE(*DEC) LEN(5 0) DCL VAR(&CNTR) TYPE(*DEC) LEN(5 0) DCL VAR(&OFFSET) TYPE(*DEC) LEN(5 0) VALUE(1) DCL VAR(&OUTDEV) TYPE(*CHAR) LEN(6) DCL VAR(&DISP) TYPE(*DEC) LEN(5 0) DCL VAR(&SUBSTR) TYPE(*DEC) LEN(5 0) VALUE(1) DCL VAR(&LABEL) TYPE(*CHAR) LEN(8) DCL VAR(&VALUE) TYPE(*DEC) LEN(8 0) DCL VAR(&LABELS) TYPE(*CHAR) LEN(96) DCL VAR(&VALUES) TYPE(*CHAR) LEN(96) + VALUE('000000000000000000000000000000000000000000000000000+ 00000000000000000000000000000000000000000000') /* Get number of entries */ CHGVAR VAR(&CNT) VALUE(%BIN(&BAR 1 2)) /* Process entries */ LOOP: + CHGVAR VAR(&CNTR) VALUE(&CNTR + 1) CHGVAR VAR(&OFFSET) VALUE(&OFFSET + 2) CHGVAR VAR(&DISP) VALUE(%BIN(&BAR &OFFSET 2)) CHGVAR VAR(&DISP) VALUE(&DISP + 3) CHGVAR VAR(&LABEL) VALUE(%SST(&BAR &DISP 8)) CHGVAR VAR(%SST(&LABELS &SUBSTR 8)) VALUE(&LABEL) CHGVAR VAR(&DISP) VALUE(&DISP + 8) CHGVAR VAR(&VALUE) VALUE(%BIN(&BAR &DISP 4)) CHGVAR VAR(%SST(&VALUES &SUBSTR 8)) VALUE(&VALUE) CHGVAR VAR(&SUBSTR) VALUE(&SUBSTR + 8) IF COND(&CNTR *LT &CNT) THEN(GOTO CMDLBL(LOOP)) /* Call program to produce bar chart */ CALL PGM(BAR001RG) PARM(&CNT &LABELS &VALUES + &HEADING &OUTDEV &DEVTYPE) ENDPGM
Creating Presentation Graphics with GDDM
Figure 5 BAR001RG RPG Program
*==============================================================* * * * To compile: * * * * CRTRPGPGM PGM(XXX/BAR001RG) SRCFILE(XXX/QRPGSRC) * * * *==============================================================* E LAB 12 8 E VAL 12 8 0 * I DS I B 1 40LINES I B 5 80POINTS I B 9 120COUNT I B 13 160LENGTH I B 17 200DEVID I B 21 240FAMILY I B 25 280PROCNT I B 29 320PROLST I B 33 360NAMCNT I B 37 400USAGE I B 41 440PATRN I B 45 480ATTYPE I B 49 520ATMOD I DS I 1 96 VAL I 1 96 VALS * C *ENTRY PLIST C PARM CNT 50 C PARM LABELS 96 C PARM VALUES 96 C PARM HEADNG 50 C PARM OUTDEV 6 C PARM DEVTYP 4 * C OUTDEV IFEQ '*' C MOVEL'5292M2' TOKEN 8 C ELSE C MOVELDEVTYP TOKEN C ENDIF * Load arrays with labels and values C MOVEALABELS LAB C MOVELVALUES VALS * Initialize graphics C CALL 'GDDM' C PARM 'FSINIT 'GDDM 8 * Open device C CALL 'GDDM' C PARM 'DSOPEN 'GDDM C PARM 1 DEVID C PARM 1 FAMILY C PARM TOKEN C PARM 0 PROCNT C PARM 0 PROLST C PARM 1 NAMCNT C PARM '* 'NAMLST 10 * Use device C CALL 'GDDM' C PARM 'DSUSE 'GDDM C PARM 1 USAGE C PARM 1 DEVID * * Specify heading text C CALL 'GDDM' C PARM 'CHHEAD 'GDDM C PARM 50 LENGTH C PARM HEADNG * * Specify label text C CALL 'GDDM' C PARM 'CHXLAB 'GDDM C PARM CNT COUNT C PARM 8 LENGTH C PARM LAB * * Specify bar chart type C CALL 'GDDM' C PARM 'CHSET 'GDDM C PARM 'CBAR 'OPTION 8 * * Specify no legend option C CALL 'GDDM' C PARM 'CHSET 'GDDM C PARM 'NOLEGEND'OPTION * * Specify values option C CALL 'GDDM' C PARM 'CHSET 'GDDM C PARM 'VALUES 'OPTION * * Specify shading pattern C CALL 'GDDM' C PARM 'CHPAT 'GDDM C PARM 1 COUNT C PARM 15 PATRN * * Plot the bar chart C CALL 'GDDM' C PARM 'CHBAR 'GDDM C PARM 1 LINES C PARM CNT POINTS C PARM VAL * * If output is display, perform output/input C OUTDEV IFEQ '*' C CALL 'GDDM' C PARM 'ASREAD 'GDDM C PARM ATTYPE C PARM ATMOD C PARM COUNT C ELSE * * If output is print, perform output C CALL 'GDDM' C PARM 'FSFRCE 'GDDM C ENDIF * * Terminate graphics processing C CALL 'GDDM' C PARM 'FSTERM 'GDDM * C SETON LR
LATEST COMMENTS
MC Press Online