ABAP 动态内表 read table

这个程序展示了 如何动态内表的时候read 操作 loop 的时候 where条件的拼接

REPORT ztest_xy6.
DATA: BEGIN OF lt_tmp OCCURS 10,
        hkont    TYPE char10,
        sumty(2) TYPE c,
      END OF lt_tmp.
DATA: ls_tmp LIKE lt_tmp,
      ls_tp2 LIKE lt_tmp.
FIELD-SYMBOLS:  TYPE x.
DEFINE m_tmp.
  clear lt_tmp.
  lt_tmp-hkont = &1.
  lt_tmp-sumty = &2.
  append lt_tmp.
END-OF-DEFINITION.
m_tmp '0090020020' '22'.
m_tmp '0090020020' '21'.
m_tmp '0090010010' 'C1'.
m_tmp '0020110100' 'C1'.

ASSIGN: ls_tmp TO  CASTING.
ls_tmp-hkont = '0090020020'. ls_tmp-sumty = '22'.
DATA gt_where TYPE TABLE OF string.
gt_where = VALUE #(
*                    ( |with key| )
                    ( | HKONT = '0090020020'  AND| )
                    ( | SUMTY = '21'| ) ).


DATA:gv_where TYPE string.
gv_where = |Hello | & |world| .
WRITE:/ gv_where.
READ TABLE lt_tmp WITH KEY .
IF sy-subrc = 0.
  WRITE: / lt_tmp-hkont,lt_tmp-sumty.
ENDIF.


LOOP AT lt_tmp WHERE (gt_where).
  WRITE: / lt_tmp-hkont,lt_tmp-sumty.
ENDLOOP.

你可能感兴趣的:(abap)