【IT168 技术文章】
ABAP动态查询的实现:可以完全实现动态查询,每个字段都可以动态。
(1) 利用宏
(2) 利用abap指针
(3) 利用FIELD-SYMBOL
具体实现:
1.结构的动态查询
DEFINE Select_DATA_TO_WA.
Select &1
FROM &2
INTO CORRESPONDING FIELDS OF &3
Where (&4).
EXIT.
ENDSelect.
END-OF-DEFINITION.
2.变量的动态查询
DEFINE Select_DATA_TO_VARIANT.
Select &1
FROM &2
INTO &3
Where (&4).
EXIT.
ENDSelect.
END-OF-DEFINITION.
3.内表的动态查询
DEFINE Select_DATA_TO_VARIANT.
Select &1
FROM &2
INTO CORRESPONDING FIELDS OF TABLE &3
Where (&4).
EXIT.
ENDSelect.
END-OF-DEFINITION.
具体程序实现:
DATA: L_FIELD(100) TYPE C,
L_TABLE(10) TYPE C,
L_COND(100) TYPE C.
DATA: I_COND TYPE TALBE OF L_COND.
FIELD-SYMBOLS TYPE ANY.
START-OF-Selection.
CONCATENATE‘CARRID’‘CONNID’‘CITYFROM’
INTO L_S SEPARATE BY SPACE.
CONCATENATE‘CONNID =‘‘’‘0123’‘’’’INTO L_COND.
APPEND COND TO I_COND.
L_TABLE =‘SPFLI’.
IF IS ASSIGNED.
UNASSIGN .
ASSIGN SPFLI TO .
ELSE.
ASSIGN SPFLI TO .
ENDIF.
Select_DATA_TO_WA (L_S) (L_TABLE) I_COND.