如何获取abap中内表的行数?

发布于 2024-07-11 00:52:29 字数 89 浏览 4 评论 0原文

如何获取内表的行数? 我想我可以循环播放它。 但必须有一个更明智的方法。

我不知道这是否有什么不同,但代码应该在 4.6c 版本上运行。

How do I get the row count of an internal table? I guess that I can loop on it. But there must be a saner way.

I don't know if it makes a difference but the code should run on 4.6c version.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

萌无敌 2024-07-18 00:52:29

还有一个用于此任务的内置函数:

variable = lines( itab_name ).

就像 IronGoofy 描述的“纯”ABAP 语法一样,该函数“lines( )”将表itab_name 的行数写入变量。

There is also a built-in function for this task:

variable = lines( itab_name ).

Just like the "pure" ABAP syntax described by IronGoofy, the function "lines( )" writes the number of lines of table itab_name into the variable.

辞取 2024-07-18 00:52:29

您可以使用以下函数:

 DESCRIBE TABLE <itab-Name> LINES <variable>

调用后,变量包含内表的行数。

You can use the following function:

 DESCRIBE TABLE <itab-Name> LINES <variable>

After the call, variable contains the number of rows of the internal table .

乖乖公主 2024-07-18 00:52:29

除了推荐的之外,

DESCRIBE TABLE <itab-Name> LINES <variable>

还有系统变量SY-TFILL

来自文档:

在DESCRIBE TABLE、LOOP AT和READ TABLE语句之后,访问内表的行数。

示例脚本:

REPORT ytest.

DATA pf_exclude TYPE TABLE OF sy-ucomm WITH HEADER LINE.

START-OF-SELECTION.
  APPEND '1' TO pf_exclude.
  APPEND '2' TO pf_exclude.
  APPEND '3' TO pf_exclude.
  APPEND '4' TO pf_exclude.

  WRITE: / 'sy-tfill = ', sy-tfill.

  DESCRIBE TABLE pf_exclude.
  WRITE: / 'sy-tfill = ', sy-tfill, 'after describe table'.

  sy-tfill = 0. "Reset
  READ TABLE pf_exclude INDEX 1 TRANSPORTING NO FIELDS.
  WRITE: / 'sy-tfill = ', sy-tfill, 'after read table'.


  sy-tfill = 0. "Reset
  LOOP AT pf_exclude.
    WRITE: / 'sy-tfill = ', sy-tfill, 'in loop with', pf_exclude.
    sy-tfill = 0. "Reset
  ENDLOOP.

结果:

sy-tfill =           0
sy-tfill =           4  after describe tabl
sy-tfill =           4  after read table
sy-tfill =           4  in loop with 1
sy-tfill =           0  in loop with 2
sy-tfill =           0  in loop with 3
sy-tfill =           0  in loop with 4

请注意第二个条目的值 0:SY-TFILL 不会在每个步骤中更新,仅在第一个循环之后更新。

我建议仅使用 SY-TFILL,如果您在 READ 后直接需要它(1)...如果在 READ 和使用 SY 之间还有其他命令-TFILL,总是存在系统变量改变的危险。

(1) 或描述表。

Beside the recommended

DESCRIBE TABLE <itab-Name> LINES <variable>

there is also the system variable SY-TFILL.

From documentation:

After the statements DESCRIBE TABLE, LOOP AT and READ TABLE, the number of rows of the accessed internal table.

Example script:

REPORT ytest.

DATA pf_exclude TYPE TABLE OF sy-ucomm WITH HEADER LINE.

START-OF-SELECTION.
  APPEND '1' TO pf_exclude.
  APPEND '2' TO pf_exclude.
  APPEND '3' TO pf_exclude.
  APPEND '4' TO pf_exclude.

  WRITE: / 'sy-tfill = ', sy-tfill.

  DESCRIBE TABLE pf_exclude.
  WRITE: / 'sy-tfill = ', sy-tfill, 'after describe table'.

  sy-tfill = 0. "Reset
  READ TABLE pf_exclude INDEX 1 TRANSPORTING NO FIELDS.
  WRITE: / 'sy-tfill = ', sy-tfill, 'after read table'.


  sy-tfill = 0. "Reset
  LOOP AT pf_exclude.
    WRITE: / 'sy-tfill = ', sy-tfill, 'in loop with', pf_exclude.
    sy-tfill = 0. "Reset
  ENDLOOP.

The result:

sy-tfill =           0
sy-tfill =           4  after describe tabl
sy-tfill =           4  after read table
sy-tfill =           4  in loop with 1
sy-tfill =           0  in loop with 2
sy-tfill =           0  in loop with 3
sy-tfill =           0  in loop with 4

Please get attention of the value 0 for the 2nd entry: SY-TFILL is not updated with each step, only after the first loop.

I recommend the usage SY-TFILL only, if you need it direct after the READ(1)... If there are other commands between the READ and the usage of SY-TFILL, there is always the danger of a change of the system variable.

(1) or describe table.

情泪▽动烟 2024-07-18 00:52:29
  DATA : V_LINES TYPE I. "declare variable
  DESCRIBE TABLE <ITAB> LINES V_LINES. "get no of rows
  WRITE:/ V_LINES. "display no of rows

参考文献:
http://www.sapnuts.com/courses/core -abap/internal-table-work-area.html

  DATA : V_LINES TYPE I. "declare variable
  DESCRIBE TABLE <ITAB> LINES V_LINES. "get no of rows
  WRITE:/ V_LINES. "display no of rows

Refreance:
http://www.sapnuts.com/courses/core-abap/internal-table-work-area.html

梦里南柯 2024-07-18 00:52:29

功能模块 EM_GET_NUMBER_OF_ENTRIES 还将提供行计数。 它需要 1 个参数 - 表名称。

The functional module EM_GET_NUMBER_OF_ENTRIES will also provide the row count. It takes 1 parameter - the table name.

花开柳相依 2024-07-18 00:52:29

您还可以使用 OPEN Sql 使用 COUNT 分组子句查找行数,并且还有系统字段 SY-LINCT 来计算表的行数 (ROWS)。

you can also use OPEN Sql to find the number of rows using the COUNT Grouping clause and also there is system field SY-LINCT to count the lines(ROWS) of your table.

生死何惧 2024-07-18 00:52:29

如果我正确理解你的问题,你想知道内部表的条件循环期间的行号。
如果您使用内部表,则可以使用系统变量 sy-tabix。 如果您需要更多信息,请参阅 ABAP 文档(尤其是有关 内部表处理)。

例子:

LOOP AT itab INTO workarea
        WHERE tablefield = value.

     WRITE: 'This is row number ', sy-tabix.

ENDLOOP.

if I understand your question correctly, you want to know the row number during a conditional loop over an internal table.
You can use the system variable sy-tabix if you work with internal tables. Please refer to the ABAP documentation if you need more information (especially the chapter on internal table processing).

Example:

LOOP AT itab INTO workarea
        WHERE tablefield = value.

     WRITE: 'This is row number ', sy-tabix.

ENDLOOP.
猫弦 2024-07-18 00:52:29
data: vcnt(4).

clear vcnt.

LOOP at itab WHERE value = '1'.
  add 1 to vcnt.
ENDLOOP.

答案将是 3。 (vcnt = 3)。

data: vcnt(4).

clear vcnt.

LOOP at itab WHERE value = '1'.
  add 1 to vcnt.
ENDLOOP.

The answer will be 3. (vcnt = 3).

鱼忆七猫命九 2024-07-18 00:52:29

我认为没有 SAP 参数可以实现这种结果。 尽管下面的代码可以实现。

LOOP AT intTab.

  AT END OF value.

    result = sy-tabix.

    write result.  

  ENDAT.

ENDLOOP.

I don't think there is a SAP parameter for that kind of result. Though the code below will deliver.

LOOP AT intTab.

  AT END OF value.

    result = sy-tabix.

    write result.  

  ENDAT.

ENDLOOP.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文