using perl on an as/400 / iseries

39
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

Upload: dacey

Post on 13-Jan-2016

81 views

Category:

Documents


0 download

DESCRIPTION

Presented by David Mount Owner of Texas400 Computer Consulting See www.texas400.com for more on Perl on the iSeries / AS400. Using Perl on an AS/400 / iSeries. Reasons to Pay Attention. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Using Perl on an AS/400 / iSeries

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

Page 2: Using Perl on an AS/400 / iSeries

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

Page 3: Using Perl on an AS/400 / 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

Page 4: Using Perl on an AS/400 / iSeries

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

Page 5: Using Perl on an AS/400 / iSeries

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?

Page 6: Using Perl on an AS/400 / iSeries

Answer to these questions is:

The Internet

The Internet

The Internet

Page 7: Using Perl on an AS/400 / iSeries

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

Page 8: Using Perl on an AS/400 / iSeries

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

Page 9: Using Perl on an AS/400 / iSeries

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

Page 10: Using Perl on an AS/400 / iSeries

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

Page 11: Using Perl on an AS/400 / iSeries

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

Page 12: Using Perl on an AS/400 / iSeries

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

Page 13: Using Perl on an AS/400 / iSeries

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

Page 14: Using Perl on an AS/400 / iSeries

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

Page 15: Using Perl on an AS/400 / iSeries

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

Page 16: Using Perl on an AS/400 / iSeries

Configure HTTP Server for CGI

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

%%EBCDIC%%

Page 17: Using Perl on an AS/400 / iSeries

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

Page 18: Using Perl on an AS/400 / iSeries

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

Page 19: Using Perl on an AS/400 / iSeries
Page 20: Using Perl on an AS/400 / iSeries

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

Page 21: Using Perl on an AS/400 / iSeries

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

Page 22: Using Perl on an AS/400 / iSeries

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>

Page 23: Using Perl on an AS/400 / iSeries
Page 24: Using Perl on an AS/400 / iSeries

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

Page 25: Using Perl on an AS/400 / iSeries

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

Page 26: Using Perl on an AS/400 / iSeries
Page 27: Using Perl on an AS/400 / iSeries
Page 28: Using Perl on an AS/400 / iSeries

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

Page 29: Using Perl on an AS/400 / iSeries
Page 30: Using Perl on an AS/400 / iSeries

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>

Page 31: Using Perl on an AS/400 / iSeries
Page 32: Using Perl on an AS/400 / iSeries

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

Page 33: Using Perl on an AS/400 / iSeries
Page 34: Using Perl on an AS/400 / iSeries
Page 35: Using Perl on an AS/400 / iSeries

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

Page 36: Using Perl on an AS/400 / iSeries
Page 37: Using Perl on an AS/400 / iSeries
Page 38: Using Perl on an AS/400 / iSeries

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?

Page 39: Using Perl on an AS/400 / iSeries

Duh!!!!

It’s an AS/400!