How CGI Programs Work
Most CGI programs include the following three stages:
vParsing CGI programs
vData manipulation within a CGI program
vResponse generation by a CGI program

Parsing

Parsing is the first stage of a CGI program. In this stage, the program takes the
data from QUERY_STRING environment variable, command line arguments using
argv() or standard input. When the method is GET, the system reads the data from
the QUERY_STRING environment variable or command line arguments by using
argv(). There is no way to determine the length of data in QUERY_STRING. The
system encodes the QUERY_STRING data in the request header.
An example of data read in the QUERY_STRING variable (%%MIXED%% mode):
NAME=Eugene+T%2E+Fox&ADDR=etfox%40ibm.net&INTEREST=RCO
Parsing breaks the fields at the ampersands and decodes the ASCII hexadecimal
characters. The results look like this:
NAME=Eugene T. Fox
ADDR=etfox@ibm.net
INTEREST=RCO
You can use the QtmhCvtDb API to parse the information into a structure.The
CGI program can refer to the structure fields. If using %%MIXED%% input mode,
the %xxencoding values are in ASCII and must be converted into the %xx
EBCDIC encoding values before calling QtmhCvtDb. If using %%EBCDIC%%
mode, the server will do this conversion for you. The system converts ASCII
%xxfirst to the ASCII character and then to the EBCDIC character. Ultimately,
the system sets the EBCDIC character to the %xxin the EBCDIC CCSID. For
code samples, use the following URL to the AS/400 web site:
http://www.as400.ibm.com/tstudio/index.htm.
When the method is post, the system reads the data from standard input. Before
the CGI attempts to read standard input, it must check environment variables
REQUEST_METHOD and CONTENT_LENGTH. Read standard input only when
the REQUEST_METHOD is POST. The read must specify no more than
CONTENT_LENGTH bytes. Attempts to specify more than CONTENT_LENGTH
bytes on reading standard input are not defined.

Data manipulation

Data manipulation is the second stage of a CGI program. In this stage, the
program takes the parsed data and performs the appropriate action. For example, a
CGI program designed to process an application form might perform one of the
following functions:
1. Take the input from the parsing stage
2. Convert abbreviations into more meaningful information
3. Plug the information into an e-mail template
4. Use SNDDST to send the e-mail.

Response generation

Response generation is the final stage of a CGI program. In this stage, the program
formulates its response to the web server, which forwards it to the browser. The
response contains MIME headers that vary depending on the type of response.
12 WebProgramming Guide V4R5