CREATE PROCEDURE "demoadm".b_k_buch() DEFINE dw_oper varchar(50,0); DEFINE err_id int; DEFINE err_sql int; DEFINE err_isam int; DEFINE err_txt varchar(150,0); DEFINE err_msg varchar(250,0); DEFINE i int; DEFINE pv_action char(1); DEFINE pv_mandant char(2); DEFINE pv_journr int; DEFINE pv_periode int; DEFINE pv_kto char(15); DEFINE pv_gktr char(15); DEFINE pv_gkst char(15); DEFINE pv_betrag decimal(13,2); DEFINE pv_menge decimal(22,7); DEFINE sv_kst_nr char(15); DEFINE sv_ktr_nr char(15); DEFINE sv_kart_nr char(15); DEFINE sv_mandant char(2); DEFINE sv_jahr decimal(4,0); DEFINE sv_periode decimal(2,0); DEFINE sv_betrag decimal(13,2); DEFINE sv_menge decimal(22,7); LET dw_oper = 'Start'; LET err_id = 0; BEGIN WORK; SET LOCK MODE TO WAIT 10; BEGIN ON EXCEPTION SET err_sql, err_isam, err_txt LET err_msg = 'ERR[' ||err_sql|| ',' ||err_isam|| ',' ||err_id|| ']:' ||err_txt|| ' # ' ||dw_oper; SYSTEM 'echo "B_k_buch: '||err_msg||'" >> /var/tmp/log.dwb'; END EXCEPTION; FOREACH dw_curs1 FOR SELECT l.er_id, l.lv_action, l.lv_mandant, l.lv_journr, l.lv_periode, l.lv_kto, l.lv_gktr, l.lv_gkst, l.lv_betrag, l.lv_menge INTO err_id, pv_action, pv_mandant, pv_journr, pv_periode, pv_kto, pv_gktr, pv_gkst, pv_betrag, pv_menge FROM DWE_k_buch l ON EXCEPTION UPDATE DWE_k_buch SET er_retry = er_retry + 1 WHERE er_id = err_id ; END EXCEPTION; LET dw_oper = 'Computing variables'; LET sv_kst_nr = pv_gkst; LET sv_ktr_nr = pv_gktr; LET sv_kart_nr = pv_kto; LET sv_mandant = pv_mandant; LET sv_jahr = 1900 + TRUNC(pv_journr/10000000); LET sv_periode = pv_periode; LET sv_betrag = pv_betrag; LET sv_menge = pv_menge; -- Negate Values -- IF pv_action = 'D' THEN LET sv_betrag = -sv_betrag; LET sv_menge = -sv_menge; END IF LET dw_oper = 'Updating sr_saldo_k'; UPDATE sr_saldo_k SET betrag = betrag + sv_betrag, menge = menge + sv_menge WHERE (kst_nr = sv_kst_nr) AND (ktr_nr = sv_ktr_nr) AND (kart_nr = sv_kart_nr) AND (mandant = sv_mandant) AND (jahr = sv_jahr) AND (periode = sv_periode) ; IF DBINFO('sqlca.sqlerrd2') < 1 THEN INSERT INTO sr_saldo_k ( kst_nr, ktr_nr, kart_nr, mandant, jahr, periode, betrag, menge ) VALUES ( sv_kst_nr, sv_ktr_nr, sv_kart_nr, sv_mandant, sv_jahr, sv_periode, sv_betrag, sv_menge ); END IF LET dw_oper = 'Deleting from DWE_k_buch'; DELETE FROM DWE_k_buch WHERE CURRENT OF dw_curs1; END FOREACH END SET LOCK MODE TO NOT WAIT; COMMIT WORK; END PROCEDURE
HTML-Autor: Rohloff, Datenbank: demodb, Datenstand: 31.05.00 17:07