Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CLASS zcl_sales_order_bapis DEFINITION
- PUBLIC
- FINAL
- CREATE PUBLIC .
- PUBLIC SECTION.
- TYPES: BEGIN OF gy_variantvalue.
- INCLUDE TYPE zcl_zquotations_v2_mpc=>ts_variantvalues.
- TYPES: navvalues TYPE STANDARD TABLE OF zcl_zquotations_v2_mpc=>ts_values WITH DEFAULT KEY.
- TYPES: END OF gy_variantvalue.
- TYPES: BEGIN OF gy_material.
- INCLUDE TYPE zcl_zquotations_v2_mpc=>ts_material.
- TYPES: navvariantvalues TYPE STANDARD TABLE OF gy_variantvalue WITH DEFAULT KEY.
- TYPES: END OF gy_material.
- TYPES: BEGIN OF gy_quotation.
- INCLUDE TYPE zcl_zquotations_v2_mpc=>ts_quotation.
- TYPES: navcustomerdetail TYPE zcl_zquotations_v2_mpc=>ts_customerdetail.
- TYPES: navmaterial TYPE STANDARD TABLE OF gy_material WITH DEFAULT KEY.
- TYPES: navmessages TYPE STANDARD TABLE OF zcl_zquotations_v2_mpc=>ts_messages WITH DEFAULT KEY.
- TYPES: END OF gy_quotation.
- METHODS sales_order_create
- IMPORTING
- is_request TYPE gy_quotation
- EXPORTING
- es_request TYPE gy_quotation.
- METHODS sales_order_update
- IMPORTING
- is_request TYPE gy_quotation
- EXPORTING
- es_request TYPE gy_quotation.
- METHODS set_x_variable
- IMPORTING
- !i_strucnam TYPE data
- CHANGING
- !e_strucnam TYPE data .
- PROTECTED SECTION.
- PRIVATE SECTION.
- DATA: lt_qii TYPE STANDARD TABLE OF bapisditm.
- DATA: lt_qiix TYPE STANDARD TABLE OF bapisditmx.
- DATA: lt_qp TYPE STANDARD TABLE OF bapiparnr.
- DATA: lt_qa TYPE STANDARD TABLE OF bapiaddr1.
- DATA: lt_qcr TYPE STANDARD TABLE OF bapicucfg.
- DATA: lt_qcrf TYPE STANDARD TABLE OF bapicuref.
- DATA: lt_qci TYPE STANDARD TABLE OF bapicuins.
- DATA: lt_qcv TYPE STANDARD TABLE OF bapicuval.
- DATA: lt_schdl TYPE STANDARD TABLE OF bapischdl.
- DATA: lt_qcpo TYPE STANDARD TABLE OF bapicuprt.
- DATA: lt_bc TYPE STANDARD TABLE OF bapicond.
- DATA: lt_bcx TYPE STANDARD TABLE OF bapicondx.
- DATA: lt_t TYPE STANDARD TABLE OF bapisdtext.
- METHODS provide_quotation_tables
- IMPORTING
- is_request TYPE gy_quotation
- EXPORTING
- es_request TYPE gy_quotation
- quotation_header_in TYPE bapisdhd1
- quotation_header_inx TYPE bapisdhd1x
- quotation_items_in LIKE lt_qii
- quotation_items_inx LIKE lt_qiix
- quotation_partners LIKE lt_qp
- quotation_cfgs_ref LIKE lt_qcr
- quotation_cfgs_refinst LIKE lt_qcrf
- quotation_cfgs_inst LIKE lt_qci
- quotation_cfgs_value LIKE lt_qcv
- quotation_cfgs_part_of LIKE lt_qcpo
- quotation_schedules_in LIKE lt_schdl
- quotation_conditions_in LIKE lt_bc
- quotation_conditions_inx LIKE lt_bcx
- quotation_text LIKE lt_t
- quotation_addr LIKE lt_qa
- .
- ENDCLASS.
- CLASS ZCL_SALES_ORDER_BAPIS IMPLEMENTATION.
- METHOD provide_quotation_tables.
- CONSTANTS:
- c_sold_to_party TYPE char2 VALUE 'AG',
- c_ship_to_party TYPE char2 VALUE 'WE',
- c_sales_rep TYPE char2 VALUE 'AF',
- c_employee TYPE char2 VALUE 'ZM',
- c_quotation TYPE char2 VALUE 'AG'.
- DATA:
- lt_quotation_conditions_in TYPE TABLE OF bapicond,
- lt_quotation_conditions_inx TYPE TABLE OF bapicondx,
- ls_quotation_header_in TYPE bapisdhd1,
- lt_quotation_items_in TYPE TABLE OF bapisditm,
- lt_quotation_items_inx TYPE TABLE OF bapisditmx,
- lt_quotation_partners TYPE TABLE OF bapiparnr,
- lt_quotation_addr TYPE TABLE OF bapiaddr1,
- lt_quotation_cfgs_ref TYPE TABLE OF bapicucfg,
- lt_quotation_cfgs_refinst TYPE TABLE OF bapicuref,
- lt_quotation_cfgs_inst TYPE TABLE OF bapicuins,
- lt_quotation_cfgs_value TYPE TABLE OF bapicuval,
- lt_quotation_cfgs_part_of TYPE TABLE OF bapicuprt,
- ls_customerdetail TYPE zcl_zquotations_v2_mpc=>ts_customerdetail,
- lt_materials TYPE STANDARD TABLE OF gy_material WITH DEFAULT KEY,
- lt_chars TYPE STANDARD TABLE OF gy_variantvalue WITH DEFAULT KEY,
- lt_char_values TYPE STANDARD TABLE OF zcl_zquotations_v2_mpc=>ts_values,
- lt_quotation_text TYPE TABLE OF bapisdtext,
- lt_quotation_schedules_in TYPE TABLE OF bapischdl,
- ls_message TYPE bapiret2,
- lt_return TYPE bapirettab,
- lr_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
- lv_mts TYPE boolean,
- rt_mats TYPE RANGE OF matnr,
- lv_mtart TYPE mara-mtart,
- rt_mtart TYPE RANGE OF mara-mtart,
- lv_vkb TYPE xuvalue,
- lv_vkbur TYPE vbak-vkbur,
- lv_sales_office TYPE vkbur,
- ls_text LIKE LINE OF lt_quotation_text,
- lv_itm_number TYPE num6 VALUE '000000',
- lv_mat TYPE char18,
- lv_plant TYPE char4,
- lv_config_id TYPE num6 VALUE '000000',
- lv_inst_id TYPE num8 VALUE '00000000',
- lv_sap_code TYPE t006-msehi,
- lv_iso_code TYPE t006-isocode
- .
- CREATE OBJECT lr_busi_exc.
- lt_materials = is_request-navmaterial.
- " Get list of materials
- LOOP AT lt_materials ASSIGNING FIELD-SYMBOL(<ls_mat>).
- APPEND INITIAL LINE TO rt_mats ASSIGNING FIELD-SYMBOL(<ls_rt_mats>).
- <ls_rt_mats>-sign = 'I'.
- <ls_rt_mats>-option = 'EQ'.
- <ls_rt_mats>-low = |{ <ls_mat>-material ALPHA = IN }|.
- <ls_mat>-material = <ls_rt_mats>-low.
- ENDLOOP.
- " Check for MTS > when MTS > no root id needed
- SELECT mtart, matnr FROM mara INTO TABLE @DATA(lt_mtart) WHERE matnr IN @rt_mats.
- " MTS material: ZFE2, ZHAW, NLAG
- APPEND INITIAL LINE TO rt_mtart ASSIGNING FIELD-SYMBOL(<ls_rt_mtart>).
- <ls_rt_mtart>-low = 'ZFE2'.
- APPEND INITIAL LINE TO rt_mtart ASSIGNING <ls_rt_mtart>.
- <ls_rt_mtart>-low = 'ZHAW'.
- APPEND INITIAL LINE TO rt_mtart ASSIGNING <ls_rt_mtart>.
- <ls_rt_mtart>-low = 'NLAG'.
- LOOP AT rt_mtart ASSIGNING <ls_rt_mtart>.
- <ls_rt_mtart>-sign = 'I'.
- <ls_rt_mtart>-option = 'EQ'.
- ENDLOOP.
- " Read partner info from FE
- ls_customerdetail = is_request-navcustomerdetail.
- APPEND INITIAL LINE TO lt_quotation_partners ASSIGNING FIELD-SYMBOL(<ls_partner>).
- " ADD Sold to party
- <ls_partner>-partn_role = c_sold_to_party.
- <ls_partner>-partn_numb = ls_customerdetail-soldtoparty.
- APPEND <ls_partner> TO lt_quotation_partners.
- CLEAR <ls_partner>.
- " ADD Ship to party
- <ls_partner>-partn_role = c_ship_to_party.
- " If ship-to-party = SITE > derive ship-to-party
- APPEND INITIAL LINE TO lt_quotation_addr ASSIGNING FIELD-SYMBOL(<ls_addr>).
- IF ls_customerdetail-shiptoparty NS 'WERF' AND ls_customerdetail-shiptoparty NS 'BAUSTELLE' AND
- ls_customerdetail-shiptoparty NS 'CHANTIER' AND ls_customerdetail-shiptoparty NS 'SITE'.
- <ls_partner>-partn_numb = ls_customerdetail-shiptoparty.
- <ls_partner>-name = ls_customerdetail-shiptoname.
- ELSEIF ls_customerdetail-countryregion EQ 'BE'.
- SELECT SINGLE kunnr, name1
- INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
- FROM kna1
- WHERE land1 EQ @ls_customerdetail-countryregion
- AND ktokd EQ '0002'
- AND pstlz EQ @ls_customerdetail-postalcode.
- IF sy-subrc <> 0.
- " SITE NOT AVAILABLE
- ls_message-message = 'BE WERF not found'.
- ls_message-type = 'E'.
- APPEND ls_message TO lt_return.
- " Transfer the error message(s) into the exception object
- lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
- RAISE EXCEPTION lr_busi_exc.
- ENDIF.
- ELSEIF ls_customerdetail-countryregion EQ 'FR'.
- " Retrieve sales office
- GET PARAMETER ID 'VKB' FIELD lv_vkb.
- CLEAR lv_vkbur.
- CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
- EXPORTING
- input = lv_vkb
- IMPORTING
- output = lv_vkbur.
- " check if sales office is linked to the current sales organisation.
- IF NOT lv_vkbur IS INITIAL.
- SELECT SINGLE vkbur
- FROM tvkbz
- INTO lv_sales_office
- WHERE vkorg EQ ls_customerdetail-salesorg
- AND vtweg EQ ls_customerdetail-distributionchannel
- AND spart EQ ls_customerdetail-division
- AND vkbur EQ lv_vkbur.
- ENDIF.
- " Choose French ship-to based on user parameter
- IF lv_sales_office EQ 'K221'.
- SELECT SINGLE kunnr, name1
- INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
- FROM kna1
- WHERE land1 EQ @ls_customerdetail-countryregion
- AND ktokd EQ 'CPDA'
- AND kunnr EQ 'CHANTP221'
- AND aufsd EQ @space.
- IF sy-subrc <> 0.
- SELECT SINGLE kunnr, name1
- INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
- FROM kna1
- WHERE land1 EQ @ls_customerdetail-countryregion
- AND ktokd EQ 'CPDA'
- AND aufsd EQ @space.
- IF sy-subrc <> 0.
- " ERROR HANDLING > SITE NOT AVAILABLE
- ls_message-message = 'FR WERF with sales office K221 not found'.
- ls_message-type = 'E'.
- APPEND ls_message TO lt_return.
- " Transfer the error message(s) into the exception object
- lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
- RAISE EXCEPTION lr_busi_exc.
- ENDIF.
- ENDIF.
- ELSE.
- SELECT SINGLE kunnr, name1
- INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
- FROM kna1
- WHERE land1 EQ @ls_customerdetail-countryregion
- * AND ktokd EQ 'CPDA' " TODO: check if record is available on the system
- AND kunnr EQ 'CHANTIERFR'
- AND aufsd EQ @space.
- IF sy-subrc <> 0.
- SELECT SINGLE kunnr, name1
- INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
- FROM kna1
- WHERE land1 EQ @ls_customerdetail-countryregion
- AND ktokd EQ 'CPDA'
- AND aufsd EQ @space.
- IF sy-subrc <> 0.
- " SITE NOT AVAILABLE
- ls_message-message = 'FR WERF not found'.
- ls_message-type = 'E'.
- APPEND ls_message TO lt_return.
- " Transfer the error message(s) into the exception object
- lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
- RAISE EXCEPTION lr_busi_exc.
- ENDIF.
- ENDIF.
- ENDIF.
- ELSE.
- SELECT SINGLE kunnr, name1
- INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
- FROM kna1
- WHERE land1 EQ @ls_customerdetail-countryregion
- AND ktokd EQ 'CPDA'.
- IF sy-subrc <> 0.
- " SITE NOT AVAILABLE
- ls_message-message = 'WERF not found'.
- ls_message-type = 'E'.
- APPEND ls_message TO lt_return.
- " Transfer the error message(s) into the exception object
- lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
- RAISE EXCEPTION lr_busi_exc.
- ENDIF.
- ENDIF.
- " If ship-to-party = SITE then FE should provide the transport-zone
- <ls_partner>-transpzone = ls_customerdetail-shiptotransportzone.
- " Street number
- <ls_partner>-street = ls_customerdetail-street(35).
- " City code
- <ls_partner>-city = ls_customerdetail-city.
- " Country
- <ls_partner>-country = ls_customerdetail-countryregion.
- <ls_partner>-postl_code = ls_customerdetail-postalcode.
- <ls_partner>-telephone = ls_customerdetail-telephone.
- <ls_partner>-region = ls_customerdetail-regioncode.
- MOVE-CORRESPONDING <ls_partner>
- TO <ls_addr>.
- <ls_addr> = CORRESPONDING #( <ls_partner> MAPPING
- postl_cod1 = postl_code
- tel1_numbr = telephone
- ).
- <ls_addr>-street = ls_customerdetail-street(40).
- <ls_addr>-street_lng = ls_customerdetail-street.
- <ls_partner>-addr_link = '0000000001'.
- <ls_addr>-addr_no = '0000000001'.
- <ls_addr>-house_no = ls_customerdetail-shiptohousenr.
- SELECT SINGLE spras FROM kna1 INTO <ls_addr>-langu WHERE kunnr = ls_customerdetail-shiptoparty.
- UNASSIGN <ls_addr>.
- IF is_request-salesrep <> ''.
- " Providing sales representative
- APPEND <ls_partner> TO lt_quotation_partners.
- CLEAR <ls_partner>.
- <ls_partner>-partn_role = c_sales_rep.
- <ls_partner>-partn_numb = is_request-salesrep.
- ENDIF.
- " Providing employee responsible
- APPEND <ls_partner> TO lt_quotation_partners.
- CLEAR <ls_partner>.
- <ls_partner>-partn_role = c_employee.
- SELECT SINGLE pernr FROM pa0105 INTO <ls_partner>-partn_numb WHERE usrid EQ sy-uname. "#EC CI_NOFIRST key field is not available for where clause
- <ls_partner>-partn_numb = |{ <ls_partner>-partn_numb ALPHA = IN }|.
- ls_quotation_header_in-qt_valid_f = ls_customerdetail-validfrom.
- ls_quotation_header_in-qt_valid_t = ls_customerdetail-validto.
- ls_quotation_header_in-req_date_h = ls_customerdetail-deliveryuntil.
- ls_quotation_header_in-pmnttrms = ls_customerdetail-paymentterms.
- ls_quotation_header_in-incoterms1 = ls_customerdetail-incoterms.
- ls_quotation_header_in-incoterms2 = ls_customerdetail-incoterms2.
- ls_quotation_header_in-name = ls_customerdetail-contactperson.
- ls_quotation_header_in-price_list = ls_customerdetail-pricelist.
- ls_quotation_header_in-doc_type = c_quotation.
- ls_quotation_header_in-sales_org = ls_customerdetail-salesorg.
- ls_quotation_header_in-distr_chan = ls_customerdetail-distributionchannel.
- ls_quotation_header_in-division = ls_customerdetail-division.
- ls_quotation_header_in-purch_no_c = ls_customerdetail-customerref.
- " Get language of sold to party
- data lv_sold_to_party_language type spras.
- select single SPRAS from kna1
- into lv_sold_to_party_language
- where KUNNR = ls_customerdetail-soldtoparty.
- " HEADER TEXT
- IF is_request-navcustomerdetail-headertext IS NOT INITIAL.
- ls_text-text_id = 'Z003'.
- ls_text-langu = lv_sold_to_party_language.
- ls_text-format_col = '*'.
- ls_text-text_line = is_request-navcustomerdetail-headertext.
- APPEND ls_text TO lt_quotation_text.
- ENDIF.
- LOOP AT lt_materials ASSIGNING <ls_mat>.
- READ TABLE lt_mtart ASSIGNING FIELD-SYMBOL(<ls_mtart>) WITH KEY matnr = <ls_mat>-material.
- IF <ls_mtart>-mtart IN rt_mtart.
- " MTS material
- lv_mts = abap_true.
- ELSE.
- " No MTS material
- lv_mts = abap_false.
- ENDIF.
- lv_mat = |{ <ls_mat>-material ALPHA = IN }|.
- lv_plant = <ls_mat>-plant.
- lv_itm_number = <ls_mat>-itemnrlong.
- " ITEM TEXT
- CLEAR ls_text.
- IF <ls_mat>-itemtext IS NOT INITIAL.
- ls_text-itm_number = lv_itm_number.
- ls_text-text_id = 'Z011'.
- ls_text-langu = lv_sold_to_party_language.
- ls_text-format_col = '*'.
- ls_text-text_line = <ls_mat>-itemtext.
- APPEND ls_text TO lt_quotation_text.
- ENDIF.
- APPEND INITIAL LINE TO lt_quotation_schedules_in ASSIGNING FIELD-SYMBOL(<lv_qsi>).
- <lv_qsi>-itm_number = lv_itm_number.
- <lv_qsi>-req_qty = <ls_mat>-quantity.
- <lv_qsi>-sched_line = '0001'.
- APPEND INITIAL LINE TO lt_quotation_items_inx ASSIGNING FIELD-SYMBOL(<lv_updateflag>).
- <lv_updateflag> = <ls_mat>-updateflag.
- IF <ls_mat>-manualprice IS NOT INITIAL.
- APPEND INITIAL LINE TO lt_quotation_conditions_in ASSIGNING FIELD-SYMBOL(<lv_qci>).
- <lv_qci>-itm_number = lv_itm_number.
- <lv_qci>-cond_type = 'PN00'.
- <lv_qci>-cond_value = <ls_mat>-manualprice / 10.
- " TODO: Conversion
- " box -> box
- " m2 -> m2
- " PC -> ST
- IF <ls_mat>-manualpriceunit EQ 'PC'.
- <lv_qci>-cond_unit = 'ST'.
- ELSE.
- <lv_qci>-cond_unit = <ls_mat>-manualpriceunit.
- ENDIF.
- APPEND INITIAL LINE TO lt_quotation_conditions_inx ASSIGNING FIELD-SYMBOL(<lv_qcix>).
- <lv_qcix>-itm_number = lv_itm_number.
- <lv_qcix>-cond_type = 'X'.
- <lv_qcix>-cond_value = 'X'.
- <lv_qcix>-cond_unit = 'X'.
- <lv_qcix>-updateflag = 'U'.
- ENDIF.
- APPEND INITIAL LINE TO lt_quotation_items_in ASSIGNING FIELD-SYMBOL(<ls_item>).
- <ls_item>-itm_number = lv_itm_number.
- <ls_item>-po_itm_no = lv_itm_number.
- <ls_item>-poitm_no_s = ls_customerdetail-customerref.
- <ls_item>-material = lv_mat.
- <ls_item>-plant = lv_plant.
- <ls_item>-alt_to_itm = <ls_mat>-alternativeforitem.
- <ls_item>-target_qty = <ls_mat>-quantity.
- lv_iso_code = <ls_mat>-quantityunit.
- CALL FUNCTION 'UNIT_OF_MEASURE_ISO_TO_SAP'
- EXPORTING
- iso_code = lv_iso_code " ISO code for the measurement unit
- IMPORTING
- sap_code = lv_sap_code " SAP code for the measurement unit
- EXCEPTIONS
- not_found = 1
- OTHERS = 2.
- IF sy-subrc <> 0.
- " PROCEED
- ENDIF.
- IF lv_sap_code <> ''.
- <ls_item>-target_qu = lv_sap_code.
- <ls_item>-sales_unit = lv_sap_code.
- ELSE.
- <ls_item>-target_qu = <ls_mat>-quantityunit.
- <ls_item>-sales_unit = <ls_mat>-quantityunit.
- ENDIF.
- <ls_item>-short_text = ''.
- " CHARACTERISTICS
- lt_chars = <ls_mat>-navvariantvalues.
- lv_config_id = lv_config_id + 1.
- lv_inst_id = lv_inst_id + 1.
- IF lv_mts EQ abap_false.
- " ADD entry in configs reference table
- APPEND INITIAL LINE TO lt_quotation_cfgs_ref ASSIGNING FIELD-SYMBOL(<ls_ref>).
- " external item number
- <ls_ref>-posex = lv_itm_number.
- " external configuration id
- <ls_ref>-config_id = lv_config_id.
- <ls_ref>-root_id = '00000001'.
- " ADD entry in configs instance table
- APPEND INITIAL LINE TO lt_quotation_cfgs_inst ASSIGNING FIELD-SYMBOL(<ls_inst>).
- " External configuration id.
- <ls_inst>-config_id = lv_config_id.
- " Instance number in configuration.
- <ls_inst>-inst_id = '00000001'.
- <ls_inst>-obj_type = 'MARA'.
- <ls_inst>-class_type = '300'.
- <ls_inst>-obj_key = lv_mat.
- " Quantity
- <ls_inst>-quantity = <ls_item>-target_qty.
- " Quantity unit
- <ls_inst>-quantity_unit = <ls_item>-target_qu.
- LOOP AT lt_chars ASSIGNING FIELD-SYMBOL(<ls_char>) where manuallychanged = 'X'.
- lt_char_values = <ls_char>-navvalues.
- " CHARACTERISTIC DETAILS
- LOOP AT lt_char_values ASSIGNING FIELD-SYMBOL(<ls_char_values>).
- APPEND INITIAL LINE TO lt_quotation_cfgs_value ASSIGNING FIELD-SYMBOL(<ls_value>).
- " External configuration id
- <ls_value>-config_id = lv_config_id.
- " Instance number in configuration
- <ls_value>-inst_id = '00000001'. "lv_inst_id.
- " Characteristic name
- <ls_value>-charc = <ls_char>-char.
- <ls_value>-value = <ls_char_values>-value.
- ENDLOOP.
- ENDLOOP.
- ENDIF.
- ENDLOOP.
- MOVE-CORRESPONDING ls_quotation_header_in TO quotation_header_in.
- MOVE-CORRESPONDING lt_quotation_items_in TO quotation_items_in.
- MOVE-CORRESPONDING lt_quotation_items_inx TO quotation_items_inx.
- MOVE-CORRESPONDING lt_quotation_partners TO quotation_partners.
- MOVE-CORRESPONDING lt_quotation_cfgs_ref TO quotation_cfgs_ref.
- MOVE-CORRESPONDING lt_quotation_cfgs_refinst TO quotation_cfgs_refinst.
- MOVE-CORRESPONDING lt_quotation_cfgs_inst TO quotation_cfgs_inst.
- MOVE-CORRESPONDING lt_quotation_cfgs_value TO quotation_cfgs_value.
- MOVE-CORRESPONDING lt_quotation_schedules_in TO quotation_schedules_in.
- MOVE-CORRESPONDING lt_quotation_cfgs_part_of TO quotation_cfgs_part_of.
- MOVE-CORRESPONDING lt_quotation_conditions_in TO quotation_conditions_in.
- MOVE-CORRESPONDING lt_quotation_conditions_inx TO quotation_conditions_inx.
- MOVE-CORRESPONDING lt_quotation_text TO quotation_text.
- MOVE-CORRESPONDING lt_quotation_addr TO quotation_addr.
- ENDMETHOD.
- METHOD sales_order_create.
- DATA:
- lv_salesdocument TYPE bapivbeln-vbeln,
- ls_sold_to_party TYPE bapisoldto,
- ls_ship_to_party TYPE bapishipto,
- ls_billing_party TYPE bapipayer,
- lt_return TYPE TABLE OF bapiret2,
- lr_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
- lv_error TYPE flag,
- ls_quotation_header_in TYPE bapisdhd1,
- ls_quotation_header_inx TYPE bapisdhd1x,
- lt_quotation_items_in TYPE TABLE OF bapisditm,
- lt_quotation_items_inx TYPE TABLE OF bapisditmx,
- lt_quotation_partners TYPE TABLE OF bapiparnr,
- lt_quotation_addr TYPE TABLE OF bapiaddr1,
- lt_quotation_cfgs_ref TYPE TABLE OF bapicucfg, "BAPICUCFG
- lt_quotation_cfgs_refinst TYPE TABLE OF bapicuref,
- lt_quotation_cfgs_inst TYPE TABLE OF bapicuins, "BAPICUINS
- lt_quotation_cfgs_value TYPE TABLE OF bapicuval, "BAPICUVAL
- lt_quotation_cfgs_part_of TYPE TABLE OF bapicuprt,
- lt_quotation_schedules_in TYPE TABLE OF bapischdl,
- lt_quotation_schedules_inx TYPE TABLE OF bapischdlx,
- lt_quotation_text TYPE TABLE OF bapisdtext,
- lt_quotation_conditions_in LIKE lt_bc,
- lt_quotation_conditions_inx LIKE lt_bcx,
- ls_cust LIKE es_request-navcustomerdetail,
- lt_mat LIKE es_request-navmaterial,
- lv_index TYPE i.
- TRY.
- " Import input table that will be used by BAPI_QUOTATION_CREATEFROMDATA2
- CALL METHOD provide_quotation_tables
- EXPORTING
- is_request = is_request
- IMPORTING
- quotation_header_in = ls_quotation_header_in
- quotation_items_in = lt_quotation_items_in
- quotation_partners = lt_quotation_partners
- quotation_cfgs_ref = lt_quotation_cfgs_ref
- quotation_cfgs_refinst = lt_quotation_cfgs_refinst
- quotation_cfgs_inst = lt_quotation_cfgs_inst
- quotation_cfgs_value = lt_quotation_cfgs_value
- quotation_cfgs_part_of = lt_quotation_cfgs_part_of
- quotation_schedules_in = lt_quotation_schedules_in
- quotation_conditions_in = lt_quotation_conditions_in
- quotation_conditions_inx = lt_quotation_conditions_inx
- quotation_text = lt_quotation_text
- quotation_addr = lt_quotation_addr.
- CATCH /iwbep/cx_mgw_busi_exception. "/iwbep/cx_mgw_tech_exception.
- APPEND INITIAL LINE TO es_request-navmessages ASSIGNING FIELD-SYMBOL(<ls_message>).
- <ls_message>-type = 'E'.
- <ls_message>-message = 'SITE NOT AVAILABLE'.
- <ls_message>-key = '0'.
- <ls_message>-char = 'X'.
- EXIT.
- ENDTRY.
- CALL METHOD set_x_variable
- EXPORTING
- i_strucnam = ls_quotation_header_in
- CHANGING
- e_strucnam = ls_quotation_header_inx.
- ls_quotation_header_inx-updateflag = ' '.
- LOOP AT lt_quotation_schedules_in ASSIGNING FIELD-SYMBOL(<ls_quotation_si>).
- APPEND INITIAL LINE TO lt_quotation_schedules_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_six>).
- CALL METHOD set_x_variable
- EXPORTING
- i_strucnam = <ls_quotation_si>
- CHANGING
- e_strucnam = <ls_quotation_six>.
- <ls_quotation_six>-itm_number = <ls_quotation_si>-itm_number.
- <ls_quotation_six>-sched_line = <ls_quotation_si>-sched_line.
- " I: insert
- <ls_quotation_six>-updateflag = 'I'.
- ENDLOOP.
- LOOP AT lt_quotation_items_in ASSIGNING FIELD-SYMBOL(<ls_quotation_item>).
- APPEND INITIAL LINE TO lt_quotation_items_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_itemx>).
- CALL METHOD set_x_variable
- EXPORTING
- i_strucnam = <ls_quotation_item>
- CHANGING
- e_strucnam = <ls_quotation_itemx>.
- <ls_quotation_itemx>-itm_number = <ls_quotation_item>-itm_number.
- " I: insert
- <ls_quotation_itemx>-updateflag = 'I'.
- ENDLOOP.
- " Setting Fiori flag in memory > this will trigger user exit ZMV45AFZZ_MOVE_FIELD_TO_VBAK01
- CALL FUNCTION 'ZS_SD_SET_SO_ITEM_DATA'
- EXPORTING
- iv_fiori_flag = abap_true.
- CALL FUNCTION 'BAPI_QUOTATION_CREATEFROMDATA2'
- EXPORTING
- quotation_header_in = ls_quotation_header_in " Order header
- quotation_header_inx = ls_quotation_header_inx
- IMPORTING
- salesdocument = lv_salesdocument " Sales and Distribution Document Number
- TABLES
- quotation_items_in = lt_quotation_items_in " Item Data Input
- quotation_items_inx = lt_quotation_items_inx
- quotation_partners = lt_quotation_partners " Partners
- quotation_cfgs_ref = lt_quotation_cfgs_ref " Configuration: Reference data
- quotation_cfgs_inst = lt_quotation_cfgs_inst " Configuration: Instances
- quotation_cfgs_value = lt_quotation_cfgs_value " Configuration: Characteristic values
- quotation_schedules_in = lt_quotation_schedules_in
- quotation_schedules_inx = lt_quotation_schedules_inx
- quotation_conditions_in = lt_quotation_conditions_in
- quotation_conditions_inx = lt_quotation_conditions_inx
- quotation_text = lt_quotation_text
- partneraddresses = lt_quotation_addr
- return = lt_return. " Error Text
- " ERROR HANDLING
- LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_error>).
- APPEND INITIAL LINE TO es_request-navmessages ASSIGNING <ls_message>.
- <ls_message>-type = <fs_error>-type.
- <ls_message>-message = <fs_error>-message.
- <ls_message>-key = '0'.
- <ls_message>-char = 'X'.
- IF <fs_error>-type CA 'AEX'.
- lv_error = abap_true.
- es_request-key = '0'.
- es_request-action = 'A'.
- es_request-salesdocument = 'X'.
- ls_cust-key = '0'.
- es_request-navcustomerdetail = ls_cust.
- APPEND INITIAL LINE TO lt_mat ASSIGNING FIELD-SYMBOL(<ls_mat>).
- <ls_mat>-key = '0'.
- es_request-navmaterial = lt_mat.
- ENDIF.
- ENDLOOP.
- " Disabling Fiori flag in memory
- CALL FUNCTION 'ZS_SD_SET_SO_ITEM_DATA'
- EXPORTING
- iv_fiori_flag = abap_false.
- UNASSIGN <fs_error>.
- IF lv_error EQ abap_true.
- CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
- ELSE.
- CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = abap_true.
- " Letter I is send to the FE to indicate the successful creation of a new quotation
- es_request-key = 'I'.
- es_request-salesdocument = lv_salesdocument.
- ENDIF.
- ENDMETHOD.
- METHOD sales_order_update.
- " This method will update a certain quotation with the parameters passed from the my quotation application v2
- DATA:
- lv_salesdocument TYPE bapivbeln-vbeln,
- ls_sold_to_party TYPE bapisoldto,
- ls_ship_to_party TYPE bapishipto,
- ls_billing_party TYPE bapipayer,
- lt_return TYPE TABLE OF bapiret2,
- lt_return_2 TYPE TABLE OF bapiret2,
- lr_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
- lv_error TYPE flag,
- lt_quotation_conditions_in LIKE lt_bc,
- lt_quotation_conditions_inx LIKE lt_bcx,
- lt_quotation_addr LIKE lt_qa,
- lv_sales_doc_in TYPE bapivbeln-vbeln,
- ls_quotation_header_in TYPE bapisdhd1,
- ls_quotation_header_inx TYPE bapisdhd1x,
- lt_quotation_items_in TYPE TABLE OF bapisditm,
- lt_quotation_items_inx TYPE TABLE OF bapisditmx,
- lt_quotation_text TYPE TABLE OF bapisdtext,
- lt_quotation_partners TYPE TABLE OF bapiparnr,
- lt_quotation_cfgs_ref TYPE TABLE OF bapicucfg,
- lt_quotation_cfgs_refinst TYPE TABLE OF bapicuref,
- lt_quotation_cfgs_inst TYPE TABLE OF bapicuins,
- lt_quotation_cfgs_value TYPE TABLE OF bapicuval,
- lt_quotation_cfgs_part_of TYPE TABLE OF bapicuprt,
- lt_quotation_schedules_in TYPE TABLE OF bapischdl,
- lt_quotation_schedules_inx TYPE TABLE OF bapischdlx,
- lt_vbap TYPE TABLE OF posnr,
- lv_vbap TYPE posnr,
- lv_salesdoc TYPE vbeln,
- rt_posnr TYPE RANGE OF posnr,
- lt_partnerchanges TYPE TABLE OF bapiparnrc,
- lt_partneraddresses TYPE TABLE OF bapiaddr1,
- ls_quotation_header_inx_2 TYPE bapisdh1x,
- ls_cust LIKE es_request-navcustomerdetail,
- lt_mat LIKE es_request-navmaterial,
- lv_index TYPE i.
- CREATE OBJECT lr_busi_exc.
- " import tables for create_quotation BAPI
- CALL METHOD provide_quotation_tables
- EXPORTING
- is_request = is_request
- IMPORTING
- quotation_header_in = ls_quotation_header_in
- quotation_items_in = lt_quotation_items_in
- quotation_partners = lt_quotation_partners
- quotation_cfgs_ref = lt_quotation_cfgs_ref
- quotation_cfgs_refinst = lt_quotation_cfgs_refinst
- quotation_cfgs_inst = lt_quotation_cfgs_inst
- quotation_cfgs_value = lt_quotation_cfgs_value
- quotation_cfgs_part_of = lt_quotation_cfgs_part_of
- quotation_schedules_in = lt_quotation_schedules_in
- quotation_conditions_in = lt_quotation_conditions_in
- quotation_conditions_inx = lt_quotation_conditions_inx
- quotation_text = lt_quotation_text
- quotation_addr = lt_quotation_addr.
- lv_sales_doc_in = is_request-salesdocument.
- lv_sales_doc_in = |{ lv_sales_doc_in ALPHA = IN }| .
- CALL METHOD set_x_variable
- EXPORTING
- i_strucnam = ls_quotation_header_in
- CHANGING
- e_strucnam = ls_quotation_header_inx.
- ls_quotation_header_inx-updateflag = 'U'.
- " I : add new item
- " U : update current item
- LOOP AT lt_quotation_schedules_in ASSIGNING FIELD-SYMBOL(<ls_quotation_si>).
- APPEND INITIAL LINE TO lt_quotation_schedules_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_six>).
- CALL METHOD set_x_variable
- EXPORTING
- i_strucnam = <ls_quotation_si>
- CHANGING
- e_strucnam = <ls_quotation_six>.
- <ls_quotation_six>-itm_number = <ls_quotation_si>-itm_number.
- <ls_quotation_six>-sched_line = <ls_quotation_si>-sched_line.
- <ls_quotation_six>-updateflag = 'U'.
- ENDLOOP.
- lv_salesdoc = is_request-salesdocument.
- " Check the existence of item lines for the quotation
- " > if the item line is new we need to set the insert flag
- " > else we set the update flag
- SELECT posnr FROM vbap INTO TABLE @lt_vbap WHERE vbeln = @lv_salesdoc.
- LOOP AT lt_vbap INTO lv_vbap.
- APPEND INITIAL LINE TO rt_posnr ASSIGNING FIELD-SYMBOL(<ls_rt_posnr>).
- <ls_rt_posnr>-sign = 'I'.
- <ls_rt_posnr>-option = 'EQ'.
- <ls_rt_posnr>-low = lv_vbap.
- ENDLOOP.
- LOOP AT lt_quotation_items_in ASSIGNING FIELD-SYMBOL(<ls_quotation_item>).
- APPEND INITIAL LINE TO lt_quotation_items_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_itemx>).
- CALL METHOD set_x_variable
- EXPORTING
- i_strucnam = <ls_quotation_item>
- CHANGING
- e_strucnam = <ls_quotation_itemx>.
- <ls_quotation_itemx>-itm_number = <ls_quotation_item>-itm_number.
- IF <ls_quotation_item>-itm_number IN rt_posnr.
- <ls_quotation_itemx>-updateflag = 'U'.
- ELSE.
- <ls_quotation_itemx>-updateflag = 'I'.
- ENDIF.
- ENDLOOP.
- " EXTRACT SHIPTO PARTNER & ADDRESS for PARTNER UPDATE BAPI
- MOVE-CORRESPONDING lt_quotation_addr TO lt_partneraddresses.
- ls_quotation_header_inx_2-updateflag = 'U'.
- LOOP AT lt_quotation_partners ASSIGNING FIELD-SYMBOL(<ls_partner>) WHERE partn_role EQ 'WE'.
- APPEND INITIAL LINE TO lt_partnerchanges ASSIGNING FIELD-SYMBOL(<ls_partner_change>).
- <ls_partner_change>-document = lv_sales_doc_in.
- <ls_partner_change>-updateflag = 'U'.
- <ls_partner_change>-addr_link = <ls_partner>-addr_link.
- <ls_partner_change>-partn_role = <ls_partner>-partn_role.
- <ls_partner_change>-p_numb_new = <ls_partner>-partn_numb.
- <ls_partner_change>-p_numb_new = |{ <ls_partner_change>-p_numb_new ALPHA = IN }| .
- ENDLOOP.
- " Retrieve the configuration of the quotation
- DATA:
- i_bapi_view TYPE order_view,
- i_memory_read TYPE order_read-mem_access,
- i_with_header_conditions TYPE xfeld,
- sales_documents TYPE TABLE OF sales_key,
- order_headers_out TYPE TABLE OF bapisdhd,
- order_items_out TYPE TABLE OF bapisdit,
- order_schedules_out TYPE TABLE OF bapisdhedu,
- order_business_out TYPE TABLE OF bapisdbusi,
- order_partners_out TYPE TABLE OF bapisdpart,
- order_address_out TYPE TABLE OF bapisdcoad,
- order_statusheaders_out TYPE TABLE OF bapisdhdst,
- order_statusitems_out TYPE TABLE OF bapisditst,
- order_conditions_out TYPE TABLE OF bapisdcond,
- order_cond_head TYPE TABLE OF bapicondhd,
- order_cond_item TYPE TABLE OF bapicondit,
- order_cond_qty_scale TYPE TABLE OF bapicondqs,
- order_cond_val_scale TYPE TABLE OF bapicondvs,
- order_contracts_out TYPE TABLE OF bapisdcntr,
- order_textheaders_out TYPE TABLE OF bapisdtehd,
- order_textlines_out TYPE TABLE OF bapitextli,
- order_flows_out TYPE TABLE OF bapisdflow,
- order_cfgs_curefs_out TYPE TABLE OF bapicurefm,
- order_cfgs_cucfgs_out TYPE TABLE OF bapicucfgm,
- order_cfgs_cuins_out TYPE TABLE OF bapicuinsm,
- order_cfgs_cuprts_out TYPE TABLE OF bapicuprtm,
- order_cfgs_cuvals_out TYPE TABLE OF bapicuvalm,
- order_cfgs_cublbs_out TYPE TABLE OF bapicublbm,
- order_cfgs_cuvks_out TYPE TABLE OF bapicuvkm,
- order_billingplans_out TYPE TABLE OF bapisdbpl,
- order_billingdates_out TYPE TABLE OF bapisdbpld,
- order_creditcards_out TYPE TABLE OF bapiccardm,
- extensionout TYPE TABLE OF bapiparex.
- i_bapi_view-configure = 'X'.
- APPEND LV_SALES_DOC_IN TO sales_documents.
- CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
- EXPORTING
- i_bapi_view = i_bapi_view " Bapi View for Data Reduction
- i_memory_read = ''
- i_with_header_conditions = i_with_header_conditions
- TABLES
- sales_documents = sales_documents " Document Numbers to Be Selected
- order_headers_out = order_headers_out " Order Headers for Document Numbers
- order_items_out = order_items_out " Order Item Data for Document Numbers
- order_schedules_out = order_schedules_out " Order Schedule Lines for Document Numbers
- order_business_out = order_business_out " Business Data for Document Numbers
- order_partners_out = order_partners_out " Order Partners for Document Numbers
- order_address_out = order_address_out
- order_statusheaders_out = order_statusheaders_out " Header Status for Document Numbers
- order_statusitems_out = order_statusitems_out " Item Status for Document Numbers
- order_conditions_out = order_conditions_out " Order Conditions for Document Numbers
- order_cond_head = order_cond_head
- order_cond_item = order_cond_item
- order_cond_qty_scale = order_cond_qty_scale
- order_cond_val_scale = order_cond_val_scale
- order_contracts_out = order_contracts_out " Contract Data for Document Numbers
- order_textheaders_out = order_textheaders_out " Text Header Information for Document Numbers
- order_textlines_out = order_textlines_out " Text Lines for Document Numbers
- order_flows_out = order_flows_out " Document Flows for Document Numbers
- order_cfgs_curefs_out = order_cfgs_curefs_out " Instance in the Configuration for Document Numbers
- order_cfgs_cucfgs_out = order_cfgs_cucfgs_out " Configuration Data for Document Numbers
- order_cfgs_cuins_out = order_cfgs_cuins_out " Instance Data for Document Numbers
- order_cfgs_cuprts_out = order_cfgs_cuprts_out " PartOf Data for Document Numbers
- order_cfgs_cuvals_out = order_cfgs_cuvals_out " Characteristic Value Assignment for Document Numbers
- order_cfgs_cublbs_out = order_cfgs_cublbs_out " Configuration BLOB for Document Numbers
- order_cfgs_cuvks_out = order_cfgs_cuvks_out
- order_billingplans_out = order_billingplans_out " Billing Plan for Document Numbers
- order_billingdates_out = order_billingdates_out " Billing Plan Deadlines for Document Numbers
- order_creditcards_out = order_creditcards_out " Credit Cards for Document Numbers
- extensionout = extensionout.
- * " POSEX > config_id
- * " 0010 > 1
- * " 0020 > 2
- * " 0030 > 3
- * " 0040 > 4
- * types: begin of gy_posex_mapping,
- * posex_new type CU_POSEX,
- * posex_old type cu_posex,
- * config_id type CUXCFG_ID,
- * end of gy_posex_mapping.
- * data lt_posex_mapping type table of gy_posex_mapping.
- *
- * LOOP AT is_request-navmaterial ASSIGNING FIELD-SYMBOL(<ls_mat>).
- * append INITIAL LINE TO lt_posex_mapping
- * ASSIGNING FIELD-SYMBOL(<ls_posex_mapping>).
- * <ls_posex_mapping>-posex_new = <ls_mat>-itemnrlong.
- * <ls_posex_mapping>-posex_old = <ls_mat>-itemnrlongold.
- * read table order_cfgs_cucfgs_out
- * with key posex = <ls_mat>-itemnrlongold
- *
- * endloop.
- data lt_quotation_cfgs_value_mc TYPE TABLE OF bapicuval.
- lt_quotation_cfgs_value_mc = lt_quotation_cfgs_value.
- loop at order_cfgs_cuvals_out ASSIGNING FIELD-SYMBOL(<ls_cuvals_out>).
- read table lt_quotation_cfgs_value_mc TRANSPORTING NO FIELDS WITH KEY charc = <ls_cuvals_out>-charc config_id = <ls_cuvals_out>-config_id.
- if sy-subrc = 0.
- * " Entry is found > do nothing
- else.
- " Append an entry
- APPEND INITIAL LINE TO lt_quotation_cfgs_value ASSIGNING FIELD-SYMBOL(<ls_cfg>).
- <ls_cfg>-config_id = <ls_cuvals_out>-config_id.
- <ls_cfg>-inst_id = <ls_cuvals_out>-inst_id.
- <ls_cfg>-charc = <ls_cuvals_out>-charc.
- <ls_cfg>-value = <ls_cuvals_out>-value.
- <ls_cfg>-author = <ls_cuvals_out>-author.
- endif.
- endloop.
- " The partner tables & addresses will be updated by the BAPI_CUSTOMERQUOTATION_CHANGE below
- CLEAR lt_quotation_partners.
- CLEAR lt_quotation_addr.
- CALL FUNCTION 'BAPI_QUOTATION_CREATEFROMDATA2'
- EXPORTING
- salesdocumentin = lv_sales_doc_in
- quotation_header_in = ls_quotation_header_in " Order header
- quotation_header_inx = ls_quotation_header_inx
- IMPORTING
- salesdocument = lv_salesdocument " Sales and Distribution Document Number
- TABLES
- quotation_items_in = lt_quotation_items_in " Item Data Input
- quotation_items_inx = lt_quotation_items_inx
- quotation_partners = lt_quotation_partners " Partners
- quotation_cfgs_ref = lt_quotation_cfgs_ref " Configuration: Reference data
- quotation_cfgs_inst = lt_quotation_cfgs_inst " Configuration: Instances
- quotation_cfgs_value = lt_quotation_cfgs_value " Configuration: Characteristic values
- quotation_schedules_in = lt_quotation_schedules_in
- quotation_schedules_inx = lt_quotation_schedules_inx
- quotation_conditions_in = lt_quotation_conditions_in
- quotation_conditions_inx = lt_quotation_conditions_inx
- partneraddresses = lt_quotation_addr
- quotation_text = lt_quotation_text
- return = lt_return. " Error Text
- " ERROR HANDLING
- LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_error>).
- lr_busi_exc->get_msg_container( )->add_message( EXPORTING iv_msg_type = <fs_error>-type iv_msg_text = <fs_error>-message iv_msg_id = <fs_error>-id iv_msg_number = <fs_error>-number
- iv_msg_v1 = <fs_error>-message_v1 iv_msg_v2 = <fs_error>-message_v2 iv_msg_v3 = <fs_error>-message_v3 iv_msg_v4 = <fs_error>-message_v4 ).
- APPEND INITIAL LINE TO es_request-navmessages ASSIGNING FIELD-SYMBOL(<ls_message>).
- <ls_message>-type = <fs_error>-type.
- <ls_message>-message = <fs_error>-message.
- <ls_message>-key = '0'.
- <ls_message>-char = 'X'.
- IF <fs_error>-type CA 'AEX'.
- lv_error = abap_true.
- ls_cust-key = '0'.
- es_request-navcustomerdetail = ls_cust.
- APPEND INITIAL LINE TO lt_mat ASSIGNING FIELD-SYMBOL(<ls_mat>).
- <ls_mat>-key = '0'.
- es_request-navmaterial = lt_mat.
- es_request-salesdocument = 'X'.
- ENDIF.
- ENDLOOP.
- UNASSIGN <fs_error>.
- "COMMIT
- IF lv_error EQ abap_true.
- CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
- RETURN.
- ELSE.
- CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = abap_true.
- ENDIF.
- " Separate BAPI is used to update partner & address info
- CALL FUNCTION 'BAPI_CUSTOMERQUOTATION_CHANGE'
- EXPORTING
- salesdocument = lv_sales_doc_in " Sales and Distribution Document Number
- quotation_header_inx = ls_quotation_header_inx_2 " Quotation Header Checkbox
- TABLES
- return = lt_return_2 " Return Code
- partnerchanges = lt_partnerchanges " Partner changes
- partneraddresses = lt_partneraddresses. " BAPI Reference Structure for Addresses (Org./Company)
- APPEND LINES OF lt_return_2 TO lt_return.
- " ERROR HANDLING
- LOOP AT lt_return ASSIGNING <fs_error>.
- lr_busi_exc->get_msg_container( )->add_message( EXPORTING iv_msg_type = <fs_error>-type iv_msg_text = <fs_error>-message iv_msg_id = <fs_error>-id iv_msg_number = <fs_error>-number
- iv_msg_v1 = <fs_error>-message_v1 iv_msg_v2 = <fs_error>-message_v2 iv_msg_v3 = <fs_error>-message_v3 iv_msg_v4 = <fs_error>-message_v4 ).
- APPEND INITIAL LINE TO es_request-navmessages ASSIGNING <ls_message>.
- <ls_message>-type = <fs_error>-type.
- <ls_message>-message = <fs_error>-message.
- <ls_message>-key = '0'.
- <ls_message>-char = 'X'.
- IF <fs_error>-type CA 'AEX'.
- lv_error = abap_true.
- ls_cust-key = '0'.
- es_request-navcustomerdetail = ls_cust.
- APPEND INITIAL LINE TO lt_mat ASSIGNING <ls_mat>.
- <ls_mat>-key = '0'.
- es_request-navmaterial = lt_mat.
- es_request-salesdocument = 'X'.
- ENDIF.
- ENDLOOP.
- UNASSIGN <fs_error>.
- "COMMIT
- IF lv_error EQ abap_true.
- CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
- RETURN.
- ELSE.
- CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = abap_true.
- ENDIF.
- data lv_sold_to_party_language type spras.
- " Read sold to party language
- select single SPRAS from kna1
- into lv_sold_to_party_language
- where KUNNR = is_request-navcustomerdetail-soldtoparty.
- "handle possible removal of header/item texts
- "header text
- IF is_request-navcustomerdetail-headertext IS INITIAL.
- IF lv_salesdocument IS NOT INITIAL.
- DATA lv_quot TYPE vbeln_va.
- DATA lv_name TYPE tdobname.
- DATA lt_lines TYPE TABLE OF tline.
- lv_quot = |{ lv_salesdocument ALPHA = IN }|.
- lv_name = lv_quot.
- "Retrieve & convert header text
- CALL FUNCTION 'READ_TEXT'
- EXPORTING
- id = 'Z003'
- language = lv_sold_to_party_language
- name = lv_name
- object = 'VBBK'
- TABLES
- lines = lt_lines
- EXCEPTIONS
- id = 1
- language = 2
- name = 3
- not_found = 4
- object = 5
- reference_check = 6
- wrong_access_to_archive = 7
- OTHERS = 8.
- IF sy-subrc EQ 0.
- CALL FUNCTION 'DELETE_TEXT'
- EXPORTING
- id = 'Z003' " Text ID of text to be deleted
- language = lv_sold_to_party_language " Language of text to be deleted
- name = lv_name " Name of text to be deleted
- object = 'VBBK' " Text object of text to be deleted
- savemode_direct = 'X'
- .
- IF sy-subrc <> 0.
- lv_error = abap_true.
- ENDIF.
- ENDIF.
- ENDIF.
- ENDIF.
- "item text
- LOOP AT is_request-navmaterial ASSIGNING FIELD-SYMBOL(<ls_items>).
- IF <ls_items>-itemtext IS INITIAL.
- IF lv_salesdocument IS NOT INITIAL AND <ls_items>-itemnrlong IS NOT INITIAL.
- DATA lv_quot_i TYPE vbeln_va.
- DATA lv_name_i TYPE tdobname.
- lv_name_i = |{ lv_salesdocument ALPHA = IN }{ <ls_items>-itemnrlong ALPHA = IN }|.
- FREE lt_lines.
- "Retrieve & convert header text
- CALL FUNCTION 'READ_TEXT'
- EXPORTING
- id = 'Z011'
- language = lv_sold_to_party_language
- name = lv_name_i
- object = 'VBBP'
- TABLES
- lines = lt_lines
- EXCEPTIONS
- id = 1
- language = 2
- name = 3
- not_found = 4
- object = 5
- reference_check = 6
- wrong_access_to_archive = 7
- OTHERS = 8.
- IF sy-subrc EQ 0.
- CALL FUNCTION 'DELETE_TEXT'
- EXPORTING
- id = 'Z011' " Text ID of text to be deleted
- language = lv_sold_to_party_language " Language of text to be deleted
- name = lv_name_i " Name of text to be deleted
- object = 'VBBP' " Text object of text to be deleted
- savemode_direct = 'X'
- .
- IF sy-subrc <> 0.
- lv_error = abap_true.
- ENDIF.
- ENDIF.
- ENDIF.
- ENDIF.
- ENDLOOP.
- IF lv_error EQ abap_true.
- CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
- ELSE.
- CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
- EXPORTING
- wait = abap_true.
- " The letter U is send to FE to indicate a successful sales document update
- es_request-key = 'U'.
- es_request-salesdocument = lv_salesdocument.
- ENDIF.
- ENDMETHOD.
- METHOD set_x_variable.
- DATA: lv_times TYPE i,
- lv_structref TYPE REF TO cl_abap_structdescr,
- lt_comp TYPE abap_compdescr_tab,
- ls_comp TYPE LINE OF abap_compdescr_tab,
- lv_xfield TYPE char40.
- FIELD-SYMBOLS <fs> TYPE any.
- FIELD-SYMBOLS <fs_field> TYPE any.
- lv_structref ?= cl_abap_structdescr=>describe_by_data( i_strucnam ).
- LOOP AT lv_structref->components INTO ls_comp.
- APPEND ls_comp TO lt_comp.
- ENDLOOP.
- DESCRIBE TABLE lt_comp LINES lv_times.
- DO lv_times TIMES.
- ASSIGN COMPONENT sy-index OF STRUCTURE i_strucnam TO <fs>.
- IF sy-subrc <> 0.
- EXIT.
- ELSE.
- IF NOT <fs> IS INITIAL.
- READ TABLE lt_comp INDEX sy-index INTO ls_comp.
- IF sy-subrc = 0.
- CONCATENATE 'e_strucnam' ls_comp-name INTO lv_xfield SEPARATED BY '-'.
- ASSIGN (lv_xfield) TO <fs_field>.
- IF sy-subrc = 0.
- <fs_field> = 'X'.
- ENDIF.
- ENDIF.
- ENDIF.
- ENDIF.
- ENDDO.
- ENDMETHOD.
- ENDCLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement