Learn from sources
       star Member EXERCISE in CGIDEV2 / QRPGLESRC

       *********************************************************************
       *  RPG ILE MODULE CGIDEV2/EXERCISE
       *
       *  After compiling this RPG MODULE,
       *  create the related program with the following command:
       *
       *  CRTPGM CGIDEV2/EXERCISE MODULE(CGIDEV2/EXERCISE) ACTGRP(C2EXERCISE)
       *
       *  To run the program, enter the following
       *  in the command line of your web browser
       *     http://.../cgidev/html/opinion.html
       *
       *********************************************************************
       *  Input string parameters
       *                        Keyword          Meaning
       *                        Lng              National language
       *                        Subject          Person or subject
       *                                         about whom or which
       *                                         an opinion is asked
       *********************************************************************
       /copy CGIDEV2/qrpglesrc,hspecs
       /copy CGIDEV2/qrpglesrc,hspecsbnd
       /copy CGIDEV2/qrpglesrc,prototypeb
       /copy CGIDEV2/qrpglesrc,usec
       /copy CGIDEV2/qrpglesrc,variables3
       *--------------------------------------------------------------------
       *  SOME PROGRAM VARIABLES
       *--------------------------------------------------------------------
       * External HTML
      D extHtml         s           2000    inz('/cgidev/html/exercise.txt')
       * Indicators for GetHtmlIfsMult subprocedure
      D IfsMultIndicators...
      d                 ds
      D  NoErrors                       n
      D  NameTooLong                    n
      D  NotAccessible                  n
      D  NoFilesUsable                  n
      D  DupSections                    n
      D  FileIsEmpty                    n
       * Variables parsed from input query string
      D subject         s             30a
       * Variables required by subprocedure "random"
      DMyRandom         S             10u 0                                      Random number
      DMyLow            S             10u 0                                      Low end of range
      DMyHigh           S             10u 0                                      High end of range
       *
      DTimeN            s              6s 0
      DTimeC            s              6a
       *=====================================================================
       * PROCESS
       *=====================================================================
       * Receive query string from the browser
       /copy CGIDEV2/qrpglesrc,prolog3
       * Parse it into program variables
      C                   eval      subject = zhbgetvar('subject')
       * Load external html
      C                   eval      IfsMultIndicators = getHtmlIfsMult(
      C                             %trim(exthtml):'«as400»')
       *==================
       * Time of the day
      C                   time                    TimeN
      C                   move      timen         TimeC
       * Set the variables for the html output skeleton
       *  1- Subject
      C                   callp     updHTMLvar('ABOUT':%trimr(subject))
       *  2- Time (unedited)
      C                   callp     updHTMLvar('TIME':timec)
       *  3- Time (edited)
      C                   callp     updhtmlvar('TIMEEDIT':
      C                             %trim(%editw(timen:'  :  :  ')))
       * Issue the first part of the answer
       * (about your question ... my opinion is)
      C                   callp     wrtsection('part1')
       * Find a random integer between 1 and 5
      C                   eval      MyLow = 1
      C                   eval      MyHigh = 50
      C                   eval      MyRandom = random(MyLow:MyHigh)
       * Issue the second part of the answer
       * (my opinion)
      C                   if        MyRandom «= 10
      C                   callp     wrtsection('answer1')
      C                   endif
      C                   if        MyRandom » 10 and MyRandom «= 20
      C                   callp     wrtsection('answer2')
      C                   endif
      C                   if        MyRandom » 20 and MyRandom «= 30
      C                   callp     wrtsection('answer3')
      C                   endif
      C                   if        MyRandom » 30 and MyRandom «= 40
      C                   callp     wrtsection('answer4')
      C                   endif
      C                   if        MyRandom » 40
      C                   callp     wrtsection('answer5')
      C                   endif
       * Issue the third part of the answer
       * (end html)
      C                   callp     wrtsection('part3')
       * Send the html buffer
      C                   callp     wrtsection('*fini')
       * Back to caller
      C                   return
0.022 sec.s