Sunday, March 13, 2011

DYNAMIC Open SQL statement

Just this morning I have created a dynamic sql. I have a sample code below:


REPORT  ZTST_DYN_SQL.

TABLES: zfli_dev.

DATA: v_flds TYPE string.
DATA: v_tabname(8TYPE c.
DATA: v_where_stmnt TYPE string.
DATA: it_zfli_dev TYPE STANDARD TABLE OF zfli_dev.
DATA: wa_zfli_dev TYPE zfli_dev.

v_flds = 'DEVID name'.
v_tabname = 'ZFLI_DEV'.
v_where_stmnt = 'devid = 4 or devid = 11'.

FIELD-SYMBOLS: <my_tab> type STANDARD TABLE,
               <wa_tab> like LINE OF it_zfli_dev.

ASSIGN it_zfli_dev TO <my_tab>.


SELECT (v_flds) FROM (v_tabname)
  INTO CORRESPONDING FIELDS OF TABLE <my_tab>
  WHERE (v_where_stmnt).

  LOOP AT <my_tab> ASSIGNING <wa_tab>.

    write /: <wa_tab>-devid.
    write: <wa_tab>-NAME.

  ENDLOOP.


Now, you got the picture! Happy coding!

No comments:

Post a Comment