ABAP动态取得数据

动态取得数据的方法

 

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.

 

 

具体程序实现:

 

Code

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 <fs> 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 <fs> IS ASSIGNED.

  UNASSIGN  <fs> .

  ASSIGN SPFLI TO <fs>.

ELSE.

ASSIGN SPFLI TO <fs>.

ENDIF.

 

SELECT_DATA_TO_WA (L_S) (L_TABLE) <fs> I_COND.

 

你可能感兴趣的:(abap)