INTERFACE zif_cor_request_handler
PUBLIC .
* Reference to next handler in chain
DATA o_next_obj TYPE REF TO zif_cor_request_handler .
* Factory method for instantiating chain handler
CLASS-METHODS get_chain_instance
IMPORTING
VALUE(is_variant) TYPE char10 OPTIONAL
EXPORTING
VALUE(er_object) TYPE REF TO zif_cor_request_handler .
* Method to execute handler logic
METHODS handle_request
IMPORTING
!i_header TYPE zscor_header
!i_items TYPE ztcor_items
!i_control TYPE zscor_control .
METHODS set_next
IMPORTING
!er_next_object TYPE REF TO zif_cor_request_handler .
ENDINTERFACE.
CLASS zcl_cor_email_handler DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES zif_cor_request_handler .
PROTECTED SECTION.
PRIVATE SECTION.
ALIASES o_next_obj
FOR zif_cor_request_handler~o_next_obj .
ENDCLASS.
CLASS ZCL_COR_EMAIL_HANDLER IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_COR_EMAIL_HANDLER=>ZIF_COR_REQUEST_HANDLER~GET_CHAIN_INSTANCE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_VARIANT TYPE CHAR10(optional)
* | [<---] ER_OBJECT TYPE REF TO ZIF_COR_REQUEST_HANDLER
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_cor_request_handler~get_chain_instance.
CASE is_variant.
WHEN 'BILL'.
er_object = NEW zcl_cor_email_handler_billing( ).
WHEN 'DUNN'.
er_object = NEW zcl_cor_email_handler_dunning( ).
WHEN 'INFO'.
er_object = NEW zcl_cor_email_handler_info( ).
WHEN OTHERS.
er_object = NEW zcl_cor_email_handler( ).
ENDCASE.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_COR_EMAIL_HANDLER->ZIF_COR_REQUEST_HANDLER~HANDLE_REQUEST
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_HEADER TYPE ZSCOR_HEADER
* | [--->] I_ITEMS TYPE ZTCOR_ITEMS
* | [--->] I_CONTROL TYPE ZSCOR_CONTROL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_cor_request_handler~handle_request.
WRITE:/'-> Executing email handler'.
* <Implement handler logic here>
IF o_next_obj IS BOUND.
WRITE:/'........Calling next handler in chain.....'.
CALL METHOD me->o_next_obj->handle_request
EXPORTING
i_header = i_header
i_items = i_items
i_control = i_control.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_COR_EMAIL_HANDLER->ZIF_COR_REQUEST_HANDLER~SET_NEXT
* +-------------------------------------------------------------------------------------------------+
* | [--->] ER_NEXT_OBJECT TYPE REF TO ZIF_COR_REQUEST_HANDLER
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_cor_request_handler~set_next.
me->o_next_obj = er_next_object.
ENDMETHOD.
ENDCLASS.
class ZCL_COR_EMAIL_HANDLER_BILLING definition
public
inheriting from ZCL_COR_EMAIL_HANDLER
create public .
public section.
methods ZIF_COR_REQUEST_HANDLER~HANDLE_REQUEST
redefinition .
protected section.
private section.
aliases O_NEXT_OBJ
for ZIF_COR_REQUEST_HANDLER~O_NEXT_OBJ .
ENDCLASS.
CLASS ZCL_COR_EMAIL_HANDLER_BILLING IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_COR_EMAIL_HANDLER_BILLING->ZIF_COR_REQUEST_HANDLER~HANDLE_REQUEST
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_HEADER TYPE ZSCOR_HEADER
* | [--->] I_ITEMS TYPE ZTCOR_ITEMS
* | [--->] I_CONTROL TYPE ZSCOR_CONTROL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_cor_request_handler~handle_request.
WRITE:/'-> Executing email handler (Billing)'.
* <Implement handler logic here>
IF me->o_next_obj IS BOUND.
WRITE:/'........Calling next handler in chain.....'.
CALL METHOD o_next_obj->handle_request
EXPORTING
i_header = i_header
i_items = i_items
i_control = i_control.
ENDIF.
ENDMETHOD.
ENDCLASS.
REPORT ztrigger_cor_request.
* CoR Chain related control table
DATA lt_controls TYPE STANDARD TABLE OF ztcor_controller.
DATA wa_control TYPE ztcor_controller.
* Holds CoR Objects to build chain
DATA o_corobj TYPE REF TO zif_cor_request_handler.
DATA o_cormain TYPE REF TO zif_cor_request_handler.
DATA o_nextobj TYPE REF TO zif_cor_request_handler.
DATA lv_variant TYPE char10 VALUE 'BILL'.
* Header, item and control parameters for handlers to implement logic
DATA wa_header TYPE zscor_header.
DATA lt_items TYPE ztcor_items.
DATA wa_contr TYPE zscor_control.
SELECT * FROM ztcor_controller INTO TABLE lt_controls WHERE active = 'X'.
LOOP AT lt_controls INTO wa_control.
IF o_corobj IS NOT BOUND.
CALL METHOD (wa_control-handler_class)=>zif_cor_request_handler~get_chain_instance
EXPORTING
is_variant = lv_variant
IMPORTING
er_object = o_corobj.
o_cormain = o_corobj.
ELSE.
CALL METHOD (wa_control-handler_class)=>zif_cor_request_handler~get_chain_instance
EXPORTING
is_variant = lv_variant
IMPORTING
er_object = o_nextobj.
CALL METHOD o_corobj->set_next EXPORTING er_next_object = o_nextobj.
o_corobj = o_nextobj.
ENDIF.
ENDLOOP.
WRITE:/ 'Entering handler chain..'.
CALL METHOD o_cormain->handle_request
EXPORTING i_header = wa_header i_items = lt_items i_control = wa_contr .
WRITE:/ '.. Handler chain Finished'.
Trigger COR request - Testing
Entering handler chain..
-> Executing email handler (Billing)
........Calling next handler in chain.....
-> Executing fax handler
........Calling next handler in chain.....
-> Executing sms handler
.. Handler chain Finished
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |