sap abap中动态指定查询条件
生活随笔
收集整理的這篇文章主要介紹了
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. 這種方法適用于內表,也適用于數據庫表,注意動態條件一定要用()括起來,不然編譯會通不過。
"
"單據狀態過濾條件,將沒有選擇的狀態包函在其中,然后統一刪除。
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. 這種方法適用于內表,也適用于數據庫表,注意動態條件一定要用()括起來,不然編譯會通不過。
總結
以上是生活随笔為你收集整理的sap abap中动态指定查询条件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP SD销售收入科目确定VKOA
- 下一篇: Linq to sql 实现多条件的动态