您的当前位置:首页正文

sap abap log程序

2024-11-11 来源:个人技术集锦

1.成果:

1.数据库表设计:

2.报表

*&---------------------------------------------------------------------*
*& Report ZFUNC_LOG
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zfunc_log.

*&---------------------------------------------------------------------*
* 数据定义部分
*
*&---------------------------------------------------------------------*
TABLES:  zfunc_log.
TYPE-POOLS: slis, vrm, abap,icon.

DATA: BEGIN OF gs_out,
        sel.
    INCLUDE TYPE zfunc_log.
DATA: stext TYPE tftit-stext,
      icon  TYPE icon-internal,
      icon2 TYPE icon-internal,
      icon3 TYPE icon-internal,
      icon4 TYPE icon-internal,
      END OF gs_out.
DATA: gt_out LIKE TABLE OF gs_out.
FIELD-SYMBOLS: <fs_out> LIKE gs_out.


DATA: gs_fieldcat TYPE lvc_s_fcat,              "字段工作区
      gt_fieldcat TYPE lvc_t_fcat.

DATA: gs_list TYPE lvc_s_drop.
DATA: gt_list TYPE lvc_t_drop.

DATA: gt_listheader TYPE slis_t_listheader,            "ALV 表头
      gs_setting    TYPE lvc_s_glay,
      gs_layout     TYPE lvc_s_layo.                  "ALV布局工作区

DATA: gs_sort TYPE lvc_s_sort,
      gt_sort TYPE lvc_t_sort.
DATA: gs_stbl TYPE lvc_s_stbl.
DATA: gcl_alv_grid TYPE REF TO cl_gui_alv_grid.
DATA: gs_events TYPE slis_alv_event,
      gt_events TYPE slis_t_event.
DATA: gv_msg TYPE string.

DATA: gv_new_id TYPE abap_bool.
DATA: gv_zz_log_id TYPE zfunc_log-id.

DATA: gcl_root TYPE REF TO cx_root.

SELECTION-SCREEN BEGIN OF BLOCK bk01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_id    FOR zfunc_log-id,
                s_name FOR zfunc_log-func_name,
                s_erdat FOR zfunc_log-erdat,
                s_erzet FOR zfunc_log-erzet,
                s_ernam FOR zfunc_log-ernam,
                s_msgty FOR zfunc_log-msgty,
                s_msgtxt FOR zfunc_log-msgtxt,
                s_zd    FOR zfunc_log-xuterminal,
                s_ip    FOR zfunc_log-ip.
SELECTION-SCREEN END OF BLOCK bk01.

*&---------------------------------------------------------------------*
* 流程部分
*
*&---------------------------------------------------------------------*

INITIALIZATION.
  s_erdat[] = VALUE #( ( sign = 'I'
                       option = 'BT'
                          low = sy-datum - 15
                         high = sy-datum ) ).

START-OF-SELECTION.

END-OF-SELECTION.
  PERFORM frm_ready_report.
  PERFORM frm_pre_fieldcat.   "设置字段
  PERFORM frm_set_event.      "设置事件
  PERFORM frm_set_header.     "设置表头
  PERFORM frm_set_layout.     "设置布局
  PERFORM frm_show_alv.


*&---------------------------------------------------------------------*
* 逻辑实现部分
*
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  FRM_READY_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_ready_report.
  PERFORM frm_get_data.           "获取数据
  PERFORM frm_deal_data.          "处理数据
ENDFORM.                    "FRM_READY_REPORT

*&---------------------------------------------------------------------*
*&      Form  FRM_PRE_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_pre_fieldcat .


  CLEAR gs_fieldcat.
  REFRESH gt_fieldcat.

  "动态字段名称赋值
  DATA: lo_tabdescr TYPE REF TO cl_abap_structdescr.
  DATA: ls_field_in TYPE dfies,
        lt_dfies    TYPE ddfields.

  lo_tabdescr ?= cl_abap_structdescr=>describe_by_data( gs_out ).
  CALL METHOD cl_salv_data_descr=>read_structdescr
    EXPORTING
      r_structdescr = lo_tabdescr
    RECEIVING
      t_dfies       = lt_dfies.

*  "===自动赋值fieldcat===
*  loop at lt_dfies into ls_field_in.
*    clear: gs_fieldcat.
*    move-corresponding ls_field_in to gs_fieldcat.
*    gs_fieldcat-ref_field = ls_field_in-fieldname. "参照类型字段
*    gs_fieldcat-ref_table = ls_field_in-tabname.   "参照类型的表,搜索帮助,域控制
*    if gs_fieldcat-coltext is initial.         "当COLTEXT不存在显示FILEDTEXT,如字段没域,只有手工描述的情况
*      gs_fieldcat-coltext = ls_field_in-fieldtext.
*    endif.
*    case ls_field_in-fieldname.
*      when 'MANDT' or 'SEL'.
*        continue.
*      when others.
*    endcase.
*    append gs_fieldcat to gt_fieldcat.
*  endloop.

  "===手动赋值fieldcat===
  DEFINE set_fieldcat.
    READ TABLE lt_dfies INTO ls_field_in WITH KEY fieldname = &1.
    IF sy-subrc = 0.
      CLEAR: gs_fieldcat.
      MOVE-CORRESPONDING ls_field_in TO gs_fieldcat.

      gs_fieldcat-coltext = &2.
      gs_fieldcat-edit = &3.
      gs_fieldcat-ref_table = &4.
      gs_fieldcat-ref_field = &5.
      gs_fieldcat-lowercase      = 'X'.

      IF gs_fieldcat-ref_field IS INITIAL.
        gs_fieldcat-ref_field = ls_field_in-fieldname. "参照类型字段
      ENDIF.
      IF gs_fieldcat-ref_table IS INITIAL.
        gs_fieldcat-ref_table = ls_field_in-tabname.   "参照类型的表,搜索帮助,域控制
      ENDIF.
      IF gs_fieldcat-coltext IS INITIAL.         "当coltext不存在显示filedtext,如字段没域,只有手工描述的情况
        gs_fieldcat-coltext = ls_field_in-fieldtext.
      ENDIF.
      IF gs_fieldcat-outputlen IS INITIAL.         "当coltext不存在显示filedtext,如字段没域,只有手工描述的情况
        gs_fieldcat-outputlen = 40.
      ENDIF.
      APPEND gs_fieldcat TO gt_fieldcat.
    ENDIF.
  END-OF-DEFINITION.

  set_fieldcat 'ID' '' '' '' ''."不赋值COLTEXT,带出数据元素的名称
  set_fieldcat 'FUNC_NAME' '函数名' '' '' ''. "
  set_fieldcat 'STEXT' '函数描述' '' '' ''. "
  set_fieldcat 'XUTERMINAL' '终端' '' '' ''. "
  set_fieldcat 'IP' 'IP' '' '' ''. "
  set_fieldcat 'ERDAT' '' '' '' ''. "
  set_fieldcat 'ERZET' '' '' '' ''. "
  set_fieldcat 'ERNAM' '' '' '' ''. "
  set_fieldcat 'MSGTY' '' '' '' ''. "
  set_fieldcat 'MSGTXT' '' '' '' ''. "
  set_fieldcat 'ICON'  '传入数据-转换展示' '' '' ''. "
  set_fieldcat 'ICON2' '传入数据-初始展示' '' '' ''. "
  set_fieldcat 'ICON3' '返回数据-转换展示' '' '' ''. "
  set_fieldcat 'ICON4' '返回数据-初始展示' '' '' ''. "
  set_fieldcat 'TZNTSTMPS_BEG' '开始时间戳' '' '' ''. "
  set_fieldcat 'TZNTSTMPS_END' '结束时间戳' '' '' ''. "
  set_fieldcat 'TZNTSTMPS' '时间差(秒)' '' '' ''. "

  "其他特殊处理
  LOOP AT gt_fieldcat INTO gs_fieldcat.
    IF  gs_fieldcat-fieldname CS 'ID' .
      gs_fieldcat-fix_column = 'X'.
    ENDIF.
    IF gs_fieldcat-fieldname CS 'ICON'.
      gs_fieldcat-icon = 'X'.
      gs_fieldcat-hotspot = 'X'.
    ENDIF.
    MODIFY gt_fieldcat FROM gs_fieldcat.
  ENDLOOP.


  DEFINE set_sort.  "定义排序宏
    CLEAR gs_sort.
    gs_sort-fieldname = &1.
    gs_sort-spos = 1.
    gs_sort-up = 'X'.
    gs_sort-subtot = 'X'.
    APPEND gs_sort TO gt_sort.
  END-OF-DEFINITION.
*  SET_SORT 'GJAHR'.
*  SET_SORT 'SEASON'.
ENDFORM.                    " FRM_PRE_FIELDCAT

*&---------------------------------------------------------------------*
*&      Form  FRM_SET_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_set_header .

ENDFORM.                    " FRM_SET_HEADER

*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_get_data .
  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE gt_out
    FROM zfunc_log
    WHERE id          IN s_id
      AND erdat       IN s_erdat
      AND erzet       IN s_erzet
      AND ernam       IN s_ernam
      AND msgtxt      IN s_msgtxt
      AND msgty       IN s_msgty
      AND xuterminal  IN s_zd
      AND func_name  IN s_name
      AND ip          IN s_ip    .
ENDFORM.                   " FRM_GET_DATA

*&---------------------------------------------------------------------*
*&      Form  FRM_DEAL_DATA
*----------------------------------------------------------------------*
FORM frm_deal_data.
  DATA: ls_tftit TYPE tftit,
        lt_tftit TYPE TABLE OF tftit.

*  CALL METHOD zcl_jt=>get_text_table
*    EXPORTING
*      table_name    = 'TFTIT'
*      intab_field   = 'FUNC_NAME'
*      outtab_field  = 'FUNCNAME'
*      langu_field   = 'SPRAS'
*      other_sql     = ''
*      object_struct = gs_out
*      object_table  = gt_out
*    IMPORTING
*      text_table    = lt_tftit.
  IF gt_out[] IS NOT INITIAL.
    SELECT
    * INTO TABLE lt_tftit
    FROM tftit
      FOR ALL ENTRIES IN gt_out
      WHERE funcname = gt_out-func_name
    .
  ENDIF.



  LOOP AT gt_out ASSIGNING <fs_out>.
    READ TABLE lt_tftit INTO ls_tftit WITH KEY funcname = <fs_out>-func_name BINARY SEARCH.
    IF sy-subrc = 0.
      <fs_out>-stext = ls_tftit-stext.
    ENDIF.
    <fs_out>-icon  = icon_parameter_import.
    <fs_out>-icon2 = icon_parameter_import.
    <fs_out>-icon3 = icon_parameter_result.
    <fs_out>-icon4 = icon_parameter_result.
  ENDLOOP.

  SORT gt_out BY id DESCENDING.
ENDFORM.                    "FRM_GET_DATA

*&---------------------------------------------------------------------*
*&      Form  FRM_SHOW_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_show_alv .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
*     I_INTERFACE_CHECK        = ' '
*     I_BYPASSING_BUFFER       =
*     I_BUFFER_ACTIVE          =
      i_callback_program       = sy-cprog
      i_callback_pf_status_set = 'SUB_STATUS_SET'
      i_callback_user_command  = 'SUB_USER_COMMAND'
*     I_CALLBACK_TOP_OF_PAGE   = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME         =
*     I_BACKGROUND_ID          = ' '
*     I_GRID_TITLE             =
*     I_GRID_SETTINGS          = GS_SETTING   "编辑回填数据时候打开
      is_layout_lvc            = gs_layout
      it_fieldcat_lvc          = gt_fieldcat
*     IT_EXCLUDING             =
*     IT_SPECIAL_GROUPS_LVC    =
      it_sort_lvc              = gt_sort
*     IT_FILTER_LVC            =
*     IT_HYPERLINK             =
*     IS_SEL_HIDE              =
*     I_DEFAULT                = 'X'
      i_save                   = 'A'
*     IS_VARIANT               =
      it_events                = gt_events
*     IT_EVENT_EXIT            =
*     IS_PRINT_LVC             =
*     IS_REPREP_ID_LVC         =
*     I_SCREEN_START_COLUMN    = 0
*     I_SCREEN_START_LINE      = 0
*     I_SCREEN_END_COLUMN      = 0
*     I_SCREEN_END_LINE        = 0
*     I_HTML_HEIGHT_TOP        =
*     I_HTML_HEIGHT_END        =
*     IT_ALV_GRAPHICS          =
*     IT_EXCEPT_QINFO_LVC      =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER  =
*     ES_EXIT_CAUSED_BY_USER   =
    TABLES
      t_outtab                 = gt_out
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
* Implement suGT_OUTle error handling here
  ENDIF.

ENDFORM.                    " FRM_SHOW_ALV

*&---------------------------------------------------------------------*
*&      Form  SUB_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = gt_listheader
*     I_LOGO             =
*     I_END_OF_LIST_GRID =
*     I_ALV_FORM         =
    .

ENDFORM.                    "SUB_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_set_layout .
  gs_setting-edt_cll_cb = 'X'.
  gs_layout-cwidth_opt = 'X'.
  gs_layout-box_fname = 'SEL'.
ENDFORM.                    " FRM_SET_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  SUB_STATUS_SET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'STATUS01'.
  SET TITLEBAR 'TITLE'.
ENDFORM.                    "SUB_STATUS_SET


*  ----------------------------------------------------------------------*
*         CLASS lcl_event_receiver DEFINITION
*定义类
*  ----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS data_changed FOR EVENT data_changed OF cl_gui_alv_grid
      IMPORTING er_data_changed
                  e_onf4
                  e_onf4_before
                  e_onf4_after
                  e_ucomm.
    METHODS handle_modify
                  FOR EVENT data_changed_finished OF cl_gui_alv_grid
      IMPORTING e_modified et_good_cells.
ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION

*  ----------------------------------------------------------------------*
*         CLASS lcl_event_receiver IMPLEMENTATION
* 定义方法
*  ----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD data_changed.
    PERFORM handle_data_changed USING er_data_changed.
  ENDMETHOD.
  METHOD handle_modify.
    PERFORM handle_data_finish USING e_modified et_good_cells.
  ENDMETHOD.                    "HANDLE_MODIFY
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION

FORM handle_data_finish USING e_modified TYPE char01
                               et_good_cells TYPE lvc_t_modi.
*在此处添加你自己的代码,改变传入ALV函数的那个内表的值,就能实现你的功能。
  DATA: eh_good_cells TYPE lvc_s_modi.
  DATA: lv_itab_trans_to_itab TYPE char01. "内表修改影响alv显示
  CLEAR: lv_itab_trans_to_itab.

  IF e_modified = 'X'.
    LOOP AT et_good_cells INTO eh_good_cells. "修改的行。
      READ TABLE gt_out ASSIGNING <fs_out> INDEX eh_good_cells-row_id.
      IF sy-subrc = 0.

      ENDIF.
    ENDLOOP.
*-------------------------------------------------
* 稳定刷新
    IF lv_itab_trans_to_itab IS NOT INITIAL. "假如每次修改数据都刷新ALV,非常影响速度
      gs_stbl-row = 'X'." 基于行的稳定刷新
      gs_stbl-col = 'X'." 基于列稳定刷新
      CALL METHOD gcl_alv_grid->refresh_table_display
        EXPORTING
          is_stable = gs_stbl.
    ENDIF.
  ENDIF.

ENDFORM.
FORM handle_data_changed  USING p_er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
*如果更新的reason字段长度小于10为则提示用户填入字符数不能低于10
  DATA:mod_data        TYPE lvc_t_modi,
       gs_out_mod_data TYPE lvc_s_modi.

  mod_data = p_er_data_changed->mt_mod_cells.
  LOOP AT mod_data INTO gs_out_mod_data.
  ENDLOOP.
ENDFORM.                    "handle_data_changed

*&---------------------------------------------------------------------*
*&      Form  FRM_SET_EVENT
*定义事件
*&---------------------------------------------------------------------*
FORM frm_set_event .
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = gt_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  gs_events-name = 'CALLER_EXIT'.
  gs_events-form = 'FRM_CALLER_EXIT'.
  APPEND gs_events TO gt_events.

ENDFORM.                    " FRM_SET_EVENT

*&---------------------------------------------------------------------*
*&      Form  F_CALLER_EXIT
* 注册回车事件
*&---------------------------------------------------------------------*
FORM frm_caller_exit USING ls_data TYPE slis_data_caller_exit.

  CHECK sy-batch = ''. "后台执行获取对象失败

  DATA gt_event_receiver TYPE REF TO lcl_event_receiver.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = gcl_alv_grid.


* 设置enter事件
  CALL METHOD gcl_alv_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter
    EXCEPTIONS
      error      = 1
      OTHERS     = 2.
  CALL METHOD gcl_alv_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_modified
    EXCEPTIONS
      error      = 1
      OTHERS     = 2.
  IF sy-subrc <> 0.
*   Implement suGT_OUTle error handling here
  ENDIF.
  CREATE OBJECT gt_event_receiver.
  SET HANDLER gt_event_receiver->handle_modify FOR gcl_alv_grid.
  SET HANDLER gt_event_receiver->data_changed FOR gcl_alv_grid.



ENDFORM.                   "F_CALLER_EXIT


*&---------------------------------------------------------------------*
*&      Form  SUB_USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub_user_command USING s_ucomm TYPE sy-ucomm
                            re_selfield TYPE slis_selfield.

  CALL METHOD gcl_alv_grid->check_changed_data. "触发数据变更
  CASE s_ucomm.
    WHEN '&IC1'.
      READ TABLE gt_out INTO gs_out INDEX re_selfield-tabindex.
      IF sy-subrc = 0.

        CASE re_selfield-fieldname.
          WHEN 'ICON'.
            PERFORM frm_display_json.
          WHEN 'ICON2'.
            PERFORM frm_display_json_old.
          WHEN 'ICON3'.
            PERFORM frm_display_return_json.
          WHEN 'ICON4'.
            PERFORM frm_display_return_json_old.
          WHEN OTHERS.
            SET PARAMETER ID 'LIB' FIELD gs_out-func_name.
            CALL TRANSACTION 'SE37' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
        ENDCASE.
      ENDIF.
    WHEN 'RESEND'.
      gv_new_id = ''.
      PERFORM frm_resend.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = 50
          text       = '等待2秒数据库刷新'.

      WAIT UP TO 1 SECONDS.
      PERFORM frm_ready_report.
      re_selfield-refresh = 'X'.
    WHEN 'RESEND2'.
      gv_new_id = 'X'.
      PERFORM frm_resend.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = 50
          text       = '等待2秒数据库刷新'.
      WAIT UP TO 1 SECONDS.
      PERFORM frm_ready_report.
      re_selfield-refresh = 'X'.
    WHEN 'LEAVE' OR 'EXIT' OR 'CANCEL'.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDFORM.                    "SUB_USER_COMMAND

FORM frm_display_json.
  DATA: ls_data TYPE zfunc_log_data,
        lt_data TYPE TABLE OF zfunc_log_data.
  FIELD-SYMBOLS: <ls_data> TYPE zfunc_log_data.
  DATA: lv_json_string TYPE string.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_data
    FROM zfunc_log_data
    WHERE id = gs_out-id.

  "为了合并数据,使用at end of
  SORT lt_data BY canum.
  LOOP AT lt_data INTO ls_data.
    CLEAR: ls_data-canum .
    MODIFY lt_data FROM ls_data.
  ENDLOOP.

  cl_demo_output=>next_section( `输入数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'I'.
    PERFORM frm_transdisplay_data USING ls_data ''.
  ENDLOOP.

  cl_demo_output=>next_section( `更改数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'C'.
    PERFORM frm_transdisplay_data USING ls_data ''.
  ENDLOOP.

  cl_demo_output=>next_section( `表数据` ).
  LOOP AT lt_data ASSIGNING <ls_data> WHERE func_paramtype = 'T'.

    lv_json_string = lv_json_string && <ls_data>-json_data.
    AT END OF func_parameter.
      PERFORM frm_transdisplay_data USING <ls_data> lv_json_string.
      CLEAR: lv_json_string.
    ENDAT.
  ENDLOOP.

  cl_demo_output=>end_section( ).
  cl_demo_output=>display( ).


ENDFORM.


FORM frm_display_return_json.
  DATA: ls_data TYPE zfunc_log_data,
        lt_data TYPE TABLE OF zfunc_log_data.
  FIELD-SYMBOLS: <ls_data> TYPE zfunc_log_data.
  DATA: lv_json_string TYPE string.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_data
    FROM zfunc_log_data_e
    WHERE id = gs_out-id.


  "为了合并数据,使用at end of
  SORT lt_data BY canum.
  LOOP AT lt_data INTO ls_data.
    CLEAR: ls_data-canum .
    MODIFY lt_data FROM ls_data.
  ENDLOOP.


  cl_demo_output=>next_section( `输入数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'I'.
    PERFORM frm_transdisplay_data USING ls_data ''.
  ENDLOOP.

  cl_demo_output=>next_section( `输出数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'E'.
    PERFORM frm_transdisplay_data USING ls_data ''.
  ENDLOOP.

  cl_demo_output=>next_section( `更改数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'C'.
    PERFORM frm_transdisplay_data USING ls_data ''.
  ENDLOOP.

  cl_demo_output=>next_section( `表数据` ).
  LOOP AT lt_data ASSIGNING <ls_data> WHERE func_paramtype = 'T'.

    lv_json_string = lv_json_string && <ls_data>-json_data.
    AT END OF func_parameter.
      PERFORM frm_transdisplay_data USING <ls_data> lv_json_string.
      CLEAR: lv_json_string.
    ENDAT.

  ENDLOOP.

  cl_demo_output=>end_section( ).
  cl_demo_output=>display( ).


ENDFORM.

FORM frm_transdisplay_data USING im_data TYPE zfunc_log_data
                                  im_json_data TYPE string.
  DATA: lv_post_data TYPE string.

  "动态创建工作区、内表
  DATA           objekt     TYPE REF TO data.
  FIELD-SYMBOLS  <fs_aber>    TYPE any.



  IF im_data-func_type = 'X'.
    CREATE DATA objekt TYPE (im_data-func_structure).
    ASSIGN objekt->* TO <fs_aber>.
  ELSE.
    if im_data-func_paramtype = 'I' or im_data-func_paramtype = 'E'.
      CREATE DATA objekt TYPE (im_data-func_structure)."防止importing\exporting参数类型为like时dump
      ASSIGN objekt->* TO <fs_aber>.
    ELSE.
      CREATE DATA objekt TYPE TABLE OF (im_data-func_structure).
      ASSIGN objekt->* TO <fs_aber>.
    ENDIF.
  ENDIF.

  IF im_json_data IS NOT INITIAL.
    lv_post_data = im_json_data.
  ELSE.
    lv_post_data = im_data-json_data.
  ENDIF.
  /ui2/cl_json=>deserialize( EXPORTING json = lv_post_data
                                       pretty_name = /ui2/cl_json=>pretty_mode-camel_case
                             CHANGING data = <fs_aber> ).
  lv_post_data = im_data-func_parameter.
  cl_demo_output=>write_data( value = <fs_aber> name = lv_post_data ).
ENDFORM.

FORM frm_display_json_old.

  DATA: ls_data TYPE zfunc_log_data,
        lt_data TYPE TABLE OF zfunc_log_data.
  DATA: lv_post_data TYPE string.

  DATA: lv_json_string TYPE string.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_data
    FROM zfunc_log_data
    WHERE id = gs_out-id.

  "为了合并数据,使用at end of
  SORT lt_data BY canum.
  LOOP AT lt_data INTO ls_data.
    CLEAR: ls_data-canum .
    MODIFY lt_data FROM ls_data.
  ENDLOOP.

  cl_demo_output=>next_section( `输入数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'I'.
    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    cl_demo_output=>write_data( value = ls_data-json_data name = lv_post_data ).
  ENDLOOP.

  cl_demo_output=>next_section( `更改数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'C'.
    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    cl_demo_output=>write_data( value = ls_data-json_data name = lv_post_data ).
  ENDLOOP.

  cl_demo_output=>next_section( `表数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'T'.

    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    lv_json_string = lv_json_string && ls_data-json_data.
    AT END OF func_parameter.
      cl_demo_output=>write_data( value = lv_json_string name = lv_post_data ).
      CLEAR: lv_json_string.
    ENDAT.
  ENDLOOP.

  cl_demo_output=>end_section( ).
  cl_demo_output=>display( ).
ENDFORM.


FORM frm_display_return_json_old.

  DATA: ls_data TYPE zfunc_log_data,
        lt_data TYPE TABLE OF zfunc_log_data.
  DATA: lv_post_data TYPE string.

  DATA: lv_json_string TYPE string.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_data
    FROM zfunc_log_data_e
    WHERE id = gs_out-id.


  "为了合并数据,使用at end of
  SORT lt_data BY canum.
  LOOP AT lt_data INTO ls_data.
    CLEAR: ls_data-canum .
    MODIFY lt_data FROM ls_data.
  ENDLOOP.



  cl_demo_output=>next_section( `输入数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'I'.
    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    cl_demo_output=>write_data( value = ls_data-json_data name = lv_post_data ).
  ENDLOOP.

  cl_demo_output=>next_section( `输出数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'E'.
    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    cl_demo_output=>write_data( value = ls_data-json_data name = lv_post_data ).
  ENDLOOP.

  cl_demo_output=>next_section( `更改数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'C'.
    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    cl_demo_output=>write_data( value = ls_data-json_data name = lv_post_data ).
  ENDLOOP.

  cl_demo_output=>next_section( `表数据` ).
  LOOP AT lt_data INTO ls_data WHERE func_paramtype = 'T'.

    lv_post_data = ls_data-func_parameter && `  参照类型(` && ls_data-func_structure && ')'.
    lv_json_string = lv_json_string && ls_data-json_data.
    AT END OF func_parameter.
      cl_demo_output=>write_data( value = lv_json_string name = lv_post_data ).
      CLEAR: lv_json_string.
    ENDAT.

  ENDLOOP.

  cl_demo_output=>end_section( ).
  cl_demo_output=>display( ).
ENDFORM.

FORM frm_resend.
  DATA: ls_data TYPE zfunc_log_data,
        lt_data TYPE TABLE OF zfunc_log_data.
  FIELD-SYMBOLS: <ls_data> TYPE zfunc_log_data.

  DATA: ls_ptab TYPE abap_func_parmbind,
        lt_ptab TYPE abap_func_parmbind_tab.
  DATA: lt_etab TYPE abap_func_excpbind_tab.
  DATA: BEGIN OF ls_id,
          sel,
          id        TYPE zfunc_log-id,
          func_name TYPE zfunc_log-func_name,
        END OF ls_id,
        lt_id LIKE TABLE OF ls_id.
  DATA: lv_post_data TYPE string.
  DATA: lv_json_string TYPE string.

  DATA           objekt     TYPE REF TO data.
  FIELD-SYMBOLS  <fs_aber>    TYPE any.

  CLEAR: lt_ptab[],
         lt_data[].

  lt_id = CORRESPONDING #( gt_out[] ).
  DELETE lt_id WHERE sel = ''.

  IF lt_id[] IS NOT INITIAL.
    SELECT *
      INTO CORRESPONDING FIELDS OF TABLE lt_data
      FROM zfunc_log_data
      FOR ALL ENTRIES IN lt_id
      WHERE id = lt_id-id.


    "为了合并数据,使用at end of
    SORT lt_data BY id canum.
    LOOP AT lt_data INTO ls_data.
      CLEAR: ls_data-canum .
      MODIFY lt_data FROM ls_data.
    ENDLOOP.
  ENDIF.


  LOOP AT lt_id INTO ls_id.
    CLEAR: lt_ptab[],
           lt_etab[]. " ADD BY HEZZ AT 20190105

    gv_zz_log_id = ls_id-id. "赋值当前ID
    LOOP AT lt_data ASSIGNING <ls_data> WHERE id = ls_id-id .
      "动态创建工作区、内表
      IF <ls_data>-func_type = 'X'.
        CREATE DATA objekt TYPE (<ls_data>-func_structure).
        ASSIGN objekt->* TO <fs_aber>.
      ELSE.
        CREATE DATA objekt TYPE TABLE OF (<ls_data>-func_structure).
        ASSIGN objekt->* TO <fs_aber>.
      ENDIF.

      lv_json_string = lv_json_string && <ls_data>-json_data.

      AT END OF func_parameter.

        /ui2/cl_json=>deserialize( EXPORTING json = lv_json_string
                                             pretty_name = /ui2/cl_json=>pretty_mode-camel_case
                                   CHANGING data = <fs_aber> ).

        ls_ptab-value = objekt.
*      ls_ptab-tables_wa = ''.
        ls_ptab-name      = <ls_data>-func_parameter.
        CASE <ls_data>-func_paramtype.
          WHEN 'I'.
            ls_ptab-kind      = abap_func_exporting.
          WHEN 'C'.
            ls_ptab-kind      = abap_func_changing.
          WHEN 'T'.
            ls_ptab-kind      = abap_func_tables.
          WHEN OTHERS.
        ENDCASE.

        INSERT ls_ptab INTO TABLE lt_ptab.
        CLEAR: ls_ptab.
        CLEAR: lv_json_string.
      ENDAT.
    ENDLOOP.

    "调用函数
    TRY .
        CALL FUNCTION ls_id-func_name
          PARAMETER-TABLE lt_ptab
          EXCEPTION-TABLE lt_etab.
      CATCH cx_root INTO gcl_root .
        DATA(lv_text) = gcl_root->if_message~get_longtext( ).
        MESSAGE i001(00) WITH '函数' ls_id-func_name '异常,' lv_text.
    ENDTRY.
  ENDLOOP.
ENDFORM.

2.接口
接口:ZFUNC_SAVE

FUNCTION ZFUNC_SAVE.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(HEAD) TYPE  ZFUNC_LOG
*"  TABLES
*"      DATA STRUCTURE  ZFUNC_LOG_DATA
*"      DATA_E STRUCTURE  ZFUNC_LOG_DATA_E
*"----------------------------------------------------------------------


IF head IS NOT INITIAL.
    MODIFY zfunc_log FROM head.
  ENDIF.
  IF data[] IS NOT INITIAL.
    MODIFY zfunc_log_data FROM TABLE data.
    COMMIT WORK AND WAIT.
  ENDIF.

  IF data_e[] IS NOT INITIAL.

    MODIFY zfunc_log_data_e FROM TABLE data_e.
    COMMIT WORK AND WAIT.
  ENDIF.
ENDFUNCTION.

接口:ZFUNC_UPDATE_STATU

FUNCTION ZFUNC_UPDATE_STATU.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_ID) TYPE  ZFUNC_LOG_ID
*"     VALUE(I_MSGTY) TYPE  MSGTY
*"     VALUE(I_MSGTXT) TYPE  MSGTXT
*"----------------------------------------------------------------------

DATA: ls_log TYPE zfunc_log.
  DATA: lv_d_beg   TYPE dats,
        lv_t_beg   TYPE tims,
        lv_d_end   TYPE dats,
        lv_t_end   TYPE tims,
        lv_seconds TYPE int4.

  CLEAR: ls_log,lv_d_beg,lv_t_beg,lv_d_end,lv_t_end,lv_seconds.

  DO 3 TIMES.
    SELECT SINGLE  *
       INTO CORRESPONDING FIELDS OF ls_log
       FROM zfunc_log
       WHERE id = i_id.
    IF ls_log IS INITIAL.
      WAIT UP TO 1 SECONDS.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.


  GET TIME STAMP FIELD ls_log-tzntstmps_end ."结束时间戳

  IF ls_log-tzntstmps_beg IS INITIAL.
    ls_log-tzntstmps_beg = ls_log-tzntstmps_end.
  ENDIF.

  CONVERT TIME STAMP ls_log-tzntstmps_beg TIME ZONE 'UTC+8' INTO DATE lv_d_beg TIME lv_t_beg.
  CONVERT TIME STAMP ls_log-tzntstmps_end TIME ZONE 'UTC+8' INTO DATE lv_d_end TIME lv_t_end.

  "开始结束差值
  CALL FUNCTION 'SALP_SM_CALC_TIME_DIFFERENCE'
    EXPORTING
      date_1  = lv_d_end
      time_1  = lv_t_end
      date_2  = lv_d_beg
      time_2  = lv_t_beg
    IMPORTING
      seconds = lv_seconds.

  ls_log-tzntstmps = lv_seconds.
  ls_log-msgty = i_msgty.
  ls_log-msgtxt = i_msgtxt.
  UPDATE zfunc_log SET tzntstmps = ls_log-tzntstmps
                   tzntstmps_end = ls_log-tzntstmps_end
                           msgty = ls_log-msgty
                          msgtxt = ls_log-msgtxt
                          WHERE id = i_id.
  COMMIT WORK AND WAIT.

ENDFUNCTION.

4.调用方式
包含文件:ZFUNC_TOP

*&---------------------------------------------------------------------*
*& Include ZFUNC_TOP
*&---------------------------------------------------------------------*
"因为通用名称,所以变量必须特殊
DATA: ls_zz_log_callstack TYPE sys_calls,
      lt_zz_log_callstack TYPE sys_callst.

DATA: ls_zz_log_save TYPE zfunc_log.

DATA: ls_zz_log_data_save TYPE zfunc_log_data,
      lt_zz_log_data_save TYPE TABLE OF zfunc_log_data.

DATA: ls_zz_log_fupararef TYPE fupararef,
      lt_zz_log_fupararef TYPE TABLE OF fupararef.

DATA: lv_zz_log_table_name TYPE string.

DATA: lv_zz_log_id TYPE zfunc_log_data-id.

DATA: lv_zz_log_opcode_usr_attr(1) TYPE x VALUE 5,
      lv_zz_log_terminal           TYPE usr41-terminal.
DATA: lv_zz_log_ip TYPE string.

"判断是否产生new id
DATA: lv_zz_log_is_run TYPE abap_bool.


FIELD-SYMBOLS: <fs_zz_log_variable> TYPE any.
FIELD-SYMBOLS: <fs_zz_log_variable_tab> TYPE ANY TABLE.

DATA: lv_zz_log_string TYPE string.

DATA:lv_zz_code TYPE msgty,
      lv_zz_message TYPE msgtxt.

包含文件:ZFUNC_BEGIN

*&---------------------------------------------------------------------*
*& Include ZFUNC_BEGIN
*&---------------------------------------------------------------------*

lv_zz_log_is_run = 'X'.

"读取重运行程序的运行ID
ASSIGN ('(ZFUNC_LOG)GV_ZZ_LOG_ID')  TO FIELD-SYMBOL(<fs_zz_log_id>).
IF <fs_zz_log_id> IS ASSIGNED.
  lv_zz_log_id = <fs_zz_log_id>.
ENDIF.

"读取重运行程序的命令
ASSIGN ('(ZFUNC_LOG)GV_NEW_ID') TO FIELD-SYMBOL(<fs_new_id>).
IF <fs_new_id> IS ASSIGNED .
  lv_zz_log_is_run = <fs_new_id>.
  IF <fs_new_id> IS NOT INITIAL.
    CLEAR: lv_zz_log_id.
  ENDIF.
ENDIF.


IF lv_zz_log_is_run IS NOT INITIAL. "运行标志

  CLEAR: lt_zz_log_data_save[].

  CALL FUNCTION 'SYSTEM_CALLSTACK'
    IMPORTING
*     callstack    = callstack
      et_callstack = lt_zz_log_callstack.

  "read first function name
  CLEAR: ls_zz_log_callstack.
  READ TABLE lt_zz_log_callstack INTO ls_zz_log_callstack WITH KEY eventtype = 'FUNC'.
  IF lt_zz_log_callstack IS INITIAL.
    EXIT.
  ENDIF.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_zz_log_fupararef
    FROM fupararef
   WHERE funcname = ls_zz_log_callstack-eventname.

  LOOP AT lt_zz_log_fupararef INTO ls_zz_log_fupararef WHERE paramtype NE 'E'.
    CLEAR: ls_zz_log_data_save.
    ls_zz_log_data_save-func_name       = ls_zz_log_callstack-eventname. "函数名称
    ls_zz_log_data_save-func_paramtype  = ls_zz_log_fupararef-paramtype.
    ls_zz_log_data_save-func_parameter  = ls_zz_log_fupararef-parameter.
    ls_zz_log_data_save-func_structure  = ls_zz_log_fupararef-structure.
    ls_zz_log_data_save-func_defaultval = ls_zz_log_fupararef-defaultval.
    ls_zz_log_data_save-func_type       = ls_zz_log_fupararef-type.
    ls_zz_log_data_save-func_class      = ls_zz_log_fupararef-class.
    ls_zz_log_data_save-func_ref_class  = ls_zz_log_fupararef-ref_class.

    IF ls_zz_log_fupararef-paramtype NE 'T'.
      ASSIGN (ls_zz_log_fupararef-parameter) TO <fs_zz_log_variable>.
      IF <fs_zz_log_variable> IS ASSIGNED.
        IF <fs_zz_log_variable> IS NOT INITIAL OR ls_zz_log_fupararef-defaultval IS NOT INITIAL.
          lv_zz_log_string = /ui2/cl_json=>serialize( data = <fs_zz_log_variable>
                                          compress = abap_true pretty_name = abap_true ).
        ENDIF.
      ENDIF.
    ELSE.
      lv_zz_log_table_name = ls_zz_log_fupararef-parameter && '[]'.
      ASSIGN (lv_zz_log_table_name) TO <fs_zz_log_variable_tab>.
      IF <fs_zz_log_variable_tab> IS ASSIGNED.
        IF <fs_zz_log_variable_tab> IS NOT INITIAL.
          lv_zz_log_string = /ui2/cl_json=>serialize( data = <fs_zz_log_variable_tab> compress = abap_true pretty_name = abap_true ).
        ENDIF.
      ENDIF.
    ENDIF.

    WHILE strlen( lv_zz_log_string ) > 0.
      IF strlen( lv_zz_log_string ) >= 1024 .
        ls_zz_log_data_save-json_data = lv_zz_log_string.
        APPEND ls_zz_log_data_save TO lt_zz_log_data_save.
        SHIFT lv_zz_log_string BY 1024 PLACES.
      ELSE.
        ls_zz_log_data_save-json_data = lv_zz_log_string.
        APPEND ls_zz_log_data_save TO lt_zz_log_data_save.
        CLEAR: lv_zz_log_string.
      ENDIF.
    ENDWHILE.
  ENDLOOP.

  "生成一个log id.
  IF lv_zz_log_id IS INITIAL.
    CALL FUNCTION 'NUMBER_GET_NEXT'
      EXPORTING
        nr_range_nr             = '01'
        object                  = 'ZFUNC_LOG'
      IMPORTING
        number                  = lv_zz_log_id
      EXCEPTIONS
        interval_not_found      = 1
        number_range_not_intern = 2
        object_not_found        = 3
        quantity_is_0           = 4
        quantity_is_not_1       = 5
        interval_overflow       = 6
        buffer_overflow         = 7
        OTHERS                  = 8.
  ENDIF.


  "网页计算机名称就是IP地址
  CALL 'ThUsrInfo' ID 'OPCODE'  FIELD lv_zz_log_opcode_usr_attr
                   ID'TERMINAL' FIELD lv_zz_log_terminal.

  DATA: lv_zz_log_regex TYPE string.
  lv_zz_log_regex = '((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))))'.
  IF NOT contains( val = lv_zz_log_terminal regex = lv_zz_log_regex ).
    CALL METHOD cl_gui_frontend_services=>get_ip_address
      RECEIVING
        ip_address           = lv_zz_log_ip
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        OTHERS               = 4.
    IF sy-subrc <> 0.
      CLEAR: lv_zz_log_ip.
    ENDIF.

  ELSE.
    lv_zz_log_ip = lv_zz_log_terminal.
  ENDIF.

  "赋值抬头
  ls_zz_log_save-id         = lv_zz_log_id.
  ls_zz_log_save-func_name  = ls_zz_log_callstack-eventname.
  ls_zz_log_save-erdat      = sy-datum.
  ls_zz_log_save-erzet      = sy-uzeit.
  ls_zz_log_save-ernam      = sy-uname.
  ls_zz_log_save-xuterminal = lv_zz_log_terminal.
  ls_zz_log_save-ip         = lv_zz_log_ip.
  ls_zz_log_save-msgty      = 'I'.
  ls_zz_log_save-msgtxt     = '开始调用'.
  GET TIME STAMP FIELD ls_zz_log_save-tzntstmps_beg."开始时间戳


  "赋值行项目
  LOOP AT lt_zz_log_data_save INTO ls_zz_log_data_save.
    ls_zz_log_data_save-id = lv_zz_log_id.
    ls_zz_log_data_save-canum = sy-tabix.
    MODIFY lt_zz_log_data_save FROM ls_zz_log_data_save.
  ENDLOOP.

  "把数据弄成异步提交模式保存,避免事务提交。
  CALL FUNCTION 'ZFUNC_SAVE' STARTING NEW TASK 'ZFUNC_BEGIN'
    EXPORTING
      head = ls_zz_log_save
    TABLES
      data = lt_zz_log_data_save.


ENDIF.

包含文件:

*&---------------------------------------------------------------------*
*& Include ZFUNC_END
*&---------------------------------------------------------------------*


IF lv_zz_log_id IS NOT INITIAL. "运行标志

  CLEAR: lt_zz_log_data_save[].

  CALL FUNCTION 'SYSTEM_CALLSTACK'
    IMPORTING
*     callstack    = callstack
      et_callstack = lt_zz_log_callstack.

  "read first function name
  CLEAR: ls_zz_log_callstack.
  READ TABLE lt_zz_log_callstack INTO ls_zz_log_callstack WITH KEY eventtype = 'FUNC'.
  IF lt_zz_log_callstack IS INITIAL.
    EXIT.
  ENDIF.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE lt_zz_log_fupararef
    FROM fupararef
   WHERE funcname = ls_zz_log_callstack-eventname.

  LOOP AT lt_zz_log_fupararef INTO ls_zz_log_fupararef.
    CLEAR: ls_zz_log_data_save.
    ls_zz_log_data_save-func_name       = ls_zz_log_callstack-eventname. "函数名称
    ls_zz_log_data_save-func_paramtype  = ls_zz_log_fupararef-paramtype.
    ls_zz_log_data_save-func_parameter  = ls_zz_log_fupararef-parameter.
    ls_zz_log_data_save-func_structure  = ls_zz_log_fupararef-structure.
    ls_zz_log_data_save-func_defaultval = ls_zz_log_fupararef-defaultval.
    ls_zz_log_data_save-func_type       = ls_zz_log_fupararef-type.
    ls_zz_log_data_save-func_class      = ls_zz_log_fupararef-class.
    ls_zz_log_data_save-func_ref_class  = ls_zz_log_fupararef-ref_class.

    IF ls_zz_log_fupararef-paramtype NE 'T'.
      ASSIGN (ls_zz_log_fupararef-parameter) TO <fs_zz_log_variable>.
      IF <fs_zz_log_variable> IS ASSIGNED.
        IF <fs_zz_log_variable> IS NOT INITIAL OR ls_zz_log_fupararef-defaultval IS NOT INITIAL.
          lv_zz_log_string = /ui2/cl_json=>serialize( data = <fs_zz_log_variable> compress = abap_true pretty_name = abap_true ).
        ENDIF.
      ENDIF.
    ELSE.
      lv_zz_log_table_name = ls_zz_log_fupararef-parameter && '[]'.
      ASSIGN (lv_zz_log_table_name) TO <fs_zz_log_variable_tab>.
      IF <fs_zz_log_variable_tab> IS ASSIGNED.
        IF <fs_zz_log_variable_tab> IS NOT INITIAL.
          lv_zz_log_string = /ui2/cl_json=>serialize( data = <fs_zz_log_variable_tab> compress = abap_true pretty_name = abap_true ).
        ENDIF.
      ENDIF.
    ENDIF.

    WHILE strlen( lv_zz_log_string ) > 0.
      IF strlen( lv_zz_log_string ) >= 1024 .
        ls_zz_log_data_save-json_data = lv_zz_log_string.
        APPEND ls_zz_log_data_save TO lt_zz_log_data_save.
        SHIFT lv_zz_log_string BY 1024 PLACES.
      ELSE.
        ls_zz_log_data_save-json_data = lv_zz_log_string.
        APPEND ls_zz_log_data_save TO lt_zz_log_data_save.
        CLEAR: lv_zz_log_string.
      ENDIF.
    ENDWHILE.
  ENDLOOP.



  "赋值行项目
  LOOP AT lt_zz_log_data_save INTO ls_zz_log_data_save.
    ls_zz_log_data_save-id = lv_zz_log_id.
    ls_zz_log_data_save-canum = sy-tabix.
    MODIFY lt_zz_log_data_save FROM ls_zz_log_data_save.
  ENDLOOP.

  "把数据弄成异步提交模式保存,避免事务提交。
  CALL FUNCTION 'ZFUNC_SAVE' STARTING NEW TASK 'ZFUNC_END'
    TABLES
      data_e = lt_zz_log_data_save.


ENDIF.

模块池:ZFUNC

*&---------------------------------------------------------------------*
*& Modulpool ZFUNC
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
PROGRAM ZFUNC.

FORM update_status USING im_log_id TYPE zfunc_log_data-id
                         im_code TYPE msgty
                         im_txt TYPE msgtxt.
  IF im_log_id IS NOT INITIAL.

    "必须要调用 zfunc_begin 后才能调用该函数
    CALL FUNCTION 'ZFUNC_UPDATE_STATU' STARTING NEW TASK 'ZFUNC_LOG'
      EXPORTING
        i_id     = im_log_id
        i_msgty  = im_code
        i_msgtxt = im_txt.
  ENDIF.

ENDFORM.

接口测试方法:

FUNCTION ZFUC_TEST01.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     REFERENCE(IV_01) TYPE  MATNR
*"     REFERENCE(I_BEDAT) TYPE  EKKO-BEDAT
*"     REFERENCE(I_DAT) TYPE  DATUM
*"     REFERENCE(I_LIKE) LIKE  EKKO-BEDAT
*"     REFERENCE(I_MARA) LIKE  MARA STRUCTURE  MARA
*"     REFERENCE(R_AKTIO) TYPE  RANGE_AKTIO_TAB
*"  TABLES
*"      IT_OUT STRUCTURE  MARA OPTIONAL
*"----------------------------------------------------------------------
INCLUDE zfunc_top.
INCLUDE zfunc_begin.



select
  * INTO TABLE IT_OUT
  FROM mara
  WHERE matnr = IV_01.


PERFORM update_status(ZFUNC) USING lv_zz_log_id 'S' '成功'.
INCLUDE zfunc_end.

ENDFUNCTION.
显示全文