Are your users tired of the old, boring green-screen applications? Using some of the enhanced DDS display functions, you can make your old applications look better and be easier to use at the same time. Youre probably already familiar with creating windows in a display file, but you may not know that you can create a Windows-like scroll bar within a subfile window. You also may not realize just how easy it is to create dynamic pull-down menus. Once youve read this article, youll know both.
Windowing Basics
I will start off with the basicsdisplay file windows. The window display file record type has been around for years, yet I am constantly amazed by how underused this tool is. A window record can be used in the same way that a standard display record would be used but will allow you to limit the cursor to the window area of the screen giving the application a more finished look. When displayed within PC5250 or another terminal client that supports enhanced display functions, these windows appear with almost a 3-D look. The key to defining a window is the WINDOW record-level DDS keyword. This keyword is used to define the look of the window including its size and position. The WINDOW DDS keyword is specified in the format WINDOW(y-position, x-position, height, width). These four parameters can be statically defined within the display file, or static values can be replaced by program-to-system fields that can be used to dynamically change these values from within your application program. You can easily add a title to your window using the WDWTITLE keyword. This keyword is specified as WDWTITLE([title-text] [title-textcolor][title-text-display-attribute] [*CENTER | *LEFT | *RIGHT] [*TOP | BOTTOM]). The title text parameter is used to specify the text to be displayed on the title. This is specified in the format (*TEXT title) where title is either a text literal or a program-to- system field name, which is to contain the title text. The title-text-color parameter is specified in the format (*COLOR color) where color is a three-letter abbreviation for the required color. The title text display attribute can be used to specify additional display attributes for the window title. This is specified using the format (*DSPATR Attrib) where Attrib is a valid display attribute code such as RI for reverse image display. The *CENTER, *LEFT, and *RIGHT parameters allow definition of where the title is displayed horizontally on the window. The *TOP and *BOTTOM parameters allow you to
define whether the title is displayed on the top or bottom of the window. You can also use the WDWBORDER keyword to change the color or display attributes of the window border. This keyword is specified using the format WDWBORDER([color] [display attribute] [characters]). The color and display attribute are specified in the same manner that is used for the WDWTITLE keyword. The characters parameter can be used to redefine the character used for the windows border when displayed on a device that is not enhanced display capable. The parameter is coded as WDWBORDER(*CHAR followed by a string containing the top left, top, top right, left, right, bottom left, bottom, and bottom right characters, in that order. Figure 1 shows a sample of how to use the WINDOW and WDWTITLE keywords within a display file. Windowing can be used in a variety of ways to make your application better looking and easier to use. A good example of this would be creating a window to contain the help text for your application. Another good example would be using a window to display a list of customers when a prompt key is pressed from within your order-entry application. Of course, this kind of list would normally be programmed using a subfile display. Thats where windowed subfiles come in.
The OS/400 List Box
Displaying a subfile within a window gives you the same functionality and look from green-screen applications that you would get by using a list box in a Windows application, and the programming technique is basically the same that you would use for a standard subfile. The main difference is that the subfile control record also contains the WINDOW keyword (and, if desired, the WDWTITLE keyword). Figure 2 contains a sample of the code that would be used to create a simple list box. Using this technique, you can easily create a program to be used as a prompt from any program needing to display similar lists. Even better, you could create a user-defined ILE function to display your list and return the selected field to the calling application as shown here:
C If *INKD = *ON
C Eval Cust=SelectCust
C EndIf
In this example, F4 would be used as the prompt key, and, when this key is pressed, the Eval op code causes the program to call the SelectCust user-defined function, which displays a list of customers using a subfile window and allows the user to select a customer. The selected customer number would then be returned into the Cust field. In the event that the user gets out of the screen without making a selection, a blank would be returned to the application. To give your subfile window a more GUI look, you can use the SFLEND(*SCRBAR *SCRBAR) DDS keyword. This will cause the application to display a scroll bar that can be used in place of the page-up and page-down keys to navigate the subfile. This record-level DDS keyword can be controlled using an indicator to selectively display the scroll bar only when the number of records in the subfile is more than one page. The *SCRBAR control is dynamic and sized based on the number of records in the subfile. The more records there are, the smaller the slide bar is. The automatic sizing is based on a
load and go subfile so if you are doing page at a time subfiles the scroll bar will not be sized in proportion to the number of records. Figure 3 shows a sample of a subfile window display using a scroll bar. If you are running this application on a display that supports enhanced display functions and a mouse (like PC5250), you can slide the bar using the mouse. The best part is that you can still run the same application on a device that doesnt handle enhanced display functions, which means your application has full backward compatibility.
Waiter, Id Like to See a Menu Please
Like display file windows, pull-down menus and menu bars allow you to give your application a more user-friendly interface. The concept with menus is this: Your application contains a menu bar, which is defined using the MNUBAR record-level display file keyword. The menu bar format contains one field, which is a two-position numeric field. The MNUBARCHC keyword is used on this field to define the menus available. This keyword uses the format MNUBARCHC(Choice_# Pull_Down_Record_Format Menu_Text &field_name). The Choice_# is the option that is returned to the application to identify what menu was selected. The pull-down record format parameter identifies the name of the record format of the pull-down to be displayed when this menu is selected. The menu text identifies what is displayed as the menu heading. The greater-than sign (>) can be used to identify the hot key to be used for this menu. When the menu is displayed, this key will be underlined. An example would be a FILE menu where the hot key is the letter
F. The menu text would be keyed in as >File and would be displayed as File. When the menu bar is in use, the F key can be used to display the associated pull-down record. The display of the menu bar is controlled using the MNUBARDSP record-level keyword, which is used on the record format that you want the menu bar to be displayed on. The format of this keyword is MNUBARDSP(menu_bar &option_field [&pull_down_field]). The first parameter defines the menu bar to be used when this record format is displayed. The &option_field parameter is the name of a hidden numeric field, which will contain the option number of the menu selected from the menu bar. The optional &pull_down_field parameter is a hidden, zoned numeric field, which upon input would contain the option selected from the pull-down format. The value returned into this variable would be 0 if no input is selected or -1 if your pull-down record does not consist of one single-choice field. Additional menu bar keywords include the menu bar switch (MNUBARSW) and menu cancel (MNUCNL) keywords, which are used at the file level to define what function keys to use to select a menu bar or to deactivate the menu bar. Defining menus also requires the definition of a pull-down record format, which is identified by the PULLDOWN record- level keyword. A pull-down menu can contain any type of field required but usually would contain a field to select an option along with a list of options. A more flexible alternative would be a subfile pull-down. Like a subfile window, a subfile pull-down is defined by adding the SFLCTL keyword to the pull-down record. The programming logic is the same logic that would be used to create any other subfile behind a subfile pull-down (i.e., subfile clear, write records, display subfile) with one difference. The displaying of the subfile pull- down is controlled by the menu bar that it is attached to. This is a very flexible way to dynamically add or remove menu options from within your application. Figure 4 (page
105) contains a sample of a basic menu bar/pull-down display file. You can see that there is not a lot of coding required to add this powerful feature to your applications.
Let the Sun Shine In
You may have worked with some applications that use windows. You may have written some applications of your own that make use of display file windowing or pull-down menus. But once youve started to consider all of the different ways that you can use these enhanced display features, youll be using them everywhere you possibly can. But windows and menus are just the beginning of what you can do with enhanced display functions. The 5250 enhanced data stream can support display objects such as radio buttons, check boxes, and push buttons, just to mention a few. Any of these can allow you to gain more control of your user interface while making your applications more user- friendly at the same time. So open up a few (enhanced display) windows and let the sun shine on your green-screen applications.
REFERENCES AND RELATED MATERIALS
AS/400e DDS Reference Version 4 (RBAF-P000-00)
A* Window display file sample
A*
A R WINDOW
A WINDOW(&TOP &LEFT 15 40)
A WDWTITLE((*TEXT 'TEST WINDOW'))
A 6 5'FIELD 1'
A 8 5'FIELD 2'
A 10 5'FIELD 3'
A FIELDA 10A B 6 15
A FIELDB 15A B 8 15
A FIELDC 8S 0B 10 15
A TOP 2S 0P
A LEFT 3S 0P
Figure 1: This shows the basic code required to generate a display file window.
A* Sample subfile window display file
A*
A* Subfile record
A R SFL1 SFL
A SEL 1A B 2 2VALUES("'1')
A CUST# 5S 0O 2 4
A CNAM 20S 0O 2 11
A*
A* Window/subfile control record
A R WINDOWSF SFLCTL(SFL1)
A CA03
A 50 SFLDSP
A 50 SFLDSPCTL
A N50 SFLDLT
A N50 SFLCLR
A 30 SFLEND(*SCRBAR *SCRBAR)
A SFLSIZ(0999)
A SFLPAG(0014)
A WINDOW(2 22 16 35)
A WDWTITLE((*TEXT 'SELECT CUSTOMER'))
Figure 2: This is a sample of the code required to display a subfile window.
Figure 3: Here is a sample of the way a subfile window is display using a scroll bar on an enhanced display (left) and a non-enhanced display (right).
A* Sample Menu Bar/Pull-Down Display file
A MNUBARSW(CA10)
A MNUCNL(CA12 12)
A*
A* Menu bar record format
A*
A R MENUBAR MNUBAR
A MNUFLD 2Y 0B 1 2
A MNUBARCHC(1 FILEMENU +
A '>FILE ')
A MNUBARCHC(2 EDITMENU +
A '>EDIT ')
A*
A* Pull down menu record formats
A*
A R FILEMENU PULLDOWN
A F1 1D 0B 1 2RANGE(1 3)
A 1 5'1. OPEN '
A 2 5'2. SAVE '
A 3 5'3. EXIT '
A R EDITMENU PULLDOWN
A F2 1D 0B 1 2RANGE(1 3)
A 1 5'1. UNDO '
A 2 5'2. COPY '
A 3 5'3. PASTE'
A R SCREEN MNUBARDSP(MENUBAR &MNUCHC)
A FIELD1 10A B 10 12
A FIELD2 5S 0B 14 12
A 24 1'F10=MENUS F12=CANCEL '
A MNUCHC 2Y 0H
Figure 4: This is the DDS source code to create menu bars and pull-downs.
LATEST COMMENTS
MC Press Online