Saturday, April 3, 2010

Create Dynamic Select in ABAP/4

In the example, i want to select data from table VBAK by created date as '20050105'. In the selected fields, i will choose them and append those fields into internal table 'it_fldtab'.
Example
TABLES: VBAK.
DATA: it_vbak TYPE TABLE OF vbak WITH HEADER LINE,
wa_fld(72) TYPE C,
it_fldtab LIKE TABLE OF wa_fld.
wa_fld = 'VBELN'.
APPEND wa_fld TO it_fldtab.
wa_fld = 'VBTYP'.
APPEND wa_fld TO it_fldtab.
wa_fld = 'AUDAT'.
APPEND wa_fld TO it_fldtab.
SELECT (it_fldtab) INTO CORRESPONDING FIELDS OF TABLE it_vbak
FROM VBAK
WHERE ERDAT = '20050105'.
IF SY-SUBRC = 0.
LOOP AT it_vbak.
write:/ it_vbak-vbeln,
it_vbak-vbtyp,
it_vbak-audat.
ENDLOOP.
ENDIF.

No comments:

Post a Comment