When reading data into an internal table using the Select command, I get the error:
An internal table is not allowed as a workarea
I do not understand the cause. I have attached the ABAP source code. What am I doing wrong?
the error happens at the following position: SELECT SINGLE * FROM (lv_infotype-infotype) INTO CORRESPONDING FIELDS OF lt_itab
infotypes: 0007, 0008, 0009, 0010, 0013, 0014, 0015, 0016, 0699.
tables: pernr, pa0007, pa0008, pa0009, pa0010, pa0013, pa0014, pa0015, pa0016, pa0699.
types: BEGIN OF ty_itab,
pernr type pernr-mstbr, "Personalnummer
infotype(6) type c,
begda type p0008-begda,
endda type p0008-endda,
UNAME type p0008-uname,
END OF ty_itab.
Data: lt_itab TYPE STANDARD TABLE OF ty_itab.
TYPES: BEGIN OF ty_infotypes,
infotype(6) TYPE c,
END OF ty_infotypes.
DATA: c_infotypes TYPE STANDARD TABLE OF ty_infotypes INITIAL SIZE 0,
lv_infotype TYPE ty_infotypes.
APPEND VALUE #( infotype = 'PA0007' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0008' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0009' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0010' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0013' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0014' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0015' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0016' ) TO c_infotypes.
APPEND VALUE #( infotype = 'PA0699' ) TO c_infotypes.
GET pernr.
LOOP AT c_infotypes INTO lv_infotype.
SELECT SINGLE * FROM (lv_infotype-infotype) INTO CORRESPONDING FIELDS OF lt_itab <=ERROR!
WHERE sprps = 'X' AND pernr = pernr-pernr.
IF sy-subrc = 0.
WRITE: / pernr-pernr, lv_infotype-infotype.
ENDIF.
ENDLOOP.
...
A SELECT SINGLE *
only returns a single row. What the syntax check is trying to tell you is that you don't need a whole table to store the result. You only need a structure. If you want the result in a table with one line for some reason, don't use SELECT SINGLE *
. Use a regular SELECT *
. And if you want to make sure you never get more than one line, you can use the addition UP TO 1 ROWS
.
However, in this particular example it appears that you want the data for all the different infotypes in one internal table. You don't want your SELECT
to overwrite the results of the previous loop iteration, you want it to append the result to those you already have. In that case you should not use INTO CORRESPONDING FIELDS OF TABLE
but APPENDING CORRESPONDING FIELDS OF TABLE
. This mode works just fine with SELECT SINGLE
and allows you to use it with an internal table instead of a structure (because appending to a structure would make even less sense).