Skip to content

Instantly share code, notes, and snippets.

@Pipp94
Created October 28, 2019 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pipp94/498eaea8e58f317c7ed27db8fcfb237f to your computer and use it in GitHub Desktop.
Save Pipp94/498eaea8e58f317c7ed27db8fcfb237f to your computer and use it in GitHub Desktop.
BAdI Implementation
CLASS zcl_s4_mf_wo_update_impl DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_badi_interface .
INTERFACES if_ex_workorder_update .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ZCL_S4_MF_WO_UPDATE_IMPL IMPLEMENTATION.
METHOD if_ex_workorder_update~archive_objects.
ENDMETHOD.
METHOD if_ex_workorder_update~at_deletion_from_database.
ENDMETHOD.
METHOD if_ex_workorder_update~at_release.
DATA: http_client TYPE REF TO if_http_client,
payload_x TYPE xstring.
DATA(order_id) = CONV i( is_header_dialog-aufnr ).
DATA(quantity) = CONV i( is_header_dialog-bmenge ).
DATA(material_id) = 111.
"Material mapping
IF is_header_dialog-matnr = |MZ-FG-C900|.
material_id = 222.
ENDIF.
DATA(payload) = | \{ "order_id":{ order_id }, "material_id":{ material_id }, "total_quantity":{ quantity } \} |.
cl_http_client=>create_by_destination(
EXPORTING
destination = 'MES_CD' " logical Destination (at the beginning of function)
IMPORTING
client = http_client ). " HTTP Client abstraction
http_client->request->set_method('POST').
http_client->request->set_content_type( 'application/json' ).
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = payload
IMPORTING
buffer = payload_x.
http_client->request->set_data( payload_x ).
http_client->send(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5 ).
IF sy-subrc = 0.
http_client->receive(
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 5 ).
ENDIF.
IF sy-subrc <> 0.
"error handling
ENDIF.
ENDMETHOD.
METHOD if_ex_workorder_update~at_save.
ENDMETHOD.
METHOD if_ex_workorder_update~before_update.
ENDMETHOD.
METHOD if_ex_workorder_update~cmts_check.
ENDMETHOD.
METHOD if_ex_workorder_update~initialize.
ENDMETHOD.
METHOD if_ex_workorder_update~in_update.
ENDMETHOD.
METHOD if_ex_workorder_update~number_switch.
ENDMETHOD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment