‎2020 Feb 05 1:22 PM
I recently came across the requirement to copy certain items of an internal table, inline declared in an select statement, to another.
First I thought I might use the FILTER statement. Turns out I can't find a syntax to inline declare the table in a way filtering can be used (only SORTED or HASHED tables).
Ok so next try: FOR iteration. Resulting in:
No type can be derived from the context for the operator "VALUE".
First I thought its related to the inline declaration within the select statement for lt_workcenter.
Turns out its not. More likely its because the FOR iteration does not provide a proper typing like WITH EMPTY KEY at least not in ABAP 750?
Or am I missing something here?
Example:
SELECT crhd~objty,
crhd~objid,
crhd~arbpl,
crhd~werks,
crtx~ktext
INTO TABLE @DATA(lt_workcenter)
FROM crhd LEFT OUTER JOIN crtx ON crhd~objty = crtx~objty
AND crhd~objid = crtx~objid
WHERE crhd~werks IN @mr_werks
AND crhd~matyp = '0004'
AND crtx~spras = @sy-langu.
DATA(lt_workcenter_nodesc) = VALUE #( FOR <fs> IN lt_workcenter WHERE ( ktext = '' ) ( fs> ) ).
‎2020 Feb 05 2:30 PM
The issue is with DATA(lt_workcenter_nodesc) = VALUE #(...):
# means that the compiler has to deduce the type for lt_workcenter_nodesc, and this is never possible if the target type is an internal table, because it could be standard, sorted or hashed, and the key is not defined too.
Solution: you must explicitly define the type:
SELECT ... INTO TABLE @DATA(lt_workcenter) ...
TYPES tt_workcenter LIKE lt_workcenter.
DATA(lt_workcenter_nodesc) = VALUE tt_workcenter( ... ).