Using components of unknown table
I have a form where I work with an unknown table. What I know is, that every table that is given to the function has i.e. the component PERNR. I want to do some things with these components (sorting the table, putting into another table etc.) but whether I use field symbols or data references I get the error that it has no structure (which is right).
For more specific information:
My tables are P2001 - P2012 (which is nice to work with, hence the numbers).
I want to pass a specific table of these to the form, but the form should treat them all the same (only in some special cases where I use a case on the string which contains the table).
If you have a solution please help me. I read most of the stuff about field symbols and data references so a short answer would help too.
Thanks in advance, Christopher
you can try like this -
PARAMETERS: dbtab TYPE c LENGTH 10, rows TYPE i DEFAULT 100. DATA dref TYPE REF TO data. FIELD-SYMBOLS: TYPE ANY TABLE, <wa> TYPE ANY, TYPE ANY. TRY. CREATE DATA dref TYPE STANDARD TABLE OF (dbtab) WITH NON-UNIQUE DEFAULT KEY. ASSIGN dref->* TO . SELECT * FROM (dbtab) UP TO rows ROWS INTO TABLE . LOOP AT ASSIGNING <wa>. DO. ASSIGN COMPONENT sy-index OF STRUCTURE <wa> TO . IF sy-subrc = 0. WRITE / . ELSE. EXIT. ENDIF. ENDDO. ULINE. ENDLOOP. CATCH cx_sy_create_data_error. WRITE 'Wrong Database!'. ENDTRY.
Hope it helps.