texAS400

  The idiosyncrasies of using PERL on the AS/400


Configure your HTTP Server to serve static HTML

Configure your HTTP Server to serve static HTML. I have configured my HTTP Server like this:

Pass /* /html/*
Welcome index.html

Any browser that hits 66.12.223.253 will look in the folder named HTML. If no document is specified, the HTTP Server will serve the document named "index.html"

To view the folders that this refers to, use the command WRKLNK.

Configure your HTTP Server to find CGI-BIN programs

You will want to configure your HTTP Server for CGI programs. Since the internet convention is to execute CGI programs via a CGI-BIN directory, I have configured my HTTP Server like this:


Enable                     GET    
Enable                     HEAD   
Enable                     POST   
EXEC /cgi-bin/* /QSYS.LIB/T40CGI.LIB/*.PGM %%EBCDIC%%

This means that a browser going to 66.12.223.253/cgi-bin/permit will cause the HTTP server to look for a program named PERMIT in the AS/400 library named T40CGI.

Authorities

The magic users QTMHHTTP and QTMHHTP1 must have authority to the programs and databases. Use GRTOBJAUT to accomplish this.

CL Program for Every PERL Script

As stated above, CGI-BIN requests will look in the library configured (in my case T40CGI) for a program. That should be a CL program that calls the PERL processor for the script.

I have a folder named PERL. I put my PERL scripts in this folder and I name the scripts with an extension of PL. So, to run the PERL script named "hello.pl", there must be a CL program in the T40CGI library that was created with this source:


PGM

CALL PGM(PERLDIST/PERL) PARM('/PERL/HELLO.PL')

ENDPGM

Remember that this program must be authorized to QTMHHTTP and QTMHHTP1

"Hello World" PERL program
#!/usr/bin/perl

use CGI qw/:standard/;

print header;
print '<html><body>';
print 'Hello World';
print '</body></html>';
HTML to Submit a Form with Permit# as Input
<html><body>
<FORM METHOD="POST" ACTION="http://66.12.223.253/cgi-bin/gtpermit"> 
Permit#
<INPUT TYPE="text" NAME="PERMT"  Maxlength=4><p>
<INPUT TYPE="Submit"  VALUE="Submit">
</form></body></html>
PERL Program "GTPERMIT" to Look Up All Records in AS/400 Database For a Permit#
use DBI;
use DBD::DB2::Constants;
use DBD::DB2;
use CGI qw/:standard/;

$val = param("PERMT");

print header;

$dbh = DBI->connect("dbi:DB2:*LOCAL") or die; 

$stmt = "SELECT * FROM T40CGI.INS WHERE INSPMT = '$val'";

$sth = $dbh->prepare($stmt) or die "prepare got error " . $dbh->err;

$sth->execute() or die "execute got error" . $dbh->err;

# output the first row of the table with column headings 
print '<table border=1>';
print '<tr><td><b>Permit#</b></td>';
print '<td><b>Type</b></td>';
print '<td><b>Date</b><t/td>';
print '<td><b>Result</b></td></tr>';

# output each row of table (each matching record)
while($data = $sth->fetchrow_hashref){
	print qq(<tr>\n);
	print qq(<td>$data->{INSPMT}</td>\n);
 	print qq(<td>$data->{INSDSC}</td>\n);
	print qq(<td>$data->{INSDTE}</td>\n);
	print qq(<td>$data->{INSRST}</td>\n);
        print qq(<td><a href=showdetl?PERMT='$data->{INSPMT}'&TYP='$data->
                {INSTYP}'>Details</a></td>\n);
	print qq(</tr>\n); }

print '</table></body></html>';
PERL Program "SHOWDETL" to Show Details of a Permit# / Inspection Type
use DBI;
use DBD::DB2::Constants;
use DBD::DB2;
use CGI qw/:standard/;

$permit = param("PERMT");
$typ    = param("TYP");

print header;

$dbh = DBI->connect("dbi:DB2:*LOCAL") or die; 

$stmt = "SELECT * FROM T40CGI.INS WHERE ((INSPMT = $permit) AND (INSTYP = $typ))";

$sth = $dbh->prepare($stmt) or die "prepare got error " . $dbh->err;

$sth->execute() or die "execute got error" . $dbh->err;

# output each value with its name in a row of the table 
print '<table border=1>';

# output each row of table (each matching record)
while($data = $sth->fetchrow_hashref){
	print qq(<tr><td>Inspection#</td><td>$data->
                {INSPMT}</td></tr>\n);
 	print qq(<tr><td>Type Inspection</td><td>$data->
                {INSDSC}</td></tr>\n);
	print qq(<tr><td>Inspection Date</td><td>$data->
                {INSDTE}</td></tr>\n);
	print qq(<tr><td>Insp Result</td><td>$data->
                {INSRST}</td></tr>\n);
        print qq(<tr><td>Comments</td><td>$data->
                {INSCMN1}</td></tr>\n);
	print qq(<tr><td></td><td>$data->
                {INSCMN2}</td></tr>\n);
	print qq(<tr><td></td><td>$data->
                {INSCMN3}</td></tr>\n);
	print qq(<tr><td>Inspector ID</td><td>$data->
                {INSINS}</td></tr>\n); }

print '</table></body></html>';
PERL Program to Read a Non-Keyed AS/400 File
#!/usr/bin/perl

use CGI qw/:standard/;

print header;
print '<html><body>';
open(INFILE, "< /QSYS.LIB/PERLDIST.LIB/README.FILE/README.MBR");
#open(INFILE, "< /QSYS.LIB/AIRFILES.LIB/IRT.FILE/IRT.MBR");
print 'open';
while () {print "$_ 
";} close(INPUT); print '</body></html>';





Back to Main Page