Select语句中Where语句动态实现的小例子

REPORT  Z_WUWEI_0016.

TABLES: TSTC.
DATA:WHERE_TAB(80) OCCURS 10 WITH HEADER LINE,
     COUNT_REC TYPE I.

SELECT-OPTIONS: S_TRX FOR TSTC-TCODE NO INTERVALS OBLIGATORY DEFAULT 'VA01'.


MOVE 'TCODE IN S_TRX' TO WHERE_TAB.
APPEND WHERE_TAB.

CONCATENATE 'AND TCODE LIKE' '''V%''' INTO WHERE_TAB SEPARATED BY SPACE.  // V% 外面加3个单引号
APPEND WHERE_TAB.

CLEAR WHERE_TAB.

SELECT COUNT( * ) INTO COUNT_REC FROM TSTC
WHERE (WHERE_TAB).

WRITE: COUNT_REC.



你可能感兴趣的:(ABAP)