sap abap中动态指定查询条件

有时候,我们事先并不知道where 后面要跟什么东西,只有在运行中才能确定,这就有点象其它语言中拼凑sql语句一样,abap也是支持的,用起来也很方便。
 
data:c_cond(100) type c.
"
"单据状态过滤条件,将没有选择的状态包函在其中,然后统一删除。
data:begin of li_conds OCCURS 0,
     cond like c_cond,
    end of li_conds.

"回完状态
    if p_st1 <> 'X'.
      CONCATENATE ' STATUS = ''' c_status01 '''' into c_cond .
      append c_cond to li_conds.
      clear c_cond.
    endif.
    "末审状态
    if p_st2 <> 'X'.
      if li_conds[] is initial.
        CONCATENATE ' STATUS = ''' c_status02 '''' into c_cond .
       else.
         CONCATENATE ' or STATUS = ''' c_status02 '''' into c_cond .
      endif.
      append c_cond to li_conds.
      clear c_cond.
    endif.
    "已审状态
    if p_st3 <> 'X'.
      if li_conds[] is initial.
        CONCATENATE ' STATUS = ''' c_status03 '''' into c_cond .
      else.
        CONCATENATE ' or STATUS = ''' c_status03 '''' into c_cond .
      endif.
      append c_cond to li_conds.
      clear c_cond.
    endif.
    "已删状态
    if p_st4 <> 'X'.
      if li_conds[] is initial.
        CONCATENATE ' STATUS = ''' c_status04 '''' into c_cond .
      else.
        CONCATENATE ' or STATUS = ''' c_status04 '''' into c_cond .
      endif.
      append c_cond to li_conds.
      clear c_cond.
    endif.
    "单据状态过滤条件,将没有选择的状态包函在其中,然后统一删除
    if li_conds[] is not initial.
      delete list1 where (li_conds) .
      delete gt_items where (li_conds).
      clear:li_conds[].
    endif.
这种方法适用于内表,也适用于数据库表,注意动态条件一定要用()括起来,不然编译会通不过。

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

转载于:http://blog.itpub.net/23353800/viewspace-733911/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值