This page provides a step-by-step example on how to use an RPG program to populate data for a map widget in a Rich Display File.
To follow the instructions you will need access to an installation of Profound UI with Visual Designer. Also, you should know how to create and compile an RPG source member in a library. Finally, you should know how to create a database file from which you will pull map data. In this tutorial, we provide sample RPG program code for populating the file.
Create the Rich Display File
In this section, we will create a new Rich Display file and add some content.
First, create a new Display File from Profound's Visual Designer. Next, name the screen MAPRF. Optionally, provide a description and title.
Add a Map
We will add a map widget by finding it in the Widgets toolbox and dragging it onto the designer canvas. Find the Map widget:
Click and drag the map onto the canvas.
In this tutorial we will use data for US States, so we need to set the map type to "usa":
Next, we need to specify from where the map gets its data. We will use an RPG program to read from a database and generate the map data in XML format, so find the property called, "chart xml", and click on it to make the Binding button appear:
Click on the Binding button indicated in the above image to get the binding panel. In this panel you can specify the name of an RPG variable that will contain the XML text for the chart. Enter "MAPXML" as the Field Name, and enter "10000" as the Length:
Press OK, and you'll see that the chart xml property is bound to a variable named MAPXML, indicated by the green text.
Note: the variable MAPXML is defined in the Display File; so later in the RPG, we will reference it but not define it.
Add and Bind Buttons
The next step in Visual Designer is to add some control buttons and bind them to variables.
In this example, we used the "Secondary" and "Cancel" button from the Blueprint Widget Set. Look in the "Widget Sets" tab and open the Blueprint Widget Set. Here, you should see a "Secondary" and a "Cancel" button. We'll use the "Cancel" button to exit the page, closing the RPG program. And we'll use the "Secondary" button to refresh the page.
To add the buttons, click and drag each onto the canvas. You can rename a button by double-clicking on it and typing a new label:
After we place and label the buttons, we'll need to bind the response to a variable. That is, when the user clicks on a button, an indicator in RPG will be set. We will code the RPG program to respond according to the user's action.
Click on the Refresh button to view its properties in the lower-right section of the screen. Look for a property named, response, which is found under the Identification group at the top of the property list.
Click on the Binding button, as indicated in the above image. When the binding panel appears, enter "BTNREFRESH" as the Field Name, then press OK.
Now do the same for the Exit button, and use "BTNEXIT" as the Field Name.
Save the Member
Next, save the Display file as a source member somewhere, such as MYLIB/QDDSSRC. Name the member, "RPGDBMAPD". We will refer to this name in our RPG code later.
Now we are ready to compile the display file. Click on the "Compile..." button located near the top of the screen:
You are prompted to confirm you are creating a Rich Display File having the name and library you specified:
Click Compile, and after a moment you should see a message indicated the file compiled successfully.
Create Sample Data
In this tutorial section you can use the IBM tool you feel comfortable with; e.g. SEU or Rational Developer.
Create a physical file named, USINCOMEP, in a library of your choice. Define the data to have a 2-character column named, "statecodes", and a 5 character column named, "statedata".
After that, copy the following sample RPG code into a RPGLE source file.
Edit your library list, if necessary, to include the library containing the file you just created. Then compile the RPG program, and run it.
Verify that the DB file was populated. For example, run the STRSQL command, and enter this query: SELECT * FROM USINCOMEP
You should see something like this image:
Now we are ready for the RPG program.
Create an RPG program
In this section we will create the RPG program to read from the database, generate the XML, and respond to user button clicks.
Create a new RPG source member, named "XMLDBMAPR", and place it in the library object of your choice. A good choice is "QRPGLESRC".
Copy the code below, and paste it into your source member:
Alternately, here is the program with fixed-form H, F, and D specs:
The specs explained:
- DFTACTGRP(*NO) is required for all Profound UI programs.
- F spec for RPGDBMAPD declares the Rich Display File™.
- Handler('PROFOUNDUI(HANDLER)') enables RPG Open Access and identifies Profound UI as the RPG OA handler
You may have noticed these same names from the display file:
- MAPRF is the name we gave the screen.
- MAPXML is the name of the variable we Bound the map widget to.
- BTNEXIT is the name of the indicator we bound the Exit button to.
Next, compile the RPG program, and continue to the next section.
Run the Program
This section explains two ways to run the program; one requires creation of a CL program. We'll first explain the method that doesn't require a CL program.
Run from Genie Screen
For this option, you will log into the IBM i using a Genie skin, set your library list, and call the program.
Starting at the Profound UI welcome screen on your IBM i, launch a genie skin:
- Click the plus sign beside "Launch Genie Skin" to expand the list of skins.
- Click on any skin you prefer to launch the skin in a new browser window or tab.
- When prompted, sign into the IBM i with your username and password.
Next, add PROFOUNDUI to your library list:
Also, add the library containing the RPG program and the display file to your list:
Finally, call the program:
You should see the map loaded inside of a browser page:
You can click refresh to reload the map from the database. Clicking Exit will close the page and return you to the Genie environment.
- If you change anything in Visual Designer, you'll need to recompile the display file. You won't see the changes until you exit and call the program again.
- If you log out of the Genie session, then you'll need to set your library list again to run the program.
Run from Rich Display Session
This method requires us to create a CL program, because we can't interact with the library list in a Rich Display environment.
In your preferred code editor, create a CL source member named, XMLDBMAPC, and place it in the QCLLESRC object. Put this code in the member:
Note: you'll want to replace "MYLIBRARY" with the name of whichever library your RPG program and Display file are found in. This code presumes they are in the same library.
Compile the CL source, and open Profound's Visual Designer in your browser. When a Rich Display session starts, the same program is called each time. We will set our CL program to be the startup program.
Click on the Launch button to view a drop-down menu:
Click on the "Maintain Initial Programs..." option to get a panel for setting the program that loads when you start a Rich Display Session:
If you don't see your username, click on the plus icon to add a new row; enter your username in the first column.
Then, you'll want to set the value in the "Program" column to "XMLDBMAPC", and set the appropriate library. You may want to first write down the original values in case you had a different initial program and want to restore it later.
Click save, and you are ready to start a new session.
Click on the Launch button again, and this time click on "Launch Session". A Profound UI session should start in a new browser window.
Enter your username and password, and click Sign On:
Now you should see your Rich Display program on the page:
- If you change anything in Visual Designer, you'll need to recompile the display file. You won't see the changes until you exit and start the program again.
- If you click Exit, you are returned to the sign on screen. You can change the URL from /profoundui/start to /profoundui/auth/start to avoid logging in repeatedly.
- You can load your CL program from a Genie screen with this command: CALL MYLIBRARY/XMLDBMAPC. Replace MYLIBRARY with the appropriate library.
- Instead of launching a session from withing Visual Designer, you can launch one from the Welcome screen:
Adding Links to the Map
Note: The example provided on this page uses an older style of XML that FusionCharts still supports. Maps using this XML will render. However, for a map to support the "chart response" or "onchartclick" properties, Profound UI only supports the newer form of XML. See Maps under the section: "Adding Links to XML and JSON Charts" for the valid XML.
This tutorial illustrated how to:
- Create a Rich Display file with a map
- Generate a sample map data file
- Create an RPG program to read the data file, and generate XML code for the map.
- Run the program in Genie.
- Create a CL program to run the program in a Rich Display session.
Using these instructions, you should be able to use different map types and data. For different map types and options, read further in the Maps article.