Writing a CGI Program

Each element of your HTML, XML, or WML interface has a corresponding CGI variable. Your application must be able to interpret the CGI input data and return an appropriate response to the user. This is where your CGI program comes in.

Your CGI program must perform three basic functions:

Function Description
Read CGI input data from the client When a user enters information onto the form, that information is sent to the CGI program in the form of CGI data. Your program must be able to read CGI input data. In ACUCOBOL-GT, this is accomplished with the ACCEPT verb.
Process the input data and arrive at results Typically, this involves either a calculation, database lookup, or file read, but it could involve a CALL to an existing COBOL program on a local or remote machine.
Generate output that can be read by the client browser    Minimally, this includes an HTTP response header with a URL pointer to the response data. Otherwise, the header may be followed by response data formatted in HTML, WML, or XML. In ACUCOBOL-GT, HTTP output is accomplished using the DISPLAY verb.

In the simplest case, your ACUCOBOL-GT CGI program can contain one ACCEPT statement and one DISPLAY statement. Even if your program is more complicated, it will always start with an ACCEPT and end with a DISPLAY. Few languages make CGI programming so simple.

When writing your CGI program, consider the following:

With these considerations in mind, you are ready to write your CGI program. The following sections describe how to accomplish the necessary I/O and processing tasks. The topic Sample CGI Programs provides some sample code for your reference.