Tips and Techniques: A "Simple" CGI Program

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

A number of you have sent me email suggesting that if you could just see a short, simple working CGI program, it would help so much in getting started.

Emphasis on the word "simple" is what the problem has been. Most "simple" examples seem to have gotten a bit complicated.

Nonetheless, here is a simple CGI program that will display the show times for a specific movie, given a Movie ID (key value). I've also included the HTML for the SHOWTM.HTML file that this CGI program reads and sends to the browser. The folder location name /MOVIES may be different on your machine, or you can create MOVIES and put the HTML in there. This technique does use HTML stored on the IFS.

This CGI program requires the CGILIB, which is part of the RPG xTools. It can also be easily converted to use the popular CGIDEV2 library by changing the /COPY and the CGI procedure names.






BNDDIR('QC2LE' : 'CGILIB')
FMDB       IF   E           DISK   
F
 /COPY XTOOLS/QCPYSRC,CGI
D html            S            256A   Inz('/movies/showtm.html')

     
C                   Callp     cgiInit()
C                   
C     Movie         KLIST     
C                   KFLD                    MID
     
C                   eval      MID = cgiGetVar('MID')
C                   callp     cgiLoadHtmlIFS(html)
C     Movie         Chain     MDB
C                   if        %Found()
C                   callp     cgiSetVar('TITLE':MTITLE)     
C                   callp     cgiWrtSection('*TOP')

C                   Dou       %EOF()
C                   callp     cgiSetVar('PLAYTIME': %Char(MTIME))
C                   callp     cgiWrtSection('SHOWTIME')
C     Movie         READE     MDB
C                   enddo
C                   callp     cgiWrtSection('THERESTOFTHEHTML')
C                   callp     cgiWrtSection('*END')
C                   eval      *INLR = *ON
C                   


The HTML source is as follows:



CGILIB Example: Movie Show Times


The remaining show times for the movie: 
/%MOVIETITLE%/ are as follows:



    /$SHOWTIME
  • /%PLAYTIME%/

  • /$TheRestOfTheHTML

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$