gpt4 book ai didi

abap - 将 ABAP 740 语法转换为 700 - VALUE & LOOP AT ... GROUP BY

转载 作者:行者123 更新时间:2023-12-04 02:21:28 25 4
gpt4 key购买 nike

我找到了一个 demo program对于我想使用的 tree salv online,但由于它使用 740 语法,我必须先将其转换。这也是进一步了解新语法的好机会。

我几乎已经完成了所有这些,但在使用 VALUE 时遇到了问题。阅读此 wiki entry ,除其他外,无法帮助我。

740中的原代码:

" Treenodes einfügen
LOOP AT it_spfli ASSIGNING FIELD-SYMBOL(<c>) GROUP BY <c>-carrid.

DATA(it_cp) = VALUE ty_it_spfli( FOR <cp> IN GROUP <c> ( <cp> ) ).

DATA(o_parent) = o_tree->get_nodes( )->add_node( related_node = ''
relationship = cl_gui_column_tree=>relat_last_child
collapsed_icon = CONV #( icon_closed_folder )
expanded_icon = CONV #( icon_open_folder )
row_style = if_salv_c_tree_style=>intensified
text = CONV #( <c>-carrid ) ).

IF lines( it_cp ) > 1.
o_parent->get_item( 'CARRID' )->set_type( if_salv_c_item_type=>button ).
o_parent->get_item( 'CARRID' )->set_value( 'all' ).
ENDIF.

LOOP AT GROUP <c> ASSIGNING FIELD-SYMBOL(<f>).
DATA(o_carrid) = o_tree->get_nodes( )->add_node( related_node = o_parent->get_key( )
relationship = cl_gui_column_tree=>relat_last_child
data_row = <f>
row_style = if_salv_c_tree_style=>intensified
text = CONV #( <f>-connid ) ).

o_carrid->get_item( 'CARRID' )->set_type( if_salv_c_item_type=>checkbox ).
o_carrid->get_item( 'CARRID' )->set_editable( abap_true ).
ENDLOOP.
ENDLOOP.

700 中的新代码,VALUE 行除外:

" new variables added to convert code to 700
DATA: o_nodes TYPE REF TO cl_salv_nodes,
o_parent TYPE REF TO cl_salv_node,
o_carrid TYPE REF TO cl_salv_node,
o_item TYPE REF TO cl_salv_item,
o_key TYPE lvc_nkey.

DATA: h_collapsed_icon TYPE salv_de_tree_image VALUE 'icon_closed_folder',
h_expanded_icon TYPE salv_de_tree_image VALUE 'icon_open_folder',
h_text_carrid TYPE lvc_value.

DATA: it_cp TYPE STANDARD TABLE OF ty_it_spfli.

SORT it_spfli BY carrid.

" Treenodes einfügen
LOOP AT it_spfli ASSIGNING <c>.

AT NEW carrid.

it_cp = value TY_IT_SPFLI( for <CP> in GROUP <c> ( <CP> ) ). <--- Here

o_nodes = o_tree->get_nodes( ).

h_text_carrid = <c>-carrid.

o_parent = o_nodes->add_node( related_node = ''
relationship = cl_gui_column_tree=>relat_last_child
collapsed_icon = h_collapsed_icon
expanded_icon = h_expanded_icon
row_style = if_salv_c_tree_style=>intensified
text = h_text_carrid ).

IF LINES( it_cp ) > 1.
o_item = o_parent->get_item( 'CARRID' ).
o_item->set_type( if_salv_c_item_type=>button ).
o_item->set_value( 'all' ).
ENDIF.

ENDAT.

o_key = o_parent->get_key( ).

o_carrid = o_nodes->add_node( related_node = o_key
relationship = cl_gui_column_tree=>relat_last_child
data_row = <c>
row_style = if_salv_c_tree_style=>intensified
text = h_text_carrid ).

o_item = o_parent->get_item( 'CARRID' ).
o_item->set_type( if_salv_c_item_type=>checkbox ).
o_item->set_editable( abap_true ).

ENDLOOP.

我现在的问题是:

  1. 我是否使用 AT NEW 正确转换了 LOOP AT ... GROUP BY
  2. 如何转换带有 VALUE 的行?

预先感谢您的帮助。

最佳答案

您无法按照您的方式进行转换。按 CARRID 分组的原始代码的外循环与 AT NEW 不完全相同,因为它会生成一个临时组表,然后您可以在任何地方使用它。没有它,你应该提前生成组。

我没有验证代码,但是为了模拟 GROUP BY,然后让其余的转换变得容易而不必重写太多,我会为原始的每个 CARRID 创建一个嵌套表:

DATA: BEGIN OF ls_spfli_carrid_group,
carrid TYPE carrid,
flights TYPE ty_it_spfli,
END OF ls_spfli_carrid_group,
lt_spfli_carrid_group LIKE STANDARD TABLE OF ls_spfli_carrid_group.

SORT it_spfli BY carrid.
LOOP AT it_spfli INTO ls_spfli.
AT NEW carrid.
it_spfli
ls_spfli_carrid_group-carrid = ls_spfli-carrid.
REFRESH ls_spfli_carrid_group-flights.
APPEND ls_spfli_carrid_group TO lt_spfli_carrid_group.
ENDAT.
APPEND ls_spfli TO ls_spfli_carrid_group-flights.
ENDLOOP.

LOOP AT lt_spfli_carrid_group INTO ls_spfli_carrid_group.
it_cp = ls_spfli_carrid_group-flights.
...
LOOP AT ls_spfli_carrid_group-flights INTO ls_flight. "Should be like the LOOP AT GROUP
ENDLOOP.
ENDLOOP.

关于abap - 将 ABAP 740 语法转换为 700 - VALUE & LOOP AT ... GROUP BY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57924591/

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