ABAP--如何在join查询中使用动态表名(其实这样是没有必要的)

最近有人问如何写在join查询中使用动态表名的方法,现在我给出一个样例,供大家参考:

REPORT demo_class_counter_event.

DATA: BEGIN OF wa,
        carrid TYPE spfli-carrid,
        connid TYPE spfli-connid,
        fldate TYPE sflight-fldate,
        bookid TYPE sbook-bookid,
      END OF wa,
      itab LIKE SORTED TABLE OF wa
                WITH UNIQUE KEY carrid connid fldate bookid.

DATA name(300) TYPE c VALUE 'spfli AS p '&
      ' INNER JOIN sflight AS f ' &
      ' ON p~carrid = f~carrid AND p~connid = f~connid '&
      ' INNER JOIN sbook   AS b '&
      ' ON b~carrid = f~carrid AND b~connid = f~connid AND b~fldate = f~fldate '.

SELECT  p~carrid p~connid f~fldate b~bookid
  INTO  CORRESPONDING FIELDS OF TABLE itab
  FROM  (name)
  WHERE p~cityfrom = 'FRANKFURT' AND
        p~cityto   = 'NEW YORK'  AND
        f~seatsmax > f~seatsocc.

LOOP AT itab INTO wa.
  AT NEW fldate.
    WRITE: / wa-carrid, wa-connid, wa-fldate.
  ENDAT.
  WRITE / wa-bookid.
ENDLOOP. 

posted on 2007-06-14 16:55  毛小娃  阅读(199)  评论(0编辑  收藏  举报

导航