Miklasz Consulting
1263 Hanes Road
Beavercreek, Ohio 45434
(937) 429-0525
E-MAIL


 
 
 
Distinguishing Characteristics
Optimization, as I use the term, is almost always misunderstood. Most people consider it to mean the smallest amount of code, or the fastest execution time. I, on the other hand, also include such factors as readability and maintainability.

What's sauce for the Manufacturing Inventory Control goose isn't necessarily sauce for the Credit Card Processing Over Rented Lines gander. Most situations call for a compromise among all the factors to represent a truly optimized program. By avoiding tricky, or highly-repetative code while maintaining an easy-to-read modular design, one can reach a balance of size, speed and maintenance cost.

This program example illustrates the use of functions and procedures to eliminate redundant code.




            

            

            
 /****************************************************************************
  *
  *     Program: regcmpny.p - REGister CoMPaNY
  *
  *              Register a business/group for classes/certification
  *
  *              Update the company-reg table from user html input from
  *              xxxxxxx.htm thru regcmpny.php
  *
  *     Project: PHSC
  *
  *      Author: Copyright 2003, MCSD - All rights reserved
  *
  ****************************************************************************/
 
 def input param this-type as char no-undo.
 def input param this-id as char no-undo.
 def input param html-id as char no-undo.
 def input param this-data as char no-undo.
 def output param short-name as char no-undo.
 
 def temp-table current-company-reg like company-reg.
 
 def stream iostrm.
 
 def var html-file as char no-undo.
 
 /************** variables for 'post' to paypal ***************/
 
 def var post-line as char no-undo.
 def var i as int no-undo.
 
 def var paid as log no-undo.
 def var not-selected as log no-undo.
 
 /************* variable for buffer comparison ****************/
 
 def var same as log no-undo.
 
 
 
 function price-calc returns char ( input type as char,
                                    input qty as int,
                                    output per-each as dec,
                                    output ext-price as dec ):
 
 /****************************************************************
  *
  * Lookup per-each price in priceguide.
  * Calculate extended price per item.
  * Accumulate the total invoice amount from calculated fields.
  *
  ****************************************************************/
 
 find priceguide where ( priceguide.type eq type )
                   and ( priceguide.low-qty le qty )
                   and ( priceguide.high-qty ge qty )
                 no-lock
                 no-error.
 
 assign per-each = priceguide.per-each
        ext-price = ( qty * per-each )
        company-reg.invoice-amt = ( company-reg.invoice-amt + ext-price ).
 
 return ''.
 
 
 end function. /* price-calc */
 
 
 assign short-name = ( this-id + '.dat' ).
 
 
 find company-reg where ( company-reg.company-reg-id eq this-id )
                  exclusive
                  no-error.
 /**********************************************
  *
  * THIS WILL NEVER, NEVER HAPPEN!!!!
  *
  **********************************************/
 if ( not ( avail ( company-reg ) ) ) then
    create company-reg.
 
 assign paid = ( company-reg.date-paid ne ? ).
 
 
 /*******************************************************
  *
  * Copy the current company-reg record to temp buffer
  *
  *******************************************************/
 
 buffer-copy company-reg to current-company-reg.
 
 
 
 if ( not ( paid ) ) then do:
 
 /*********************************************************
  *
  * Not Paid, so get (new) information and recalculate.
  *
  *********************************************************/
 
    assign company-reg.invoice-amt = 0
 
           company-reg.company-reg-id = this-id
 
           company-reg.qty-osha = int ( entry ( 1, this-data ) )
           company-reg.qty-osha-test = int ( entry ( 2, this-data ) )
           company-reg.qty-cpr = int ( entry ( 3, this-data ) )
           company-reg.qty-cpr-test = int ( entry ( 4, this-data ) )
           company-reg.qty-fa = int ( entry ( 5, this-data ) )
           company-reg.qty-fa-test = int ( entry ( 6, this-data ) )
           company-reg.qty-expr = int ( entry ( 7, this-data ) )
           company-reg.qty-aids25 = int ( entry ( 8, this-data ) )
           company-reg.qty-aids40 = int ( entry ( 9, this-data ) )
           company-reg.qty-aids70 = int ( entry ( 10, this-data ) ).
 
 
    price-calc ( input 'osha-cert',
                 input company-reg.qty-osha,
                 output company-reg.osha-per-each,
                 output company-reg.ext-price-osha ).
 
    price-calc ( input 'osha-cert',
                 input company-reg.qty-osha-test,
                 output company-reg.osha-test-per-each,
                 output company-reg.ext-price-osha-test ).
 
    price-calc ( input 'cpr',
                 input company-reg.qty-cpr,
                 output company-reg.cpr-per-each,
                 output company-reg.ext-price-cpr ).
 
    price-calc ( input 'cpr',
                 input company-reg.qty-cpr-test,
                 output company-reg.cpr-test-per-each,
                 output company-reg.ext-price-cpr-test ).
 
    price-calc ( input 'fa',
                 input company-reg.qty-fa,
                 output company-reg.fa-per-each,
                 output company-reg.ext-price-fa ).
 
    price-calc ( input 'fa',
                 input company-reg.qty-fa-test,
                 output company-reg.fa-test-per-each,
                 output company-reg.ext-price-fa-test ).
 
    price-calc ( input 'aids25',
                 input company-reg.qty-aids25,
                 output company-reg.aids25-per-each,
                 output company-reg.ext-price-aids25 ).
 
    price-calc ( input 'aids40',
                 input company-reg.qty-aids40,
                 output company-reg.aids40-per-each,
                 output company-reg.ext-price-aids40 ).
 
    price-calc ( input 'aids70',
                 input company-reg.qty-aids70,
                 output company-reg.aids70-per-each,
                 output company-reg.ext-price-aids70 ).
 
    price-calc ( input 'expr',
                 input company-reg.qty-expr,
                 output company-reg.expr-per-each,
                 output company-reg.ext-price-expr ).
 
 end. /* not paid */
 
 /**************************************************************
  *
  * Compare old record to new.  Set last-update if different.
  *
  **************************************************************/
 
 buffer-compare current-company-reg to company-reg
                save same
                no-error.
 
 if ( not ( same ) ) then
    assign company-reg.last-update = today.
 
 
 
 assign short-name = ( html-id + '.htm' )
 
 /***************************************************************
  *
  * PayPal Info
  *
  ***************************************************************/
 
        post-line = ( 'https://www.paypal.com/cgi-bin/webscr'
                    + '?cmd=_cart'
                    + '&upload=1'
                    + '&business=jd.begley@verizon.net'
                    + '&handling_cart=0'
                    + '¤cy_code=USD'
                    + '&lc=US'
                    + ( '&return=http://phsc-x.myip.us/phsc-bin/postppal.cgi'
                      + '?dothis=ppalcomp' + this-id )
                    + '&address1=' + company-reg.billto-address1
                    + '&address2=' + company-reg.billto-address2
                    + '&city=' + company-reg.billto-city
                    + '&state=' + company-reg.billto-state
                    + '&zip=' + company-reg.billto-zip
                    + '&email=' + company-reg.e-mail ).
 
 
 output stream iostrm to
        value ( 'c:\program files\apache group\apache2\htdocs\phsc-x\'
              + short-name ).
 
 put stream iostrm unformatted
     '<html>' skip ( 01 )
     '<!-- ******************************************************************' skip
     '     *' skip
     '     *     program: xxxxxxx.htm' skip
     '     *' skip
     '     *              Company Registration Review and Pay Page' skip
     '     *' skip
     '     *              Generated by PROGRESS program: regcmpny.p' skip
     '     *' skip
     '     *   interface: PayPal' skip
     '     *' skip
     '     *      author: MCSD - Copyright 2003 MCSD, All rights reserved' skip
     '     *' skip
     '     *     project: PHSC' skip
     '     *' skip
     '     ****************************************************************** -->' skip ( 01 )
     '<head>' skip
     '<font color=teal>' skip
     '<title>Registration Investment Summary</title>' skip
     skip ( 01 )
     '<script language="JavaScript"><!--' skip ( 01 )
     'function sendcart( poststr ) ~{' skip ( 01 )
     'var winparam = "width=700,height=390,scrollbars,'
                     + 'location,resizable,status";' skip ( 01 )
     '   window.open ( poststr, "paypal", winparam );' skip ( 01 )
     '}' skip ( 01 )
     '-->' skip 
     '</script>' skip ( 01 )
     '<LINK REL=STYLESHEET HREF="style2.css" TYPE="text/css">' skip
     '<body ' ( if ( paid ) then
                   'background="images/paid.gif"'
                else
                   '' ) ' bgcolor="#D8D1BE">'
     skip ( 01 )
 
     '<img src="images/letterhead.gif" align=left border=0>' skip
     '<IMG SRC="images/123.gif" WIDTH="65" HEIGHT="65" ALIGN="Right" '
         'BORDER="0"><H3><P><CENTER>'
         'Thank You for choosing PHSC for your Health & Safety Education needs<BR>' skip
         'Your REGISTRATION ID: <font color=red>' this-id
         ' </font></P></center></H3><br>' skip
     '<font color=black> ' skip
     'The following information was registered with PHSC.<br>' skip ( 01 )
     'A PHSC representative will contact you to arrange scheduling.<p> '
     skip ( 01 ).
 
 
 put stream iostrm unformatted
     '<table width=100%>' skip ( 01 )
     '   <tr colspan=100%' skip ( 01 )
     '      <td colspan=6>' skip
     '          <b>Company Registration Profile for ID: </b>' company-reg.company-reg-id
                   '    ' company-reg.reg-date  '      <b>Payment Method: </b>'
                     company-reg.pay-method ( if ( company-reg.pay-method eq 'po' ) then
                                                 ( '      <b>PO#:</b> ' + company-reg.po )
                                              else
                                                 '' ) '</td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '   <tr colspan=100%>' skip ( 01 )
     '      <td width=10% align=left><b>Coordinator: </b>' skip
     '      <td width=30% align=left><b>Name: </b>' company-reg.coordinator '</td>' skip
     '      <td width=30% align=left><b>E-mail: </b>' company-reg.e-mail '</td>' skip
     '      <td width=30% align=left><b>Telephone: </b>' company-reg.phone '</td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '   <br>' skip ( 01 )
     '</table>' skip ( 01 ).
 
 put stream iostrm unformatted
     '<table>' skip ( 01 )
     '   <tr>' skip ( 01 )
     '      <td width=10% align=right><b>Ship To: </b></td>' skip
     '      <td width=20%>' trim ( company-reg.shipto-company ) '</td>' skip ( 01 )
     '      <td width=10% align=right><b>Bill To: </b></td>' skip
     '      <td width=20% align=left>' trim ( company-reg.billto-company ) '</td>' skip ( 01 )
     '      <td width=20%>   </td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '   <tr>' skip ( 01 )
     '      <td width=10% align=right>  </td>' skip
     '      <td width=10%> Attn: ' trim ( company-reg.shipto-attn ) '</td>' skip ( 01 )
     '      <td width=10% aligh=right>  </td>' skip
     '      <td width=20% aligh=left> Attn: ' trim ( company-reg.billto-attn ) '</td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '   <tr>' skip ( 01 )
     '      <td width=10% align=right> </td>' skip
     '      <td width=10%> ' trim ( company-reg.shipto-address1 ) '</td>' skip ( 01 )
     '      <td width=10% align=right> </td>' skip
     '      <td width=20% align=left> ' trim ( company-reg.billto-address1 ) '</td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '   <tr>' skip ( 01 )
     '      <td width=10% align=right>  </td>' skip
     '      <td width=10%> ' trim ( company-reg.shipto-address2 ) '</td>' skip ( 01 )
     '      <td width=10% align=right> </td>' skip
     '      <td width=20% align=left> ' trim ( company-reg.billto-address2 ) '</td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '   <tr>' skip ( 01 )
     '      <td width=10% align=right> </td>' skip
     '      <td width=10%> ' trim ( company-reg.shipto-city ) ', ' trim ( company-reg.shipto-state ) ' '
                             trim ( company-reg.shipto-zip ) '</td>' skip ( 01 )
     '      <td width=10% align=right> </td>' skip
     '      <td width=20% align=left> ' trim ( company-reg.billto-city ) ', ' trim ( company-reg.billto-state ) ' '
                                        trim ( company-reg.billto-zip ) '</td>' skip ( 01 )
     '   </tr>' skip ( 01 )
     '</table>' skip ( 02 ).
 
 put stream iostrm unformatted
     '<pre><font color=teal><b>Classroom Training Courses</b></font>' skip.
 
 assign not-selected = true.
 
 run format-detail ( input 'OSHA Compliant First Aid Class',
                           company-reg.qty-osha,
                           company-reg.osha-per-each,
                           company-reg.ext-price-osha ).
 
 run format-detail ( input 'Adult CPR Class',
                           company-reg.qty-cpr,
                           company-reg.cpr-per-each,
                           company-reg.ext-price-cpr ).
 
 run format-detail ( input 'First Aid Class',
                           company-reg.qty-fa,
                           company-reg.fa-per-each,
                           company-reg.ext-price-fa ).
 
 run format-detail ( input 'Express First Aid',
                           company-reg.qty-expr,
                           company-reg.expr-per-each,
                           company-reg.ext-price-expr ).
 
 if ( not-selected ) then
    put stream iostrm unformatted '<i>NONE SELECTED</i>'.
 
 put stream iostrm unformatted '<br>' skip.
 
 put stream iostrm unformatted
     '<font color=teal><b>Certification/Home Study Only</b></font>' skip.
 
 assign not-selected = true.
 
 run format-detail ( input 'OSHA Compliant First Aid Cert',
                           company-reg.qty-osha-test,
                           company-reg.osha-test-per-each,
                           company-reg.ext-price-osha-test ).
 
 run format-detail ( input 'Adult CPR Cert',
                           company-reg.qty-cpr-test,
                           company-reg.cpr-test-per-each,
                           company-reg.ext-price-cpr-test ).
 
 run format-detail ( input 'First Aid Cert',
                           company-reg.qty-fa-test,
                           company-reg.fa-test-per-each,
                           company-reg.ext-price-fa-test ).
 
 run format-detail ( input 'HIV-AIDS 2.5 hr. Self Study',
                           company-reg.qty-aids25,
                           company-reg.aids25-per-each,
                           company-reg.ext-price-aids25 ).
 
 run format-detail ( input 'HIV-AIDS 4.0 hr. Self Study',
                           company-reg.qty-aids40,
                           company-reg.aids40-per-each,
                           company-reg.ext-price-aids40 ).
 
 run format-detail ( input 'HIV-AIDS 7.0 hr. Self Study',
                           company-reg.qty-aids70,
                           company-reg.aids70-per-each,
                           company-reg.ext-price-aids70 ).
 
 
 if ( not-selected ) then
    put stream iostrm unformatted '<i>NONE SELECTED</i>'.
 
 put stream iostrm unformatted
     '<p>' skip
     '                                 TOTAL INVESTMENT:'
         company-reg.invoice-amt form '>>>,>>9.99'.
 
 if ( paid ) then
    put stream iostrm unformatted
        ' <b>PAID: ' company-reg.date-paid '</b>'.
 
 put stream iostrm unformatted
     '<p>' skip
     skip ( 01 )
     '</pre>' skip
     'PLEASE PRINT THIS PAGE TO SAVE AS A REFERENCE.' skip.
 
 if ( not ( paid ) )
 and ( company-reg.pay-method eq 'pp' ) then
    put stream iostrm unformatted
        '<input type=button OnClick="sendcart ( ~'' post-line '~' )" '
               'value="Make Payment">'.
 
 put stream iostrm unformatted
     skip ( 01 )
     '</body>' skip ( 01 )
     '</html>' skip.
 
 output stream iostrm close.
 
 
 
 
 /****************************************************************************
  *********************************************************** END OF PROGRAM *
  ****************************************************************************/
 
 
 procedure format-detail:
 
 /****************************************************
  *
  * Format a consistent output line for the receipt.
  * Format the PayPal 'cart' entry.
  *
  ****************************************************/
 
 def input param class as char no-undo.
 def input param qty as int no-undo.
 def input param per-each as dec no-undo.
 def input param ext-price as dec no-undo.
 
 def var str-i as char no-undo.
 
 if ( qty ne 0 ) then do:
 
    put stream iostrm unformatted
        class form 'x(33)' qty form '>>9' ' @ ' per-each form '>,>>9.99'
                                          ' = ' ext-price form '>>>,>>9.99' skip.
    assign not-selected = false
           i = ( i + 1 )
           str-i = string ( i )
           post-line = ( post-line
                       + '&item_name_' + str-i + '=' + class
                       + '&item_number_' + str-i + '='
                         + company-reg.company-reg-id
                       + '&quantity_' + str-i + '=' + string ( qty )
                       + '&amount_' + str-i + '='
                         + trim ( string ( per-each, '>>>9.99' ) ) ).
 
 end.
 
 
 end procedure. /* format-detail */
 
 
 
 
 


         
 
 
Copyright © 1998-2011 MCSD - All Rights Reserved
Company names, logos and product names are trademarks or registered trademarks of their respective companies.
Title Graphic by JenTekk