midrange.com code scratchpad
Name:
AFRU100BB
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
09/14/2015 01:11:23 pm
IP:
Logged
Description:
Database event handler which implements data validation and business rules associated with "FRUITS" table.
Code:
  1.       //-----------------------------------------------------------------
  2.       // DB event handler for "fruits" table (evoked before insert/update)
  3.       //-----------------------------------------------------------------
  4.  
  5.      h nomain copyright('Relational Data Corporation 2015')
  6.  
  7.      fafru100l1 if   e           k disk    prefix(a_)
  8.      f                                     rename(afru100r:afru100a)
  9.  
  10.       /copy *libl/qdbssrc,rdtrghlr#1
  11.       /copy *libl/qdbssrc,rdtrginf#1
  12.       /copy *libl/qrpglesrc,rdmsgapi#1
  13.       /copy *libl/qrpglesrc,rdgenapi#1
  14.  
  15.       //-----------------------------------------------------------------
  16.       // module level data
  17.       //-----------------------------------------------------------------
  18.  
  19.      d trgptr          s               *   import
  20.  
  21.      d fruit         e ds                  qualified extname(afru100p)
  22.  
  23.       //-----------------------------------------------------------------
  24.       // initialization
  25.       //-----------------------------------------------------------------
  26.  
  27.      p init            b                   export
  28.  
  29.       /free
  30.  
  31.        msgFileOpen();
  32.  
  33.        return;
  34.  
  35.       /end-free
  36.  
  37.      p init            e
  38.  
  39.       //-----------------------------------------------------------------
  40.       // process insert or update event
  41.       //-----------------------------------------------------------------
  42.  
  43.      p process         b                   export
  44.  
  45.       /free
  46.  
  47.        fruit = trg.after;
  48.  
  49.        //-----------------------------------------------------------------
  50.        // is fruit name filled in?
  51.        //-----------------------------------------------------------------
  52.  
  53.        if fruit.name = *blanks;
  54.         trgMsgAdd(type_error
  55.          :msgGetText('FRUIT':0:'Name.')
  56.          :'NAME');
  57.         trg.escape = *on;
  58.         return;
  59.        endif;
  60.  
  61.        //-----------------------------------------------------------------
  62.        // is retail price a positive number?
  63.        //-----------------------------------------------------------------
  64.  
  65.        if fruit.rtlprice <= 0;
  66.         trgMsgAdd(type_error
  67.          :msgGetText('FRUIT':1)
  68.          :'RTLPRICE');
  69.         trg.escape = *on;
  70.         return;
  71.        endif;
  72.  
  73.        //-----------------------------------------------------------------
  74.        // is wholesale price a positive number?
  75.        //-----------------------------------------------------------------
  76.  
  77.        if fruit.whlprice <= 0;
  78.         trgMsgAdd(type_error
  79.          :msgGetText('FRUIT':1)
  80.          :'WHLPRICE');
  81.         trg.escape = *on;
  82.         return;
  83.        endif;
  84.  
  85.        //-----------------------------------------------------------------
  86.        // is purchase price a positive number?
  87.        //-----------------------------------------------------------------
  88.  
  89.        if fruit.purprice <= 0;
  90.         trgMsgAdd(type_error
  91.          :msgGetText('FRUIT':1)
  92.          :'PURPRICE');
  93.         trg.escape = *on;
  94.         return;
  95.        endif;
  96.  
  97.        //-----------------------------------------------------------------
  98.        // is purchase price less than or equal to wholesale price?
  99.        //-----------------------------------------------------------------
  100.  
  101.        if fruit.purprice <= fruit.whlprice;
  102.         trgMsgAdd(type_error
  103.          :msgGetText('FRUIT':2)
  104.          :'PURPRICE');
  105.         trg.escape = *on;
  106.         return;
  107.        endif;
  108.  
  109.        //-----------------------------------------------------------------
  110.        // is wholesale price less than or equal to retail price
  111.        //-----------------------------------------------------------------
  112.  
  113.        if fruit.whlprice <= fruit.rtlprice;
  114.         trgMsgAdd(type_error
  115.          :msgGetText('FRUIT':3)
  116.          :'WHLPRICE');
  117.         trg.escape = *on;
  118.         return;
  119.        endif;
  120.  
  121.        //-----------------------------------------------------------------
  122.        // is fruit name unique?
  123.        //-----------------------------------------------------------------
  124.  
  125.        setll (fruit.name) afru100a;
  126.  
  127.        if %equal();
  128.         trgMsgAdd(type_error
  129.          :msgGetText('FRUIT':4)
  130.          :'NAME');
  131.         trg.escape = *on;
  132.         return;
  133.        endif;
  134.  
  135.        //-----------------------------------------------------------------
  136.        // generate surrogate key for record if insert event
  137.        //-----------------------------------------------------------------
  138.  
  139.        if trg.evt = trg_insert_event;
  140.         fruit.keyseqn = genNextSeqn('AFRU100P');
  141.        endif;
  142.  
  143.        trg.after = fruit;
  144.  
  145.        return;
  146.  
  147.       /end-free
  148.  
  149.      p process         e
  150.  
  151.       //-----------------------------------------------------------------
  152.       // clean up
  153.       //-----------------------------------------------------------------
  154.  
  155.      p term            b                   export
  156.  
  157.       /free
  158.  
  159.        msgFileClose();
  160.  
  161.        *inlr = *on;
  162.  
  163.        return;
  164.  
  165.       /end-free
  166.  
  167.      p term            e
  168.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css