oracle sqr之多个procedure过程变量传递及同名变量定义

昨日测试了根据不同判断条件写入多个lis文件的sqr代码
http://space.itpub.net/9240380/viewspace-713575

 今天在此基础上,测试了如下几个功能点:
 1,过程之间(指:begin-procedure)传递参数及变量;
 2,多个过程变量是否可以命名相同的变量
 3,begin-procedure节alter-report指定特有的begin-heading

上述代码如下:
#define addtlsetup
#include 'Rptstub.lib'
#include '{libpath}tkit_batchstartup.inc'
#include '{libpath}tkit_rptheader.inc'
#include '{libpath}tkit_queappl.inc'
#include '{libpath}tkit_vars_opts.inc'
#include '{libpath}tkit_Sqrfunc.inc'

begin-setup
 Declare-layout batch-land
   rientation=landscape
   left-margin=0
   top-margin=0
   max-lines=60
   max-columns=180
 end-declare
end-setup

!20111220 newly added 无数据使用报表头
begin-heading 5 name=nodataheading
 print 'a列' (1,11)
 print 'b列' (1,20)
 print '─' (+1,2,84) fill
end-heading

!主过程调用其它子过程
begin-procedure osi-main
 begin-select
count(*) &a_1_rowcount
 from osibank.zxytestsqr z where z.a=1
 end-select
 
 begin-select
count(*) &a_2_rowcount
 from osibank.zxytestsqr z where z.a=2
 end-select
   
 if &a_1_rowcount>0
   do  query_a_1
 else
      !20111220 newly added 无数据启用指定报表头,且使用另外的lis文件
      alter-report  heading=nodataheading
      let $out='无数据表头'||'.LIS'
      new-report $out
      print '查询不到数据' (+1,0) center
      !print #b2  (+1,0) center !在主过程调用子过程产生的变量,用于测试,如写为#b2,结果为0.0,试下#_b2如何
     
 end-if
 
 if &a_2_rowcount>0
   do  query_a_2(#b2)
   print #b2 (+1,20) center
 else
      !20111220 newly added  
 end-if
 
end-procedure

!查询a=1
begin-procedure query_a_1
 let $count='变量1' ! 此过程的变量$count
 let $out1='查询1'||$count||'.LIS'
 new-report $out1
 begin-select
  position (+1)
a &a1
 move &a1 to #a1
 print #a1 (,20,10) edit 9
b &b1
 move &b1 to #b1
 print #b1 (,40,10) edit 9
 from osibank.zxytestsqr z where z.a=1
 end-select
end-procedure


!查询a=2
begin-procedure query_a_2(:#b2)
 let $count='变量2' !此过程的变量$count
 !#debug show $count
 let $out2='查询2'||$count||'.LIS'
 new-report $out2
 begin-select
  position (+1)
a &a2
 move &a2 to #a2
 print #a2 (,60,10) edit 9
b &b2
 move &b2 to #b2
 print #b2 (,80,10) edit 9
 from osibank.zxytestsqr z where z.a=2
 end-select
end-procedure

begin-procedure OSI-Startup   
End-procedure

上述示例代码产生lis文件如下:

查询2变量2.lis

        a列      b列
 ────────────────────────────────────────────────────────────────────────────────────
                                                           2                   2
                                                                                       2.00


无数据表头.lis
         a列      b列
 ────────────────────────────────────────────────────────────────────────────────────
                                                                                   查询不到数据





继续测试,sqr调用oracle存储过程2分支正常错误分别处理及错误报表lis之sqr代码
#define addtlsetup
#include 'Rptstub.lib'
#include '{libpath}tkit_batchstartup.inc'
#include '{libpath}tkit_rptheader.inc'
#include '{libpath}tkit_queappl.inc'
#include '{libpath}tkit_vars_opts.inc'
#include '{libpath}tkit_Sqrfunc.inc'

begin-setup
 Declare-layout batch-land
   rientation=landscape
   left-margin=0
   top-margin=0
   max-lines=60
   max-columns=180
 end-declare
end-setup

!20111220 newly added 无数据使用报表头
begin-heading 5 name=nodataheading
 print 'a列' (1,11)
 print 'b列' (1,20)
 print '─' (+1,2,84) fill
end-heading

!存储过程执行出错报表头
begin-heading 5 name=procerrheading
 print '存储过程错误头' (1,11)
 print '─' (+1,2,84) fill
end-heading

begin-procedure osi-main
 begin-sql
   begin
     osibank.proc_zxytestsqr(#errnbr);;
   end;;
 end-sql
 
 if #errnbr=0
   !存储过程执行出错,不再继续执行下述子过程,产生错误文件
   alter-report heading=procerrheading
   let $out='存储过程执行出错'||'.LIS'
   new-report $out
   print '错误没产生数据' (+1,0) center
 else
      !存储过程执行正常,执行下述子过程
      do submain
 end-if
end-procedure

!主过程调用其它子过程
begin-procedure submain
 begin-select
count(*) &a_1_rowcount
 from osibank.zxytestsqr z where z.a=1
 end-select
 
 begin-select
count(*) &a_2_rowcount
 from osibank.zxytestsqr z where z.a=2
 end-select
   
 if &a_1_rowcount>0
   do  query_a_1
 else
      !20111220 newly added 无数据启用指定报表头,且使用另外的lis文件
      alter-report  heading=nodataheading
      let $out='无数据表头'||'.LIS'
      new-report $out
      print '查询不到数据' (+1,0) center
      !print #b2  (+1,0) center !在主过程调用子过程产生的变量,用于测试,如写为#b2,结果为0.0,试下#_b2如何
 end-if
 
 if &a_2_rowcount>0
   do  query_a_2(#b2)
   print #b2 (+1,20) center
 else
      !20111220 newly added  
 end-if
end-procedure

!查询a=1
begin-procedure query_a_1
 let $count='变量1'
 let $out1='查询1'||$count||'.LIS'
 new-report $out1
 begin-select
  position (+1)
a &a1
 move &a1 to #a1
 print #a1 (,20,10) edit 9
b &b1
 move &b1 to #b1
 print #b1 (,40,10) edit 9
 from osibank.zxytestsqr z where z.a=1
 end-select
end-procedure


!查询a=2
begin-procedure query_a_2(:#b2)
 let $count='变量2'
 !#debug show $count
 let $out2='查询2'||$count||'.LIS'
 new-report $out2
 begin-select
  position (+1)
a &a2
 move &a2 to #a2
 print #a2 (,60,10) edit 9
b &b2
 move &b2 to #b2
 print #b2 (,80,10) edit 9
 from osibank.zxytestsqr z where z.a=2
 end-select
end-procedure

begin-procedure OSI-Startup   
End-procedure



上述sqr调用存储过程内容如下:
 create or replace procedure proc_zxytestsqr(errnbr out number)
 as
 lvncount integer;
 begin
 select count(a) into lvncount from osibank.zxytestsqr;
 if lvncount=0 then
  errnbr:=-1;
 else
  errnbr:=0;
 end if;
 end;


继续改革上述代码,添加begin-footing,输出报表尾及begin-setup的参数rows,
代码如下:
#define addtlsetup
#include 'Rptstub.lib'
#include '{libpath}tkit_batchstartup.inc'
#include '{libpath}tkit_rptheader.inc'
#include '{libpath}tkit_queappl.inc'
#include '{libpath}tkit_vars_opts.inc'
#include '{libpath}tkit_Sqrfunc.inc'

begin-setup
 Declare-layout batch-land
   rientation=landscape
   left-margin=0
   top-margin=0
   max-lines=60
   max-columns=180
 end-declare
end-setup

!20111220 newly added 无数据使用报表头
begin-heading 5 name=nodataheading
 print 'a列' (1,11)
 print 'b列' (1,20)
 print '─' (+1,2,84) fill
end-heading

!存储过程执行出错报表头
begin-heading 5 name=procerrheading
 print '存储过程错误头' (1,11)
 print '─' (+1,2,84) fill
end-heading

begin-procedure osi-main
 begin-sql
   begin
     osibank.proc_zxytestsqr(#errnbr);;
   end;;
 end-sql
 
 if #errnbr!=0
   !存储过程执行出错,不再继续执行下述子过程,产生错误文件
   alter-report heading=procerrheading
   let $out='存储过程执行出错'||'.LIS'
   new-report $out
   print '错误没产生数据' (+1,0) center
 else
      !存储过程执行正常,执行下述子过程
      do submain
 end-if
end-procedure

!主过程调用其它子过程
begin-procedure submain
 begin-select
count(*) &a_1_rowcount
 from osibank.zxytestsqr z where z.a=1
 end-select
 
 begin-select
count(*) &a_2_rowcount
 from osibank.zxytestsqr z where z.a=2
 end-select
   
 if &a_1_rowcount>0
   do  query_a_1
 else
      !20111220 newly added 无数据启用指定报表头,且使用另外的lis文件
      alter-report  heading=nodataheading
      let $out='无数据表头'||'.LIS'
      new-report $out
      print '查询不到数据' (+1,0) center
      !print #b2  (+1,0) center !在主过程调用子过程产生的变量,用于测试,如写为#b2,结果为0.0,试下#_b2如何
 end-if
 
 if &a_2_rowcount>0
   do  query_a_2(#b2)
   print #b2 (+1,20) center
 else
      !20111220 newly added  
 end-if
end-procedure

!查询a=1
begin-procedure query_a_1
 let $count='变量1'
 let $out1='查询1'||$count||'.LIS'
 new-report $out1
 begin-select
  position (+1)
a &a1
 move &a1 to #a1
 print #a1 (,20,10) edit 9
b &b1
 move &b1 to #b1
 print #b1 (,40,10) edit 9
 from osibank.zxytestsqr z where z.a=1
 end-select
end-procedure


!查询a=2
begin-procedure query_a_2(:#b2)
 let $count='变量2'
 !#debug show $count
 let $out2='查询2'||$count||'.LIS'
 new-report $out2
 begin-select
  position (+1)
a &a2
 move &a2 to #a2
 print #a2 (,60,10) edit 9
b &b2
 move &b2 to #b2
 print #b2 (,80,10) edit 99
 
 !测试添加总记录数及累计a列值
 let #count=#count+1 !输出每页记录总数
 
 let #sum_a=#sum_a+&a2 !输出每页a列累计数
 from osibank.zxytestsqr z where z.a=2
 end-select
 
 move #count to $count 999,999,999
 let $co='总记录数:'||$count
 print $co (+1,2)
 
 move #sum_a to $sum_a 999,999,999
 let $out_a='a列累计值为:'||$sum_a
 print $out_a (,100)
 
 
end-procedure

begin-procedure OSI-Startup   
End-procedure


begin-footing 5 !name=endfooting
 
  !报表尾打印位置要注意,不然可能会出现当前页没打印输出完,就会打印第二页报错,调整position即可
  page-number (+1,20)  '当前页为第' '页,'
  last-page () '共' '页。'
end-footing

上述输出.LIS报表文件如下:
变量2查询2.lis

         a列      b列
 ────────────────────────────────────────────────────────────────────────────────────
                                                           2                   2
                                                           2                   10
                                                           2                   2
 总记录数:          3                                                                             a列累计值为:          6
                                                                                       2.00
                   当前页为第1页,共1页




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-713603/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-713603/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值