TechTip: Spice Up Your Web Pages, Part Two

Web Languages
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

In my last TechTip, I spiced up an RPG CGI program by adding colors and status messages, which made the Web page more user-friendly to look at and work with. This time, I will expand it even more by adding features that display pictures and information about the various Elvis Costello records. So widen your programming knowledge—and even more important, get to know a little more about Mr. Costello.

Let me first sum up the most important things that I have changed in the RPG CGI program compared to the previous version.

  1. Instead of reading the HTML skeleton file from a source member in a library, the program now reads from an IFS skeleton document.
  2. It is now possible to display cover notes about each album.
  3. It is also possible to display an image of the cover.

Does this sound compelling? Well, let's hit the road and see where it leads to.

Reading Skeleton File from the IFS

In all my previous tips, I have been using a skeleton HTML member to read into the RPG CGI program and then using keywords to control the placement of variable data. Until now, the skeleton member has been placed in a source file, so the easiest way to edit it is using SEU or WDSC. By placing the skeleton file in the IFS, you can use your favorite HTML editor to edit the skeleton file and transfer it to the IFS by using FTP or a share.

In order to read from the IFS, you have to use APIs. Various tips and articles have been written about this subject, but the best one I have read so far is by Scott Klement. So if you are new to the IFS, I suggest you read "Working with the IFS in RPG IV." When you have read it, download the source to BUFIO_H, which is a copybook member where Scott has defined all the protoypes for the IFS APIs used in this example.

Reading the IFS File

I will only briefly explain how reading the IFS file works because this is such a huge subject that it could be a tip itself (and I would be inventing the wheel).

If you look in the FORM009 RPG CGI program and find subroutine subrCreateHTMLreply, you will see that all the overrides and the reading of the source member have been replaced by calls to Scott's prototypes. The IFSpath and IFSfile, which contain the path and the name of the skeleton file, are passed to the fopen function.

Note the 'r' parameter, which will open the file as read-only. Then the file pointer is checked; if it contains a NULL value, the skeleton file was not found or the path was incorrect. If this is the case, an error message is sent to the browser and the program ends. If everything is OK, the fgets functions are called and the first line in the IFS skeleton file is read into the program. The input buffer is moved into an internal field, and you are ready to start using the data.

A subset of the code looks like this:

BegSr subrCreateHTMLreply;                              
  file = fopen( IFSpath + '/' + IFSfile : 'r');         
 // IFS file not found                                  
 if (file = *NULL);                                     
   MakeHTML( 'ERROR - Skeleton file not found : '
           + IFSpath                                    
           + '/'                                        
           + IFSfile                                    
           + NewLine                                    
   ExSr StopPgm;                                        
 dou 1 = 2;                                             
 // Read data                                           
p_data = fgets( %addr(space): %size(space): file ); 
// End of file                                      
if  ( p_data = *NULL ) ;                            
 leave ;                                            
endif ;                                             

// Move data read into an internal field                          
   line = %str(p_data);                             

Then the program continues just as any other RPG CGI programs I have used until now.

Introducing overLib

Do you remember Figure 1 from the first "Spice Up Your Web Pages" tip? In that tip, the Web page contained four frames, but only three of them were used.

Now the RPG CGI program is modified so that the fourth frame displays the picture of the album cover in the "coverframe." This will appear when you do a mouseover in the list of albums.

Figure 1: Note the "coverframe" frame.

To do that, I will use a JavaScript library called overLib written by Erik Bosrup. overLib provides a very easy way to make small (or big) pop-ups containing all kinds of information appear anywhere on your Web page.
The strength of overLib is the following:

  • Very easy to implement
  • Very good documentation
  • Has a wide range of plug-ins
  • Has a developer community

To add overLib to your HTML document, you only have to follow three steps:

  1. Download and unzip it from here.
  2. Add the following to your HTML section:

  3. Add the following just after your section:

Done! you are now ready to start using overLib and all its functionality. If you are confused, I have created a small example you can download here. You can also view it here.

To understand how overLib works, think of an RPG program into which you can pass various keywords and parameters and have the program then add that specific function to the interface.

If you look at the code in my example, you'll see that to create a simple pop-up, you only have to add the following code:

 Pressonline which will teach you how to use overLib');" 

onmouseout="return nd();">Move mouse over this text

The mouseover event will call the overLib JavaScript function, which will display the pop-up with the look and feel defined by the default parameters.

If you, for example, want to add a red background and change the font to Times Roman size 14px, you would just add the following to the parameter list when calling overLib:

FGCOLOR,'red', TEXTFONT, 'Times Roman',TEXTSIZE, '14px'  

This would make the line look like this:

 Pressonline which will teach you how to use overLib',FGCOLOR,'red', 

TEXTFONT, 'Times Roman',TEXTSIZE, '14px');" onmouseout="return 

nd();">Move mouse over this text

See how it looks here.

Note that onmouseout will call a function called nd(), which removes the pop-up. If you do not want to remove the pop-up, remove the onmouseout event. Also note that of course you do not have to use the onmouseover event; it could as well be onclick or ondblclick.

To see all the valid parameters that can be passed to overLib, have a look at the Command Reference, which provides a very good overview of all that overLib can do.

Now you have an idea how overLib works, so let's start using it in the RPG CGI program.

First, we will prepare for overLib to be called. I will go through it step by step:

1. Create a dir in your rootdir called /rootdir/mcpressonline/spice2/ by entering the following command, replacing rootdir with your Web server's rootdir:

md '/rootdir/mcpressonline/spice2/'

2. Download and unzip the spice2 files. FTP everything to the dir you just created.

3. When you're done, your /rootdir/mcpressonline/spice2/ should look like this:

Figure 2: Your /rootdir/mcpressonline/spice2/ should look like this.

Now, if you look in the form009h.htm file, you'll see that I have added the following lines in order to make the RPG CGI program ready.

Figure 3: This code will make the RPG CGI program ready.

Adding the Cover Notes

We are now ready to start using overLib in the RPG CGI program.

(Note: The source code is available for download at the bottom of the article.)

The first thing we will do is add the possibility to see cover notes. I have created a new database called ALBUMNOTES and added a few records to it. I have also added a checkbox to the top.htm file so that you can select whether you want to see the cover notes or not.

To make it easy to add new parameters to the overLib call, I have created two compile-time arrays called Aryoverlib and Aryoverlib1. When the program starts, it builds two variables containing the data from the arrays.

So when I want to add cover notes or a cover image, I check the content of the checkbox, and when records are read, I use the ID to chain to ALBUMSNOTES.
Because JavaScript doesn't like quotes and double quotes, I created a subroutine that makes the text "pretty" by replacing these characters with the HTML codes.

Then, I scan overlibLine1 for the string %%notes%%, which uses the ReplaceIt prototype to insert the cover notes data and writes the line to the browser.

The call to overLib for the cover notes looks like this:

Figure 4: This is the call for the cover notes.

Note that I am using the onclick event to display the cover notes. Also note the STICKY and CLOSECLICK commands, which ensure that the pop-up will disappear only when Close is clicked or another pop-up is requested.

The browser now looks like Figure 5:

Figure 5: Now you can see the cover notes!

Adding the Cover Image

If you look again at Figure 3, you will note the reference to a JavaScript file called overlib_crossframe.js. The name itself almost tells us what this is used for. Because we will display the cover in the frame called coverframe (see Figure 1) using cover.htm, we need some kind of mechanism to do that. The call to overLib is shown in Figure 6:

Figure 6: Here's the call to overLib.

There are three important commands here:

  • BACKGROUND will display the cover, with %%cover%% replacing the path to the .jpg image. The path to the pictures is defined in the FORM009 RPG CGI program in constant "coverpath."
  • FIXY and FIXX will place the image in pixel 2 from top and pixel 2 from left.
  • FRAME refers to the frame called coverframe and uses the JavaScript function called "parent."

If you look at the cover.htm file, you will notice that

is also defined in this file. If it is not, the picture will not be displayed.

That's pretty much it. When the line is replaced, the browser looks like Figure 7:
Figure 7: Here's your cover image!

One very important thing here is that all the HTML files and pictures must reside on the same Web server as the RPG CGI program, because the phenomenon called cross-framing is only allowed within the same Web server .

Getting the Source Code

Some of the links below have already been presented in this article, but this list represents everything you need:

Important Reminders:
Remember to change the “your-data-lib” in the RPG source to where you placed the data files.

Change your-root-dir in constant IFSpath to your actual root dir.

When you have installed everything and compiled the RPG program (you will find the compile instructions in the header description), call the program by entering the following URL: http://your-server-name/mcpressonline/spice2/.


I hope this tip has given you some ideas about how a little JavaScript and a pretty simple RPG program can help you spice up those dull Web pages and also add some very useful functionality.

And one more very important thing: If you do not know Elvis Costello, check out his Web site. All his CDs can be bought online!

Jan Jorgensen is a programmer at Electrolux Laundry Systems Denmark. He works with stuff like RPG, HTML, JavaScript, and Perl. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..

Jan Jorgensen

Jan Jorgensen is one of the owners of, which specializes in mobile and i5 solutions. He works with RPG, HTML, JavaScript, Perl, and PHP. You can reach him at




Support MC Press Online





  • White Paper: Node.js for Enterprise IBM i Modernization

    SB Profound WP 5539

    If your business is thinking about modernizing your legacy IBM i (also known as AS/400 or iSeries) applications, you will want to read this white paper first!

    Download this paper and learn how Node.js can ensure that you:
    - Modernize on-time and budget - no more lengthy, costly, disruptive app rewrites!
    - Retain your IBM i systems of record
    - Find and hire new development talent
    - Integrate new Node.js applications with your existing RPG, Java, .Net, and PHP apps
    - Extend your IBM i capabilties to include Watson API, Cloud, and Internet of Things

    Read Node.js for Enterprise IBM i Modernization Now!


  • Profound Logic Solution Guide

    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 companyare not aligned with the current IT environment.

    Get your copy of this important guide today!


  • 2022 IBM i Marketplace Survey Results

    Fortra2022 marks the eighth edition of the IBM i Marketplace Survey Results. Each year, Fortra captures data on how businesses use the IBM i platform and the IT and cybersecurity initiatives it supports.

    Over the years, this survey has become a true industry benchmark, revealing to readers the trends that are shaping and driving the market and providing insight into what the future may bring for this technology.

  • Brunswick bowls a perfect 300 with LANSA!

    FortraBrunswick is the leader in bowling products, services, and industry expertise for the development and renovation of new and existing bowling centers and mixed-use recreation facilities across the entertainment industry. However, the lifeblood of Brunswick’s capital equipment business was running on a 15-year-old software application written in Visual Basic 6 (VB6) with a SQL Server back-end. The application was at the end of its life and needed to be replaced.
    With the help of Visual LANSA, they found an easy-to-use, long-term platform that enabled their team to collaborate, innovate, and integrate with existing systems and databases within a single platform.
    Read the case study to learn how they achieved success and increased the speed of development by 30% with Visual LANSA.


  • The Power of Coding in a Low-Code Solution

    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:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks



  • Why Migrate When You Can Modernize?

    LANSABusiness 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.
    In this white paper, you’ll learn how to think of these issues as opportunities rather than problems. We’ll explore motivations to migrate or modernize, their risks and considerations you should be aware of before embarking on a (migration or modernization) project.
    Lastly, we’ll discuss how modernizing IBM i applications with optimized business workflows, integration with other technologies and new mobile and web user interfaces will enable IT – and the business – to experience time-added value and much more.


  • UPDATED: Developer Kit: Making a Business Case for Modernization and Beyond

    Profound Logic Software, Inc.Having trouble getting management approval for modernization projects? The problem may be you're not speaking enough "business" to them.

    This Developer Kit provides you study-backed data and a ready-to-use business case template to help get your very next development project approved!

  • What to Do When Your AS/400 Talent Retires

    FortraIT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators is small.

    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:

    • Why IBM i skills depletion is a top concern
    • How leading organizations are coping
    • Where automation will make the biggest impact


  • Node.js on IBM i Webinar Series Pt. 2: Setting Up Your Development Tools

    Profound Logic Software, Inc.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. In Part 2, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Attend this webinar to learn:

    • Different tools to develop Node.js applications on IBM i
    • Debugging Node.js
    • The basics of Git and tools to help those new to it
    • Using as a pre-built development environment



  • Expert Tips for IBM i Security: Beyond the Basics

    SB PowerTech WC GenericIn this session, IBM i security expert Robin Tatam provides a quick recap of IBM i security basics and guides you through some advanced cybersecurity techniques that can help you take data protection to the next level. Robin will cover:

    • Reducing the risk posed by special authorities
    • Establishing object-level security
    • Overseeing user actions and data access

    Don't miss this chance to take your knowledge of IBM i security beyond the basics.



  • 5 IBM i Security Quick Wins

    SB PowerTech WC GenericIn today’s threat landscape, upper management is laser-focused on cybersecurity. You need to make progress in securing your systems—and make it fast.
    There’s no shortage of actions you could take, but what tactics will actually deliver the results you need? And how can you find a security strategy that fits your budget and time constraints?
    Join top IBM i security expert Robin Tatam as he outlines the five fastest and most impactful changes you can make to strengthen IBM i security this year.
    Your system didn’t become unsecure overnight and you won’t be able to turn it around overnight either. But quick wins are possible with IBM i security, and Robin Tatam will show you how to achieve them.

  • Security Bulletin: Malware Infection Discovered on IBM i Server!

    SB PowerTech WC GenericMalicious programs can bring entire businesses to their knees—and IBM i shops are not immune. It’s critical to grasp the true impact malware can have on IBM i and the network that connects to it. Attend this webinar to gain a thorough understanding of the relationships between:

    • Viruses, native objects, and the integrated file system (IFS)
    • Power Systems and Windows-based viruses and malware
    • PC-based anti-virus scanning versus native IBM i scanning

    There are a number of ways you can minimize your exposure to viruses. IBM i security expert Sandi Moore explains the facts, including how to ensure you're fully protected and compliant with regulations such as PCI.



  • Encryption on IBM i Simplified

    SB PowerTech WC GenericDB2 Field Procedures (FieldProcs) were introduced in IBM i 7.1 and have greatly simplified encryption, often without requiring any application changes. Now you can quickly encrypt sensitive data on the IBM i including PII, PCI, PHI data in your physical files and tables.
    Watch this webinar to learn how you can quickly implement encryption on the IBM i. During the webinar, security expert Robin Tatam will show you how to:

    • Use Field Procedures to automate encryption and decryption
    • Restrict and mask field level access by user or group
    • Meet compliance requirements with effective key management and audit trails


  • Lessons Learned from IBM i Cyber Attacks

    SB PowerTech WC GenericDespite the many options IBM has provided to protect your systems and data, many organizations still struggle to apply appropriate security controls.
    In this webinar, you'll get insight into how the criminals accessed these systems, the fallout from these attacks, and how the incidents could have been avoided by following security best practices.

    • Learn which security gaps cyber criminals love most
    • Find out how other IBM i organizations have fallen victim
    • Get the details on policies and processes you can implement to protect your organization, even when staff works from home

    You will learn the steps you can take to avoid the mistakes made in these examples, as well as other inadequate and misconfigured settings that put businesses at risk.



  • The Power of Coding in a Low-Code Solution

    SB PowerTech WC GenericWhen 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:

    • Discover the benefits of Low-code's quick application creation
    • Understand the differences in model-based and language-based Low-Code platforms
    • Explore the strengths of LANSA's Low-Code Solution to Low-Code’s biggest drawbacks



  • The Biggest Mistakes in IBM i Security

    SB Profound WC Generic The Biggest Mistakes in IBM i Security
    Here’s the harsh reality: cybersecurity pros have to get their jobs right every single day, while an attacker only has to succeed once to do incredible damage.
    Whether that’s thousands of exposed records, millions of dollars in fines and legal fees, or diminished share value, it’s easy to judge organizations that fall victim. IBM i enjoys an enviable reputation for security, but no system is impervious to mistakes.
    Join this webinar to learn about the biggest errors made when securing a Power Systems server.
    This knowledge is critical for ensuring integrity of your application data and preventing you from becoming the next Equifax. It’s also essential for complying with all formal regulations, including SOX, PCI, GDPR, and HIPAA
    Watch Now.

  • Comply in 5! Well, actually UNDER 5 minutes!!

    SB CYBRA PPL 5382

    TRY 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.

    Request your trial now!

  • Backup and Recovery on IBM i: Your Strategy for the Unexpected

    FortraRobot automates the routine 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:
    - Simplified backup procedures
    - Easy data encryption
    - Save media management
    - Guided restoration
    - Seamless product integration
    Make sure your data survives when catastrophe hits. Try the Robot Backup and Recovery Solution FREE for 30 days.

  • Manage IBM i Messages by Exception with Robot

    SB HelpSystems SC 5413Managing messages on your IBM i can be more than a full-time job if you have to do it manually. 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:
    - Automated message management
    - Tailored notifications and automatic escalation
    - System-wide control of your IBM i partitions
    - Two-way system notifications from your mobile device
    - Seamless product integration
    Try the Robot Message Management Solution FREE for 30 days.

  • Easiest Way to Save Money? Stop Printing IBM i Reports

    FortraRobot 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:

    - Automated report distribution
    - View online without delay
    - Browser interface to make notes
    - Custom retention capabilities
    - Seamless product integration
    Rerun another report? Never again. Try the Robot Report Management Solution FREE for 30 days.

  • Hassle-Free IBM i Operations around the Clock

    SB HelpSystems SC 5413For over 30 years, Robot has been a leader in systems management for IBM i.
    Manage your job schedule with the Robot Job Scheduling Solution. Key features include:
    - Automated batch, interactive, and cross-platform scheduling
    - Event-driven dependency processing
    - Centralized monitoring and reporting
    - Audit log and ready-to-use reports
    - Seamless product integration
    Scale your software, not your staff. Try the Robot Job Scheduling Solution FREE for 30 days.