2

我需要通过 ABAP 代码在信息类型中创​​建/编写文本。所以我正在为此寻找一个功能模块或一些“干净”的解决方案。现在我只发现这篇文章有一个“快速&肮脏”的解决方案。

我有点害怕直接从集群中更改某些内容,所以我希望也许有人可以为我提供另一种解决此问题的方法。

4

1 回答 1

1

也许会对你有所帮助。这是我遇到的最模块化和面向对象的可能性。

这是一个示例代码:

    DATA: lo_0194         TYPE REF TO cl_hrpa_infotype_0194,
          lw_pernr        TYPE p_pernr,
          fr_msg_handler  TYPE REF TO if_hrpa_message_handler,
          lr_message_list TYPE REF TO cl_hrpa_message_list,
          ls_container    TYPE  hrpad_infty_container_ref,
          lr_contain_0194 TYPE REF TO cl_hrpa_infotype_container,
          lr_upd_cluster  TYPE REF TO cl_hrpa_text_cluster,
          lt_text_194     TYPE hrpad_text_tab.

创建信息类型对象

    CREATE OBJECT lr_message_list.
    fr_msg_handler  = lr_message_list.
    TRY.
        CREATE OBJECT lo_0194
          EXPORTING
            tclas = 'A'
            infty = '0194'.
      CATCH cx_hrpa_violated_assertion INTO DATA(ls_exp).
        DATA(lw_message) = ls_exp->get_text( ).
    ENDTRY.
    IF lw_message IS INITIAL.
      "error handling
    ENDIF.

修改数据

    APPEND 'TEXT' TO lt_text_194.
    TRY.
        lr_contain_0194 ?= ls_container.
        lr_contain_0194->modify_text_tab( lt_text_194 ).
      CATCH cx_hrpa_violated_assertion INTO ls_exp.
        lw_message = ls_exp->get_text( ).
    ENDTRY.

    TRY.
        lo_0194->if_hrpa_infty_bl~modify(
           EXPORTING
             old_container   = lr_contain_0194
             massn           = space
             massg           = space
             update_mode     = VALUE hrpad_update_mode( )
             no_auth_check   = ''
             message_handler = fr_msg_handler
          IMPORTING
           is_ok             = DATA(lw_ok)
          CHANGING
            container       = ls_container ).
      CATCH cx_hrpa_violated_assertion INTO ls_exp.
        lw_message = ls_exp->get_text( ).
    ENDTRY.

更新集群

    CREATE OBJECT lr_upd_cluster.
    TRY.
        CALL METHOD lr_upd_cluster->update
          EXPORTING
            tclas         = 'A'
            pskey         = VALUE pskey( )
            histo         = abap_true
            uname         = sy-uname
            aedtm         = sy-datum
            pgmid         = VALUE old_prog( )
            text_tab      = lt_text_194
            no_auth_check = abap_true.
      CATCH   cx_hrpa_violated_assertion.
    ENDTRY.
于 2017-05-18T16:53:33.123 回答