ABAP语法讲解八(Having语句)

2022-04-14 05:40:11   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《ABAP语法讲解八(Having语句)》,欢迎阅读!
语句,语法,讲解,Having,ABAP
HAVING Clause

Basic form

... HAVING cond. Effect

Used in a SELECT command, it allows you to use a logical condition for the groups in a GROUP-BY clause. Examples

This example outputs the number of passengers and the average baggage weight for all Lufthansa flights on the 28.02.1995, where the average weight of the baggage is greater than 20 KG:

DATA: COUNT TYPE I, AVG TYPE F. DATA: CONNID LIKE SBOOK-CONNID.

SELECT CONNID COUNT( * ) AVG( LUGGWEIGHT ) INTO (CONNID, COUNT, AVG) FROM SBOOK WHERE

CARRID = 'LH' AND FLDATE = '19950228' GROUP BY CONNID

HAVING AVG( LUGGWEIGHT ) > '20.0'. WRITE: / CONNID, COUNT, AVG. ENDSELECT.

This example outputs all Lufthansa departure airports with more than 10 destinations.

TABLES: SPFLI. DATA: BEGIN OF WA.

INCLUDE STRUCTURE SPFLI. DATA: COUNT TYPE I.


DATA: END OF WA.

DATA: WA_TAB(72) TYPE C,

HTAB LIKE STANDARD TABLE OF WA_TAB WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 5,

FTAB LIKE STANDARD TABLE OF WA_TAB WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 5, COUNT TYPE I.

CLEAR: GTAB, HTAB, FTAB.

WA_TAB = 'CTYFROM COUNT( * ) AS COUNT'. APPEND WA_TAB TO FTAB. WA_TAB = 'COUNT( * ) > 10'. APPEND WA_TAB TO HTAB. WA_TAB = 'CITYFROM'. APPEND WA_TAB TO GTAB.

SELECT DISTINCT (FTAB)

INTO CORRESPONDING FIELDS OF WA FROM SPFLI WHERE

CARRID = 'LH' GROUP BY (GTAB) HAVING (HTAB).

WRITE: / WA-CITYFROM, WA-COUNT. ENDSELECT. Note

... HAVING cond does not work with pool and cluster tables. Note Performance:

The amount of data transferred from the database system to the application server is significantly reduced if you construct the aggregates and groups in the database instead of the application server.


本文来源:https://www.wddqxz.cn/e8ecc1bad9ef5ef7ba0d4a7302768e9951e76e19.html

相关推荐