04
Mon, Nov
6 New Articles

Opening Windows and Menus in DDs

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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. You’re 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 you’ve read this article, you’ll know both.

Windowing Basics

I will start off with the basics—display 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. That’s 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 doesn’t handle enhanced display functions, which means your application has full backward compatibility.

Waiter, I’d 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 you’ve started to consider all of the different ways that you can use these enhanced display features, you’ll 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


Opening_Windows_and_Menus_in_DDs04-00.png 598x226

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.


Mike Faust

Mike Faust is a senior consultant/analyst for Retail Technologies Corporation in Orlando, Florida. Mike is also the author of the books Active Server Pages Primer, The iSeries and AS/400 Programmer's Guide to Cool Things, JavaScript for the Business Developer, and SQL Built-in Functions and Stored Procedures. You can contact Mike at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Mike Faust available now on the MC Press Bookstore.

Active Server Pages Primer Active Server Pages Primer
Learn how to make the most of ASP while creating a fully functional ASP "shopping cart" application.
List Price $79.00

Now On Sale

JavaScript for the Business Developer JavaScript for the Business Developer
Learn how JavaScript can help you create dynamic business applications with Web browser interfaces.
List Price $44.95

Now On Sale

SQL Built-in Functions and Stored Procedures SQL Built-in Functions and Stored Procedures
Unleash the full power of SQL with these highly useful tools.
List Price $49.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: