有时候,我们事先并不知道where 后面要跟什么东西,只有在运行中才能确定,这就有点象其它语言中拼凑sql语句一样,abap也是支持的,用起来也很方便。
data:c_cond(100) type c.
"
"单据状态过滤条件,将没有选择的状态包函在其中,然后统一删除。
data:begin of li_conds OCCURS 0,
cond like c_cond,
end of li_conds.
"
"单据状态过滤条件,将没有选择的状态包函在其中,然后统一删除。
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_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_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 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.
if li_conds[] is not initial.
delete list1 where (li_conds) .
delete gt_items where (li_conds).
clear:li_conds[].
endif.
这种方法适用于内表,也适用于数据库表,注意动态条件一定要用()括起来,不然编译会通不过。