Application Development and Automation 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: 
Read only

dynamic assignment - runtime error.

jyothsna1234
Explorer
0 Likes
1,265

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.

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
1,173

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.

Read only

Rajasekhar_Dina
Participant
0 Likes
1,173

Hello,

You can refer the demo program DEMO_SELECT_INTO_NEW_VARIANTS which demonstrates how the NEW addition is used in different variants of the INTO clause.

Read only

Rajasekhar_Dina
Participant
0 Likes
1,173

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,173
Check online or F1 help
Read only

matt
Active Contributor
0 Likes
1,173

What would be most helpful is if you would give some details on what the error message is.

Or is it a secret?