Getting Started with IBM i RPG: Display files aka Workstation Files

Display files aka Workstation Files

Display files, also known as workstation files, are how RPG programs interact with users through screens. Whether you're prompting for a name or building dynamic interfaces with function keys and real-time data, display files are your gateway to user-friendly RPG applications.

Step 1: Create a Simple Display File

Start by creating a source member named RPGDSPF with type DSPF. Paste in this basic layout:

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

Compile it to generate the display file RPGDSPF.

Step 2: Show the Screen

Now compile and run this RPGLE program:

dcl-f rpgdspf workstn;

exfmt getname;
dsply ('Your name is ' + name);
*inlr = '1';

This program displays the screen, captures the user's input, and echoes it back using the DSPLY opcode.

Step 3: Add a More Interactive Screen

Let’s level up. Modify the display file to include a second record format called SHOWINFO, with input/output fields and function key indicators:

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)

Recompile the display file, then run this enhanced RPGLE program:

dcl-f rpgdspf workstn;
dcl-s done ind;

exfmt getname;
done = '0';
condition = 'Cloudy';

dow not done;
curtime = %time();
exfmt showinfo;

select;
when *in05;
// F5 = Refresh (no action needed)
when *in03;
// F3 = Exit
*inlr = '1';
return;
other;
// ENTER = Redisplay
endsl;
enddo;

Try changing the CONDITION field to "Raining", press Enter, then change it to "Warm" and press F5. Notice how F5 refreshes without updating the value, ENTER commits the change.

What’s Happening Behind the Scenes?

Compile with DBGVIEW(*LIST) or DBGVIEW(*ALL) and debug the program. Set a breakpoint on the EXFMT showinfo line.

Here’s the flow when EXFMT runs:

  1. Output Specs: RPG loads screen fields from program variables.

  2. Display: The screen appears.

  3. Input Specs: RPG updates variables from user input.

  4. Control Logic: RPG executes the SELECT block based on function key indicators.

  • Pressing F3 sets *IN03 (thanks to CA03(03)).

  • Pressing F5 sets *IN05.

  • Pressing Enter sets no indicators.

Summary

Display files are the bridge between RPG logic and user interaction. With just a few lines of DDS and RPGLE, you can build screens that respond to input, refresh dynamically, and handle user actions with precision.

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