• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Get Thee to the Web, Part 3

    September 22, 2010 Paul Tuohy

    In this final article, we will compare and contrast the scripting solutions available with CGIDEV2, PHP, and Java. Here are a few questions to keep in mind when considering which scripting language to use:

    • How well does it integrate with HTML/CSS/Javascript?
    • How well does it integrate with database?
    • How well does it integrate with host language calls?
    • How easy is it to learn?
    • What educational resources are available?
    • Is it well supported?
    • What frameworks are available? (Frameworks allow for very rapid development of interfaces.)
    • Is scalability an issue? (How many people will be using your application.)

    CGIDEV2

    CGIDEV2 is a toolkit (service program) of functions that provide assistance with handling browser input and output, using externally describing HTML, data handling and validation, error handling and reporting, debugging, and other miscellaneous functions.

    A common mistake people make with CGIDEV2 is thinking that it is CGI programming. It isn’t: one of the main functions of CGIDEV2 is to remove the complexity of dealing with the CGI APIs.

    CGIDEV2 is written in RPG and all source is included, so if you don’t like the way it works–change it. A couple of sample applications are also provided.

    For an RPG programmer, CGIDEV2 is easy to learn since it is written in RPG. You just have to learn how to use the CGIDEV2 subprocedures, and five of them are all you need to get up and running (which should only take a couple of hours).

    Again, since you are using RPG, you have easy access to the database and easy access to program/procedure calling.

    Since CGIDEV2 is written in RPG, you will have to have access to an i in order to experiment with it. Also, since CGIDEV2 is specific to the IBM i, there are not a lot of educational resources available–the best resource is at www.easy400.net and the Easy400 group at Yahoo groups. But that being said, there is very little to be learned (a handful of procedures), and the rest is just good old RPG.

    You also have to come up with your own solution for statelessness (using database or user spaces), but this just means finding a technique that works well for your application.

    CGIDEV2 is not as heavily integrated with HTML as some of the other options, which means that the generation of some pages can, at times, be cumbersome. Also, CGIDEV2 does not have the same level of tooling as other options, e.g., IDEs, editors, etc.

    To the best of my knowledge, the only framework that is available for CGIDEV2 is from Renaissance . It is open source and really excellent.

    Let’s have a look at a simple “Hello World” example. CGIDEV2 requires that your HTML is coded separately from your RPG. Code 1 shows the HTML for our example, which is a document stored in the IFS named “/myCGIDevDir/helloWorld.tmpl”. “/$top” identifies a section (record format) named “top”, and “/%today%/” identifies a variable (field) named “today”.

    Code 1--HTML for CGIDEV2 Hello World:
    /$top Content-type: text/html <html><body> <h1>Hello World with CGIDEV2</h1> <p>Today's date is /%today%/</p> </body></html>

    Code 2 shows the corresponding RPG program, which writes the page. The main points to note are:

    • The binding directory (MYBNDDIR) contains an entry for the CGISRVPGM2 service program.
    • The two include directives contain all required prototypes, etc., for CGIDEV2.
    • getHTMLIFS() loads the template (in Code 1) being used.
    • updHTMLVar() updates the value of a variable in the template.
    • wrtSection() writes a section of a page. The special value of *fini means the page is complete.
    Code 2--RPG for CGIDEV2 Hello World:
    H DftActGrp(*no) BndDir(MYBNDDIR) /include prototypeb /include usec /free gethtmlIFS('/myCGIDevDir/helloWorld.tmpl'); updHTMLvar('today': %char(%date())); wrtsection('top *fini'); *inLR = *On;

    CGIDEV2 is available for download at www.easy400.net.

    PHP

    The Zend distribution of PHP on i now comes supplied on the system. Alternatively, you can download it at www.zend.com.

    PHP is an interpreted (no compilation) script language that was designed with a strong focus on Web programming. It includes many strong language features for handling input from browser, has exceptional array handling (oh for some of it in RPG), and has lots and lots of BIFs.

    PHP integrates well with HTML and is very easy to learn, but it can be confusing if tackling HTML/CSS/Javascript at the same time. Although you can take an object oriented (OO) approach to PHP, it is not required and you will note a lot of similarities to RPG.

    One of the best features of PHP is that you don’t need an i in order to try it out. You can use one of the many free distributions, like XAMPP, on your PC, even accessing i data without any special configuration on i.

    Given that PHP is not specific to i, there are lots of frameworks and tools available. Some of these are open source, others are chargeable.

    There are also lots of examples available on the Web and myriad educational and reference resources, PHP.net probably being the best of these.

    It is easy to access the database from PHP–it has a set of db2_ functions–but access to program/procedure calls require that you either wrap the programs/procedures in SQL stored procedures or make use of Zend’s PHP Toolkit for i5/OS. Although both work well, the latter does have some drawbacks in that not all data types are allowed as parameters, and only 10-digit integers may be used as return values.

    Code 3 shows a PHP example of a “Hello World” script–helloWorld.php. PHP code is usually embedded in HTML, encased in <?php ? > directives, or it can construct HTML. In Figure 3, “Date()” is a PHP built-in function.

    Code 3--PHP Hello World:
    <html><body> <h1>Hello World with PHP</h1> <p>Today's date is <?php print(Date("l F d, Y")); ? > </p> </body></html>

    Java

    What can one say about Java? It is the hot, “new ” language on the block. To use Java in a Web environment you make use of JavaServer Pages (JSP) or JavaServer Faces (JSF). JSP/JSF are interpreted scripting languages that mix well with HTML. They work in the same way as PHP–the code is integrated with the HTML or can generate the HTML.

    As with PHP, JSP/JSF are not specific to i, and there are lots of frameworks and tools available. Some of these are open source, others are chargeable. There are also the corresponding myriad educational and reference resources available.

    For the traditional RPG programmer, one of the downsides of a Java approach is that you have to learn an OO language, and lots of us find that difficult to do. But you will find it easier if you have more than a passing familiarity with free form RPG and ILE. It may help you discover your hidden OO talents.

    One of the facets that might influence a company (as opposed to an individual) toward a Java solution is that many institutes are now teaching Java as first preference: so there is a large workforce readily available.

    JSP/JSF requires an Application Server, which is a little trickier to configure as opposed to the Apache Server. As with PHP, you don’t need an i in order to try it out, you can try it on your PC instead.

    Database access is not as straightforward as with PHP. You will need to use a framework for your database access. And the same difficulties apply to program/procedure calls as with PHP.

    Code 4 shows a JSP example of a “Hello World” script–helloWorld.jsp. Java code is usually embedded in HTML encased in <% %> directives), or it can construct HTML.

    Code 4--JSP Hello World:
    <html><body> <h1>Hello World with Java</h1> <p>Today's date is <%= new java.util.Date().toString() %> </p> </body> </html>

    Scalability

    Scalability relates to how many people will be accessing your application at the same time, and how well your application can handle the workload without detrimental response times.

    Usually, you would use Java for high usage, PHP for medium, and CGIDEV2 for below medium. The issue here is how to identify high, medium, and low, and I’m afraid there is no easy answer to that. It all depends on what the application is doing.

    Hardware also has a large say in the proceedings. An application running on a Power 7 machine runs faster than the same application running on Power 5.

    So, unless you have specific application knowledge that would lead you in one direction or another, I would let ease of maintenance and development be your guide.

    In Conclusion

    To get to the Web, there is no single “right way.” It depends on where are you starting from, what your programming skills are, and what size application you are developing.

    Remember to employ a tiered approach to your design, which means you treat the interface separately. This makes it is easy to change your mind and easy to implement future interfaces (e.g., iPhone, etc.).

    Remember there are commonalities , regardless of which approach you take. You need a Web server, someone to design your site, and a knowledge of HTML/CSS/Javascript.

    As with all good technical solutions, it does not have to be one or the other. You could end up with a mixture of CGIDEV2, PHP, and Java. Maybe start with CGIDEV2 (since you are familiar with RPG), and progress to PHP/Java.

    There is only one mistake you can make–doing nothing.

    Paul Tuohy is CEO of ComCon, an iSeries consulting company, and is one of the co-founders of System i Developer, which hosts the RPG & DB2 Summit conferences. He is an award-winning speaker who also speaks regularly at COMMON conferences, and is the author of “Re-engineering RPG Legacy Applications,” “The Programmers Guide to iSeries Navigator,” and the self-study course called “iSeries Navigator for Programmers.” Send your questions or comments for Paul to Ted Holt via the IT Jungle Contact page.

    RELATED STORIES

    Get Thee to the Web, Part 1

    Get Thee to the Web, Part 2



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    ARCAD Software

    Embrace VS Code for IBM i Development

    The IBM i development landscape is evolving with modern tools that enhance efficiency and collaboration. Ready to make the move to VS Code for IBM i?

    Join us for this webinar where we’ll showcase how VS Code can serve as a powerful editor for native IBM i code and explore the essential extensions that make it possible.

    In this session, you’ll discover:

    • How ARCAD’s integration with VS Code provides deep metadata insights, allowing developers to assess the impact of their changes upfront.
    • The role of Git in enabling seamless collaboration between developers using tools like SEU, RDi, and VS Code.
    • Powerful extensions for code quality, security, impact analysis, smart build, and automated RPG conversion to Free Form.
    • How non-IBM i developers can now contribute to IBM i projects without prior knowledge of its specifics, while ensuring full control over their changes.

    The future of IBM i development is here. Let ARCAD be your guide!

    Register now!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    PowerTech:  FREE Webinar! Reduce the Cost and Effort of IBM i Auditing. Sept. 29, 10 a.m. CT
    looksoftware:  RPG OA & Beyond Webinar. Sept 28 & 29. Enter to win an Amazon Kindle™
    COMMON:  Join us at the Fall 2010 Conference & Expo, Oct. 4 - 6, in San Antonio, Texas

    IT Jungle Store Top Book Picks

    Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    Chip Wars: List Price, $29.95

    Is RFID Heyday Just Around the Corner? Power 720: Same Entry Price, But More Room to Grow at Less Cost

    Leave a Reply Cancel reply

Volume 10, Number 28 -- September 22, 2010
THIS ISSUE SPONSORED BY:

WorksRight Software
SEQUEL Software
Twin Data Corporation

Table of Contents

  • Get Thee to the Web, Part 3
  • Merge Into the Synchronization Fast Lane with DB2 for i 7.1
  • Changing i/OS Password Expiration Settings

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle