Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Syntax for table

Former Member
0 Kudos

Hi All,

One simple question maybe.

In my selection screen i am getting input as one of the standard table say 'SE11'.

Now in my code i want to make a standard table or internal type/like the input given table name, in this case "SE11".

Is this possible? If yes can you give a hint on the code.

Regds,

Shashank

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Yes it is you need to use réferences and field symbols.

Here is a sample code that select all data of a given table and print it.

PARAMETERS: p_tab TYPE tabname16.

DATA: ls_tab TYPE REF TO data.
  FIELD-SYMBOLS: <ft> TYPE ANY TABLE,
                 <fs> TYPE ANY.

  TRY.
" Create the internal table 
      CREATE DATA ls_tab TYPE TABLE OF (p_tab).
" To access the reference data you need to assign it to a field symbol
      ASSIGN ls_tab->* TO <ft>.                                
      IF sy-subrc NE 0.
        MESSAGE 'Error' TYPE 'E'.
      ENDIF.
" 
      SELECT * FROM (p_tab) INTO TABLE <ft>.

      LOOP AT <ft> ASSIGNING <fs>.
        WRITE : / <fs>.
      ENDLOOP.
    CATCH cx_root.
      MESSAGE 'Error' TYPE 'E'.
  ENDTRY.

Hope it helps

Regards

1 REPLY 1

Former Member
0 Kudos

Hi

Yes it is you need to use réferences and field symbols.

Here is a sample code that select all data of a given table and print it.

PARAMETERS: p_tab TYPE tabname16.

DATA: ls_tab TYPE REF TO data.
  FIELD-SYMBOLS: <ft> TYPE ANY TABLE,
                 <fs> TYPE ANY.

  TRY.
" Create the internal table 
      CREATE DATA ls_tab TYPE TABLE OF (p_tab).
" To access the reference data you need to assign it to a field symbol
      ASSIGN ls_tab->* TO <ft>.                                
      IF sy-subrc NE 0.
        MESSAGE 'Error' TYPE 'E'.
      ENDIF.
" 
      SELECT * FROM (p_tab) INTO TABLE <ft>.

      LOOP AT <ft> ASSIGNING <fs>.
        WRITE : / <fs>.
      ENDLOOP.
    CATCH cx_root.
      MESSAGE 'Error' TYPE 'E'.
  ENDTRY.

Hope it helps

Regards