06-05-2022 10:39 PM
Hi,
The following is a snippet of programming albeit from a very old SAP tutorial. This gives runtime error. Is dynamic assignment of table name not allowed ? Is this obsolete now. Just curious. Thanks
TABLES: SPFLI, SFLIGHT.
DATA: BEGIN OF WA,
LINE(100),
END OF WA.
PARAMETERS: TABNAME(10) DEFAULT 'SPFLI'.
SELECT * FROM (TABNAME) INTO WA.
WRITE: / WA-LINE.
ENDSELECT.
IF SY-SUBRC NE 0.
WRITE: / TEXT-001.
ENDIF.
06-06-2022 8:48 AM
SELECT ... FROM (tabname) is not obsolete as you can find in the ABAP documentation.
Maybe the code was working in Non-Unicode SAP systems, but anyway the code in this tutorial (?) should have WA correspond to the structure of the table. You can find lots of working examples in the forum and in the ABAP documentation.
06-14-2022 1:39 PM
06-14-2022 1:46 PM
You can try this way:
DATA: dref TYPE REF TO data,
tabname TYPE tabname.
FIELD-SYMBOLS: <row> TYPE any,
<component> TYPE any.
PARAMETERS: P_TABNAME(10) DEFAULT 'SPFLI'.
START-OF-SELECTION.
tabname = p_tabname.
* dynamically create appropriate Data Structure
CREATE DATA dref TYPE (tabname).
ASSIGN dref->* TO <row>.
* fetch the data
SELECT *
FROM (tabname) UP TO 2 ROWS
INTO <row>.
* display the result
NEW-LINE.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <row> TO <component>.
IF sy-subrc <> 0.
EXIT. " no more components
ENDIF.
WRITE: <component>.
ENDDO.
ENDSELECT.
06-14-2022 2:32 PM
06-14-2022 3:23 PM
What would be most helpful is if you would give some details on what the error message is.
Or is it a secret?