ABAP事务码使用次数

旧版本可以使用

CALL FUNCTION 'THUSRINFO'
    TABLES
      usr_tabl = lt_uinfo.

S4新版本如下:

SE11自建表

 附上代码:

主:

REPORT zit0001.

INCLUDE zit0001_head.
INCLUDE zit0001_screen.
INCLUDE zit0001_form.

START-OF-SELECTION.
*  PERFORM frm_get_user.
  IF r1 EQ 'X'.
    PERFORM frm_get_data.
  ENDIF.
  IF r2 EQ 'X' AND sy-uname+0(2) EQ 'IT'.
    PERFORM frm_get_list.
  ENDIF.

END-OF-SELECTION.
  IF r1 EQ 'X'.
    PERFORM f_display_data.
  ENDIF.
View Code

 

包含文件 ZIT0001_HEAD:

*&---------------------------------------------------------------------*
*& 包含               ZIT0001_HEAD
*&---------------------------------------------------------------------*
TABLES: zit0001.
DATA: gt_msxxlist LIKE TABLE OF msxxlist,
      gt_uinfo    LIKE TABLE OF uinfo.
*PARAMETER: month TYPE dats DEFAULT sy-datum OBLIGATORY,
*           user TYPE usr02-bname OBLIGATORY DEFAULT sy-uname.
TYPES: BEGIN OF zusertcode,
         operation TYPE char30,
         type      TYPE char10,
         count     TYPE swncshcnt,
       END OF zusertcode.

TYPES: tt_zusertcode TYPE STANDARD TABLE OF zusertcode WITH KEY operation type.

DATA: lt_usertcode TYPE swnc_t_aggusertcode,
      wa_usertcode TYPE swncaggusertcode,
      wa           TYPE zusertcode,
      t_ut         TYPE tt_zusertcode,
      lt_result    like TABLE OF zit0001,
      ls_result    like zit0001.

CONSTANTS: cv_tcode  TYPE char30 VALUE 'Tcode',
           cv_report TYPE char30 VALUE 'Report',
           cv_count  TYPE char5 VALUE 'Count'.
DATA: gs_layout   TYPE lvc_s_layo,
      gt_fieldcat TYPE lvc_t_fcat.
View Code

 

包含文件 ZIT0001_SCREEN:

*&---------------------------------------------------------------------*
*& 包含               ZIT0001_SCREEN
*&---------------------------------------------------------------------*

SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_uname FOR sy-uname DEFAULT sy-uname,
                s_tcode FOR zit0001-entry_id.
PARAMETERS: r1 RADIOBUTTON GROUP g1 USER-COMMAND u1,
            r2 RADIOBUTTON GROUP g1.
SELECTION-SCREEN: END OF BLOCK b01.
View Code

 

包含文件 ZIT0001_FORM:

*&---------------------------------------------------------------------*
*& 包含               ZIT0001_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_USER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_user .
  DATA: desti LIKE TABLE OF msxxlist WITH HEADER LINE.
  CALL FUNCTION 'TH_SERVER_LIST'
    TABLES
      list           = gt_msxxlist
    EXCEPTIONS
      no_server_list = 1
      OTHERS         = 2.

  CALL FUNCTION 'THUSRINFO'
    TABLES
      usr_tabl              = gt_uinfo
    EXCEPTIONS
      communication_failure = 17
      system_failure        = 17.
*  LOOP AT gt_msxxlist INTO DATA(ls_msxxlist).
*    CALL FUNCTION 'THUSRINFO' DESTINATION ls_msxxlist-name
*      TABLES
*        usr_tabl              = gt_uinfo
*      EXCEPTIONS
*        communication_failure = 17
*        system_failure        = 17.
*  ENDLOOP.
  BREAK-POINT.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_LIST
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_list .
* Set date to the first day of the month
  "month+6(2) = '01'.
  CALL FUNCTION 'SWNC_COLLECTOR_GET_AGGREGATES'
    EXPORTING
      component     = 'TOTAL'
      periodtype    = 'M'
      periodstrt    = sy-datum "month
    TABLES
      usertcode     = lt_usertcode
    EXCEPTIONS
      no_data_found = 1
      OTHERS        = 2.
*  BREAK-POINT.
  DELETE lt_usertcode WHERE tasktype <> '01'.

  LOOP AT lt_usertcode ASSIGNING FIELD-SYMBOL(<user>) WHERE account IN  s_uname.
    CLEAR: ls_result.
    ls_result-gjahr = sy-datum+0(4).
    ls_result-monat = sy-datum+4(2).
    ls_result-account = <user>-account.
    ls_result-entry_id = <user>-entry_id+0(72).
    CONDENSE ls_result-entry_id NO-GAPS.
    ls_result-ztype = <user>-entry_id+72.
    ls_result-zcount = <user>-count.
    COLLECT ls_result INTO lt_result.
  ENDLOOP.

  IF lt_result[] IS NOT INITIAL.
    MODIFY zit0001 FROM TABLE lt_result.
    IF sy-subrc EQ 0.
      COMMIT WORK AND WAIT.
      WRITE / '更新成功'.
    ELSE.
      ROLLBACK WORK.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .
  LOOP AT s_tcode.
    TRANSLATE s_tcode-low TO UPPER CASE.
    TRANSLATE s_tcode-high TO UPPER CASE.
    MODIFY s_tcode.
  ENDLOOP.

  SELECT *
    INTO TABLE lt_result
    FROM zit0001
   WHERE account IN s_uname
     AND entry_id IN s_tcode.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM f_display_data .
  PERFORM f_set_layout.
  PERFORM f_set_fieldcat.
  PERFORM f_alv_display TABLES lt_result.
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 'GJAHR'    'GJAHR'    'ZIT0001'   '' ''  '年度'.
  set_fieldcat 'MONAT'    'MONAT'    'ZIT0001'   '' ''  '期间'.
  set_fieldcat 'ACCOUNT'  'ACCOUNT'  'ZIT0001'   '' ''  '账号'.
  set_fieldcat 'ENTRY_ID' 'ENTRY_ID' 'ZIT0001'   '' ''  '事务码'.
  set_fieldcat 'ZTYPE'    'ZTYPE'    'ZIT0001'   '' ''  '事务类型'.
  set_fieldcat 'ZCOUNT'   'ZCOUNT'   'ZIT0001'   '' ''  '使用次数'.


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_fieldcat_lvc    = gt_fieldcat
      i_save             = 'U'
    TABLES
      t_outtab           = it_table
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.
View Code

 

原文地址:https://www.cnblogs.com/chaguoguo/p/14067155.html