[英]read from internal table with loop and no results
In the below code, I read data from database table with SELECT
into the internal table dresult
.在下面的代码中,我使用SELECT
从数据库表中读取数据到内部表dresult
。
Reading the first line of the internal table displays the expected result, but using the LOOP
displays nothing.读取内部表的第一行显示了预期的结果,但使用LOOP
没有显示任何内容。
What's the issue?有什么问题?
Note: I tried to remove ENDSELECT
and it worked.注意:我尝试删除ENDSELECT
并且它起作用了。 Why?为什么?
REPORT ZTEST02.
"Detail Informaion
TYPES : BEGIN OF details,
d1 type arktx, " description
d2 type lfimg, "quantity
END OF details.
DATA : dresult TYPE TABLE OF details WITH HEADER LINE,
t_dresult TYPE details,
sdno TYPE vbeln.
PARAMETERS packo TYPE vbeln OBLIGATORY MATCHCODE OBJECT f4_likp.
START-OF-SELECTION.
SELECT arktx,lfimg
INTO @dresult
FROM lips as detail
LEFT JOIN marm as material
ON detail~matnr = material~matnr
LEFT OUTER JOIN vbak
ON detail~vgbel = vbak~vbeln
WHERE detail~vbeln = @packo.
ENDSELECT.
READ TABLE dresult into t_dresult INDEX 1.
write: t_dresult-d1,t_dresult-d2.
LOOP AT dresult INTO t_dresult.
write: t_dresult-d1,t_dresult-d2.
ENDLOOP.
With SELECT ... ENDSELECT
you select the data into a work area ( INTO @dresult
- which is actually the header line of the internal table with the same name).使用SELECT ... ENDSELECT
将数据选择到工作区( INTO @dresult
- 实际上是同名内部表的标题行)。 As result the internal table dresult
does not contain any data, so the LOOP
and the READ TABLE
won't work.结果内部表dresult
不包含任何数据,因此LOOP
和READ TABLE
将不起作用。
I would declare the internal table without HEADER LINE
and remove ENDSELECT
:我会声明没有HEADER LINE
的内部表并删除ENDSELECT
:
DATA: dresult type STANDARD TABLE OF details,
...
SELECT ...
INTO TABLE @dresult
Moreover, after READ TABLE
, it is always good to check if an entry was found:此外,在READ TABLE
,检查是否找到条目总是好的:
READ TABLE ...
IF sy-subrc EQ 0.
...
ENDIF.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.