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 general-purpose template that you can use for any file format, with HTML being used in this example. The template can be used for displaying dynamic content which can include variables from your program. You can learn more information about Universal Display Files here.
(I think the below explains it better.)
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:
- A program that produces dynamic HTML content for a web browser.
- A web service that outputs an XML or JSON document to a client program via HTTP.
- A plain text, XML, JSON, or CSV document on the IFS.
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.
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. (needs more elaboration on WHY you would only write certain formats once vs. writing others more than once)
Header
Below is an image of the header format:
...
As mentioned previously, we want the information in the header record format to only be written once when the invoice is created. This record format is a good place to create tables, add the invoice title, include any styling and output any static text you may want for your invoice. In the case of this example, we want certain elements of the invoice to show only once, such as: the ‘Invoice’ title, the company address, the invoice number table, and the item table. Because the header will only be written one time, this information will only be output once when you run the application and create the overall setup of the invoice.(In our example, you can place the input parameter in any record format really, you would just read that record format in your RPG program.)
Another important aspect of the header record format is the ‘input parameters’ property. In this example, we have one input parameter – the invoice number. While we've placed the input parameter on the header record format in this example, it's important to understand that it can be placed on any record format – you will just need to read that particular record format in the RPG program. In our RPG program, we will check if this parameter has been provided and show the correct invoice depending on the invoice number that is given as the parameter. We have 1 input parameter for this program that we’ve set up using the following (this pic will be bigger in the actual doc page):
We’ve :
You can see from the image above that we’ve named the parameter ‘invoice’ – this . In this example, 'invoice' will be used in the (as a query string or post data we are using the query string but we can also use it for post and put methods)parameter in the URL that will run the this program. We’ve also bound the parameter to a nine-digit 9 digit longdecimal field called ‘Invoice’. This field will be used in the RPG program, which is discussed later on this page.
...