BP: Useful report to list assigned employees

62 阅读1分钟

Created by Jerry Wang on Jul 17, 2015

如下report能够返回指定user 所管理的employee 明细

REPORT zappointment_share_calendar.
DATA: gr_employee_class TYPE REF TO cl_crm_employee_srv_impl,
      lt_filter         TYPE /iwbep/t_mgw_select_option,
      ls_filter         LIKE LINE OF lt_filter,
      ls_options        LIKE LINE OF ls_filter-select_options,
      er_entityset      TYPE REF TO data,
      er_bp             TYPE REF TO crmt_bp_odata_employee_t,
      lt_headers        TYPE tihttpnvp,
      ls_header         LIKE LINE OF lt_headers,
      lv_start           TYPE i,
      lv_end            TYPE i,
      lo_context        TYPE REF TO TD_SADL_GW_REQUEST_ENTSET."/iwbep/cl_mgw_request.
FIELD-SYMBOLS: <data> TYPE crmt_bp_odata_employee_t.
GET RUN TIME FIELD lv_start.
sy-uname = 'WANGJER'.
ls_filter-property = 'IsMyEmployee'.
ls_options-low = 'X'.
ls_options-option = 'EQ'.
ls_options-sign = 'I'.
APPEND ls_options TO ls_filter-select_options.
APPEND ls_filter TO lt_filter.
CREATE OBJECT gr_employee_class.
CREATE OBJECT lo_context.
 " EXPORTING
 "   it_headers = lt_headers.
CALL METHOD gr_employee_class->/iwbep/if_mgw_appl_srv_runtime~get_entityset
  EXPORTING
    iv_entity_name           = 'Employee'
    iv_entity_set_name       = 'EmployeeCollection'
    iv_source_name           = 'Employee'
    it_filter_select_options = lt_filter
    iv_filter_string         = `( IsMyEmployee eq 'X' )`
    io_tech_request_context  = lo_context
  IMPORTING
    er_entityset             = er_entityset.
ASSIGN er_entityset->* TO <data>.
GET RUN TIME FIELD lv_end.
lv_end = lv_end - lv_start.
WRITE: / 'Employee got:' , lines( <data> ), 'Time consumed: ' , lv_end.

下面的report是打印当前系统所有类型为developer的user所管理的employee信息,并打印出每个user取employee信息的消耗时间:

REPORT ZAPPOINTMENT_SHARE_CALENDAR1.
DATA: lt_usr02 TYPE STANDARD TABLE OF usr02,
      lt_table TYPE string_table.
SELECT bname INTO TABLE lt_table FROM usr02 where class = 'DEVELOPER'.
zcl_crm_employee_mgnt_tool=>get_assigned_employees_by_tab( lt_table ).
class ZCL_CRM_EMPLOYEE_MGNT_TOOL definition
  public
  final
  create public
  for testing .
public section.
  class-methods GET_ASSIGNED_EMPLOYEES
    importing
      !IV_NAME type SYUNAME
    returning
      value(RT_EMPLOYEE) type CRMT_BP_ODATA_EMPLOYEE_T .
  class-methods GET_ASSIGNED_EMPLOYEES_BY_TAB
    importing
      !IT_USER type STRING_TABLE .
protected section.
private section.
ENDCLASS.
CLASS ZCL_CRM_EMPLOYEE_MGNT_TOOL IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_CRM_EMPLOYEE_MGNT_TOOL=>GET_ASSIGNED_EMPLOYEES
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_NAME                        TYPE        SYUNAME
* | [<-()] RT_EMPLOYEE                    TYPE        CRMT_BP_ODATA_EMPLOYEE_T
* +--------------------------------------------------------------------------------------</SIGNATURE>
  METHOD get_assigned_employees.
    DATA: gr_employee_class TYPE REF TO cl_crm_employee_srv_impl,
          lt_filter         TYPE /iwbep/t_mgw_select_option,
          ls_filter         LIKE LINE OF lt_filter,
          ls_options        LIKE LINE OF ls_filter-select_options,
          er_entityset      TYPE REF TO data,
          er_bp             TYPE REF TO crmt_bp_odata_employee_t,
          lt_headers        TYPE tihttpnvp,
          ls_header         LIKE LINE OF lt_headers,
          lo_context        TYPE REF TO td_sadl_gw_request_entset. "/iwbep/cl_mgw_request.
    FIELD-SYMBOLS: <data> TYPE crmt_bp_odata_employee_t.
    sy-uname = iv_name.
    ls_filter-property = 'IsMyEmployee'.
    ls_options-low = 'X'.
    ls_options-option = 'EQ'.
    ls_options-sign = 'I'.
    APPEND ls_options TO ls_filter-select_options.
    APPEND ls_filter TO lt_filter.
    CREATE OBJECT gr_employee_class.
    CREATE OBJECT lo_context.
    " EXPORTING
    "   it_headers = lt_headers.
    CALL METHOD gr_employee_class->/iwbep/if_mgw_appl_srv_runtime~get_entityset
      EXPORTING
        iv_entity_name           = 'Employee'
        iv_entity_set_name       = 'EmployeeCollection'
        iv_source_name           = 'Employee'
        it_filter_select_options = lt_filter
        iv_filter_string         = `( IsMyEmployee eq 'X' )`
        io_tech_request_context  = lo_context
      IMPORTING
        er_entityset             = er_entityset.
    ASSIGN er_entityset->* TO <data>.
    rt_employee = <data>.
  ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_CRM_EMPLOYEE_MGNT_TOOL=>GET_ASSIGNED_EMPLOYEES_BY_TAB
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_USER                        TYPE        STRING_TABLE
* +--------------------------------------------------------------------------------------</SIGNATURE>
  method GET_ASSIGNED_EMPLOYEES_BY_TAB.
    DATA: lv_start TYPE i,
          lv_end TYPE i,
          lt_employee TYPE crmt_bp_odata_employee_t,
          lv_total TYPE i,
          lv_current TYPE i,
          lv_text TYPE string.
    lv_total = lines( it_user ).
    LOOP AT it_user ASSIGNING FIELD-SYMBOL(<user>).
       GET RUN TIME FIELD lv_start.
       lv_current = sy-tabix * 100 / lv_total.
       lv_text = 'Totally user: ' && lv_total && ' currently processing: ' && sy-tabix.
       CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
            PERCENTAGE = lv_current
            TEXT = lv_text.
       lt_employee = GET_ASSIGNED_EMPLOYEES( conv #( <user> ) ).
       GET RUN TIME FIELD lv_end.
       lv_end = lv_end - lv_start.
       WRITE: 'User: ' , <user>, ' employee numbers: ', lines( lt_employee ) , ' consumed time: ', lv_end.
    ENDLOOP.
  endmethod.
ENDCLASS.