Tuesday, 4 April 2023

Generic and dynamic table select query

    DATA: TAB_NAME TYPE STRING.

   DATA: R_TABLE TYPE REF TO DATA.

   FIELD-SYMBOLS: <TAB> TYPE STANDARD TABLE.

   FIELD-SYMBOLS:  <WA_TAB> TYPE DATA.


" some code to know the table name based on import parameters


   CREATE DATA R_TABLE TYPE TABLE OF (TAB_NAME).

   ASSIGN R_TABLE->* TO <TAB>.


   CREATE DATA R_TABLE LIKE LINE OF <TAB>.

   ASSIGN R_TABLE->* TO <WA_TAB>.


   SELECT * FROM (TAB_NAME) INTO TABLE <TAB>.

No comments:

Post a Comment