ContentsIndexPreviousNext

8.3.4 Sample CGI Programs

The following CGI programs were written in ACUCOBOL-GT.

Oscars sample

The first program, oscars, is designed to return the names of actors and actresses who won Oscar awards in a specified year. Notice the definition of external form items in the working storage section of this program. Notice also that the ACCEPT statement in the main logic section ACCEPTs these external form items, and that the DISPLAY statement defines the HTML templates to be used: "HTML-header-form," "HTML-footer-form," and "body-para." The contents of these templates follows.

identification division.
program-id. oscars.
remarks.
working-storage section.
01  cgi-form is external-form.
     05 y1996       pic x(5) is identified by "y1996".
     05 y1995       pic x(5) is identified by "y1995".
     05 y1994       pic x(5) is identified by "y1994".
     05 y1993       pic x(5) is identified by "y1993".
     05 y1992       pic x(5) is identified by "y1992".
01  cgi-form-table redefines cgi-form.
     05  cgi-year   pic x(5) occurs 5 times.
01  html-header-form is external-form identified by "header".
     05  opening-message pic x(40).
01  html-body-form is external-form identified by "body".
     05  ryear      pic x(5).
     05  html-oscar-info.
          10  rmovie       pic x(25).
          10  ractor       pic x(42).
          10  ractress     pic x(42).
01  html-footer-form is external-form identified by "footer".
     05  closing-message   pic x(40).
01  movie-values.
     05  1996-oscar.
          10 movie         pic x(25) value "THE ENGLISH PATIENT".
          10 actor         pic x(42) value "Geoffrey Rush SHINE".
          10 actress       pic x(42) value "Frances McDormand FARGO".
     05  1995-oscar.
          10 movie         pic x(25) value "BRAVEHEART".
          10 actor         pic x(42) value "Nicolas Gage LEAVING LAS
                           VEGAS".
          10 actress       pic x(42) value "Susan Sarandon DEAD MAN
                           WALKING".
     05  1994-oscar.
          10 movie         pic x(25) value "FORREST GUMP".
          10 actor         pic x(42) value "Tom Hanks FORREST GUMP".
          10 actress       pic x(42) value "Jessica Lange BLUE SKY".
     05  1993-oscar.
          10 movie         pic x(25) value "SCHINDLERS'S LIST".
          10 actor         pic x(42) value "Tom Hanks PHILADELPHIA".
          10 actress       pic x(42) value "Holly Hunter THE PIANO".
     05  1992-oscar.
          10 movie         pic x(25) value "UNFORGIVEN".
          10 actor         pic x(42) value "Al Pacino SCENT OF WOMAN".
          10 actress       pic x(42) value "Emma Thompson HOWARDS END".
01  movie-table redefines movie-values occurs 5 times.
     05  oscar-winners.
          10  best-movie   pic x(25).
          10  best-actor   pic x(42).
          10  best-actress pic x(42).
01  various-counters.
     05 idx-1              pic 99 value 1.
procedure division.
main-logic.
accept cgi-form.
     if cgi-form = space
          move "You did not select any years!" to opening-message
          display html-header-form
          move "Back up and try again." to closing-message
     else
          move "Acucorp CGI in action." to opening-message
          display html-header-form
          perform display-body-para
          move "THE END." to closing-message
     end-if.
     display html-footer-form.
     stop run.
display-body-para.
     perform varying idx-1 from 1 by 1 until idx-1 > 12
          if cgi-year(idx-1) = space
               continue
          else
               move cgi-year(idx-1) to ryear
               move movie-table(idx-1) to html-oscar-info
               display html-body-form
          end-if
     end-perform.
Header.htm
<HTML><HEAD><TITLE>ACUCOBOL-GT CGI Header</TITLE></HEAD>
<BODY>
<H2>%%opening-message%%</H2>
<CENTER><H1>Oscar Winners</H1>
<HR>
<TABLE border cellspacing=0 cellpadding=5>
<TR>
<TH colspan=4 align=center>Your Selections</TH>
</TR>
<TR align=center>
<TH>Year</TH>
<TH>Best Movie</TH>
<TH>Best Actor</TH>
<TH>Best Actress</TH>
</TR>
Footer.htm
</TABLE>
</CENTER>
<H2>%%closing-message%%</H2>
<HR>
<P>The information you requested was processed by the ACUCOBOL-GT CGI program.
<BR>Following the CGI standard, ACUCOBOL-GT 4.0 was able to send <BR>the
requested data items to the appropriate templates and <BR>return the completed HTML
document back to you.</P>
</BODY></HTML>
Body.htm
<TR align=center>
<TD>%%ryear%%</TD>
<TD>%%rmovie%%</TD>
<TD>%%ractor%%</TD>
<TD>%%ractress%%</TD>
</TR>
Oscar.htm
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>ACUCOBOL-GT CGI Example</TITLE>
<META NAME="Template" CONTENT="C:\PROGRAM FILES\MICROSOFT
OFFICE\OFFICE\html.dot">
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080">
<H2>ACUCOBOL-GT CGI Example using ACUCOBOL-GT 4.0.</H2>
<H3>This example shows how easily you can use ACUCOBOL-GT 4.0 to act as a CGI
program.
<BR>User input is transferred from the following HTML page to a ACUCOBOL-GT
4.0 program running <BR>
on the web server. The appropriate output is returned.</H3>
<P><HR></P>
<H1 ALIGN="CENTER">Oscar Trivia</H1>
<P>Select a year(s)and press the Submit Query button. <BR>
The Best Picture, Best Actor and Best Actress for each year selected will be
returned. </P>
<FORM ACTION="http://your_server_name/Scripts/oscars.acu" METHOD="post">
<P>Year: </P>
<P>
<INPUT TYPE="checkbox" NAME="y1996" VALUE="1996">
1996
<INPUT TYPE="checkbox" NAME="y1995" VALUE="1995">
1995
<INPUT TYPE="checkbox" NAME="y1994" VALUE="1994">
1994
<INPUT TYPE="checkbox" NAME="y1993" VALUE="1993">
1993
<INPUT TYPE="checkbox" NAME="y1992" VALUE="1992">
1992
<P>
<INPUT TYPE="submit"  VALUE="Submit Query" >
</P></FORM></BODY>
</HTML>

Hello User sample

The following CGI program assumes that the user has been asked to enter his or her name, and that the entered name is stored in the CGI variable "username". This can be accomplished using the following HTML form:

<body>
 <form action="/cgi-bin/simple.acu" method="get">
 Please enter your name or leave blank for "anonymous":
 <input type="text" name="username" size=60>
 <input type="submit" value="Submit">
 </form>
 </body>

This program also uses an HTML template, "greeting.html". Here is an example:

<body>
 Hello %%username%%
 This Web page is still under construction.
 Please try again in a few days.
 </body>

The CGI program then, is as follows:

identification division.
program-id. simple.
remarks.
data division.
working-storage section.
01  input-output-form is external-form is identified by "greeting".
    03  user-name  pic x(60) identified by "username".
procedure division.
main-logic.
    accept input-output-form.
    display input-output-form.

Substituting a URL sample

This program demonstrates using an external form to substitute a URL for the output.

identification division.
program-id. acusrch.
remarks.
data division.
working-storage section.
01  acucorp-search-url  pic x(40) is external-form
          identified by "http://www.acucorp.com/cgi-bin/acusearch".
procedure division.
main-logic.
     display acucorp-search-url.