时间:2021-07-01 10:21:17 帮助过:2人阅读
例子:
DATA:GT_ITAB TYPE STANDARD TABLE OF SFLIGHT. DATA:GS_ITAB LIKE LINE OF GT_ITAB. DATA:GS_LINE TYPE C LENGTH 72."最多恶意容纳72位CHAR类型 DATA:GT_LIST LIKE TABLE OF GS_LINE(72). GS_LINE = ‘CARRID CONNID‘. SELECT DISTINCT (GS_LINE) INTO CORRESPONDING FIELDS OF TABLE GT_ITAB FROM SFLIGHT. IF SY-SUBRC = 0. LOOP AT GT_ITAB INTO GS_ITAB. WRITE:/ GS_ITAB-CARRID,GS_ITAB-CONNID. ENDLOOP. ENDIF.
动态指定SELECT语句的WHERE条件
可以动态地写SELECT语句的WHERE条件。下列语句中的itab可以定义成最大为72位的内表。
SELECT...WHERE(<itab>)
例子1:
DATA GS_WHERE TYPE C LENGTH 72. DATA GV_CARRNAME TYPE SCARR-CARRNAME. DATA GV_CARRID TYPE SCARR-CARRID VALUE ‘AC‘. CONCATENATE ‘CARRID = ‘‘‘GV_CARRID‘‘‘‘ INTO GS_WHERE. SELECT SINGLE CARRNAME INTO GV_CARRNAME FROM SCARR WHERE (GS_WHERE). WRITE:/ GV_CARRNAME.
结果:
是在数据库表SCARR中读取字段值CARRID等于AC的SELECT语句,在这里动态的给出了WHERE条件。
当需要给出两个字段以上查询条件时要把查询条件追加到内表中使用,如以下例子。
例子2:
结果:
ABAP 动态SQL语句
标签:tin alt class end tab table new name inf