In this document we will see how to add a custom button to the Shopping Cart and the code for this button in order to call to a custom component for show some data.
This can be applied also to other documents like PO, CTR, etc.
Now we’re going to use the code wizard
DATA: lo_nd_zz_sc_guid TYPEREFTO if_wd_context_node,
lo_el_zz_sc_guid TYPEREFTO if_wd_context_element,
ls_zz_sc_guid TYPE wd_this->element_zz_sc_guid.
lo_nd_zz_sc_guid = wd_context->get_child_node( name = wd_this->wdctx_zz_sc_guid ).
lo_el_zz_sc_guid = lo_nd_zz_sc_guid->get_element( ).
* Set the parameter value to the context node;
ls_zz_sc_guid-sc_guid = zz_sc_guid.
lo_el_zz_sc_guid->set_static_attributes(
EXPORTING
static_attributes = ls_zz_sc_guid ).
Adding the button to SC
DATA: lv_id TYPE string,
lv_event_id TYPE fpm_event_id.
DATA: lo_nd_oif_application TYPEREFTO if_wd_context_node,
lo_nd_variant TYPEREFTO if_wd_context_node,
lo_nd_toolbar TYPEREFTO if_wd_context_node,
lo_nd_button TYPEREFTO if_wd_context_node,
lo_el_button TYPEREFTO if_wd_context_element,
lo_nd_other_functions TYPEREFTO if_wd_context_node.
DATA: lv_substring TYPE string,
lv_substring_i TYPEi,
lv_node_name TYPE string,
lv_position TYPE string,
lv_length TYPEi,
lv_seq TYPEi.
DATA: lv_boid TYPE bbp_guid.
DATA:lt_keys TYPESTANDARDTABLEOF string,
lv_key LIKELINEOF lt_keys.
TYPES:BEGINOF y_parameters,
name TYPE string,
valueTYPE string,
ENDOF y_parameters.
DATA: lt_parameters TYPESTANDARDTABLEOF y_parameters,
ls_parameter LIKELINEOF lt_parameters.
* Obtain parameters;
DATA: lo_fpm TYPEREFTO if_fpm.
lo_fpm = cl_fpm_factory=>get_instance( ).
lo_fpm->raise_event_by_id( lv_event_id ).
lt_keys = lo_fpm->mo_app_parameter->get_keys( ).
LOOPAT lt_keys INTO lv_key.
ls_parameter-name = lv_key.
lo_fpm->mo_app_parameter->get_value(
EXPORTING iv_key = lv_key
IMPORTING ev_value = ls_parameter-value ).
INSERT ls_parameter INTOTABLE lt_parameters.
ENDLOOP.
lv_id = wdevent->get_string( 'ID' ).
lo_nd_oif_application = wd_context->get_child_node( name = wd_this->wdctx_oif_application ).
lo_nd_variant = lo_nd_oif_application->get_child_node( name = wd_this->wdctx_variant ).
lo_nd_toolbar = lo_nd_variant->get_child_node( name = wd_this->wdctx_toolbar ).
lo_nd_other_functions = lo_nd_toolbar->get_child_node( name = wd_this->wdctx_other_functions ).
lv_substring = lv_id.
lv_length = STRLEN( lv_id ).
lv_seq = lv_length - 3.
IF lv_id+lv_seq = '_CP'.
lv_substring = lv_substring(lv_seq).
lv_id = lv_substring.
ENDIF.
WHILE lv_substring CS'_'.
lv_position = sy-fdpos + 1.
lv_substring = lv_substring+lv_position.
ENDWHILE.
IF lv_substring CO'1234567890'.
lv_substring_i = lv_substring.
ENDIF.
* item action
IF lv_id CS'_item'.
ELSE.
* header action
IF lv_id CA '0123456789'.
lv_position = sy-fdpos - 1.
lv_node_name = lv_id(lv_position).
IF lv_id CS 'OTHER_FUNCTIONS'.
lo_nd_button = lo_nd_other_functions->get_child_node( name = wd_this->wdctx_button ).
lo_nd_button->set_lead_selection_index( index = lv_substring_i ).
lo_el_button = lo_nd_button->get_element( ).
TRY.
lo_el_button->get_attribute(
EXPORTING
name = `EVENT_ID`
IMPORTING
value = lv_event_id ).
CATCH cx_wd_context.
ENDTRY.
* Read the guid of the SC:
READ TABLE lt_parameters INTO ls_parameter WITH KEY name = 'SAPSRM_BOID'.
lv_boid = ls_parameter-value.
* Leave the method if it isn't a custom action
IF lv_event_id(1) NE 'ZZ'.
RETURN.
ENDIF.
* Action triggered;
CASE lv_event_id.
WHEN 'ZZ_SC_EXTRA_INFO'.
"We need to put here our code for the button...
ENDCASE.
ENDIF.
ENDIF.
ENDIF.
DATA: lv_url TYPE string,
d_url(255) TYPEc,
lv_app_name TYPE string,
host TYPE string,
port TYPE string,
out_protocol TYPE string,
in_parameters TYPE tihttpnvp,
wa_params LIKELINEOF in_parameters,
lv_iview TYPE string,
gf_value_old TYPE /sapsrm/char512,
gf_clength TYPE int2.
DATA: lo_window_manager TYPEREFTO if_wd_window_manager,
lo_api_component TYPEREFTO if_wd_component,
lo_window TYPEREFTO if_wd_window.
* Use the WD application created and pass a value to the parameter SC_GUID:
wa_params-name = 'ZZ_SC_GUID'.
wa_params-value = lv_boid.
APPEND wa_params TO in_parameters.
lv_app_name = 'ZZ_SC_EXTRA_INFO'.
CALLMETHOD cl_http_server=>if_http_server~get_location
IMPORTING
host = host
port = port
out_protocol = out_protocol.
CALLMETHOD cl_wd_utilities=>construct_wd_url
EXPORTING
application_name = lv_app_name
in_host = host
in_port = port
in_protocol = out_protocol
in_parameters = in_parameters
namespace = 'sap'
IMPORTING
out_absolute_url = lv_url.
lo_api_component = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).
CALLMETHOD lo_window_manager->create_external_window
EXPORTING
url = lv_url
RECEIVING
window = lo_window.
lo_window->open( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.