简体   繁体   English

在内部表 (ABAP) 上使用 SELECT

[英]use SELECT on internal table (ABAP)

I am still very inexperienced with SAP ABAP .我对 SAP ABAP仍然非常缺乏经验。

I have an internal table that I want to filter further and further based on whether data is present.我有一个内部表,我想根据数据是否存在进一步过滤。

I have tried the following, but unfortunately I cannot apply a SELECT to an internal table.我尝试了以下方法,但不幸的是我无法将SELECT应用于内部表。

How can I solve this problem?我怎么解决这个问题?

Hope I have explained my problem clearly enough!希望我已经足够清楚地解释了我的问题!

"Here I'm getting the hole database into my internal table 
SELECT * FROM TABLE
  INTO CORRESPONDING FIELDS OF TABLE @itab.

"This should be my first filter if iv_name is not initial
IF iv_name IS NOT INITIAL.
  SELECT * FROM itab
    WHERE NAME = @iv_name
    INTO CORRESPONDING FIELDS OF TABLE @itab. 
ENDIF.

"This should be my second filter if iv_age is not initial
IF iv_age IS NOT INITIAL.
  SELECT * FROM itab
    WHERE AGE = @iv_age
    INTO CORRESPONDING FIELDS OF TABLE @itab. 
ENDIF.

There are several ways in ABAP to achieve your goal. ABAP 中有多种方法可以实现您的目标。 You can use the DELETE keyword to filter the data in an internal table:您可以使用 DELETE 关键字来过滤内表中的数据:

IF iv_name IS NOT INITIAL    
  DELETE itab WHERE name NE iv_name.
ENDIF.

Another possibility is to use the FILTER keyword, but the prerequisite is, that the internal table is TYPE SORTED or HASHED:另一种可能是使用 FILTER 关键字,但先决条件是内部表是 TYPE SORTED 或 HASHED:

itab = FILTER #( itab WHERE name = iv_name ).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM