midrange.com code scratchpad
Name:
Generate School Course Catalog
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
04/07/2012 04:32:00 am
IP:
Logged
Description:
This is an example of a typical interface / design pattern that we use for generating colorful, graphical, reports.

These procedures are called from a web application. A PDF file is generated and downloaded to a web browser. This service program uses somewhat high-level browser, report, and SQL interfaces.

Procedures beginning with:

"wtn" -> Browser.
"rpt" -> Report.
"csr" -> SQL Cursor.
Code:
  1.      h copyright('2012 Relational Data Corporation') nomain
  2.  
  3.       //-----------------------------------------------------------------
  4.       // copy members
  5.       //-----------------------------------------------------------------
  6.  
  7.       /copy *libl/qrpglesrc,xrpt100#1
  8.       /copy *libl/qrpglesrc,rdcsrapi#1
  9.       /copy *libl/qrpglesrc,rdrptapi#1
  10.       /copy *libl/qrpglesrc,rdwtnapi#1
  11.       /copy *libl/qrpglesrc,rdfmtapi#1
  12.       /copy *libl/qsissrc,sisssch#1
  13.  
  14.       //-----------------------------------------------------------------
  15.       // module level variables
  16.       //-----------------------------------------------------------------
  17.  
  18.      d ytmlink         ds                  import qualified
  19.      d  district                     10a
  20.      d  school                       10a
  21.      d  fyr                           4a
  22.      d  term                          4a
  23.  
  24.      d dept            ds                  qualified dim(3)
  25.      d  id                           10a
  26.  
  27.      d c1              s               *   inz(*null)
  28.      d r1              s               *   inz(*null)
  29.      d filter          s            128a   varying
  30.      d odd             s               n
  31.      d str             s            256a   varying
  32.      d ext             s             10a   varying
  33.  
  34.      d squote          c                   ''''
  35.  
  36.       //-----------------------------------------------------------------
  37.       // generate report
  38.       //-----------------------------------------------------------------
  39.  
  40.      p rptxGen         b                   export
  41.      d rptxGen         pi              n
  42.  
  43.       /free
  44.  
  45.        clear dept;
  46.  
  47.        r1 = rptOpen('SCRS100A');
  48.        c1 = csrNew('SCRS100P');
  49.  
  50.        csrSetOrder('DEPT, TITLL, COURSE, EXTENSION');
  51.  
  52.        dept(1).id = wtnFldGet('DEPT');
  53.  
  54.        filter = 'DISTRICT = ' + squote + ytmlink.district + squote +
  55.         ' AND SCHOOL = ' + squote + ytmlink.school + squote;
  56.  
  57.        if dept(1).id <> *blanks;
  58.         filter = filter + ' AND DEPT = ' +
  59.          squote + %trimr(dept(1).id) + squote;
  60.        endif;
  61.  
  62.        filter = filter + ' AND SCRUB <> ' + squote + '1' + squote;
  63.  
  64.        csrSetFilter(filter);
  65.        csrRefresh();
  66.  
  67.        if csrGoto(csr_next);
  68.         rptRecWrt('BEGRPT');
  69.         exsr page_head;
  70.        else;
  71.         return *on;
  72.        endif;
  73.  
  74.        csrGoto(csr_bof);
  75.  
  76.        dow csrGoto(csr_next);
  77.         exsr report_detail;
  78.        enddo;
  79.  
  80.        rptRecWrt('ENDCRS');
  81.        rptRecWrt('ENDRPT');
  82.  
  83.        return *on;
  84.  
  85.        //-----------------------------------------------------------------
  86.        // output detail lines
  87.        //-----------------------------------------------------------------
  88.  
  89.        begsr report_detail;
  90.  
  91.         dept(3).id = csrColStr('DEPT');
  92.  
  93.         if dept(2) <> dept(3);
  94.          rptRecWrt('ENDCRS');
  95.          rptPageBreak();
  96.          exsr page_head;
  97.         endif;
  98.  
  99.         dept(2) = dept(3);
  100.  
  101.         rptRecSet('DETAIL');
  102.  
  103.         if odd;
  104.          rptVarSet('cls':'odd');
  105.         else;
  106.          rptVarSet('cls':'even');
  107.         endif;
  108.  
  109.         odd = not odd;
  110.  
  111.         ext = %trimr(csrColStr('EXTENSION'));
  112.         str = %trimr(csrColStr('TITLL')) +
  113.          ' (' + %trimr(csrColStr('COURSE'));
  114.  
  115.         if ext <> '';
  116.          str = str + '-' + ext;
  117.         endif;
  118.  
  119.         str = str + ')';
  120.         str = str + ' [' + %trimr(csrColStr('GRADESCL')) + ']';
  121.  
  122.         rptVarSet('crs':str);
  123.         rptVarSet('fr':%char(csrColInt('TERMFROM')));
  124.         rptVarSet('to':%char(csrColInt('TERMTO')));
  125.         rptVarSet('tm':%char(csrColInt('TERMS')));
  126.         rptVarSet('cd':%editc(%dech(csrColFloat('CREDITS'):4:2):'2'));
  127.         rptVarSet('pt':%char(csrColInt('PARTCRED')));
  128.         rptVarSet('gp':%editc(%dech(csrColFloat('GRDPNTADJ'):4:2):'2'));
  129.         rptVarSet('nl':%char(csrColInt('MINLEVEL')));
  130.         rptVarSet('xl':%char(csrColInt('MAXLEVEL')));
  131.         rptVarSet('na':%editc(%dech(csrColFloat('MINAGE'):3:1):'2'));
  132.         rptVarSet('xa':%editc(%dech(csrColFloat('MAXAGE'):3:1):'2'));
  133.         rptVarSet('gn':%trimr(csrColStr('GENDERS')));
  134.         rptVarSet('ps':%editc(%dech(csrColFloat('PASSPCT'):4:1):'2'));
  135.         rptVarSet('ap':%trimr(csrColStr('APPROVAL')));
  136.  
  137.         rptRecWrt('DETAIL');
  138.  
  139.        endsr;
  140.  
  141.        //-----------------------------------------------------------------
  142.        // output page headers
  143.        //-----------------------------------------------------------------
  144.  
  145.        begsr page_head;
  146.  
  147.         odd = *on;
  148.         csrGoto(csr_relative:0);
  149.  
  150.         dept(3).id = csrColStr('DEPT');
  151.         dept(2) = dept(3);
  152.  
  153.         rptRecSet('PAGEHEAD');
  154.  
  155.         rptVarSet('school':sschDesc(ytmlink.school));
  156.         rptVarSet('date':fmtDate(%date():4));
  157.         rptVarSet('dept'
  158.          :%trimr(dept(3).id));
  159.  
  160.         rptRecWrt('PAGEHEAD');
  161.         rptRecWrt('BEGCRS');
  162.  
  163.        endsr;
  164.  
  165.       /end-free
  166.  
  167.      p rptxGen         e
  168.  
  169.       //-----------------------------------------------------------------
  170.       // generate PDF
  171.       //-----------------------------------------------------------------
  172.  
  173.      p rptxCrtPdf      b                   export
  174.      d rptxCrtPdf      pi              n
  175.  
  176.       /free
  177.  
  178.         return rptToPdf(600);
  179.  
  180.       /end-free
  181.  
  182.      p rptxCrtPdf      e
  183.  
  184.       //-----------------------------------------------------------------
  185.       // clean up
  186.       //-----------------------------------------------------------------
  187.  
  188.      p rptxClose       b                   export
  189.  
  190.       /free
  191.  
  192.        csrClose();
  193.        rptClose(*off);
  194.  
  195.       /end-free
  196.  
  197.      p rptxClose       e
  198.  
© 2004-2019 by midrange.com generated in 0.005s valid xhtml & css