Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Overview

In this example, we’ll show you how to display a static HTML invoice with dynamic content using a Universal Display File. A Universal Display File is a display file that an RPG program can use to create dynamic text output. The output can be transmitted to a client via HTTP or written to a stream file on the IBM i Integrated File System (IFS). For example, Universal Display Files can be used to create:

...

The rest of this documentation page will show you how to create an invoice using a Universal Display File. If you aren't familiar with Universal Display Files, you can learn more general information about them here


Info
titleFiles

Below are the files that include the source code for the both the RPG program and the Universal Display File used in this example: 

Universal Display File Design

For this example, we organized our data into 4 separate record formats: header, detail, footer and error. You should separate your logic into multiple record formats based on the data that you want to display. While it’s not necessary to use multiple record formats in your Universal Display File, we recommend this approach to more easily manage your logic. In this example, the data in the header, footer and error record formats is data that we want our program to only output once. Data in the detail record format is written multiple times, depending on the data in the database file that you’re using. In the next few sections of this documentation, we will break down the individual record formats into further detail.

...

The error format will display any errors that you may receive when attempting to run this program. For example, the RPG program would display the contents of the error format if the user did not provide the required parameter before attempting to run the program. In this example, if no invoice number is given, the error record format would notify the user that they had forgotten to provide this parameter for the program.

RPG Program

In this section, we will explain our RPG program along with some important details that are needed for this example. Below is the RPG program in its entirety:

...

Once your program reads the appropriate record format that the input parameter is defined on, you can then use this parameter in your program. In this example, if an invoice number is provided and it is a valid number, then the program should continue as expected and write the remaining record formats: header, detail and footer. However, this program does handle the event that an invoice number isn't passed or an incorrect invoice number is used. You can see this in lines 25 - 27 in the program above. If an invoice number isn't given as a parameter, or if the invoice number that is given cannot be found, then the program will show the error record format along with a message stating that the invoice can't be found. 

Configuring the URL

Before launching the Universal Display File program, you will need to configure the URL using the Web Connector. The Web Connector lets you map a URL like http://server:port/profoundui/universal/myprogram to a program using a Universal Display File. Note that “server” and “port” are simply generic names for example purposes – “server” would be replaced with the actual server name and “port” would need to be replaced with the correct port number for the instance. You can read more about the Web Connector and configuring URL mappings here.

...

So, having /invoice in the URL will result in the program INVOICE01R in library INVOICE being called. This is also where we will reference the input parameter that was discussed previously. You will need to provide the invoice number in the parameter of the URL when launching this program in order for this to work as expected. The following is the complete URL used to run this program: http://server:port/profoundui/universal/invoice?invoice=53696.

End Result

Once you have compiled your Universal Display File, compiled your RPG program and configured your URL using the Web Connector, you should be able to launch your program. For example purposes, we are using this program as a stand-alone invoice, however, this program could be used with another program to dynamically set the URL parameter to show different invoices based on the invoice number that is provided. The following image shows the result for invoice number 53696: