Home > AS/400 Tips > iSeries programmer tips > Getting started with CGIDEV2 -- Part 2
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Getting started with CGIDEV2 -- Part 2


Paul Tuohy
05.23.2005
Rating: -4.94- (out of 5)


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


In my previous article ("Getting Started with CGIDEV2 – Part 1"), I discussed how to write a program using CGIDEV2 to produce a simple report for the Web. Now it's time to look at how you can get information from a Web page in a browser into your RPG program.

The CGI APIs used to retrieve and process data from the Web are cumbersome, to say the least, so this is one of the areas where CGIDEV2 proves invaluable.

Since it is rare that you will fit a complete report on one Web page, let's look at another version of the Product Report used in the previous article, which allows the user to "page" through the report.

Figure 1 shows an example of a page of the report. The list is by Product Category, and the user can click on the "Next Page" link to view the products in the next category.

[TABLE]

Figure 1: Output from a simple "print" style CGI program with Next Page option

The HTML

So how does a browser send information to a program? There are two methods that can be used – GET and POST. We will look at the difference between the two in a moment but the end result of both is that the browser sends a parameter string along with the program call. You have often seen these in URLs when accessing the internet. A URL with a parameter string has the following format:

//server/directory/programname?parm1=value&parm2=value&parm3=....

The parameter string starts with a '?' followed by the name of a parameter field, followed by the value of the parameter. Subsequent parameters are delimited by a '&'.

The paging logic is that when the user clicks the next page link, the program is called along with a parameter identifying the category to be listed.

Figure 2 shows the HTML for the report page. In a change from the example in the previous article, this html source is using delimiters of '' to indicate a section and '' to indicate a variable


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


RELATED CONTENT
iSeries programmer tips
Groovy programming on IBM i
EGL Rich UI on IBM i: Do you Dojo?
Running PHP open source applications: NOBODY needs authority
Programming for the Web on the IBM i, what is possible
Using geocoding on AS/400 to enhance your Web presence
The best technologies and tools for System i programmers in 2009
Seven IBM i project lessons learned in 2008
Documenting nested program structures on the AS/400
What is an integrated database?
An automated CL method of moving a query from AS/400 to Excel

iSeries application development tools
Migrating from RPG to EGL on IBM i
EGL Rich UI on IBM i: Do you Dojo?
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
AS/400 lessons from the past, present, and future: A holiday tale
Documenting nested program structures on the AS/400
Learn the i: iSeries DevCon coming up in Orlando
Application modernization in the i world
System i virtualization prevents T-Mobile busy signal
iSeries application development tools Research

Web Development
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
RPG application modernization for i5
Web skills crucial to iSeries programmer professional development

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


; this makes the html document a little easier to manage with a design tool like WebSphere Developer's Studio Client (WDSC).

Figure 2: HTML for report page with Next Page link.

The important section is nextlink at the very end of the source. It identifies the Next Page text with a hyperlink to recall the RPG program and pass a parameter which identifies the next category code to be displayed. For example, when displaying the list of products for category '01' and where '05' is the next category, the Next Page link would have a hyperlink of

cgi-bin/cvallrep2a?CGICatCod=05

The CGI program

Figure 3 shows the source of the CGIDEV2 program CVALLREP2A. What you are really interested in here is how the program receives the parameters passed from the browser because they are not passed using a good old parameter list. The program makes use of five of the CGIDEV2 subprocedures: gethtmlIFS, wrtsection, updHTMLvar, ZhbGetInput and ZhbGetVar.

Figure 3: A simple CGIDEV2 program with Next Page logic.

Important items to note:

Running the program

With the server running, open your browser and enter this URL:

http://iseriesservername/cgi-bin/CVALLREP2A

where iseriesservername is the name of your iSeries. All being well, the results of your efforts will be displayed in the browser. Clicking on the Next Page link should bring you to the next category, until you reach end of file.

Using a form

The simple way of passing parameters to a program is to pass them on the hyperlink. But what if you want to have the user enter a value? Figure 4 shows an example of a form being used to request a starting category. The user enters a category code and clicks on the Submit Query button to call the CVALLREP2A program with the entered category.

[TABLE]

Figure 4: Using a form to request a value.

The form is stored as a static HTML document. (You do not need to use a CGI program to display it.) Figure 5 shows the HTML for the form.

Figure 5: HTML for a form.

The definition of the form is delimited by a <FORM> and a </FORM> tag. The <FORM> tag contains the name of the form (getCategory), the action to be taken when a submit button is pressed (identify the program to be called) and the method to be used (GET or POST).

A GET method means that the parameter string will be passed exactly as it is on the Next Page hyperlink, and the parameter string will appear on the URL when the program is called. A POST method means that the parameter string does not appear on the URL when the program is called.

If you were using the standard CGI APIs you would have to use different APIs to retrieve the parameter string after first determining whether GET or POST was used when the program was called. One of the features of the ZhbGetInput subprocedure is that it does all that for you and you don't really care whether GET or POST was used. Having said that, POST means you get an easier to read URL.

Within the form you can have standard text along with the definition of input fields. Input fields are identified by an <INPUT> tag. The <INPUT> tag contains the type of entry (text and submit in this example -- more about those in a moment), the name of the parameter field (CGICatCod to correspond to what the program is expecting), the Maximum Length of the field and the value to be displayed.

A type of text means the input field is simply text. HTML does not cater for numbers, so even if you are entering a number, you define the type as text. A type of submit means it is a submit button and clicking it causes the form to be submitted (i.e. the program identified in the action for the form is called). You can change the text displayed in the button by giving it a value. In the next article we will look at the various types available (there are lots of them) and how to start customizing the use of submit buttons.

And what changes need to be made to the CVALLREP2A program? That's easy -- NONE!

Changing the Next Page link

One of the downsides of hyperlinks is that they are implicitly GET methods; so why not change the Next Page link to use a button with a POST method instead of a hyperlink? In the CVALLREP2A HTML document simply change the definition of the nextlink section to that shown in Figure 6. The type of hidden is the same as a hidden field in a display file. Also note the value for the submit button.

Figure 6: Using a form to define a button as opposed to a hyperlink.

One step further

Now you know how to send data from a program to a browser and how to get data from a browser into a program. In the next article you will see how easy it is to use those capabilities to write a maintenance program.

---------------------------
About the author: Paul Tuohy is CEO of ComCon, an iSeries consulting company. He is the author of Re-Engineering RPG Legacy Applications and is one of the quoted industry experts in the IBM Redbook "Who Knew You Could Do That With RPG IV?"


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.




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