20
Sat, Apr
5 New Articles

The Pop-up Calendar Window

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

The odds are pretty good that you can see at least one calendar from where you are now seated. Calendars have always been a necessary part of any business environment. In respect to information services, almost all data entry functions involve one or more date fields. If you take these two facts under consideration, you could probably draw the following logical conclusion: Combining an online calendar with data entry functions will save labor and enhance ease of use. It is this very premise that serves as the foundation for this article.

Past and Present

If you followed our article last month (“Turning Pop-ups into Home Runs,” MC, August 1998), you will remember that our focus was on using pop-up windows to enhance software “usability.” This month’s focus is going to follow the same theme, except that we will show you how to code a pop-up calendar that is ready for the Year 2000 and beyond.

The simple print request program seen in Figure 1 looks very much the same as the print request program we looked at last month. The RPG IV code in Figure 2 is the code to replace the Browse subroutine in the PRT002RG program we published last month (the differences in the subroutine are represented by the shaded area of the code). You may find the code for the PRT002DF display file and the PRT002RG RPG IV program either in last month’s issue of Midrange Computing or on the Web site at http://www.midrangecomputing.com/code.

What’s new in this article is the pop-up window calendar program seen in Figure 3. The pop-up calendar can go back to January 1, 1901 (the base date used in the calendar program) or forward for the next 8,000 years or so (assuming IBM maintains the sliding window. It is currently 40, but it will probably be 50 in the next couple of years or so). This can be accomplished because of the date data type and the date “math” that RPG IV

allows us to use. Obviously, the calendar program is Y2K safe and may be called from any RPG III or RPG IV program.

What a Difference a Date Makes...

Let’s begin by talking about the simple print request prompt screen seen in Figure
1. If you read last month’s article, you will remember that this program allows operators to press the F4 prompt key when the cursor is located on the printer field. The result of this action is that a pop-up window with a list of available printers is presented on the screen.

This month, we updated the program so that the operator could also press the F4 prompt key when the cursor is located on either the “from” or “to” date fields.

The pop-up calendar seen in Figure 3 will be presented when F4 is pressed and the cursor is located on either field. The operators may use the Page Up or Page Down key to scroll through the months until they find the desired month, day, and year. They may then select a date by keying the two digits they see on-screen, which represent the date they wish to select. The corresponding date will be returned to the calling program.

By examining the code in Figure 2, you can see that the Browse subroutine calls the CAL001RG program (which you can download from the MC Web site at http://www.midrangecomputing. com/code), which presents the pop-up calendar, or it calls the WIN001RG program (seen in last month’s article), which presents a pop-up window for printer selection.

The determination for which program is called is predicated upon the name of the field where the cursor resides when the F4 key is pressed. If the cursor is on the field named PRINTER, the WIN001RG program will be called so that the operator may select a valid printer from the selections presented in the pop-up window program. If the cursor happens to be positioned on the fields named FROMDATE or TODATE, the CAL001RG program will be called, and the pop-up calendar will be presented.

Regardless of which program is called, the operator will have the opportunity to select one of the options, and the associated value will be returned to the print request prompt screen.

In last month’s article, we discussed how the Return Cursor Location (RTNCSRLOC) DDS keyword utilized in our display file (seen in last month’s article) can be used to tell your RPG programs where the cursor is located when certain functions are performed. In that example, the field named CSRFLD (cursor field) is defined as a hidden field (designated by a usage of H in column 38) at the field level of the display file and then used in the record level when the RTNCSRLOC keyword is specified. The combination of these two DDS allows us to query the field named CSRLOC from within our RPG IV program to determine the field name where the cursor resides at the time F4 is pressed. If the field name in CSRLOC is deemed to be “browse” or “prompt” capable, the appropriate pop-up window program is called and the operator makes the desired selection.

The CSRROW (cursor row) and CSRCOL (cursor column) hidden fields defined in the display file are used in conjunction with the CSRLOC (cursor location) DDS record- level keyword to set the cursor location, once the browse function has been performed. This function is explained in detail in last month’s article.

I’m Late! I’m Late for a Very Important Date!

Now that we have covered the background material and the print request prompt program, it is finally time to get to the principal purpose of this article.

The pop-up calendar seen in Figure 3 is coded using the display file described in Figure 4 and the RPG IV program CAL001RG.

Taking a look at the DDS for the display file in Figure 4, you can see that the primary record format is coded using DDS window keywords that invite the system to take care of the pop-up window management for you. The Page Up and Page Down keys are allowed because that is how the operator will page back and forth through the months and years.

We also specified a dummy format with the KEEP and ASSUME DDS keywords, but this format is never used. This code is generally required when one interactive program calls another program that happens to present a DDS window. When the KEEP and ASSUME keywords are not present in the display file of the called program, the display format of the calling program is inexplicably blanked out, even though the DDS window keywords are present.

The code for the CAL001RG RPG IV program uses a base date of January 1, 1901, as we mentioned earlier. We could have chosen any arbitrary date as our basis for our calendar calculations. We chose a date quite far in the past because it made our coding a little easier. Regardless of the base date used, the Add Duration (ADDDUR) and Subtract Duration (SUBDUR) operation codes, which were added with RPG IV, may then be used to create a very simple calendar program.

There are two parameters for our calendar program. We allowed for a return code (aptly named ReturnCode) and a six-digit date (which we named PassDate). If the operator presses one of the function keys, we simply pass a value back to the calling program, indicating the function that was chosen. If the operator chooses to select a date by keying in the two digits that correlate to a date seen on the on-screen calendar, the selection is translated to a six-digit date (as mmddyy); it is then passed back to the calling program, along with a return code indicating that a valid date selection was chosen.

When the operator presses Page Up or Page Down, we use ADDDUR or SUBDUR to add or subtract a month from the displayed calendar and then redisplay the screen. If the operator keys a date that is not displayed on the screen, an error indicator is turned on and the screen is redisplayed along with the error.

For aesthetic purposes, we also added a compile-time array representing the names of the months. This table is used to simply convert the numerical month to its alphanumeric equivalent so it can be displayed in the heading.

We also used an old RPG trick to highlight the current date on the calendar. By setting the appropriate hexadecimal values, you can control screen display attributes on the fly. For our purposes here, we wanted to be able to show the current date as high intensity. To do so required that we define two fields: one for setting on high intensity and another to return the screen to normal intensity. The calendar subroutine concatenates these fields around the two-digit day if the display date happens to match the current date.

We could have added a little code to implement DDS pull-down menus to help aid in the selection of the month and year, but, because of space constraints, we will have to leave that for yet another article.

This program is coded so generically that it can easily be called from any place where a date is required. As you can see from the code in the Browse subroutine in Figure 2, it is very simple to implement this handy pop-up calendar window.

The Dating Game, RPG IV Style

We have written numerous articles about RPG IV and the date data type. This article includes yet another example of how to combine RPG IV and the date data type to make your system ready for the next century. The AS/400 is ready for the twenty-first century. Are you?

<>
<>
<>

The_Pop-up_Calendar_Window04-00.png 900x500

Figure 1: Simple print request program

***** subroutine: “Browse” ***********************************

***** perform browse/prompt function ***************************
C Browse begsr * find and set cursor location so cursor will stay at same position when

* screen is redisplayed
c Bin div 256 CsrRow
c mvr CsrCol
c eval *in77 = *on * if prompt was requested on a “prompt capable” field, get window
c Select
c when csrfld = ‘PRINTER’
c call ‘WIN001RG’
c parm *blanks ReturnCode
c parm csrfld FileName
c parm *blanks PassCode
c if ReturnCode = ‘50’
c movel PassCode Printer
c endif * browse date fields
c when csrfld = ‘FROMDATE’ or
c csrfld = ‘TODATE’
c call ‘CAL001RG’
c parm *blanks ReturnCode
c parm *zeros PassDate 6 0
c if ReturnCode = ‘50’
c if CsrFld = ‘FROMDATE’
c movel PassDate FromDate
c endif
c if CsrFld = ‘TODATE’
c movel PassDate ToDate
c endif
c endif
c endsl
csr endsr

Figure 2: Replacement “Browse” subroutine for the PRT002RG program

<>
<>
<>

Figure 3: Pop-up calendar window


*===============================================================

* To compile:

*

* CRTDSPF FILE(XXX/CAL001DF) SRCFILE(XXX/QDDSSRC)

*

*===============================================================

A DSPSIZ(24 80 *DS3) CHGINPDFT

A CA03 CA12

A R WINDOW

A WINDOW(9 45 12 30 *NOMSGLIN *NORSTCA SR)

A ROLLUP(95)

A ROLLDOWN(96)

A HEADING 30A O 1 1DSPATR(HI)

A COLOR(RED)

A 3 1’ Sun Mon Tue Wed Thr Fri Sat’

A DSPATR(HI)

A WEEK1 30A O 4 1

A WEEK2 30A O 5 1

A WEEK3 30A O 6 1

A WEEK4 30A O 7 1

A WEEK5 30A O 8 1

A WEEK6 30A O 9 1

A 10 2’Key date, press Enter.....’

A DSPATR(HI)

A COLOR(BLU)

A KEYDAY 2Y 0B 10 29DSPATR(HI)

A CHECK(RZ)

A 41 DSPATR(PC)

A 41 ERRMSG(‘The day you have keyed is n-

A ot valid’)

A 12 1’F3=Exit’

A COLOR(BLU)

A 12 9’F12=Previous’

A COLOR(BLU)

A 12 22’Page keys’

A COLOR(BLU)

A R DUMMY

A KEEP

A ASSUME

A 1 3’ ‘

Figure 4: The CAL001DF display file



The_Pop-up_Calendar_Window05-00.png 899x514
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$

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: