gpt4 book ai didi

abap - 从一组记录中选择最大字段值?

转载 作者:行者123 更新时间:2023-12-05 08:40:27 24 4
gpt4 key购买 nike

我需要从 每个不同的 VKONT 的 itab 中获取具有最高 EXBEL 寄存器 的行。

如果源表中有几行具有相同的最高 EXBEL 值,则结果表可能包含同一 VKONT 值的几行。

实际源表:

SPARTE  VKONT         EXBEL
05 800000008422 1NSN150900000058
L2 800000008422 1NSN150900000058
05 800000008422 1NSN150900000037
L2 800000008422 1NSN150900000037
05 800000008422 1NSN150900000013
L2 800000008422 1NSN150900000013
05 800000008415 1HSN151200000009
S1 800000008415 1HSN151200000009
05 800000008415 1HSN151200000008
S1 800000008415 1HSN151200000008
L1 800000008422 1NSN150900000050
L1 800000008422 1NSN150900000029
L1 800000008422 1NSN150900000023
05 800000008415 1HSN151200000012
S1 800000008415 1HSN151200000012
05 800000008422 1NSN150900000058
L2 800000008422 1NSN150900000058
05 800000008415 1HSN151200000009
S1 800000008415 1HSN151200000009

预期结果表:

SPARTE  VKONT         EXBEL
05 800000008422 1NSN150900000058
L2 800000008422 1NSN150900000058
05 800000008415 1HSN151200000012
S1 800000008415 1HSN151200000012

我尝试了不同的解决方案,但没有奏效。

我们将不胜感激。

劳尔。

最佳答案

从7.52开始,可以select在内部表上。示例代码如下。

TYPES:
BEGIN OF ty_s_value,
sparte TYPE char2,
vkont TYPE char12,
exbel TYPE char16,
END OF ty_s_value.

TYPES:
ty_t_value TYPE STANDARD TABLE OF ty_s_value .

DATA:
lt_value TYPE ty_t_value.

lt_value = VALUE #(
( sparte = '05' vkont = '800008422' exbel = '0000000000000001')
( sparte = 'l2' vkont = '800008422' exbel = '0000000000000002')
( sparte = 'l2' vkont = '800008422' exbel = '0000000000000004')
( sparte = '05' vkont = '800008423' exbel = '0000000000000003')
( sparte = 'l2' vkont = '800008423' exbel = '0000000000000002')
( sparte = 'l2' vkont = '800008423' exbel = '0000000000000005')
).

SELECT FROM @lt_value AS a FIELDS a~sparte, a~vkont, MAX( a~exbel ) AS exbel
GROUP BY a~sparte, a~vkont
ORDER BY a~sparte, a~vkont INTO TABLE @DATA(result).

关于abap - 从一组记录中选择最大字段值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55284258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com