SAP ABAP 动态内表的条件查询(SORT / READ TABLE / LOOP)

SAP ABAP 动态内表的条件查询(SORT / READ TABLE / LOOP)

简介: 动态内表是动态报表的核心,动态内表的条件操作能有效解决性能问题。这篇文章用于普及动态内表在 SORT / READ TABLE / LOOP 中使用条件查询。

关键字:SAP ABAP 动态内表 条件查询 SORT / READ TABLE / LOOP

文章目录

  • SAP ABAP 动态内表的条件查询(SORT / READ TABLE / LOOP)
    • 1. 测试结果
    • 2. 完整代码
    • 3. SORT
    • 4. READ TABLE
    • 5. LOOP
    • 其他


1. 测试结果

SAP ABAP 动态内表的条件查询(SORT / READ TABLE / LOOP)_第1张图片

2. 完整代码

下述代码是我记录动态内表操作的其中一个 demo ,其中省去了动态内表的构建而直接引用了一个标准表,这对测试结果无影响。

report ytest_lb001.

data:gt_t001 type table of t001 with header line.

field-symbols: type standard table,
               type any,
                 type any.

constants:cons_bukrs type fieldname value 'BUKRS'.

data:gv_string type string.

start-of-selection.

  "省去动态内表构建
  select * into table gt_t001 from t001 where land1 = 'DE'.
  assign gt_t001[] to .


  write:/ `SORT:` color col_total.
  sort  by (cons_bukrs).
  loop at  assigning .
    assign component 'BUKRS' of structure  to .
    if sy-subrc = 0.
      write:/ .
    endif.
  endloop.

  write:/.

  write:/ `READ TABLE:` color col_total.
  read table  assigning  with key (cons_bukrs) = 'MCA2' binary search."需要前面的 SORT
  if sy-subrc = 0.
    assign component 'BUKRS' of structure  to .
    if sy-subrc = 0.
      write:/ .
    endif.
  endif.

  write:/.

  write:/ `LOOP:` color col_total.
  gv_string = `BUKRS = 'MCA2'`.
  loop at  assigning  where (gv_string).
    assign component 'BUKRS' of structure  to .
    if sy-subrc = 0.
      write:/ .
    endif.
  endloop.

3. SORT

动态内表的 SORT 条件指定,

  sort  by (cons_bukrs).
  loop at  assigning .
    assign component 'BUKRS' of structure  to .
    if sy-subrc = 0.
      write:/ .
    endif.
  endloop.

4. READ TABLE

动态内表的 READ TABLE 条件指定,

  read table  assigning  with key (cons_bukrs) = 'MCA2' binary search."需要前面的 SORT
  if sy-subrc = 0.
    assign component 'BUKRS' of structure  to .
    if sy-subrc = 0.
      write:/ .
    endif.
  endif.

5. LOOP

动态内表的 LOOP 条件指定,

  gv_string = `BUKRS = 'MCA2'`.
  loop at  assigning  where (gv_string).
    assign component 'BUKRS' of structure  to .
    if sy-subrc = 0.
      write:/ .
    endif.
  endloop.

其他

我的微信群、QQ群和其他发布平台。

  • 关于微信群、QQ群和其他发布平台

长期提供开发和运维服务。

  • 关于提供开发和运维服务的详情

你可能感兴趣的:(SAP,ABAP,李斌的分享笔记本,SAP,ABAP,动态内表,条件查询,READ,TABLE,LOOP)