FILTER是ABAP中的一个关键字,用于在内部表中进行数据筛选和过滤,以便于提取所需的数据集。
FILTER关键字用于从内部表中筛选符合特定条件的数据行。它通过提供条件表达式,只返回满足条件的数据行,从而在不修改原始数据的情况下生成一个新的内部表。FILTER关键字在处理大量数据时非常有用,可以有效地减少内部表的大小,同时提高代码的可读性和可维护性。
REPORT ZJERRY_FILTER.
DATA: lt_spfli TYPE STANDARD TABLE OF spfli
WITH NON-UNIQUE SORTED KEY carr_city COMPONENTS carrid,
lt_lh TYPE TABLE OF spfli.
SELECT * INTO TABLE lt_spfli FROM spfli.
"data(lt) = FILTER #( lt_spfli using key carrid where carrid = '1' ).
lt_lh = FILTER #( lt_spfli using key carr_city where carrid = conv #( 'LH' ) ).
BREAK-POINT.
filter 之前:
filter 之后:
第二个例子:
report z.
TYPES: BEGIN OF ty_person,
name type string,
age type int4,
end of ty_person.
data: lt_person type STANDARD TABLE OF ty_person
with NON-UNIQUE SORTED KEY person_key COMPONENTS age,
lt_old1 like lt_person,
lt_old2 like lt_person,
ls_person type ty_person.
ls_person-name = 'Tom'. ls_person-age = '21'. INSERT ls_person into table lt_person.
ls_person-name = 'Jim'. ls_person-age = '62'. INSERT ls_person into table lt_person.
ls_person-name = 'Bob'. ls_person-age = '70'. INSERT ls_person into table lt_person.
ls_person-name = 'Kate'. ls_person-age = '30'. INSERT ls_person into table lt_person.
LOOP AT lt_person INTO ls_person WHERE age > 60.
INSERT ls_person INTO TABLE lt_old1.
ENDLOOP.
lt_old2 = FILTER #( lt_person USING KEY person_key where age > 60 ).
IF lt_old1 = lt_old2.
BREAK-POINT.
ENDIF.
总结
FILTER关键字是SAP ABAP中用于数据筛选和过滤的强大工具。它允许开发人员根据特定条件从内部表中提取所需的数据,从而简化了数据处理过程,提高了代码的可读性和可维护性。通过上述示例,我们可以看到FILTER关键字在实际开发中的应用,以及如何使用它来从员工信息中筛选出符合条件的数据。
标签:age,lt,FILTER,person,ABAP,ls,SAP,spfli From: https://www.cnblogs.com/sap-jerry/p/17662822.html