Home > AS/400 Tips > iSeries programmer tips > Implementing a browser interface in COBOL: Creating your graphic Web page
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Implementing a browser interface in COBOL: Creating your graphic Web page


Rich Loeber, Contributor
08.18.2009
Rating: --- (out of 5)


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


Rich Loeber

In my initial article on implementing a browser interface to your System i application in COBOL, I demonstrated how to read a simple HTML form page and extract the data shown on the form. In that article, the form was a simple logon screen with two fields, a user profile and password.

Once you've logged onto a system, you will need to present your browser user with a Web page that they can work with. You may want to present a series of options to choose from, like a menu. Or, you may want to display some contents of a database, or a combination of these things.

In my application, I chose the latter and ended up displaying a series of records from a database file along with a series of action buttons. Some of the buttons apply to specific records in the database while other are more global in nature. In this example, I'll concentrate on what you need to do to create your Web page for display in your browser session and how to send that information from your COBOL program.

Creating a Web page for display
To create a Web page for display, you will need to use the CGI API known as Write Standard Output (QtmhWrStout). The API is quite easy to use and only has three parameters. These are a text field that contains what you want to put to the Web page, a length factor that is coded in binary form (Comp-4) and the ubiquitous API error field. In my application, I have these three fields coded as follows:

        01  Out-Data    Pic x(4000) Value Space. 
    01  Out-Len     Pic s9(8)   Value Zero Comp-4.
    01  API-Error.
        03  E-BytesP   Pic s9(10) Comp-4 Value 64.  
        03  E-BytesA   Pic s9(10) Comp-4 Value Zero.
        03  E-MsgId    Pic x(7).                    
        03  E-Reserved Pic x(1).                    
        03  E-Data     Pic x(40).  

The output data text field should be large enough to contain the most information that you will be placing on the Web page in a single call. Keep in mind that you can call the API multiple times to build your Web page in segments. So, the field only needs to be as large as the largest segment. The output length is a number that represents the total number of characters that you are putting to the page during the call. The API error code is a standard format that can be used for all calls.

In my application, I found that the COBOL STRING command was most helpful and useful in building Web page segments. Here is an example of how to get your page started by writing the opening HTML statements. This HTML shows the TITLE parameter that you want used and starts the BODY section of your page:

        String  'Content-type: text/html', cr-lf, cr-lf,
                 '<HTML>',
                 '<TITLE>iFileAudit Work With Files</TITLE>',
               cr-lf,
                 '<BODY>', cr-lf, '|'
                 delimited by size into Out-Data.
    Write-Out.
        Inspect Out-Data tallying Out-Ctr for characters 
            after '|'.
        Compute Out-Len = 4000 - Out-Ctr - 1.
        Call linkage type is procedure 'QtmhWrStout'
                   using Out-Data, Out-Len, API-Error.
        Move space to Out-Data.
        Move zero to Out-Len, Out-Ctr.
    End-Write-Out.                        

Note the use of the upright bar (|) marker character to show where the end of the data to be written is located. This is used in the Write-Out routine to calculate the exact length of the data being written to your web page. The INSPECT verb will count the number of blank characters in the Out-Data field that follow the marker and place it in the program field called Out-Ctr. This is then used in the following COMPUTE statement to calculate the exact length of the data being sent to your web page. If your data stream has any legitimate uses of the upright bar character, you will have to pick a different character to use for your marker.

Also, note the use of a field named cr-lf. This is used to help with the readability of the HTML presented for your Web page and represents a single character carriage-return, line-feed defined with a value of X'15'. Its use is entirely optional, but I found it helpful when looking at the generated HTML source from within my browser during debug testing.

Finishing the Out-Data field
Once you have gotten this far, it is just a matter for filling the Out-Data field with more HTML to complete the information you want shown on your Web page. The key to this process is understanding how the Write Standard Output API works. All subsequent writes to your Web page can be accomplished by a simple PERFORM of the Write-Out routine shown here.

For example, the following might be used to place a graphic in the center of the body section of your page and then add some page title text:

    String '<center>',
             '<IMG SRC="/page_head.gif" BORDER=0><p>',
          '<h2>Welcome To My Application</h2>', cr-lf, 
          '</center>', '|' 
            delimited by size into Out-Data.
    Perform Write-Out.

In my next article, I will show a you how you can display a list of records from an IBM i database file on your Web page.

If you have any questions about this topic, you can reach me at rich@kisco.com, I'll give it my best shot. All email messages will be answered.

ABOUT THE AUTHOR: Rich Loeber is president of Kisco Information Systems Inc. in Saranac Lake, N.Y. The company is a provider of various security products for the IBM i market.

Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
iSeries COBOL programming
Implementing a browser interface in COBOL: Displaying database fields
Implementing a browser interface in COBOL: Getting started
Allow access to data from a stored procedure result set using COBOL or RPG
Eight steps for creating program documentation using AS/400 utilities
Coloring source lines with COBOL and using a shortcut from within PDM
Top 10 programmer tips YTD
Slow system performance
Changing the font size
New option within the WRKSYSACT command
Retrieve a program statement/line number
iSeries COBOL programming Research

Web Development
Implementing a browser interface in COBOL: Getting started
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Groovy programming on IBM i
Running PHP open source applications: NOBODY needs authority
Zend Web software teams up with IBM System i
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
AS/400 lessons from the past, present, and future: A holiday tale
Application modernization strategies for System i

iSeries programmer tips
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Implementing a browser interface in COBOL: Displaying database fields
Taking advantage of CL advancements, starting with V5R3
TAATOOL: Useful tools for programmers on IBM i
Implementing a browser interface in COBOL: Getting started
Making the most of RPG data handling on IBM i
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
WebSphere Development Studio Client (WDSC)  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts