Wednesday, December 4, 2024

DDS display file windows

I was asked a question about using DDS Windows with display files, that is when I noticed I did not have any examples of them. IMHO that is an omission on my part, and I am going to correct here. The examples I will be giving will also answer the question I was asked.

We have been able to create "pop-up" Windows using DDS Display files for many releases, and I have used them for scenarios where a user presses F4 in a field on the display file, a window is displays containing a subfile that the user can select a record from. I am going to keep the following examples much simpler than that, enough to be able to demonstrate some of the features of DDS windows. Examples of coding subfiles in RPG can be found elsewhere on this website.

For these examples I am using one display file and one RPG program. I am going to "break" the display's code into parts so I can describe what is going on and what is different from others. The RPG program can just be shown in one place, as it is very simple. Here is that RPG program:

01  **free
02  ctl-opt option(*srcstmt) dftactgrp(*no) ;

03  dcl-f TESTDSPF workstn indds(Ind) sfile(W4_SFL : W4_RRN) ;

04  dcl-ds Ind qualified ;
05    Exit ind pos(3) ;
06  end-ds ;

07  dow (*on) ;
08    exfmt SCREEN ;

09    if (Ind.Exit) ;
10      leave ;
11    endif ;

12    select FLD001 ;
13      when-is '1' ;
14        exfmt WINDOW1 ;
15      when-is '2' ;
16        W2_LINE = 7 ;
17        W2_POS = 2 ;
18        exfmt WINDOW2 ;
19      when-is '3' ;
20        exfmt WINDOW3 ;
21      when-is '4' ;
22        LoadW4_SFL() ;
23        exfmt WINDOW4 ;
24      when-is '5' ;
25        exfmt WINDOW5 ;
26      when-is '6' ;
27        exfmt WINDOW6 ;
28    endsl ;
29  enddo ;

30  *inlr = *on ;

Line 3: File definition for the display file. I am using an indicator area to rename the indicators from the display file to proper names. And the display file contains a subfile.

Lines 4 – 6: This is the indicator data structure. There is only one indicator in the display file, which I am giving the name of 'Exit'.

Line 7: Start of a "never ending" Do loop.

Line 8: Display the record format SCREEN, using the Execute Format, EXFMT, operation code.

Lines 9 – 11. If the F3 key is pressed the Do loop exited, and the program will end.

Lines 12 – 28: This is an example of the new Select operation code. I put the name of the variable or field I want to compare various values to I do not have to repeat its name. When I use the When Is operation code I just have to put the value of variable to compare to.

The file level keywords in the display file are:

01 A                                      DSPSIZ(24 80 *DS3)
02 A                                      CA03(03 'Exit')
03 A                                      INDARA
04 A                                      ERRSFL

The important keywords to notice are:

Line 3: The indicator area is the other "end" of RPG's indicator data structure,

Line 4: Rather than use a message subfile, that I would need to maintain, I am using a Error Subfile, ERRSFL, which allows for the IBM i operating system to do all the maintenance work for me.

After the program is compiled I call it. The record format SCREEN is displayed.

05 A          R SCREEN
06 A                                  2  2'Field .'
07 A            FLD001         1A  B  2 10

It just contains a single field, FLD001, whatever value I enter into it will display my various DDS windows.

For the sake of this example I am only going to enter the values '1' to '6' in the field.

In the first example I entered '1' in the field and pressed enter. This took me to the first window, record format WINDOW1.

08 A          R WINDOW1                   WINDOW(10 10 3 10)
09 A                                  2  2'Window 1'

Line 8: What I wanted to show here was the purpose of the found numbers in the Window keyword. The numbers represent:

  1. Starting on this line
  2. Starting in this position on that line
  3. Number of lines in the window (height)
  4. Number of positions in the window (width)

In the above example the top lefthand corner is on the tenth line and in the tenth position on that line. There are three lines within the window, and it is ten character wide. This looks like:

I press the Enter key and return to the first screen.

Now I enter '2' and press Enter. WINDOW2 is displayed.

While this window looks similar to Window 1 its definition is different:

10 A          R WINDOW2                   WINDOW(&W2_LINE &W2_POS 3 10)
11 A            W2_LINE        2S 0P
12 A            W2_POS         3S 0P
13 A                                  2  2'Window 2'

Line 10: In the WINDOW keyword there are two "Program-to-System" fields. These are being used to position the window on the screen.

Lines 11 and 12: These are the definitions of the two fields, notice that they have 'P' Use column. This is what defines them as "Program-to-System" fields.

Personally I do not code the WINDOW keyword the way I have shown in WINDOW1 and WINDOW2. I do not like hard-coding the position of the window, as shown in WINDOW1, as if I move the field to another part of the screen I have to remember to change the line and position values too. WINDOW2 in IMHO makes it too complicated. Firstly, I need to calculate where I want the window to be. Secondly, I have to remember to set the fields before I display the window.

My preference is to use the method that I have in WINDOW3.

I enter '3' in FLD001 and WINDOW3 is displayed.

Source code for WINDOW3 is:

14 A          R WINDOW3                   WINDOW(*DFT 3 10)
15 A                                  2  2'Window 3'

Line 14: The *DFT means the position the window at the default position in relation to the field FLD001. For FLD001 the window is displayed on the line below and in the same position.

I prefer using the *DFT as no matter where I move FLD001 to, the operating system determines the best place for the window to be positioned.

My next example shows how I can have a subfile in a window. For all subfiles there is a subfile record format, W4_SFL, and a subfile control record format, WINDOW4:

16 A          R W4_SFL                    SFL
17 A            W4_RRN         2S 0H
18 A            TEXT          10A  O  3  2
    *-------------------------------------------------------
19 A          R WINDOW4                   SFLCTL(W4_SFL)
20 A                                      WINDOW(*DFT 9 12)
21 A                                      SFLPAG(5)
22 A                                      SFLSIZ(10)
23 A                                      SFLDSP
24 A                                      SFLDSPCTL
25 A                                  1  2'Window 4'

When '4' is entered into FLD001 the RPG program calls the subprocedure LoadW4 to load the subfile:

31  dcl-proc LoadW4_SFL ;
32    for W4_RRN = 1 to 9 ;
33      TEXT = 'Line = ' + %char(W4_RRN) ;
34      write W4_SFL ;
35    endfor ;
36  end-proc ;

Lines 32 – 35: I am going to write nine lines to the subfile. All the lines will contain the text: 'Line = ' followed by the line number.

After loading the subfile I display WINDOW4:


This example shows that I do not need a separate subfile control record format, the window's record format can do the same thing.

The last two examples have to do with the message line appears on the screen.

When '5' is entered WINDOW5 is displayed:

26 A          R WINDOW5                   WINDOW(*DFT 5 14)
27 A                                  2  2'Window 5'
28 A                                  4  2'Field .'
29 A            W5_FLD         1A  B  4 10VALUES('A')

Line 29: I have added the VALUES keyword to W5_FLD. The only character it will accept as valid is 'A'.

When I enter a character in W5_FLD that is not 'A' as expected an error message is displayed at the bottom of the window. As the window is narrow it is hard to understand what the message is:

IMHO that is not really use friendly. I want to move the message to the message area at the bottom of the screen. WINDOW6 shows how I can do that.

'6' is entered into FLD001 and WINDOW6 looks identical to WINDOW5.

The code for WINDOW keyword in WINDOW6 is the only really significant difference:

30 A          R WINDOW6                   WINDOW(*DFT 5 14 *NOMSGLIN)
31 A                                  2  2'Window 6'
32 A                                  4  2'Field .'
33 A            W6_FLD         1A  B  4 10VALUES('A')

Line 30:

*NOMSGLIN means that there is no message line in the window.

At the start the window looks like:

Now when I enter a character that is not 'A' in W6_FLD and press Enter, the message is displayed at the bottom of the screen.

Personally, this is my preference.

I hope you will find what I have written above useful. For the person whose question started this, you now have your answer too.

 

This article was written for IBM i 7.5, and should work for some earlier releases too.

4 comments:

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.