This is a mirror of a wonderful article from RPG Cafe!
(Short URL: https://ibm.biz/rpgCafe_Freeform_Rpg_Tutorial)

Display Files

This chapter introduces you to using display files, also called "workstation files"

First, let's create a display file

Paste the following source into a source member with the name RPGDSPF and the source type of DSPF. The file has one input field, NAME.

A          R GETNAME
A                                  5  5'What is your name?'
A            NAME          25A  I  5 25CHECK(LC)

Compile the file. It creates a display file called RPGDSPF.

Show a screen

Compile and run the following program.

dcl-f rpgdspf workstn;
exfmt getname;
dsply ('Your name is ' + name);
*inlr = '1';

This program just shows the screen and reads the input value. Then it uses the DSPLY opcode to show the value that it got.

A more complex interaction

Change the display file source to add another record format. The new record format SHOWINFO has some input/output fields (identified by the B for "Both") and an output field. Recompile the source to get a new version of the file.

A          R GETNAME
A 5 5'What is your name?'
A NAME 25A I 5 25 A CHECK(LC)
A R SHOWINFO CA03(03) CA05(05)
A 5 5'Hello '
A NAME 25A B 5 12 A CHECK(LC)
A CURTIME T O 9 2 A 9 15'Current time'
A DSPATR(HI)
A CONDITION 10A B 10 2 A CHECK(LC)
A 10 15'Current condition'
A 23 2'F3=Exit F5=Refresh'
A                                      COLOR(BLU)

Compile and run the following program. When you get to the part where it shows you the current time, try changing the condition to something else, say "Raining". The next time you see the screen, it shows "Raining". Try changing it to something else, say "Warm", but this time press F5 instead of pressing Enter. It shows "Raining" again. You can also change the name in the same way.

dcl-f rpgdspf workstn;
dcl-s done ind;
exfmt getname;
done = '0';
condition = 'Cloudy';
dow not done;
  curtime = %time();
  exfmt showinfo;
  select;
    when *in05;
        // Refresh, handled automatically
    when *in03;
        // Exit
        *inlr = '1';
        return;
    other;
        // Just show the screen again
    endsl;
  enddo;

What's going on in the RPG program?

Compile the program with the listing view DBGVIEW(*LIST) or DBGVIEW(*ALL), and run it under debug.

Set a breakpoint on the EXFMT opcode in the loop that works with the SHOWINFO record format.

Run the program, and see what happens on the EXFMT opcode.

  1. First, it goes to some generated Output specifications, which set the fields into the output buffer from the RPG program variables.
  2. Then it shows the screen.
  3. Then, after you press ENTER, it goes to the generated Input specifications where it loads the RPG program variables from the input buffer.
  4. Then it finally goes to the RPG SELECT statement following the EXFMT.
  5. If you pressed F3, the *IN03 indicator was set on. (Due to the CA03(03) coding in the display file source.)
  6. Similarly, if you pressed F5, *IN05 was set on.
  7. If you pressed ENTER, no indicator was set on.

Debugging

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>