范例(cxmt052):当单身新增、修改、删除时,汇总单身的应付金额,更新并显示到单头上;
1、自定义函数,主要是用在单身新增、修改时调用:
1)
PRIVATE FUNCTION cxmt052_totalPrice() #定义变数 DEFINE id INT DEFINE totalPrice LIKE xmcnuc_t.xmcnuc007 #初始化应付总金额 LET totalPrice = 0 #遍历单身计算应付总金额 FOR id = 1 TO g_xmcouc_d.getLength() LET totalPrice = totalPrice + g_xmcouc_d[id].xmcouc010 END FOR LET g_xmcnuc_m.xmcnuc007 = totalPrice DISPLAY BY NAME g_xmcnuc_m.xmcnuc007 #更新单头应付总金额 UPDATE xmcnuc_t SET xmcnuc007 = totalPrice WHERE xmcnucent = g_enterprise AND xmcnucdocno = g_xmcnuc_m.xmcnucdocno END FUNCTION
2)单身新增后:
#add-point:單身新增後 name="input.body.a_insert" CALL cxmt052_totalPrice() #end add-point
3)单身修改更新后:
#add-point:單身修改後 name="input.body.a_update" CALL cxmt052_totalPrice() #end add-point
2、单身删除时,在程序执行完毕后,行才会在单身列表中删掉,所以在这里遍历单身汇总金额的时候,要把删除的那条数据排除不汇总:
#add-point:delete_b段define(客製用) name="delete_b.define_customerization" DEFINE id INT DEFINE totalPrice LIKE xmcnuc_t.xmcnuc007 #end add-point
#add-point:delete_b段刪除前 name="delete_b.b_delete" #end add-point DELETE FROM xmcouc_t WHERE xmcoucent = g_enterprise AND xmcoucdocno = ps_keys_bak[1] AND xmcoucseq = ps_keys_bak[2] #add-point:delete_b段刪除中 name="delete_b.m_delete" LET totalPrice = 0 FOR id = 1 TO g_xmcouc_d.getLength() IF g_xmcouc_d[id].xmcoucseq = ps_keys_bak[2] THEN CONTINUE FOR END IF LET totalPrice = totalPrice + g_xmcouc_d[id].xmcouc010 END FOR LET g_xmcnuc_m.xmcnuc007 = totalPrice DISPLAY BY NAME g_xmcnuc_m.xmcnuc007 UPDATE xmcnuc_t SET xmcnuc007 = totalPrice WHERE xmcnucent = g_enterprise AND xmcnucdocno = g_xmcnuc_m.xmcnucdocno #end add-point