Created by Wang, Jerry, last modified on Dec 06, 2014
class ZCL_MESSAGE_HANDLER definition
public
final
create private .
public section.
interfaces IF_BSP_WD_MESSAGE_HANDLER .
class-methods GET_INSTANCE
returning
value(RO_INSTANCE) type ref to ZCL_MESSAGE_HANDLER .
protected section.
private section.
class-data SO_INSTANCE type ref to ZCL_MESSAGE_HANDLER .
class-data SV_COUNT type I .
constants CV_COUNT type I value 3. "#EC NOTEXT
methods CONSTRUCTOR .
ENDCLASS.
CLASS ZCL_MESSAGE_HANDLER IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_MESSAGE_HANDLER->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
method CONSTRUCTOR.
sv_count = 0.
endmethod.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_MESSAGE_HANDLER=>GET_INSTANCE
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_INSTANCE TYPE REF TO ZCL_MESSAGE_HANDLER
* +--------------------------------------------------------------------------------------</SIGNATURE>
method GET_INSTANCE.
IF so_instance IS INITIAL.
CREATE OBJECT so_instance.
ENDIF.
ro_instance = so_instance.
endmethod.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MESSAGE_HANDLER->IF_BSP_WD_MESSAGE_HANDLER~HANDLE_MESSAGE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_MESSAGE TYPE BSP_WD_MESSAGE
* +--------------------------------------------------------------------------------------</SIGNATURE>
method IF_BSP_WD_MESSAGE_HANDLER~HANDLE_MESSAGE.
endmethod.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MESSAGE_HANDLER->IF_BSP_WD_MESSAGE_HANDLER~VERIFY_MESSAGE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_MESSAGE TYPE BSP_WD_MESSAGE
* | [<-()] RV_IS_VALID TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
method IF_BSP_WD_MESSAGE_HANDLER~VERIFY_MESSAGE.
IF sv_count = cv_count.
rv_is_valid = abap_false.
sv_count = 0.
RETURN.
ENDIF.
sv_count = sv_count + 1.
rv_is_valid = abap_true.
endmethod.
ENDCLASS.
class ZCL_IM_CL_JERRY_CREATE definition
public
final
create public .
public section.
interfaces IF_EX_CRM_DOCUMENTS .
protected section.
private section.
type-pools ABAP .
class-data SV_IS_IN_BADI type ABAP_BOOL .
ENDCLASS.
CLASS ZCL_IM_CL_JERRY_CREATE IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_IM_CL_JERRY_CREATE->IF_EX_CRM_DOCUMENTS~CARRY_OUT_ACTION
* +-------------------------------------------------------------------------------------------------+
* | [--->] CHANGED_DOCUMENTS TYPE CRMT_KW_DOCUMENT_CHANGE
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD if_ex_crm_documents~carry_out_action.
CONSTANTS: cv_max_size TYPE int4 VALUE 20480. "20KB
CHECK sy-uname = 'WANGJER'.
DATA: lt_loios TYPE skwf_ios,
ls_error TYPE skwf_error,
lv_size TYPE sdok_fsize,
lt_badios TYPE skwf_ioerrs.
READ TABLE changed_documents ASSIGNING FIELD-SYMBOL(<first_line>) INDEX 1.
CHECK sy-subrc = 0.
CHECK <first_line>-action = 'CREATE_DOCUMENT'.
DATA(ls_bo) = VALUE sibflporb( instid = <first_line>-instidbor
typeid = <first_line>-typeidbor
catid = <first_line>-catidbor ).
DATA(ls_loios) = VALUE skwf_io( objtype = <first_line>-objtype class = <first_line>-class objid = <first_line>-objid ).
APPEND ls_loios TO lt_loios.
CALL METHOD cl_crm_documents=>get_file_info
EXPORTING
loio = ls_loios
IMPORTING
file_size = lv_size.
CHECK lv_size >= cv_max_size.
CALL METHOD cl_crm_documents=>delete
EXPORTING
business_object = ls_bo
ios = lt_loios
IMPORTING
bad_ios = lt_badios
error = ls_error.
COMMIT WORK AND WAIT.
DATA(lo_service) = cl_bsp_wd_message_service=>get_instance( ).
DATA(lo_message) = zcl_message_handler=>get_instance( ).
lo_service->add_message( EXPORTING iv_msg_type = 'E' iv_msg_id = 'ZCM_JERRY_TEST' iv_msg_number = '000'
iv_verification = lo_message ).
ENDMETHOD.
ENDCLASS.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":