存储过程在PBscript中的使用方法

简单的审核操作,调用存储过程的方法如下:

long ll_row
string ls_message, ls_mtrl_no

if dw_main.rowcount() < 1 then return

SetPointer(HourGlass!)
sqlca.autocommit = True

DECLARE lp_diaobo PROCEDURE FOR proc_mm_create_pur_req_new_db  ;  
execute lp_diaobo;
close lp_diaobo;

sqlca.autocommit = False
SetPointer(Arrow!)

if sqlca.sqlcode = -1 then
ls_message = sqlca.sqlerrtext
messagebox('操作提示', '审核失败! 错误信息为:' + ls_message, stopsign!)
else
messagebox('操作提示', '审核成功!')
dw_main.retrieve()
end if


其中 sybase存储过程定义如下:
create proc proc_mm_create_pur_req_new_db
as

declare @dept_no char(10), @mtrl_no char(8), @req_amount decimal(18, 4),
  @req_unit char(12), @req_type char(12), @req_date smalldatetime,
  @ware_no char(10), @supp_no char(10), @order_no integer,
  @sheet_no integer, @order_amount decimal(18, 4), @order_type char(20),
  @arrive_date smalldatetime, @mtrl_cycle decimal(8, 2),
  @ware_dist char(12), @real_stock decimal(18, 4), @li_item integer,
  @real_trans decimal(18, 4), @ldt_today smalldatetime,
           @adt_plan_date smalldatetime, @ls_order_status char(3),
           @ls_res_dept char(10), @ls_dept_r3 char(4), @ls_local varchar(12)

select @ldt_today = convert(smalldatetime,convert(char(10), getdate(), 102))

update supp_mtrl_pur_assign_d
   set res_dept_r3 = loca_no
   from dept_to_r3
   where supp_mtrl_pur_assign_d.res_dept = dept_to_r3.dept_no and
         fun_type = '工厂' and
         ( res_dept_r3 = '' or res_dept_r3 = null )

declare lcu_pr_info cursor for
  SELECT supp_mtrl_pur_assign_m.dept_no,  
supp_mtrl_pur_assign_m.mtrl_no,  
supp_mtrl_pur_assign_m.plan_date,  
supp_mtrl_pur_assign_d.req_date,  
supp_mtrl_pur_assign_d.assign_qty,  
supp_mtrl_pur_assign_m.unit_no_l,  
supp_mtrl_pur_assign_m.dispo,  
supp_mtrl_pur_assign_m.stock_qty,  
supp_mtrl_pur_assign_m.trans_qty,
            supp_mtrl_pur_assign_d.res_dept,
            supp_mtrl_pur_assign_d.res_dept_r3,
            supp_mtrl_pur_assign_d.item_no
FROM supp_mtrl_pur_assign_d,  
supp_mtrl_pur_assign_m 
WHERE ( supp_mtrl_pur_assign_d.dept_no = supp_mtrl_pur_assign_m.dept_no ) and 
( supp_mtrl_pur_assign_d.dept_no_r3 = supp_mtrl_pur_assign_m.dept_no_r3 ) and 
( supp_mtrl_pur_assign_m.mtrl_no = supp_mtrl_pur_assign_d.mtrl_no ) and 
( supp_mtrl_pur_assign_d.plan_date = supp_mtrl_pur_assign_m.plan_date ) and 
( supp_mtrl_pur_assign_m.status = '调拨' ) AND
            ( supp_mtrl_pur_assign_d.res_dept <> '' or
              supp_mtrl_pur_assign_d.res_dept = null ) and
            ( supp_mtrl_pur_assign_d.assign_qty > 0 ) and
            substring(supp_mtrl_pur_assign_m.dept_no_r3, 1, 1) <> '2'
      order by supp_mtrl_pur_assign_m.dept_no,  
   supp_mtrl_pur_assign_m.mtrl_no

open lcu_pr_info
fetch lcu_pr_info into @dept_no, @mtrl_no, @adt_plan_date,
            @arrive_date, @req_amount, @req_unit, @req_type,
            @real_stock, @real_trans, @ls_res_dept, @ls_dept_r3,
            @li_item

while @@sqlstatus != 2
begin
if @@sqlstatus = 1
begin
raiserror 30001 "从服务器中取数据失败!"
return
end

      select @ls_local = department.isnative
      from department
      where department.departmentid = @dept_no

      if @ls_local <> '本地' or @ls_local = null
begin
SELECT @ware_no = higerdepartment.departmentid
FROM higerdepartment, materialascription a
where a.typename = higerdepartment.departmentid and
higerdepartment.ranktype = '行政' and
higerdepartment.ancientrankid = 20 and
a.classname = '仓库镒史掷? AND 
higerdepartment.ancientid = @dept_no and
a.materialid = @mtrl_no and
a.rank = 1

if substring(@ls_dept_r3, 1, 1) = '2'
select @ls_order_status = '2'
else
select @ls_order_status = '8'

select @supp_no = @ls_res_dept

exec proc_getserialnumber 'supp_mtrl_purclist', @dept_no, @sheet_no out

select @ware_dist = rtrim(@ware_no) + '-1'

insert supp_mtrl_purclist
( dept_no, purc_sheet_no, ware_cc, supp_no,
mtrl_no, order_amount, unit_no, the_order_date,
plan_stat, plan_amount, the_price, purc_type,
arrive_date, ware_no, m_unit, c_rrencyname,
plan_type, real_stock, real_trans
)
values ( @dept_no, @sheet_no, @ware_no, @supp_no,
@mtrl_no, @order_amount, @req_unit, @adt_plan_date,
@ls_order_status, @req_amount, 0, @order_type,
@arrive_date, @ware_dist, '元', '人民币',
'月旬', @real_stock, @real_trans
)

         update supp_mtrl_pur_assign_d
         set sheet_no = @sheet_no
         where supp_mtrl_pur_assign_d.dept_no = @dept_no and 
   supp_mtrl_pur_assign_d.mtrl_no = @mtrl_no and 
   supp_mtrl_pur_assign_d.plan_date = @adt_plan_date and
               supp_mtrl_pur_assign_d.item_no = @li_item

insert supp_mtrl_pur_r3
( dept_no, mtrl_no, order_no, order_date,
mrp_ctrl, req_amount, req_plan, stock_amount,
trans_amount, stock_anq, mtrl_cycle, req_unit,  
req_dept, req_type, req_status, item_no,
on_amount, conf_amount, staff_no, staff_name
)
select supp_mtrl_pur_assign_m.dept_no,  
supp_mtrl_pur_assign_m.mtrl_no,
supp_mtrl_pur_assign_d.sheet_no,
supp_mtrl_pur_assign_m.plan_date,
supp_mtrl_pur_assign_m.mrp_ctrl,
supp_mtrl_pur_assign_m.req_all + supp_mtrl_pur_assign_m.sec_qty
- supp_mtrl_pur_assign_m.stock_qty - supp_mtrl_pur_assign_m.trans_qty,
supp_mtrl_pur_assign_m.req_all,
supp_mtrl_pur_assign_m.stock_qty,  
supp_mtrl_pur_assign_m.trans_qty,
supp_mtrl_pur_assign_m.sec_qty,  
supp_mtrl_pur_assign_m.mtrl_cycle,
supp_mtrl_pur_assign_m.unit_no_l,
supp_mtrl_pur_assign_m.dept_no_r3,
supp_mtrl_pur_assign_m.dispo,
'完成', 1,
supp_mtrl_pur_assign_d.req_qty,
supp_mtrl_pur_assign_d.req_qty,
supp_mtrl_pur_assign_m.staff_no,
supp_mtrl_pur_assign_m.staff_name
FROM supp_mtrl_pur_assign_d,  
  supp_mtrl_pur_assign_m 
WHERE ( supp_mtrl_pur_assign_d.dept_no = supp_mtrl_pur_assign_m.dept_no ) and 
( supp_mtrl_pur_assign_d.dept_no_r3 = supp_mtrl_pur_assign_m.dept_no_r3 ) and 
( supp_mtrl_pur_assign_m.mtrl_no = supp_mtrl_pur_assign_d.mtrl_no ) and 
( supp_mtrl_pur_assign_d.plan_date = supp_mtrl_pur_assign_m.plan_date ) and 
supp_mtrl_pur_assign_d.dept_no = @dept_no and 
   supp_mtrl_pur_assign_d.mtrl_no = @mtrl_no and 
   supp_mtrl_pur_assign_d.plan_date = @adt_plan_date and
               supp_mtrl_pur_assign_d.item_no = @li_item

end

fetch lcu_pr_info into @dept_no, @mtrl_no, @adt_plan_date,
@arrive_date, @req_amount, @req_unit, @req_type,
@real_stock, @real_trans, @ls_res_dept, @ls_dept_r3,
                     @li_item
end

close lcu_pr_info
deallocate cursor lcu_pr_info

update supp_mtrl_pur_assign_m
set status = '完成'
   from supp_mtrl_pur_assign_d
where supp_mtrl_pur_assign_d.dept_no = supp_mtrl_pur_assign_m.dept_no and 
supp_mtrl_pur_assign_d.dept_no_r3 = supp_mtrl_pur_assign_m.dept_no_r3 and 
supp_mtrl_pur_assign_m.mtrl_no = supp_mtrl_pur_assign_d.mtrl_no and 
supp_mtrl_pur_assign_d.plan_date = supp_mtrl_pur_assign_m.plan_date and
         supp_mtrl_pur_assign_d.res_dept <> '' and
supp_mtrl_pur_assign_m.status = '调拨'

   select @ldt_today

 -----------------------------------------带参数的存储过程调用----------------------------------------

DECLARE erp_efficiency PROCEDURE FOR

        erp_efficiency('','','')

        EXECUTE erp_efficiency

 

你可能感兴趣的:(Sybase)