接口通用日志存储,以及查看

  在外部调用接口时,通常会需要保存外部的调用记录,期间会用到表,这里将传入的表转换成json格式(也可以转换成XML),并存入通用日志表中。

1.SE11,新建通用的LOG表,表结构参考下图:

接口通用日志存储,以及查看

 

 

 2.在接口中,如果需要保存记录,则调用下面代码。

接口通用日志存储,以及查看
DATA: json_ser TYPE REF TO cl_trex_json_serializer,
        json_des TYPE REF TO cl_trex_json_deserializer.
  DATA: jsonstr TYPE string.

CREATE OBJECT json_ser
    EXPORTING
      data = it_plm007[].
  CALL METHOD json_ser->serialize.
  CALL METHOD json_ser->get_data
    RECEIVING
      rval = jsonstr.

  ls_zrfc_logs-funcname   = Z_RFC_PLM_007.
  ls_zrfc_logs-zsystem    = p_system.
  ls_zrfc_logs-uname      = p_uname.
  ls_zrfc_logs-zname1     = p_name1.
  ls_zrfc_logs-erdat      = sy-datum.
  ls_zrfc_logs-uzeit      = sy-uzeit.
*  ls_zrfc_logs-ep_type    = ep_type.
*  ls_zrfc_logs-ep_message = ep_message.
  ls_zrfc_logs-jsonstr1   = jsonstr.

  MODIFY zrfc_logs FROM ls_zrfc_logs.
  IF sy-subrc EQ 0.
    COMMIT WORK AND WAIT.
  ELSE.
    ROLLBACK WORK.
  ENDIF.
View Code

3.写个查看日志的报表

效果如下图所示

接口通用日志存储,以及查看

 

 

 接口通用日志存储,以及查看

 

 

 附上代码:

主程序:

接口通用日志存储,以及查看
*&---------------------------------------------------------------------*
*& Report ZIT0010
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zit0010.
INCLUDE zit0010_head.
INCLUDE zit0010_screen.
INCLUDE zit0010_form.



START-OF-SELECTION.
  PERFORM frm_get_data. "动态创建内表 <dyn_table>,并生成lt_alv_cat
  PERFORM frm_get_data2.

END-OF-SELECTION.
  PERFORM f_display_data.
View Code

包含文件ZIT0010_HEAD

接口通用日志存储,以及查看
*&---------------------------------------------------------------------*
*& 包含               ZIT0010_HEAD
*&---------------------------------------------------------------------*

TABLES:tftit.

DATA: d_ref      TYPE REF TO data,
      d_ref2     TYPE REF TO data,
      lt_alv_cat TYPE TABLE OF lvc_s_fcat,
      ls_alv_cat LIKE LINE OF lt_alv_cat.

DATA: lt_table LIKE TABLE OF dntab.
DATA: ls_table TYPE dntab.

DATA: dyn_table TYPE REF TO data.
DATA: dyn_wa TYPE REF TO data.
FIELD-SYMBOLS :<dyn_table> TYPE table,
               <dyn_wa>    TYPE any,
               <dyn_field> TYPE any,
               <fs_str>    TYPE any.


DATA: dyn_table2 TYPE REF TO data.
DATA: dyn_wa2 TYPE REF TO data.


FIELD-SYMBOLS :<dyn_table2> TYPE table,
               <dyn_wa2>    TYPE any,
               <dyn_field2> TYPE any,
               <fs_str2>    TYPE any.
DATA: go_excel    TYPE ole2_object,
      go_workbook TYPE ole2_object,
      go_sheet    TYPE ole2_object.
DATA: gs_layout   TYPE lvc_s_layo,
      gt_fieldcat TYPE lvc_t_fcat.

TYPES: BEGIN OF sy_output,
         funcname   TYPE  zrfc_logs-funcname,
         zsystem    TYPE  zrfc_logs-zsystem,
         uname      TYPE  zrfc_logs-uname,
         zname1     TYPE  zrfc_logs-zname1,
         erdat      TYPE  zrfc_logs-erdat,
         uzeit      TYPE  zrfc_logs-uzeit,
         posnr      TYPE  zrfc_logs-posnr,
         p_str1     TYPE  zrfc_logs-p_str1,
         p_str2     TYPE  zrfc_logs-p_str2,
         p_str3     TYPE  zrfc_logs-p_str3,
         p_str4     TYPE  zrfc_logs-p_str4,
         p_str5     TYPE  zrfc_logs-p_str5,
         ep_type    TYPE  zrfc_logs-ep_type,
         ep_message TYPE  zrfc_logs-ep_message,
         jsonstr1   TYPE  zrfc_logs-jsonstr1,
         jsonstr2   TYPE  zrfc_logs-jsonstr2,
         jsonstr3   TYPE  zrfc_logs-jsonstr3,
         jsonstr4   TYPE  zrfc_logs-jsonstr4,
         jsonstr5   TYPE  zrfc_logs-jsonstr5,
         structure  TYPE  fupararef-structure.
TYPES: zcolor(4),
       message   TYPE char200, "
       cellcolor TYPE lvc_t_scol,
       slbox,
       END OF sy_output.

DATA: gt_output TYPE TABLE OF sy_output,
      gs_output TYPE sy_output.
DATA: gt_fupararef LIKE TABLE OF fupararef,
      gs_fupararef LIKE fupararef.

DATA: gt_events TYPE slis_t_event,
      gs_events LIKE LINE OF gt_events.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA: gt_bad_cells TYPE lvc_t_modi.
*data: gt_fieldcat type lvc_t_fcat.
DATA: g_row_id TYPE lvc_s_roid-row_id.
FIELD-SYMBOLS: <gs_outtab> TYPE any.

CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA:go_grid           TYPE REF TO cl_gui_alv_grid,
     go_event_receiver TYPE REF TO lcl_event_receiver.

*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
        IMPORTING sender
                    e_fieldname
                    e_fieldvalue
                    es_row_no
                    er_event_data
                    et_bad_cells
                    e_display,
      on_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING e_onf4
                    e_onf4_before
                    e_onf4_after
                    er_data_changed
                    e_ucomm
                    sender.
*  PRIVATE SECTION.
*    TYPES: ddshretval_table TYPE TABLE OF ddshretval.
*    CLASS-METHODS: my_f4
*      IMPORTING sender        TYPE REF TO cl_gui_alv_grid
*                et_bad_cells  TYPE lvc_t_modi
*                es_row_no     TYPE lvc_s_roid
*                er_event_data TYPE REF TO cl_alv_event_data
*                e_display     TYPE c
*                e_fieldname   TYPE lvc_fname
*      EXPORTING im_lt_f4      TYPE ddshretval_table.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD on_f4.
*    FIELD-SYMBOLS:<fs_alv> TYPE gs_output.
    CASE e_fieldname.
      WHEN STRUCTURE.
        READ TABLE gt_output ASSIGNING FIELD-SYMBOL(<fs_alv>) INDEX es_row_no-row_id.
        IF sy-subrc = 0.
          PERFORM frm_get_sturct_f4 USING <fs_alv>-funcname CHANGING <fs_alv>-structure.
          LOOP AT gt_output ASSIGNING FIELD-SYMBOL(<ls_output>) WHERE funcname EQ <fs_alv>-funcname.
            <ls_output>-structure = <fs_alv>-structure.
          ENDLOOP.
        ENDIF.

* WHEN .
      WHEN OTHERS.
    ENDCASE.
    PERFORM f_refresh_alv.

*    CALL METHOD go_grid->refresh_table_display.
*    DATA: ls_f4 TYPE ddshretval,
*          lt_f4 TYPE TABLE OF ddshretval.
*    FIELD-SYMBOLS: <itab> TYPE lvc_t_modi.
*    DATA: ls_modi TYPE lvc_s_modi.
*    CALL METHOD my_f4
*      EXPORTING
*        sender        = sender
*        es_row_no     = es_row_no
*        er_event_data = er_event_data
*        et_bad_cells  = et_bad_cells
*        e_display     = e_display
*        e_fieldname   = e_fieldname
*      IMPORTING
*        im_lt_f4      = lt_f4.
*    ASSIGN er_event_data->m_data->* TO <itab>.
*    read table lt_f4 into ls_f4 with key fieldname = ‘STRUCTURE‘.
*    if not ls_f4 is initial.
*      ls_modi-row_id    = es_row_no-row_id.
*      ls_modi-fieldname = ‘STRUCTURE‘.
*      ls_modi-value     = ls_f4-fieldval.
*      append ls_modi to <itab>.
*      ls_modi-row_id = es_row_no-row_id.
*      ls_modi-fieldname = ‘VALUE‘.
*      if ls_f4-fieldval < ‘D‘.
*        ls_modi-value = 100.
*      elseif ls_f4-fieldval < ‘R‘.
*        ls_modi-value = 1000.
*      else.
*        ls_modi-value = 10000.
*      endif.
*      append ls_modi to <itab>.
*    endif.
*    READ TABLE lt_f4 INTO ls_f4 WITH KEY fieldname = ‘STRUCTURE‘.
*    IF NOT ls_f4 IS INITIAL.
*      ls_modi-row_id    = es_row_no-row_id.
*      ls_modi-fieldname = ‘STRUCTURE‘.
*      ls_modi-value     = ls_f4-fieldval.
*      APPEND ls_modi TO <itab>.
*    ENDIF.
*    er_event_data->m_event_handled = ‘X‘.
  ENDMETHOD.
  METHOD on_data_changed.
  ENDMETHOD.                    "on_data_changed
*  METHOD my_f4.
*    DATA: lw_tab      LIKE LINE OF gt_output,
*          lt_fcat     TYPE lvc_t_fcat,
*          ls_fieldcat TYPE lvc_s_fcat,
*          l_tabname   TYPE dd03v-tabname,
*          l_fieldname TYPE dd03v-fieldname,
*          l_help_valu TYPE help_info-fldvalue,
*          lt_bad_cell TYPE lvc_t_modi,
*          lp_wa       TYPE REF TO data.
*    FIELD-SYMBOLS: <l_field_value> TYPE any,
*                   <ls_wa>         TYPE any.
*    CALL METHOD sender->get_frontend_fieldcatalog
*      IMPORTING
*        et_fieldcatalog = lt_fcat.
*    READ TABLE gt_output INDEX es_row_no-row_id INTO lw_tab.
*    CREATE DATA lp_wa LIKE LINE OF gt_output.
*    ASSIGN lp_wa->* TO <ls_wa>.
*    <ls_wa> = lw_tab.
*    READ TABLE lt_fcat WITH KEY fieldname = e_fieldname INTO ls_fieldcat.
*    MOVE ls_fieldcat-ref_table TO l_tabname.
*    MOVE ls_fieldcat-fieldname TO l_fieldname.
*    ASSIGN COMPONENT ls_fieldcat-fieldname OF STRUCTURE lw_tab TO <l_field_value>.
*    WRITE <l_field_value> TO l_help_valu.
*    PERFORM f4_set USING sender
*                       lt_fcat
*                       lt_bad_cell
*                       es_row_no-row_id
*                       <ls_wa>.
*    CALL FUNCTION ‘F4IF_FIELD_VALUE_REQUEST‘
*      EXPORTING
*        tabname          = l_tabname
*        fieldname        = l_fieldname
*        display          = e_display
*        value            = l_help_valu
*        callback_program = ‘STRUCTURE‘ "‘ZTEST7‘
*        callback_form    = ‘F4‘
*      TABLES
*        return_tab       = im_lt_f4
*      EXCEPTIONS
*        parameter_error  = 1
*        no_values_found  = 2
*        OTHERS           = 3.
*  ENDMETHOD.                                               "my_f4
ENDCLASS. "lcl_event_receiver

*FORM f4_set USING r_grid TYPE REF TO cl_gui_alv_grid
*                    rt_fieldcat TYPE lvc_t_fcat
*                    rt_bad_cells TYPE lvc_t_modi
*                    r_row_id TYPE lvc_s_roid-row_id
*                    rs_outtab.
*  g_grid = r_grid.
*  gt_fieldcat = rt_fieldcat.
*  gt_bad_cells = rt_bad_cells.
*  g_row_id     = r_row_id.
*  ASSIGN rs_outtab TO <gs_outtab>.
*ENDFORM.                                                    "f4_set
View Code

包含文件ZIT0010_SCREEN

接口通用日志存储,以及查看
*&---------------------------------------------------------------------*
*& 包含               ZIT0010_SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_fname FOR tftit-funcname,
                s_uname FOR sy-uname,
                s_erdat FOR sy-datum.

SELECTION-SCREEN: END OF BLOCK b01.
View Code

包含文件

接口通用日志存储,以及查看
*&---------------------------------------------------------------------*
*& 包含               ZIT0010_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .
*取出表结构的字段目录

  CALL FUNCTION NAMETAB_GET
    EXPORTING
      langu          = sy-langu
      tabname        = ZRFC_LOGS
    TABLES
      nametab        = lt_table
    EXCEPTIONS
      no_texts_found = 1.
*根据取出的字段目录生成参考字段目录

  CLEAR lt_alv_cat.
  LOOP AT lt_table INTO ls_table.
*    IF LS_TABLE-FIELDNAME NE ‘MANDT‘.
    ls_alv_cat-fieldname = ls_table-fieldname.
    ls_alv_cat-ref_table = ZRFC_LOGS.
    ls_alv_cat-ref_field = ls_table-fieldname.
    IF ls_table-fieldname EQ MEINS.
      ls_alv_cat-no_convext = X.
*      CLEAR: ls_alv_cat-ref_field,ls_alv_cat-ref_table.
    ENDIF.
    ls_alv_cat-seltext   = ls_table-fieldtext.
    ls_alv_cat-scrtext_l = ls_table-fieldtext.
    ls_alv_cat-scrtext_m = ls_table-fieldtext.
    ls_alv_cat-scrtext_s = ls_table-fieldtext.
    APPEND ls_alv_cat TO lt_alv_cat.
*    ENDIF.
    CLEAR ls_alv_cat.
  ENDLOOP.

*内表创建

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_alv_cat
    IMPORTING
      ep_table        = d_ref.


*指定生成的内表到字段符号
*  ASSIGN d_ref->* TO <dyn_table>.
*
**创建动态工作区结构
*  CREATE DATA dyn_wa LIKE LINE OF <dyn_table>.

*创建动态工作区
*  ASSIGN dyn_wa->* TO <dyn_wa>.

* zcolor
  DELETE lt_alv_cat[] WHERE fieldname EQ MANDT.
*  ls_alv_cat-fieldname = ‘ZCOLOR‘.
**  ls_alv_cat-ref_table = ‘ZFICOS025‘.
**  ls_alv_cat-ref_field = ‘ZCOLOR‘.
*  ls_alv_cat-seltext   = ‘更新结果‘.
*  ls_alv_cat-scrtext_l = ‘更新结果‘.
*  ls_alv_cat-scrtext_m = ‘更新结果‘.
*  ls_alv_cat-scrtext_s = ‘更新结果‘.
*  APPEND ls_alv_cat TO lt_alv_cat.
*  ls_alv_cat-fieldname = ‘MESSAGE‘.
**  ls_alv_cat-ref_table = ‘ZFICOS025‘.
**  ls_alv_cat-ref_field = ‘MESSAGE‘.
*  ls_alv_cat-seltext   = ‘更新信息‘.
*  ls_alv_cat-scrtext_l = ‘更新信息‘.
*  ls_alv_cat-scrtext_m = ‘更新信息‘.
*  ls_alv_cat-scrtext_s = ‘更新信息‘.
*  APPEND ls_alv_cat TO lt_alv_cat.
  ls_alv_cat-fieldname  = STRUCTURE.
  ls_alv_cat-ref_table  = FUPARAREF.
  ls_alv_cat-ref_field  = STRUCTURE.
  ls_alv_cat-seltext    = JSON转换结构.
  ls_alv_cat-scrtext_l  = JSON转换结构.
  ls_alv_cat-scrtext_m  = JSON转换结构.
  ls_alv_cat-scrtext_s  = JSON转换结构.
  ls_alv_cat-edit       = X.
  ls_alv_cat-f4availabl = X.
  APPEND ls_alv_cat TO lt_alv_cat.
  CLEAR: ls_alv_cat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA2
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data2 .
  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE @gt_output
    FROM zrfc_logs
   WHERE funcname IN @s_fname
     AND uname in @s_uname
     AND erdat IN @s_erdat.
  SELECT *
    INTO TABLE @gt_fupararef
    FROM fupararef
   WHERE funcname IN @s_fname
     AND paramtype EQ T.

  LOOP AT gt_output INTO gs_output.
    READ TABLE gt_fupararef INTO gs_fupararef WITH KEY funcname = gs_output-funcname.
    IF sy-subrc EQ 0.

    ENDIF.
    CLEAR: gs_output.
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_display_data .
  PERFORM f_set_layout.
*  PERFORM F_SET_FIELDCAT.
  PERFORM f_set_event.
  PERFORM f_alv_display TABLES gt_output.
ENDFORM.
FORM f_set_event.
  gs_events-name = CALLER_EXIT.
  gs_events-form = CALLER_EXIT.
  APPEND gs_events TO gt_events[].
ENDFORM.
FORM f_set_layout.
  CLEAR: gs_layout.
  gs_layout-box_fname = SLBOX.
  gs_layout-zebra = X.
  gs_layout-cwidth_opt = X.
  gs_layout-ctab_fname = CELLCOLOR.
ENDFORM.
*FORM F_SET_FIELDCAT.
*  CLEAR: GT_FIELDCAT[].
*  DATA: LS_FIELDCAT TYPE LVC_S_FCAT.
*  DEFINE SET_FIELDCAT.
*    CLEAR: LS_FIELDCAT.
*    LS_FIELDCAT-FIELDNAME = &1.
*    LS_FIELDCAT-REF_FIELD = &2.
*    LS_FIELDCAT-REF_TABLE = &3.
*    LS_FIELDCAT-CONVEXIT  = &4.
*    LS_FIELDCAT-DO_SUM    = &5.
*    LS_FIELDCAT-SELTEXT   = &6.
*    LS_FIELDCAT-SCRTEXT_L = &6.
*    LS_FIELDCAT-SCRTEXT_M = &6.
*    LS_FIELDCAT-SCRTEXT_S = &6.
*    LS_FIELDCAT-COLTEXT   = &6.
*    APPEND LS_FIELDCAT TO GT_FIELDCAT.
*  END-OF-DEFINITION.
**显示内容
*  SET_FIELDCAT ‘RBUKRS‘ ‘RBUKRS‘ ‘ACDOCA‘ ‘‘ ‘‘  ‘公司代码‘.
*  SET_FIELDCAT ‘GJAHR‘  ‘GJAHR‘  ‘ACDOCA‘ ‘‘ ‘‘  ‘会计年度‘.
*  SET_FIELDCAT ‘BUDAT‘  ‘BUDAT‘  ‘ACDOCA‘ ‘‘ ‘‘  ‘过账日期‘.
*ENDFORM.
FORM f_alv_display TABLES it_table.
  CALL FUNCTION REUSE_ALV_GRID_DISPLAY_LVC
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = F_SET_PF_STATUS
      i_callback_user_command  = F_USER_COMMAND
      is_layout_lvc            = gs_layout
      it_events                = gt_events
      it_fieldcat_lvc          = lt_alv_cat
      i_save                   = U
    TABLES
      t_outtab                 = it_table
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM f_set_pf_status USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS STD.
ENDFORM.
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM f_user_command USING r_ucomm LIKE sy-ucomm
 rs_selfield TYPE slis_selfield.
  PERFORM f_check_change_data.
  CASE r_ucomm.
    WHEN ZCHANGE.
*      PERFORM frm_save_zchange. "保存资产更改数据
    WHEN &IC1."双击事件
      READ TABLE gt_output INTO gs_output INDEX rs_selfield-tabindex.
      IF sy-subrc EQ 0.
*        BREAK it0003.
        IF gs_output-structure IS INITIAL.
          MESSAGE 请选择结构名 TYPE S DISPLAY LIKE E.
        ENDIF.
        CHECK NOT gs_output-structure IS INITIAL.

        IF rs_selfield-fieldname+0(7) EQ JSONSTR.
          PERFORM frm_get_lvcs.
          PERFORM frm_change_json USING rs_selfield-fieldname.
          PERFORM frm_display_alv2.
        ENDIF.



      ENDIF.
  ENDCASE.
  PERFORM f_refresh_alv.
ENDFORM.
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM f_check_change_data.
  DATA: lo_grid TYPE REF TO cl_gui_alv_grid.
  CALL FUNCTION GET_GLOBALS_FROM_SLVC_FULLSCR
    IMPORTING
      e_grid = lo_grid.
  lo_grid->check_changed_data( ).
ENDFORM.
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM f_refresh_alv.
  DATA: lo_grid      TYPE REF TO cl_gui_alv_grid,
        ls_is_stable TYPE lvc_s_stbl.
  CALL FUNCTION GET_GLOBALS_FROM_SLVC_FULLSCR
    IMPORTING
      e_grid = lo_grid.
  ls_is_stable-col = X.
  ls_is_stable-row = X.
  lo_grid->refresh_table_display(
  EXPORTING
  is_stable = ls_is_stable
  EXCEPTIONS
  finished = 1
  OTHERS = 2 ).
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.
FORM frm_get_sturct_f4  USING    pc_func TYPE fupararef-funcname
                       CHANGING pc_struc TYPE fupararef-structure.

  DATA:lt_ret_tab TYPE TABLE OF ddshretval WITH HEADER LINE.

  DATA: lt_fupararef LIKE TABLE OF fupararef.
  lt_fupararef[] = gt_fupararef[].
  DELETE lt_fupararef[] WHERE funcname NE pc_func.
*  BREAK it0003.


  CALL FUNCTION F4IF_INT_TABLE_VALUE_REQUEST
    EXPORTING
      retfield        = STRUCTURE
      value_org       = S
    TABLES
      value_tab       = lt_fupararef
      return_tab      = lt_ret_tab
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
  IF sy-subrc = 0.
    READ TABLE lt_ret_tab INDEX 1.
    IF sy-subrc = 0  AND lt_ret_tab-fieldval IS NOT INITIAL.
      pc_struc = lt_ret_tab-fieldval.
    ENDIF.
  ENDIF.

ENDFORM.                    " FRM_GET_ARKTX_F4

FORM caller_exit USING ls_data TYPE slis_data_caller_exit.
*  BREAK it0003.
*  DATA: call_f4 TYPE REF TO lcl_event_receiver.
*  CREATE OBJECT call_f4.
*  CALL METHOD call_f4->HANDLE_F4_HELP.
  DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid.
  DATA: lt_wa_f4 TYPE lvc_s_f4,
        lt_f4    TYPE lvc_t_f4.
  CALL FUNCTION GET_GLOBALS_FROM_SLVC_FULLSCR
    IMPORTING
      e_grid = l_ref_alv.
  SET HANDLER lcl_event_receiver=>on_f4 FOR l_ref_alv.
  SET HANDLER lcl_event_receiver=>on_data_changed FOR l_ref_alv.
  lt_wa_f4-fieldname  = STRUCTURE.
  lt_wa_f4-register   = X.
  lt_wa_f4-getbefore  = X.
  lt_wa_f4-chngeafter = X.
  APPEND lt_wa_f4 TO lt_f4.
  CALL METHOD l_ref_alv->register_f4_for_fields
    EXPORTING
      it_f4 = lt_f4.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_LVCS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*      -->P_RS_SELFIELD_FIELDNAME  text
*&---------------------------------------------------------------------*
FORM frm_get_lvcs.
  FIELD-SYMBOLS :<fs_filed> TYPE any.
  ASSIGN COMPONENT STRUCTURE OF STRUCTURE gs_output TO <fs_filed>.
  CLEAR: lt_table[].
  DATA: lv_tabname TYPE dntab-tabname.
  lv_tabname = <fs_filed>.
*取出表结构的字段目录
  CALL FUNCTION NAMETAB_GET
    EXPORTING
      langu          = sy-langu
      tabname        = lv_tabname
    TABLES
      nametab        = lt_table
    EXCEPTIONS
      no_texts_found = 1.
*根据取出的字段目录生成参考字段目录

  CLEAR lt_alv_cat.
  LOOP AT lt_table INTO ls_table.
*    IF LS_TABLE-FIELDNAME NE ‘MANDT‘.
    ls_alv_cat-fieldname = ls_table-fieldname.
    ls_alv_cat-ref_table = <fs_filed>.
    ls_alv_cat-ref_field = ls_table-fieldname.
    IF ls_table-fieldname EQ MEINS.
      ls_alv_cat-no_convext = X.
*      CLEAR: ls_alv_cat-ref_field,ls_alv_cat-ref_table.
    ENDIF.
    ls_alv_cat-seltext   = ls_table-fieldtext.
    ls_alv_cat-scrtext_l = ls_table-fieldtext.
    ls_alv_cat-scrtext_m = ls_table-fieldtext.
    ls_alv_cat-scrtext_s = ls_table-fieldtext.
    APPEND ls_alv_cat TO lt_alv_cat.
*    ENDIF.
    CLEAR ls_alv_cat.
  ENDLOOP.

*内表创建

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_alv_cat
    IMPORTING
      ep_table        = d_ref.


*指定生成的内表到字段符号
  ASSIGN d_ref->* TO <dyn_table>.

*创建动态工作区结构
  CREATE DATA dyn_wa LIKE LINE OF <dyn_table>.

*创建动态工作区
  ASSIGN dyn_wa->* TO <dyn_wa>.

* zcolor
*  DELETE lt_alv_cat[] WHERE fieldname EQ ‘MANDT‘.
*  ls_alv_cat-fieldname = ‘ZCOLOR‘.
**  ls_alv_cat-ref_table = ‘ZFICOS025‘.
**  ls_alv_cat-ref_field = ‘ZCOLOR‘.
*  ls_alv_cat-seltext   = ‘更新结果‘.
*  ls_alv_cat-scrtext_l = ‘更新结果‘.
*  ls_alv_cat-scrtext_m = ‘更新结果‘.
*  ls_alv_cat-scrtext_s = ‘更新结果‘.
*  APPEND ls_alv_cat TO lt_alv_cat.
*  ls_alv_cat-fieldname = ‘MESSAGE‘.
**  ls_alv_cat-ref_table = ‘ZFICOS025‘.
**  ls_alv_cat-ref_field = ‘MESSAGE‘.
*  ls_alv_cat-seltext   = ‘更新信息‘.
*  ls_alv_cat-scrtext_l = ‘更新信息‘.
*  ls_alv_cat-scrtext_m = ‘更新信息‘.
*  ls_alv_cat-scrtext_s = ‘更新信息‘.
*  APPEND ls_alv_cat TO lt_alv_cat.
*  BREAK it0003.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_CHANGE_JSON
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_change_json USING    p_rs_selfield_fieldname.
  DATA : json_ser TYPE REF TO cl_trex_json_serializer,
         json_des TYPE REF TO cl_trex_json_deserializer.
  FIELD-SYMBOLS :<fs_filed> TYPE any.
  ASSIGN COMPONENT p_rs_selfield_fieldname OF STRUCTURE gs_output TO <fs_filed>.
  DATA: lv_json TYPE string.
  lv_json = <fs_filed>.

*  FIELD-SYMBOLS :<fs_filed2> TYPE any.
*  ASSIGN COMPONENT ‘STRUCTURE‘ OF STRUCTURE gs_output TO <fs_filed2>.
*  DATA: lv_tabname TYPE tabname.
*  lv_tabname = <fs_filed2>.


  DATA: ls_zbpms011 LIKE zbpms011.
  DATA : jsonstr TYPE string.
  CREATE OBJECT json_des.
  IF lv_json+0(1) EQ [. "表结构
    CALL METHOD json_des->deserialize
      EXPORTING
        json = lv_json
      IMPORTING
        abap = <dyn_table>. "<dyn_table>.
  ELSE.
    CALL METHOD json_des->deserialize
      EXPORTING
        json = lv_json
      IMPORTING
        abap = <dyn_wa>. "<dyn_table>.
    APPEND <dyn_wa> TO <dyn_table>.
  ENDIF.

*  BREAK it0003.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV2
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_display_alv2 .
  PERFORM f_set_layout2.
*  PERFORM F_SET_FIELDCAT.
*  PERFORM f_set_event.
  PERFORM f_alv_display TABLES <dyn_table>.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_SET_LAYOUT2
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_set_layout2 .
  CLEAR: gs_layout.
*  gs_layout-box_fname = ‘SLBOX‘.
  gs_layout-zebra = X.
  gs_layout-cwidth_opt = X.
*  gs_layout-ctab_fname = ‘CELLCOLOR‘.
ENDFORM.
View Code

 

接口通用日志存储,以及查看

上一篇:ISA2004发布应用程序服务器


下一篇:C# LINQ 详解 From Where Select Group Into OrderBy Let Join