我是abap语言的新手,我正在尝试练习内部连接语句,但我不知道在输出之前我是否能够获得select语句的行数.
这就是我想要达到的目标.
<--------------------------------------- >
<总行数>找到的记录|
Column Header 1|Column Header 2 ..
<data .... retrieve>
<--------------------------------------- >
以下是我的选择声明:
SELECT spfli~carrid scarr~carrname sflight~planetype sflight~fldate sflight~price spfli~cityfrom spfli~cityto
INTO (g_carrid ,g_carrname ,g_planetype,g_fldate ,g_price ,g_cityfrom ,g_cityto) FROM spfli
INNER JOIN sflight
ON spfli~carrid = sflight~carrid AND spfli~connid = sflight~connid
INNER JOIN scarr
ON scarr~carrid = spfli~carrid
WHERE spfli~carrid = s_carrid-low.
WRITE: / g_carrname ,g_planetype,g_fldate ,g_price ,g_cityfrom ,g_cityto.
ENDSELECT.
Run Code Online (Sandbox Code Playgroud)
如果您对如何使用内部表格有任何建议和想法,请给我看一个示例.我真的很想学.谢谢你和上帝保佑.
系统变量SY-DBCNT应该为您提供所选行数,但仅在选择结束后给出.
SELECT-ENDSELECT的替代方法是使用SELECT INTO TABLE一次性选择所有行到内部表中(前提是您没有一次选择太多!).
例如:
data: lt_t000 type table of t000.
select * from t000 into table lt_t000.
Run Code Online (Sandbox Code Playgroud)
这将从该表中选择所有内容,一次进入内部表.因此,您可以做的是声明一个内部表,其中包含当前INTO子句中的所有字段,然后为内部表指定INTO TABLE.
执行SELECT后,SY-DBCNT将包含所选行的数量.
这是一个完整的例子,围绕你问题中的SELECT语句构建,我没有检查它是否合理,所以我希望它有效!
tables: spfli.
select-options: s_carrid for spfli-carrid.
* Definition of the line/structure
data: begin of ls_dat,
carrid type s_carr_id,
carrname type s_carrname,
planetype type s_planetye,
fldate type s_date,
price type s_price,
cityfrom type s_from_cit,
cityto type s_to_city,
end of ls_dat.
* Definition of the table:
data: lt_dat like table of ls_dat.
* Select data
select spfli~carrid scarr~carrname sflight~planetype sflight~fldate sflight~price spfli~cityfrom spfli~cityto
into table lt_dat
from spfli
inner join sflight
on spfli~carrid = sflight~carrid and spfli~connid = sflight~connid
inner join scarr
on scarr~carrid = spfli~carrid
where spfli~carrid = s_carrid-low.
* Output data
write: 'Total records selected', sy-dbcnt.
loop at lt_dat into ls_dat.
write: / ls_dat-carrid, ls_dat-carrname, ls_dat-planetype, ls_dat-fldate, ls_dat-price, ls_dat-cityfrom, ls_dat-cityto.
endloop.
Run Code Online (Sandbox Code Playgroud)
注意:报告(类型1)程序仍然支持使用标题行声明内部表格以实现向后兼容性的概念,但不鼓励这样做!希望它有效!