内表练习题

定义工作区和TYPES

*根据SFLIGH(航班)表,查询航线编号CARRID为‘LH’都有哪些航班,
在屏幕上输出航班编号CONNID、航班日期FLDATE、票价PRICE、飞机类型PLANETYPE、币种CURRENCY

TYPES:BEGIN OF ty_sflight,
      CONNID TYPE sflight-CONNID,
      FLDATE TYPE sflight-FLDATE,
      PRICE TYPE sflight-PRICE,
      PLANETYPE TYPE sflight-PLANETYPE,
      CURRENCY TYPE sflight-CURRENCY,
      END OF ty_sflight.
DATA: sflight_itab TYPE TABLE OF ty_sflight,
      sflight_wspace TYPE ty_sflight.
SELECT
  sflight~CONNID
  sflight~FLDATE
  sflight~PRICE
  sflight~PLANETYPE
  sflight~CURRENCY
FROM
  sflight
INTO TABLE
  sflight_itab
WHERE
  CARRID = 'LH'.
LOOP AT sflight_itab INTO sflight_wspace.
  WRITE:/ sflight_wspace-CONNID,sflight_wspace-FLDATE,
        sflight_wspace-PRICE,sflight_wspace-PLANETYPE,
        sflight_wspace-CURRENCY.
ENDLOOP.

MESSAGE S000

不需要定义工作区和TYPES

REPORT ZABAP1903_07NEIBIAO LINE-COUNT 5.  "LINE-COUNT 5:每5行为一个块
DATA: sflight_itab TYPE TABLE OF  SFLIGHT  WITH HEADER LINE.    " WITH HEADER LINE:带有表头行的内表,TYPE TABLE OF:后面这接跟表名,从数据库表只取自己需要的字段
SELECT
  sflight~CONNID
  sflight~FLDATE
  sflight~PRICE
  sflight~PLANETYPE
  sflight~CURRENCY
FROM
  sflight
INTO CORRESPONDING FIELDS OF TABLE
  sflight_itab
WHERE
  CARRID = 'LH'.
LOOP AT sflight_itab.
  WRITE:/ sflight_itab-CONNID,sflight_itab-FLDATE,
        sflight_itab-PRICE,sflight_itab-PLANETYPE,
        sflight_itab-CURRENCY.
ENDLOOP.

多表查询

TABLES: SFLIGHT,SPFLI.
TYPES: BEGIN OF ty_sflight_spfli,
        CARRID TYPE SFLIGHT-CARRID,
        FLDATE TYPE SFLIGHT-FLDATE,
        PRICE TYPE SFLIGHT-PRICE,
        PLANETYPE TYPE SFLIGHT-PLANETYPE,
        CITYFROM TYPE SPFLI-CITYFROM,
        CITYTO TYPE SPFLI-CITYTO,
        FLTIME TYPE SPFLI-FLTIME,
       END OF ty_sflight_spfli.

DATA: gt_itab TYPE TABLE OF ty_sflight_spfli,
      wa_wspace TYPE ty_sflight_spfli.

SELECT
  SFLIGHT~CARRID
  SFLIGHT~FLDATE
  SFLIGHT~PRICE
  SFLIGHT~PLANETYPE
  SPFLI~CITYFROM
  SPFLI~CITYTO
  SPFLI~FLTIME
FROM SFLIGHT INNER JOIN SPFLI ON SFLIGHT~CONNID = SPFLI~CONNID
INTO CORRESPONDING FIELDS OF TABLE gt_itab
WHERE SFLIGHT~PLANETYPE = 'DC-10-10' AND SFLIGHT~FLDATE BETWEEN '20190101' AND '20190701'.

LOOP AT gt_itab INTO wa_wspace.
  WRITE: wa_wspace-CARRID,
        / wa_wspace-FLDATE,
        / wa_wspace-PRICE,
        / wa_wspace-PLANETYPE,
        / wa_wspace-CITYFROM,
        / wa_wspace-CITYTO,
        / wa_wspace-FLTIME.
ENDLOOP.

你可能感兴趣的:(内表练习题)