//----------------------------------------------------------------- // DB event handler for "fruits" table (evoked before insert/update) //----------------------------------------------------------------- h nomain copyright('Relational Data Corporation 2015') fafru100l1 if e k disk prefix(a_) f rename(afru100r:afru100a) /copy *libl/qdbssrc,rdtrghlr#1 /copy *libl/qdbssrc,rdtrginf#1 /copy *libl/qrpglesrc,rdmsgapi#1 /copy *libl/qrpglesrc,rdgenapi#1 //----------------------------------------------------------------- // module level data //----------------------------------------------------------------- d trgptr s * import d fruit e ds qualified extname(afru100p) //----------------------------------------------------------------- // initialization //----------------------------------------------------------------- p init b export /free msgFileOpen(); return; /end-free p init e //----------------------------------------------------------------- // process insert or update event //----------------------------------------------------------------- p process b export /free fruit = trg.after; //----------------------------------------------------------------- // is fruit name filled in? //----------------------------------------------------------------- if fruit.name = *blanks; trgMsgAdd(type_error :msgGetText('FRUIT':0:'Name.') :'NAME'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // is retail price a positive number? //----------------------------------------------------------------- if fruit.rtlprice <= 0; trgMsgAdd(type_error :msgGetText('FRUIT':1) :'RTLPRICE'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // is wholesale price a positive number? //----------------------------------------------------------------- if fruit.whlprice <= 0; trgMsgAdd(type_error :msgGetText('FRUIT':1) :'WHLPRICE'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // is purchase price a positive number? //----------------------------------------------------------------- if fruit.purprice <= 0; trgMsgAdd(type_error :msgGetText('FRUIT':1) :'PURPRICE'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // is purchase price less than or equal to wholesale price? //----------------------------------------------------------------- if fruit.purprice <= fruit.whlprice; trgMsgAdd(type_error :msgGetText('FRUIT':2) :'PURPRICE'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // is wholesale price less than or equal to retail price //----------------------------------------------------------------- if fruit.whlprice <= fruit.rtlprice; trgMsgAdd(type_error :msgGetText('FRUIT':3) :'WHLPRICE'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // is fruit name unique? //----------------------------------------------------------------- setll (fruit.name) afru100a; if %equal(); trgMsgAdd(type_error :msgGetText('FRUIT':4) :'NAME'); trg.escape = *on; return; endif; //----------------------------------------------------------------- // generate surrogate key for record if insert event //----------------------------------------------------------------- if trg.evt = trg_insert_event; fruit.keyseqn = genNextSeqn('AFRU100P'); endif; trg.after = fruit; return; /end-free p process e //----------------------------------------------------------------- // clean up //----------------------------------------------------------------- p term b export /free msgFileClose(); *inlr = *on; return; /end-free p term e