Using Perl on an AS/400 / iSeries Presented by David Mount – Owner of Texas400 Computer Consulting...

Post on 23-Dec-2015

222 views 0 download

Tags:

Transcript of Using Perl on an AS/400 / iSeries Presented by David Mount – Owner of Texas400 Computer Consulting...

Using Perl on an AS/400 / iSeries

Presented by David Mount– Owner of Texas400 Computer Consulting

See www.texas400.com for more on Perl on the

iSeries / AS400

Reasons to Pay Attention

You may actually want to provide the public or your users with internet access to some of your data – PERL is an easy and FREE way to do this

PERL is a great way to learn about CGI programming as well at HTML and HTTP server

Someday, you may have the chance to port a PERL application to your iSeries

Typical Computer User’s Understanding of AS/400 / iSeries

What’s an AS/400? What’s an iSeries? Old architecture that uses green screens Programs written in RPG Runs applications written 10 to 15 years ago Doesn’t belong in the same sentence as “internet” Upload data via PC Support or Client Access Really different from world of PC’s and internet Isolated from rest of world

We have the opportunity to educate the IT public about AS400 / iSeries

Internet Accessible – Free Telnet products (www.symtrax.com)

Uploads and Downloads over internet with FTP Internet remote printing to IP addressable

printers SMTP Server – Send emails HTTP Server – web hosting Various CGI programming capabilities

Career questions to keep you awake at night

What programming language should I be learning?

What computer platform will be in use in 5 to 10 years?

What can I learn today that will still be valuable in 5 to 10 years?

Answer to these questions is:

The Internet

The Internet

The Internet

TCP-IP issues are the same regardless of the platform

Once you configure FTP Server on AS/400, you already know how to do it on Windows

The FTP client on OS/400 is operationally very similar to the FTP on windows and Linux

Getting the SMTP server working involves learning about DNS, mail forwarding, third party relay

Roadmap of next 25 slides

Write a “Welcome to my page” static HTML page Use PERL to output “Hello World” to browser Write an HTML form to accept PERMIT# Write a PERL program to process the CGI data, lookup

the permit inspections and write to browser Use a link to look up specific info about an inspection Read a non-keyed file and write it to the browser

Non platform specific things to know for web site programming

HTML formatting– Static HTML– Forms with fields– Links with Query Strings

How to FTP HTML to web server Web server configuration Default folder, CGI-BIN directory

Http Server Directives for Static HTML

So that a browser going to my AS/400 will be served the HTML in “index.html” in the “html” folder (get there with WRKLNK), use these two directives:

Pass /* /html/*Welcome index.html

There is nothing magic about the HTML folder. I created it from the WRKLNK screen

To make a “Welcome” page

Use a PC to create a document named “index.html” with the following:

<html><body>Welcome to my home page</body></html>

Use FTP to put that document in the HTML folder Specifically, connect to 66.12.223.253 with remote

directory of /html Use a browser to go to 66.12.223.253 and you should

see the Welcome page

Download and Install PERL

PERL (Practical Extraction and Report Language) An interpretted language (don’t compile) Written in C as a quick and dirty language Used by Unix administrators for years Probably the most common CGI programming

language www.cpan.org/ports/ to download the free library

PERL Resources

Vast supplies of sample code on the internet Many Perl and CGI / PERL books “Writing CGI Applications with PERL” by Kevin

Meltzer and Brent Michalski

PERL Executable Code

I used WRKLNK and MD PERL commands to create a directory named PERL

I FTP my PERL documents to the PERL directory

Hello World Program

Use notepad to create a document named Hello.PL #!/usr/bin/perl

use CGI qw/:standard/;

print header;

print '<html><body>';

print 'Hello World';

print '</body></html>'; FTP document to AS/400

Configure HTTP Server for CGI

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

%%EBCDIC%%

CL Program

Compile a CL program named HELLO CALL PGM(PERLDIST/PERL) +

PARM('/PERL/HELLO.PL')

Program must be where you told the HTTP server that CGI-BIN programs are. In my case, the library T40CGI

Make sure QTMHHTTP and QTMHHTP1 have authority to everything

Program execution time!

When browser goes to66.12.223.253/cgi-bin/hello

The HTTP server maps anything coming to “cgi-bin”

to T40CGI library

So, HTTP server tries to run the program HELLO

from T40CGI library

What is CGI?

Common Gateway Interface A defined standard for executing programs with

parameters Conceptually similar to a DDS display file Invoke a CGI program with either a link from a web

page or a submit button on a form Data arrives as a string of field names and values:

gtpermit.pgm?PERMT=1234&USR=David

Different ways to process CGI

RPG ILE program using IBM supplied API’s (see Brad Stones’s eRPG book)

IBM’s Easy400 tool

(see www-922.ibm.com) 3rd Party Products like ProGen WebSmart PERL

CGI form with submit button --- named GTPERMIT.HTML

<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>

Program Execution Time!

When submit button is clicked:String “66.12.223.253/cgi-bin/gtpermit?PERMT=1234”Goes to IP address 66.12.223.253

The HTTP server maps anything coming to “cgi-bin” to T40CGI library

So, HTTP server tries to run the program GTPERMIT with the query string of ?PERMT=1234

We need a program named GTPERMIT to read this value and respond

Use SQL to read AS/400 database

Need to read value from CGI form

and then… Build the SQL string:

SELECT * FROM T40CGI/INS WHERE INSPMT = ‘1234’

and then…

Show the data

Put new Perl program on AS400

FTP this Perl program named “gtpermt” to the AS/400

Create a CL to run it Make sure the database and the CL program

are usable by QTMHTTP and QTMMHTP1 Click on the submit button

Add a link to see details of inspection

Add this line as the last column of table: print q(<td><a href=showdetl?PERMT=

$data->{INSPMT}&TYP=$data->{INSTYP} >Details</a></td>\n);

Builds a string like:

<a href=showdetl?PERMT=1234&TYP=DW>

Details</a>

Perl Program named showdetl.pl

Get parms from query string Build the SQL string:

SELECT * FROM T40CGI/INS WHERE INSPMT = ‘1234’ AND INSTYP = ‘DW’

and then…

Show the data

Put new program on AS/400

FTP this Perl program named “showdetl” to the AS/400

Create a CL to run it Make sure the CL program is usable by

QTMHTTP and QTMMHTP1

At Your Next Company Meeting

Can users use the internet to get on the iSeries?

Can people upload and download data from the AS400 over the internet?

Can our computer host web pages? Can we process CGI input? Can we run PERL?

Duh!!!!

It’s an AS/400!