AS400 Web Development
by Vince Lewis
This is one man's explanation of how to get your AS400 serving web pages
quickly, with the least amount of learning curve, and for free. This is based on
months of painful learning experience, so I'm writing this down in the hope that
others don't have to go through the pain that I did.
What you will find in this article: -A strategy for going forwards -Important
lessons to learn -links to reference material -Links to the best AS400 RPGLE web
development tool - which, coincidentally, is free
What you will not find in this article -Sample code - although we do link to
some -An HTML lesson
Which way forwards for existing applications ? With the benefit of hindsight,
this is easy. For existing applications, leave them alone, and buy some kind of
nasty screen scraping tool. There are loads out there, take your pick based on
budget etc. There's been free options from IBM from the beginning - eg at V4R5
you had Workstation Gateway, but this was quite nasty and got dropped once the
world went to V5 where it was replaced by the web facing tool.
Why am I saying this ? Well, two major reasons. First, cost. It takes a lot of
re-engineering to take an RPG program and convert it to Java, or .Net, or
whatever. Even if you get an automation tool to do it. Besides that, you need to
totally re-test everything afterwards to ensure the business rules have not been
broken, which is no mean feat.
The second reason is that web pages follow the CGI methodolgoy, which is a set
of standards across both web servers (ie web sites) and web clients (ie browers)
for how information is exchanged between the two. OK, so say you don't want to
have to learn Java, but you do want to work from your existing apps. You could
stay with RPG and web enable it, which is perfectly acceptable and removes much
of your learning curve, but then most interactive applications simply are not
geared around the CGI methodology, they expect that when a screen is displayed
the program stays open until it gets the input and then carries on. With the CGI
methodology the client requests information from the server. The server then
sends the information back to the client, but then frees up the program on the
server - job done.
This type of client server approach is stateless, ie the server forgets all
about the client once it's served the data. This is far more akin to the
mainframe model, where you get a screen of input into a program which then deals
with it.
Which way forwards for new applications ? Now this is a whole new kettle of
fish. Web and HTML is really good for new applications. Particularly useful for
reports, and drill down reports. For example, you get an initial page of summary
financial data, let's say by cost centre. You could then click on the cost
centre to see by department, then click on department to see individual cost
codes, etc. And, for new interactive systems, you can give people a much more
familiar interface to use, with drop downs and radio buttons and some nice
fluffy images.
So which technology to use ? Again, there are a myriad of ways you can go.
There's the Websphere / Java servlet route, the problems of which are well
documented. There are also a number of "RPG web server" application generators
that can build sites for you from templates. There's NetData, the IBM AS400
scripting language. Did I mention earlier that you can write web pages in RPG ?
So you've heard about NetData for AS400. Well, this is a real interpretive
scripting language, similar to PHP or ASP, which is part of the AS400 operating
system, even at V5R2M0 and above. This has many advantages. It's built into the
OS, free, resides on your AS400, fast to develop in since no compile is
required, and flexible. The disadvantages are only two. Most importantly, it's
no longer supported on anything but an AS400 - so how long till IBM drop support
completely ? The second disadvantage is that since it's interpretive it's much
slower than an RPGLE program, for example. For simple examples, and easy reports
etc, this really wont matter, but for complex number crunching stuff then it
will. I have in the past had to rewrite certain netdata scripts into RPG for
performance reasons, and the compiled RPG version run typically 7-10 times
faster.
It's certainly worth considering for simple web pages, especially simple reports
because the speed to delivery and learning curve is probably the shortest out of
all the non-RPG routes. However, you will need to be able to write SQL
statements to extract the data off the 400, but since uou are reading this page
I'm sure you wont have a problem. IBM has some excellent redbooks on this, so go
look them up.
Also, if you want to get seriously into this, then there is a piece of code
editing software called UltraEdit. Put simply, it is the best bit of software
for editing I have ever found, it'd really really cheap, and it works across
HTML, javascript, and even NetData by means of a softcoded reference file which
tells the editor what the syntax for each language is. So go to download
ultredit, then visit my website to download the NetData extension (free). When
downloaded, save it in the UltraEdit program folder, overwriting the current
version
Lastly, a company called ATS have produced a hands-on Net.Data course for AS400,
and are the only people to have done so we believe
So how do you write an RPG Web page? Hold your horses ! Before we jump headlong
in to this, some very brief web explanation is required. I'll keep this short,
since if you're reading this page you probably know a bit about this kind of
stuff anyway.
A web page consists of a big pile of text, delimted by "tags". HTML stands for
"hypertext markup language", as you all know, but have you considered what the
word "markup" actually means to you ? Well, I'll tell you. It means that the
HTML does nothing but layout the page. All you have effectively done is move the
presentation layer from being a DSPF showing on a dumb terminal to an HTML page
showing in a browser.
So, to be clear on this, you don't actually need a program until you start doing
something dynamic, and in your case as an AS400 programmer this means retrieving
or storing data from the database. Your traditional "hello world" program in the
web world is not actually a program, it's just a pile of text standing in a flat
file that you send to the browser. It is static information.
When you come to writing your first web program in RPG (or any other language)
you'll soon discover that all you are actually doing is generating HTML text on
the fly to be sent to the client. Also, unlike interactive programs running on
green screen, you'll effectively be writing one program per screen.
Do I need to buy a good book on this ? You will notice that there are a number
of books on "E-RPG" or "RPG for Web" that you can go and buy. You will also
notice that, in particular, there is one person whose name you'll see associated
with "E-RPG" and this guy has successfully turned himself into the self
proclaimed RPG Web Guru. Well, fair play to the guy, he's made a fair living off
the back of it. But, in my humble opinion, the only books you will ever need are
a good HTML book and a really good Javascript book.
Scared ? Well, to an extent you shouldn't be. Think about it - you know
databases, you know RPG, you know AS400s, and dynamic web pages on the AS400 are
simply RPGLE programs. And you know how to write those already. What you don't
know is HTML and, far more importantly, javascript. These are things you really
will need to learn.
I am now about to explain why you do NOT need any RPG books. This is the
important bit on this page. If you take nothing else away, take this.
The important steps are :
to understand the CGI model - ie one page at a time, and then the program
closes. to keep the application layer separate from the presentation layer. to
realise where your responsibilities lie The last two steps are easy. The problem
you are likely to have is in your brain. You are an AS400 programmer, writing
RPG, you can do anything. HTML is, after all, just plain text - not even code !
Surely as a seasoned programmer I can do this ....? Well, yes and no. Yes, you
could write an HTML page. Yes, it will display data in the browser. No, it'll
look like crap. I mean, it'll look like a green screen converted to a web page,
purely because this is what you are used to.
So, realise where your responsibilities lie. Your job is to generate the dynamic
parts of the site, to make the right data appear in the right place upon
request. Your job is not to design the look and feel of the site. This is simply
not your remit, and with good reason - coders and designers are a different
breed. So, keep the design of the site and the code that puts dynamic data
separate. That is, keep the application layer separate from the presentation
layer.
Keeping the code and the base HTML page separate is key to getting a
maintainable website under development.
So first off go find a designer. Expectations will be higher. So, grab your
designer and get a mock up page done in HTML. Make a note to your designer that
they will be using absolute not relative paths for images etc, since that's what
an AS400 uses. Next, for any pages where data is to be sent to the AS400 from
the client, ie an "input screen", go away and find a javascript programmer.
(Your web designer may or may not be able to assist here). You need a javascript
programmer to perform client side checking before it gets to the server, for
obvious things like mandatory fields, checking that a number is in fact a
number, dates, etc. Yes, you could do this on the server, but it's less CPU
intensive to do it on the client, and you get an instant response back to the
customer which is a whole nicer experience.
Okay so what about the RPG ?
This bit is easy, and free. Go to Easy400, and download the CGIDEV2 library.
Install it on your AS400 and away you go. Want more help ? There is loads on
this site. Tutorials, code samples, whole sites, etc, etc. It's a real gem, go
visit and learn !
This is, simply put, the best and most useful advice I can give. This set of
free libraries from IBM encapsulates all of the functions required into a
service program that you simply bind to your RPGLE program. Since your
application layer is separated from your presentation layer, the methodology is
simple.
Stick your HTML file from your designer on the AS400. Build a program that reads
in the HTML file, possibly a section at a time, and substitutes the values the
designer has used in the mockup for the real values from the database. Send the
result back to the browser
Sounds scary ? Shouldn't do. Loading a section of a web page is a single
function. Replacing some text with a value is another single function. Sending
the resulting HTML back to the client is a single function. Getting a value
passed to the AS400 from a web page is, you've guessed it, a single function. So
basically with this set of libraries you will have abstracted out the CGI bit
into a service program, leaving you to concentrate on the business tasks
required by the program.
I realise this sounds totally unglamourous. That's because it is - it's still
coding after all !
About the Author: Vince
Lewis is an IT professional of 15 years. He has more information on AS400s and
Testing at his site,
http://www.crimsonsolutions.co.uk.
Source
of article:
www.goarticles.com
| |
|