有没有类似“移动对应忽略首字母”之类的东西?

发布于 2025-01-01 11:41:18 字数 167 浏览 0 评论 0原文

我正在寻找一种类似于 MOVE-CORRESPONDING IGNORING INITIALS 的语言构造或功能模块。简而言之,我想要的功能与 MOVE-CORRESPONDING source TO dest 完全相同,但忽略 source 中初始的所有字段。

有这样的事吗?

I am looking for a language construct or a function module which would be MOVE-CORRESPONDING IGNORING INITIALS like. Simply put I want something that works exactly like MOVE-CORRESPONDING source TO dest but ignoring all the fields which are initial in the source.

Is there someting like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撞了怀 2025-01-08 11:41:18

我已经准备了我自己的一段代码,我想分享一下。它并不完美,不适用于复杂的结构。然而,除了在平面结构上工作之外,我现在不需要任何其他东西。

CLASS lcl_utilities DEFINITION FINAL CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS:
      move_corresponding_ignore_init
        IMPORTING
          i_str_source TYPE any
        CHANGING
          c_str_dest   TYPE any.
ENDCLASS.

CLASS lcl_utilities IMPLEMENTATION.
  METHOD move_corresponding_ignore_init.
    DATA:
      l_rcl_abap_structdescr TYPE REF TO cl_abap_structdescr.

    l_rcl_abap_structdescr ?= cl_abap_typedescr=>describe_by_data( i_str_source ).
    LOOP AT l_rcl_abap_structdescr->components ASSIGNING FIELD-SYMBOL(<fs_str_component>).
      ASSIGN COMPONENT <fs_str_component>-name OF STRUCTURE c_str_dest TO FIELD-SYMBOL(<fs_dest_field>).
      IF sy-subrc = 0.
        ASSIGN COMPONENT <fs_str_component>-name OF STRUCTURE i_str_source TO FIELD-SYMBOL(<fs_source_field>).
        ASSERT sy-subrc = 0.
        IF <fs_source_field> IS NOT INITIAL.
          <fs_dest_field> = <fs_source_field>.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.                    "move_corresponding_ignore_init
ENDCLASS.

...和一个小宏,以便更像一种语言结构来使用它。

DEFINE move_corresponding_ignore_init.
  lcl_utilities=>move_corresponding_ignore_init(
    exporting
      i_str_source = &1
    changing
      c_str_dest   = &2
  ).
END-OF-DEFINITION.

I have prepared my own piece of code that I want to share. It is not perfect, it will not work with complex structures. However I do not need anything more right now than to work on flat structures.

CLASS lcl_utilities DEFINITION FINAL CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS:
      move_corresponding_ignore_init
        IMPORTING
          i_str_source TYPE any
        CHANGING
          c_str_dest   TYPE any.
ENDCLASS.

CLASS lcl_utilities IMPLEMENTATION.
  METHOD move_corresponding_ignore_init.
    DATA:
      l_rcl_abap_structdescr TYPE REF TO cl_abap_structdescr.

    l_rcl_abap_structdescr ?= cl_abap_typedescr=>describe_by_data( i_str_source ).
    LOOP AT l_rcl_abap_structdescr->components ASSIGNING FIELD-SYMBOL(<fs_str_component>).
      ASSIGN COMPONENT <fs_str_component>-name OF STRUCTURE c_str_dest TO FIELD-SYMBOL(<fs_dest_field>).
      IF sy-subrc = 0.
        ASSIGN COMPONENT <fs_str_component>-name OF STRUCTURE i_str_source TO FIELD-SYMBOL(<fs_source_field>).
        ASSERT sy-subrc = 0.
        IF <fs_source_field> IS NOT INITIAL.
          <fs_dest_field> = <fs_source_field>.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.                    "move_corresponding_ignore_init
ENDCLASS.

...and a small macro in order to use it more less like a language construct.

DEFINE move_corresponding_ignore_init.
  lcl_utilities=>move_corresponding_ignore_init(
    exporting
      i_str_source = &1
    changing
      c_str_dest   = &2
  ).
END-OF-DEFINITION.
身边 2025-01-08 11:41:18

不存在任意结构的语言构造。对于字符字段,您可以使用 OVERLAY ...WITH,但如果您尝试对结构执行此操作,则会导致非常混乱的代码以及可变长度内容的许多不可预见的麻烦。最好的选择是使用 RTTI (运行时类型识别) 来执行此操作,但在检查初始值时要小心。

There is no language construct for arbitrary structures. For character fields, you can use OVERLAY ... WITH, but if you try to do this with structures, it leads to really messy code and lots of unforseen trouble with variable-length content. The best bet would be to use RTTI (Runtime Type Identification) to do this, but be careful when checking for initial values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文