"动态where条件
DATA WHERE_TAB(80) OCCURS 0 WITH HEADER LINE.
IF P_NOPUSH IS NOT INITIAL.
* WHERE_TAB = 'A~FRGRL NE '''' AND B~LOEKZ NE ''S'' OR B~LOEKZ NE ''L'' AND B~ELIKZ NE ''X'''.
* APPEND where_tab.
WHERE_TAB = 'EKKO~FRGRL NE '''''.
APPEND WHERE_TAB.
WHERE_TAB = 'AND EKPO~LOEKZ NE ''S'''.
APPEND WHERE_TAB.
WHERE_TAB = 'OR EKPO~LOEKZ NE ''L'''.
APPEND WHERE_TAB.
WHERE_TAB = 'AND EKPO~ELIKZ NE ''X'''.
APPEND WHERE_TAB.
CLEAR WHERE_TAB.
ENDIF.
"采购订单
SELECT
*
FROM EKKO AS A
INNER JOIN EKPO AS B ON A~EBELN = B~EBELN
INNER JOIN EKET AS C ON B~EBELN = C~EBELN
INTO CORRESPONDING FIELDS OF TABLE @GT_TAB_TEMP
WHERE B~WERKS IN @S_WERKS
AND A~LIFNR IN @S_LIFNR
AND A~EKGRP IN @S_EKGRP
AND A~EBELN IN @S_EBELN
AND A~BSART IN @S_BSART
AND B~PSTYP IN @S_PSTYP
AND B~MATNR IN @S_MATNR
AND C~EINDT IN @S_EINDT
AND A~AEDAT IN @S_AEDAT
AND A~ERNAM IN @S_ERNAM
AND B~LOEKZ IN @S_LOEKZ
AND (WHERE_TAB)
.
WHERE_TAB = ‘A~FRGRL NE ‘’’’ AND B~LOEKZ NE ‘‘S’’ OR B~LOEKZ NE ‘‘L’’
AND B~ELIKZ NE ‘‘X’’’. 转义字符为’ 比如WHERE_TAB = ‘B~LOEKZ NE ‘‘S’’’
其中’B~LOEKZ NE ‘‘S’’’ 就是 ’ B~LOEKZ NE ’ ‘s’ ’ ’
需要注意的点:
1、单引号的转义,如上
2、动态条件一定要用()括起来,不然编译会通不过。
3、一定要APPEND。 (APPEND WHERE_TAB)