🙂
Adding new line items to an Inbound delivery (with PO reference)
Method 1:
data: lv_li type ref to /spe/cl_id_handling, xs_lips type lipsvb, x_uepos type xfeld, e_result type /SPE/INB_RESULT. lv_li ?= /spe/cl_class_factory=>create_class( i_name = '/SPE/CL_ID_HANDLING' ). lv_li->a_vbeln = '0180000160'. " inbound delivery number CALL METHOD lv_li->select EXPORTING i_vbeln = lv_li->a_vbeln IMPORTING e_result = e_result. xs_lips-lfimg = '5'. xs_lips-vgbel = '5500000007'. " purschasir xs_lips-vgpos = '000010'. call method lv_li->item_add exporting i_line = 2 "new pos. changing xs_lips = xs_lips x_uepos = x_uepos. call method lv_li->save importing e_result = e_result.
Method 2:
FM IDOC_INPUT_DELVRY:
ENHANCEMENT 15 DIMP_GENERAL_SAPLV55K. LT_DELIVERY_EXTEND-DELIVERY_NUMBER = s_koko-vbeln_vl. * ... CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC' EXPORTING DELIVERY_EXTEND = LT_DELIVERY_EXTEND TABLES REQUEST = LT_REQUEST CREATEDITEMS = LT_CREATEDITEMS RETURN = LT_RETURN.
Method 3:
Just began to use external delivery numbers. In this case such deliveries can be deleted and re-created with the same number.
Iterate field values and field names of unknown table
form fill_fcontent using it_tab type any table " iterate field values changing it_fcont type rsanm_file_table. " für Z_LIEFZ data: lro_structdescr type ref to cl_abap_structdescr, lt_components type cl_abap_structdescr=>component_table, lv_row type string. constants con_tab type c value cl_abap_char_utilities=>horizontal_tab. field-symbols: <ls_comp> like line of lt_components, <fs_field>, <wa> type any. loop at it_tab assigning <wa>. if lt_components is initial. lro_structdescr ?= cl_abap_typedescr=>describe_by_data( <wa> ). lt_components = lro_structdescr->get_components( ). endif. do. "iterate all columns in the row assign component sy-index of structure <wa> to <fs_field>. if sy-subrc <> 0. exit. endif. read table lt_components assigning <ls_comp> index sy-index. lv_row = lv_row && <fs_field> && con_tab. enddo. append lv_row to it_fcont. clear lv_row. endloop. endform. form fill_fheader using gs_line type any " iterate field names changing it_filcont type rsanm_file_table. " für Z_LIEFZ data: lro_structdescr type ref to cl_abap_structdescr, lt_components type cl_abap_structdescr=>component_table, lv_row type string. constants con_tab type c value cl_abap_char_utilities=>horizontal_tab. field-symbols: <ls_comp> like line of lt_components, <fs_field>, <wa> type any. clear it_filcont. assign gs_line to <wa>. if lt_components is initial. lro_structdescr ?= cl_abap_typedescr=>describe_by_data( <wa> ). lt_components = lro_structdescr->get_components( ). endif. do. assign component sy-index of structure <wa> to <fs_field>. if sy-subrc <> 0. exit. endif. read table lt_components assigning <ls_comp> index sy-index. lv_row = lv_row && <ls_comp>-name && con_tab. enddo. append lv_row to it_filcont. clear lv_row. endform.
Einfacher REST-Service (ohne OData)
1. SE11: neue Tabelle ZREST_TAB:
MANDT:MANDT
ID:VBELN
CUSTOMER_NAME:NAME1
MOBILE:TELF1
EMAIL:AD_SMTPADR
DESCR:CHAR100
STATUS:CHAR10
ACTION_TAKEN:CHAR100
CLOSING_DATE:SYDATUM
CREATEDBY:SYUNAME
CREATEDON:SYDATUM
TIME:SYUZEIT
2. SNRO ZRESTC:NUMC10
3. Neue Klasse ZCL_WEBCO_RHANDLER und eine Überschreibung:
class ZCL_WEBCO_RHANDLER definition public inheriting from CL_REST_HTTP_HANDLER final create public . public section. methods IF_REST_APPLICATION~GET_ROOT_HANDLER redefinition . endclass.
if_rest_application~get_root_handler redefinition:
data lo_router type ref to cl_rest_router. create object lo_router. lo_router->attach( exporting iv_template = '/webco' " Unified Name for Resources (-URI) iv_handler_class = 'ZCL_WEBCO_RESOURCEP' " Object Type Name ). ro_root_handler = lo_router.
4. Neue Klasse ZCL_WEBCO_RESOURCEP und zwei Überschreibungen:
class ZCL_WEBCO_RESOURCEP definition public inheriting from CL_REST_RESOURCE final create public . public section. methods IF_REST_RESOURCE~GET redefinition . methods IF_REST_RESOURCE~POST redefinition . endclass.
if_rest_resource~get redefinition:
data: lv_string1 type vbeln, lv_string2 type string, ls_co type zrest_tab, ui2_cl_json type ref to cl_trex_json_serializer. lv_string1 = mo_request->get_uri_query_parameter( iv_name = 'ID' ). call function 'CONVERSION_EXIT_ALPHA_INPUT' exporting input = lv_string1 importing output = lv_string1. select single * from zrest_tab into corresponding fields of ls_co where id = lv_string1. create object ui2_cl_json exporting data = ls_co. " Data to serialize ui2_cl_json->serialize( ). lv_string2 = ui2_cl_json->get_data( ). mo_response->create_entity( )->set_string_data( iv_data = lv_string2 ). mo_response->set_header_field( exporting iv_name = 'Content-Type' " Header Name iv_value = 'application/json' " Header Value ).
if_rest_resource~post redefinition:
data: lv_response type string, lv_data type string, ls_com type zrest_tab, lt_co type standard table of zrest_tab with default key, ui2d_cl_json type ref to cl_trex_json_deserializer, ui2s_cl_json type ref to cl_trex_json_serializer, lo_entity type ref to if_rest_entity, lo_response type ref to if_rest_entity. lo_entity = mo_request->get_entity( ). lo_response = mo_response->create_entity( ). "read string data i.e json lv_data = lo_entity->get_string_data( ). create object ui2d_cl_json. ui2d_cl_json->deserialize( exporting json = lv_data importing abap = lt_co ). read table lt_co into ls_com with key mandt = 800. call function 'NUMBER_GET_NEXT' exporting nr_range_nr = '01' object = 'ZRESTC' quantity = '1' importing number = ls_com-id exceptions ... . ... ls_com-createdby = sy-uname. ls_com-createdon = sy-datum. ls_com-time = sy-uzeit. insert into zrest_tab values ls_com. create object ui2s_cl_json exporting data = lt_co. " Data to serialize ui2s_cl_json->serialize( ). lv_response = ui2s_cl_json->get_data( ). lo_response->set_string_data( iv_data = lv_response ). endmethod.
5. SICF neuer Service /sap/bc/rest/webco — HandlerList:ZCL_WEBCO_RHANDLER
6. (Test) SoapUI https://sapgw.sys100.sap.sd:8000/sap/bc/rest/webco (x-csrf-Token?)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[{ mandt: "100", id: "", customer_name: "Skoda", mobile: "4910501986903", email: "abap@sap.sd", descr: "REST POST 0", status: "Accepted", action_taken: "", closing_date: "00000000", createdby: "", createdon: "00000000", time: "000000" }] |
Die Tabelle ZREST_TAB enthält jetzt die neue Zeilen.
ABAP Query — clean some output entries
END-OF-SELECTION (nach Liste):
field-symbols: <g00> type table, <wa_g00> type any, <k1> type any, <ks> type any. data: it_g00 type char100 value '%G00[]', lv_kna1land type string, lv_knasland type string. assign (it_g00) to <g00>. if <g00> is assigned. loop at <g00> assigning <wa_g00>. lv_kna1land = '<wa_g00>-kna1-land1'. lv_knasland = '<wa_g00>-knas-land1'. unassign: <k1>, <ks>. assign: (lv_kna1land) to <k1>, (lv_knasland) to <ks>. if <k1> is assigned. if <ks> is assigned. if <k1> eq <ks>. delete <g00>. endif. endif. endif. endloop. endif. " END-OF-SELECTION
EWM/ABAP — Adjust quantity
function y_adjo. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(IV_DLV_NUM) TYPE STRING *"---------------------------------------------------------------------- data: lt_k_item type /scdl/t_sp_k_item ,lv_lfr type /scdl/dl_docid ,lv_qty type /scdl/db_proci_o-qty ,wa_k_item like line of lt_k_item ,ls_action type /scdl/s_sp_act_action ,ls_prcode type /scwm/dlv_prcode_add_str ,lo_prd_out type ref to /scdl/cl_sp_prd_out ,lt_a_item type /scdl/t_sp_a_item ,lv_rejected type boole_d ,lo_message_box type ref to /scdl/cl_sp_message_box ,lt_a_head type /scdl/t_sp_a_head ,lt_k_head type /scdl/t_sp_k_head ,wa_k_head like line of lt_k_head ,lt_return_codes type /scdl/t_sp_return_code. field-symbols: <fs_action_control>. ls_action-action_code = /scwm/if_dl_c=>sc_ac_prcode_add. create data ls_action-action_control type /scwm/dlv_prcode_add_str. * Lieferung select single docid into lv_lfr from /scdl/db_refdoc where refdocno eq iv_dlv_num and refdoccat eq 'ODR'. select docid into wa_k_item-docid from /scdl/db_proch_o where docno = '00000000000000000000000000000101423'. endselect. select itemid from /scdl/db_proci_o into wa_k_item-itemid where docno = '00000000000000000000000000000101423' and itemno = '0000000040'. endselect. if sy-subrc ne 0. message s038(/scdl/bo_action) display like 'E'. " Keine Lieferung gefunden endif. append wa_k_item to lt_k_item. if lo_prd_out is initial. create object lo_message_box. create object lo_prd_out exporting io_message_box = lo_message_box iv_mode = /scdl/cl_sp=>sc_mode_classic iv_doccat = /scdl/if_dl_doc_c=>sc_doccat_out_prd. endif. * Select Delivery wa_k_head-docid = wa_k_item-docid. append wa_k_head to lt_k_head. clear lv_rejected. refresh lt_return_codes. lo_prd_out->/scdl/if_sp1_aspect~select( exporting inkeys = lt_k_head aspect = /scdl/if_sp_c=>sc_asp_head importing outrecords = lt_a_head rejected = lv_rejected return_codes = lt_return_codes ). * Lieferung sperren clear lv_rejected. refresh lt_return_codes. lo_prd_out->lock( exporting inkeys = lt_k_head aspect = /scdl/if_sp_c=>sc_asp_head lockmode = /scdl/if_sp1_locking=>sc_exclusive_lock importing rejected = lv_rejected return_codes = lt_return_codes ). * check if any error occurred "mcr_fill_error 'Lock delivery failed'. * adjust delivery clear lv_rejected. refresh lt_return_codes. ls_action-action_code = /scwm/if_dl_c=>sc_ac_prcode_add. create data ls_action-action_control type /scwm/dlv_prcode_add_str. assign ls_action-action_control->* to <fs_action_control>. ls_prcode-prcode = 'O001'. ls_prcode-qty = -1. ls_prcode-uom = 'ST'. <fs_action_control> = ls_prcode. lo_prd_out->/scdl/if_sp1_action~execute( exporting aspect = /scdl/if_sp_c=>sc_asp_item inkeys = lt_k_item inparam = ls_action action = /scdl/if_sp_c=>sc_act_execute_action importing outrecords = lt_a_item rejected = lv_rejected return_codes = lt_return_codes ). * check if any error occurred if lv_rejected is not initial. " or line_exists( lt_return_codes[ failed = 'x'] ). " rollback work. " mcr_fill_error 'delivery qty adjust failed'. else. lo_prd_out->save( ). commit work and wait. " ls_odo-msgtxt = 'delivery qty adjust successfully'. endif. /scwm/cl_tm=>cleanup( ). endfunction.
OData POST
I have created OData service in SEGW and published it.
There are two case :
1.)With CSRF token —
By Default Gateway will generate the CSRF token, if any of CUD(Create, Update and Delete) operation we are doing it is mandatory to pass this token(CSRF ).
So before any CUD operation, Retrieve a CSRF token with a non-modifying request(get method).
Validity of this Token is 30 mins (which can further be altered by Tcode RZ11(Parameter : http/security_session_timeout) might be there is some diffrent mecanism as well
Fetching mechanism : In client side need to put one parameter X-CSRF-Token(‘X-CSRF-Token’) with the value ‘Fetch’ is sent along with the non-modifying request.
2.) Without CSRF token —
without CSRF first we need to override standard behavior of service, in SICF node for each service need to maintain parameter in GUI configuration as below :
Parameter Name: ~CHECK_CSRF_TOKEN
Parameter Value: 0/1 (disable/enable)
And At client level in Header need to pass X in Header
(‘X-Requested-With’: ‘X’)
Requested URI: /sap/opu/odata/sap/mein-dienst/infosatzSet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-8"?> <entry xml:base="http://sapondev100.sap.sd/sap/opu/odata/sap/zz_record/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"> <id>http://sapondev100.sap.sd/sap/opu/odata/sap/zz_record/infosatzSet(1)</id> <title type="text">infosatzSet(1)</title> <updated>2000-01-01T01:01:01Z</updated> <category term="zz_record.infosatz" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> <link href="infosatzSet(1)" rel="self" title="infosatz"/> <content type="application/xml"> <m:properties> <d:Index>43</d:Index> <d:Kschl>unas</d:Kschl> </m:properties> </content> </entry> |
Web service ABAP method (for /inbound-idoc):
method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY. data ir_deep_entity type zz_record_mpc_ext=>ts_deep_entity. io_data_provider->read_entry_data( IMPORTING es_data = ir_deep_entity ). copy_data_to_ref( exporting is_data = ir_deep_entity changing cr_data = er_deep_entity ). endmethod.
redefined MPC_EXT DEFINE Method:
data: lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation, lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ, lo_complex_type TYPE REF TO /iwbep/if_mgw_odata_cmplx_type, lo_property TYPE REF TO /iwbep/if_mgw_odata_property, lo_entity_set TYPE REF TO /iwbep/if_mgw_odata_entity_set. super->define( ). lo_entity_type = model->get_entity_type( iv_entity_name = 'E_Kopf' ). " Pos lo_entity_type->bind_structure( iv_structure_name = 'zz_record_mpc_ext=>ts_deep_entity' ).
MPC_EXT Types:
* variable names should be same as of 'Navigation Property' name created * in Entity 'Kopf' / 'Pos' else structure can not be referred in code. * types: " (create in MPC_EXT Class) * begin of ts_deep_entity, * kopf type standard table of ts_infosatz with default key, * pos type standard table of ts_staffelpos with default key, * end of ts_deep_entity. types: ty_t_soitem type standard table of zz_record_mpc=>ts_staffelpos with default key. *" Represents full - header with one of more items types: begin of ty_s_so. include type zz_record_mpc=>ts_infosatz. types: SOItems type ty_t_soitem, end of ty_s_so. data: ls_so type ty_s_so, ls_item type zz_record_mpc=>ts_staffelpos.
Debug OData requests: blogs.sap.com/2016/10/29/method-not-allowed-error-trouble-shoot
FM Popup-Window with input field
Include LZPOPUPTOP
function-pool zpopup. "MESSAGE-ID .. data: i_title type char50, textline1 type char80, textline2 type char80, textmenge type i, l_antwort type char1, txt_wert type char30. * INCLUDE LZPOPUPD... " Local class definition
function zsd_popup_text_input . *"---------------------------------------------------------------------- *"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(IV_TITLE) TYPE STRING *" VALUE(I_TEXT) TYPE C *" EXPORTING *" VALUE(E_COUNT) TYPE INT4 *" VALUE(ANSWER) *" EXCEPTIONS *" CANCELLED *"---------------------------------------------------------------------- i_title = iv_title. answer = '2'. call function 'TEXT_SPLIT' exporting length = 40 text = i_text importing line = textline1 rest = textline2. textmenge = 0. txt_wert = text-001. call screen 0500 starting at 5 10. " Return results: answer = l_antwort. e_count = textmenge. endfunction. module pbo0500_status output. set titlebar 'TEXT_INPUT' with i_title. set pf-status 'ZPOPUP'. case sy-ucomm. when 'YES'. l_antwort = '1'. leave to screen 0. when 'NO'. l_antwort = '2'. leave to screen 0. endcase. endmodule. form pai0500_user_command . set screen 0. leave screen. endform.
Change spool request name (ewm)
To change spool request name for printing forms (they are was set up in SPPFCADM transaction) we can add next enhancement into FM /SCWM/EXECUTE_PPF_WO_PDF (warehouse order):
ENHANCEMENT 1 Y_PPF_WO_PDF. "active version field-symbols: <ft> type /scwm/tt_whohu_pdf. assign ('LT_WHOHU_PDF') to <ft>. if <ft> is assigned. zscwm_ex_prnt_pdf_wo=>set_whohu_ref( changing ct_whohu = <ft> ). endif. data: v_text1(10) ,v_text2(10) ,v_text3(10) ,v_text4(20). xs_output_params-reqnew = 'X'. xs_output_params-reqfinal = 'X'. split xs_output_params-covtitle at ' ' into v_text1 v_text2 v_text3 v_text4. clear: xs_output_params-covtitle. case iv_form. when 'Y_ZAKAZ_WO_MULTIPLE'. xs_output_params-covtitle = v_text3 && ' - Заказ на комплектование - ' && v_text2. when 'Y_ZAKAZ__WO_HUIDENT'. xs_output_params-covtitle = v_text3 && ' - ЕО (Handling unit) - ' && v_text2. when 'Y_BIRKA_DETALI_UZLA'. xs_output_params-covtitle = v_text3 && ' - Бирка №1 - ' && v_text2. when 'Y_BIRKA_DETALI_UZLA_N0'. xs_output_params-covtitle = v_text3 && ' - Бирка №0 - ' && v_text2. endcase. ENDENHANCEMENT.
For HU forms (FM /SCWM/EXECUTE_PPF_HU_PDF):
ENHANCEMENT 1 YEI_PPF_HU_PDF. "active version FIELD-SYMBOLS: <ft> TYPE /scwm/tt_huhdr_int. ASSIGN ('IT_HUHDR') TO <ft>. IF <ft> IS ASSIGNED. yscwm_ex_prnt_pdf_hu=>set_huhdr_ref( CHANGING ct_huhdr = <ft> ). ENDIF. ENDENHANCEMENT.