Process a Display File in ILE RPG (RPGIV)
You are aware of how to declare your display file in an ILE RPG program. Now, we will learn how to process a diplay file.
To display a screen of a display we have to follow the following steps.
- Declare the Display file in F-Spec- We have already learnt how to declare a display file.
- Populate the field values of the record format to be displayed.- In ILE RPG we process a screen or panel as record format. One screen may be divided into several record formats. We need to populate all the fields of the record format we wish to process, one by one.
- Write the record format to display the screen and read the same immediately after writing, to take user input. Alternatively we use the opcode ExFmt for combined Write and Read.
The program given in the example is a very simple program which explains the concept learnt above.
//The source of the display file. AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions+++++++++++ A DSPSIZ(24 80 *DS3) A R CUST01 A 11 21'First Display File!Press Enter to- A Exit' A DSPATR(BL)
//Source code of the ILE RPG Program. ** Declare the display file FFilename++IPEASF.....L.....A.Device+. FCUSTDSPF CF E WorkStn ** Display the screen CL0N01Factor1+++++++Opcode&ExtFactor2+ C Write CUST01 C Read CUST01 ** C Return
The above program simply displays a screen. You press enter and the program ends. Though this program was very much simple, however it clears several concepts. You could have used ExFmt instead of the two Write and Read Opcodes. Just write your own code and try it yourself. You can see the output of the displayed screen here.
Simple RPG IV Interactive Program
The next RPGIV example displays a screen with two input fields (Actually of "both" type). The user enters two numbers and the program displays their sum as output field. This program again, is very simple. The source codes of the display file as well as the ILE RPG program itself are given below.
The objective of the program is to
- Display an input screen
- Take two numeric inputs
- Sum the user inputs inside the program
- Display the sum.
Display File's source
A DSPSIZ(24 80 *DS3) A R SUM01 ** FUNCTION KEY DEFINED A CF01 ** SCREEN FIELDS AND LABELS A 2 2'Sum Of Two Numbers' A COLOR(WHT) A DSPATR(UL) A 5 2'Enter two Numbers and Press Enter A to get their sum.' A 7 2'Enter First Number :' A $NUM1 10 0B 7 23 A 8 2'Enter Second Number:' A $NUM2 10 0B 8 23 A 10 23'-----------' A 11 17'Sum =' A $SUM 11 0O 11 23COLOR(WHT) A 23 2'F1=Exit' A COLOR(BLU)
Source of the RPGLE Program
** Declare the file FSUMDSPF CF E WorkStn ** Loop untile F1 is pressed C DoW Not *INKA ** Display the screen C ExFmt SUM01 ** Return with user input. ** Calculate the sum of two input fields from the screen C Eval $sum = $num1 + $num2 C EndDo ** F1 has been pressed to end program. Free up resources ** before ending the program C Eval *InLr = *On C Return
You can see the output of a sample run of the program here.
From the above program we learn the following things.
- To continuously display a screen we place the "exfmt statement" inside a loop.
- The control returns to the program only if some valid function key is pressed. Otherwise an error 'Function key is invalid.' is thrown on the screen.
- If you do not define any function key, even then the system defines the Return key. Actually this why we were able to end the program in the previous example. If we have to check whether Enter key was pressed or not, We simply check for all other function keys. If no other key has been pressed then it means that the Return key was pressed on screen.
- Before ending the program we set the Lr Indicator on. This is to the system that the program is ending. Close all the files which were automatically opened by this program.
- 5769 reads
