Advertisement
Guest User

Untitled

a guest
Aug 31st, 2018
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.45 KB | None | 0 0
  1.  
  2. CLASS zcl_sales_order_bapis DEFINITION
  3. PUBLIC
  4. FINAL
  5. CREATE PUBLIC .
  6.  
  7. PUBLIC SECTION.
  8.  
  9. TYPES: BEGIN OF gy_variantvalue.
  10. INCLUDE TYPE zcl_zquotations_v2_mpc=>ts_variantvalues.
  11. TYPES: navvalues TYPE STANDARD TABLE OF zcl_zquotations_v2_mpc=>ts_values WITH DEFAULT KEY.
  12. TYPES: END OF gy_variantvalue.
  13.  
  14. TYPES: BEGIN OF gy_material.
  15. INCLUDE TYPE zcl_zquotations_v2_mpc=>ts_material.
  16. TYPES: navvariantvalues TYPE STANDARD TABLE OF gy_variantvalue WITH DEFAULT KEY.
  17. TYPES: END OF gy_material.
  18.  
  19.  
  20. TYPES: BEGIN OF gy_quotation.
  21. INCLUDE TYPE zcl_zquotations_v2_mpc=>ts_quotation.
  22. TYPES: navcustomerdetail TYPE zcl_zquotations_v2_mpc=>ts_customerdetail.
  23. TYPES: navmaterial TYPE STANDARD TABLE OF gy_material WITH DEFAULT KEY.
  24. TYPES: navmessages TYPE STANDARD TABLE OF zcl_zquotations_v2_mpc=>ts_messages WITH DEFAULT KEY.
  25. TYPES: END OF gy_quotation.
  26.  
  27.  
  28. METHODS sales_order_create
  29. IMPORTING
  30. is_request TYPE gy_quotation
  31. EXPORTING
  32. es_request TYPE gy_quotation.
  33.  
  34. METHODS sales_order_update
  35. IMPORTING
  36. is_request TYPE gy_quotation
  37. EXPORTING
  38. es_request TYPE gy_quotation.
  39.  
  40.  
  41. METHODS set_x_variable
  42. IMPORTING
  43. !i_strucnam TYPE data
  44. CHANGING
  45. !e_strucnam TYPE data .
  46.  
  47.  
  48. PROTECTED SECTION.
  49. PRIVATE SECTION.
  50. DATA: lt_qii TYPE STANDARD TABLE OF bapisditm.
  51. DATA: lt_qiix TYPE STANDARD TABLE OF bapisditmx.
  52.  
  53. DATA: lt_qp TYPE STANDARD TABLE OF bapiparnr.
  54. DATA: lt_qa TYPE STANDARD TABLE OF bapiaddr1.
  55. DATA: lt_qcr TYPE STANDARD TABLE OF bapicucfg.
  56. DATA: lt_qcrf TYPE STANDARD TABLE OF bapicuref.
  57. DATA: lt_qci TYPE STANDARD TABLE OF bapicuins.
  58. DATA: lt_qcv TYPE STANDARD TABLE OF bapicuval.
  59. DATA: lt_schdl TYPE STANDARD TABLE OF bapischdl.
  60. DATA: lt_qcpo TYPE STANDARD TABLE OF bapicuprt.
  61. DATA: lt_bc TYPE STANDARD TABLE OF bapicond.
  62. DATA: lt_bcx TYPE STANDARD TABLE OF bapicondx.
  63. DATA: lt_t TYPE STANDARD TABLE OF bapisdtext.
  64.  
  65. METHODS provide_quotation_tables
  66. IMPORTING
  67. is_request TYPE gy_quotation
  68.  
  69. EXPORTING
  70. es_request TYPE gy_quotation
  71. quotation_header_in TYPE bapisdhd1
  72. quotation_header_inx TYPE bapisdhd1x
  73.  
  74. quotation_items_in LIKE lt_qii
  75. quotation_items_inx LIKE lt_qiix
  76.  
  77. quotation_partners LIKE lt_qp
  78. quotation_cfgs_ref LIKE lt_qcr
  79. quotation_cfgs_refinst LIKE lt_qcrf
  80. quotation_cfgs_inst LIKE lt_qci
  81. quotation_cfgs_value LIKE lt_qcv
  82.  
  83. quotation_cfgs_part_of LIKE lt_qcpo
  84.  
  85. quotation_schedules_in LIKE lt_schdl
  86.  
  87. quotation_conditions_in LIKE lt_bc
  88. quotation_conditions_inx LIKE lt_bcx
  89.  
  90. quotation_text LIKE lt_t
  91.  
  92. quotation_addr LIKE lt_qa
  93. .
  94.  
  95.  
  96.  
  97. ENDCLASS.
  98.  
  99.  
  100.  
  101. CLASS ZCL_SALES_ORDER_BAPIS IMPLEMENTATION.
  102.  
  103.  
  104. METHOD provide_quotation_tables.
  105.  
  106. CONSTANTS:
  107. c_sold_to_party TYPE char2 VALUE 'AG',
  108. c_ship_to_party TYPE char2 VALUE 'WE',
  109. c_sales_rep TYPE char2 VALUE 'AF',
  110. c_employee TYPE char2 VALUE 'ZM',
  111. c_quotation TYPE char2 VALUE 'AG'.
  112.  
  113. DATA:
  114. lt_quotation_conditions_in TYPE TABLE OF bapicond,
  115. lt_quotation_conditions_inx TYPE TABLE OF bapicondx,
  116. ls_quotation_header_in TYPE bapisdhd1,
  117. lt_quotation_items_in TYPE TABLE OF bapisditm,
  118. lt_quotation_items_inx TYPE TABLE OF bapisditmx,
  119. lt_quotation_partners TYPE TABLE OF bapiparnr,
  120. lt_quotation_addr TYPE TABLE OF bapiaddr1,
  121. lt_quotation_cfgs_ref TYPE TABLE OF bapicucfg,
  122. lt_quotation_cfgs_refinst TYPE TABLE OF bapicuref,
  123. lt_quotation_cfgs_inst TYPE TABLE OF bapicuins,
  124. lt_quotation_cfgs_value TYPE TABLE OF bapicuval,
  125. lt_quotation_cfgs_part_of TYPE TABLE OF bapicuprt,
  126. ls_customerdetail TYPE zcl_zquotations_v2_mpc=>ts_customerdetail,
  127. lt_materials TYPE STANDARD TABLE OF gy_material WITH DEFAULT KEY,
  128. lt_chars TYPE STANDARD TABLE OF gy_variantvalue WITH DEFAULT KEY,
  129. lt_char_values TYPE STANDARD TABLE OF zcl_zquotations_v2_mpc=>ts_values,
  130. lt_quotation_text TYPE TABLE OF bapisdtext,
  131. lt_quotation_schedules_in TYPE TABLE OF bapischdl,
  132. ls_message TYPE bapiret2,
  133. lt_return TYPE bapirettab,
  134. lr_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
  135. lv_mts TYPE boolean,
  136. rt_mats TYPE RANGE OF matnr,
  137. lv_mtart TYPE mara-mtart,
  138. rt_mtart TYPE RANGE OF mara-mtart,
  139. lv_vkb TYPE xuvalue,
  140. lv_vkbur TYPE vbak-vkbur,
  141. lv_sales_office TYPE vkbur,
  142. ls_text LIKE LINE OF lt_quotation_text,
  143. lv_itm_number TYPE num6 VALUE '000000',
  144. lv_mat TYPE char18,
  145. lv_plant TYPE char4,
  146. lv_config_id TYPE num6 VALUE '000000',
  147. lv_inst_id TYPE num8 VALUE '00000000',
  148. lv_sap_code TYPE t006-msehi,
  149. lv_iso_code TYPE t006-isocode
  150. .
  151.  
  152.  
  153. CREATE OBJECT lr_busi_exc.
  154.  
  155. lt_materials = is_request-navmaterial.
  156.  
  157. " Get list of materials
  158. LOOP AT lt_materials ASSIGNING FIELD-SYMBOL(<ls_mat>).
  159. APPEND INITIAL LINE TO rt_mats ASSIGNING FIELD-SYMBOL(<ls_rt_mats>).
  160. <ls_rt_mats>-sign = 'I'.
  161. <ls_rt_mats>-option = 'EQ'.
  162. <ls_rt_mats>-low = |{ <ls_mat>-material ALPHA = IN }|.
  163. <ls_mat>-material = <ls_rt_mats>-low.
  164. ENDLOOP.
  165.  
  166.  
  167. " Check for MTS > when MTS > no root id needed
  168. SELECT mtart, matnr FROM mara INTO TABLE @DATA(lt_mtart) WHERE matnr IN @rt_mats.
  169.  
  170. " MTS material: ZFE2, ZHAW, NLAG
  171. APPEND INITIAL LINE TO rt_mtart ASSIGNING FIELD-SYMBOL(<ls_rt_mtart>).
  172. <ls_rt_mtart>-low = 'ZFE2'.
  173. APPEND INITIAL LINE TO rt_mtart ASSIGNING <ls_rt_mtart>.
  174. <ls_rt_mtart>-low = 'ZHAW'.
  175. APPEND INITIAL LINE TO rt_mtart ASSIGNING <ls_rt_mtart>.
  176. <ls_rt_mtart>-low = 'NLAG'.
  177.  
  178. LOOP AT rt_mtart ASSIGNING <ls_rt_mtart>.
  179. <ls_rt_mtart>-sign = 'I'.
  180. <ls_rt_mtart>-option = 'EQ'.
  181. ENDLOOP.
  182.  
  183.  
  184. " Read partner info from FE
  185. ls_customerdetail = is_request-navcustomerdetail.
  186. APPEND INITIAL LINE TO lt_quotation_partners ASSIGNING FIELD-SYMBOL(<ls_partner>).
  187.  
  188. " ADD Sold to party
  189. <ls_partner>-partn_role = c_sold_to_party.
  190. <ls_partner>-partn_numb = ls_customerdetail-soldtoparty.
  191. APPEND <ls_partner> TO lt_quotation_partners.
  192. CLEAR <ls_partner>.
  193.  
  194. " ADD Ship to party
  195. <ls_partner>-partn_role = c_ship_to_party.
  196. " If ship-to-party = SITE > derive ship-to-party
  197. APPEND INITIAL LINE TO lt_quotation_addr ASSIGNING FIELD-SYMBOL(<ls_addr>).
  198.  
  199. IF ls_customerdetail-shiptoparty NS 'WERF' AND ls_customerdetail-shiptoparty NS 'BAUSTELLE' AND
  200. ls_customerdetail-shiptoparty NS 'CHANTIER' AND ls_customerdetail-shiptoparty NS 'SITE'.
  201. <ls_partner>-partn_numb = ls_customerdetail-shiptoparty.
  202. <ls_partner>-name = ls_customerdetail-shiptoname.
  203. ELSEIF ls_customerdetail-countryregion EQ 'BE'.
  204. SELECT SINGLE kunnr, name1
  205. INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
  206. FROM kna1
  207. WHERE land1 EQ @ls_customerdetail-countryregion
  208. AND ktokd EQ '0002'
  209. AND pstlz EQ @ls_customerdetail-postalcode.
  210. IF sy-subrc <> 0.
  211.  
  212. " SITE NOT AVAILABLE
  213. ls_message-message = 'BE WERF not found'.
  214. ls_message-type = 'E'.
  215. APPEND ls_message TO lt_return.
  216.  
  217. " Transfer the error message(s) into the exception object
  218. lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
  219. RAISE EXCEPTION lr_busi_exc.
  220.  
  221. ENDIF.
  222.  
  223. ELSEIF ls_customerdetail-countryregion EQ 'FR'.
  224.  
  225.  
  226. " Retrieve sales office
  227. GET PARAMETER ID 'VKB' FIELD lv_vkb.
  228. CLEAR lv_vkbur.
  229. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  230. EXPORTING
  231. input = lv_vkb
  232. IMPORTING
  233. output = lv_vkbur.
  234.  
  235. " check if sales office is linked to the current sales organisation.
  236. IF NOT lv_vkbur IS INITIAL.
  237. SELECT SINGLE vkbur
  238. FROM tvkbz
  239. INTO lv_sales_office
  240. WHERE vkorg EQ ls_customerdetail-salesorg
  241. AND vtweg EQ ls_customerdetail-distributionchannel
  242. AND spart EQ ls_customerdetail-division
  243. AND vkbur EQ lv_vkbur.
  244. ENDIF.
  245.  
  246. " Choose French ship-to based on user parameter
  247. IF lv_sales_office EQ 'K221'.
  248. SELECT SINGLE kunnr, name1
  249. INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
  250. FROM kna1
  251. WHERE land1 EQ @ls_customerdetail-countryregion
  252. AND ktokd EQ 'CPDA'
  253. AND kunnr EQ 'CHANTP221'
  254. AND aufsd EQ @space.
  255. IF sy-subrc <> 0.
  256. SELECT SINGLE kunnr, name1
  257. INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
  258. FROM kna1
  259. WHERE land1 EQ @ls_customerdetail-countryregion
  260. AND ktokd EQ 'CPDA'
  261. AND aufsd EQ @space.
  262. IF sy-subrc <> 0.
  263. " ERROR HANDLING > SITE NOT AVAILABLE
  264. ls_message-message = 'FR WERF with sales office K221 not found'.
  265. ls_message-type = 'E'.
  266. APPEND ls_message TO lt_return.
  267.  
  268. " Transfer the error message(s) into the exception object
  269. lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
  270. RAISE EXCEPTION lr_busi_exc.
  271.  
  272. ENDIF.
  273. ENDIF.
  274. ELSE.
  275. SELECT SINGLE kunnr, name1
  276. INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
  277. FROM kna1
  278. WHERE land1 EQ @ls_customerdetail-countryregion
  279. * AND ktokd EQ 'CPDA' " TODO: check if record is available on the system
  280. AND kunnr EQ 'CHANTIERFR'
  281. AND aufsd EQ @space.
  282. IF sy-subrc <> 0.
  283. SELECT SINGLE kunnr, name1
  284. INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
  285. FROM kna1
  286. WHERE land1 EQ @ls_customerdetail-countryregion
  287. AND ktokd EQ 'CPDA'
  288. AND aufsd EQ @space.
  289. IF sy-subrc <> 0.
  290.  
  291. " SITE NOT AVAILABLE
  292. ls_message-message = 'FR WERF not found'.
  293. ls_message-type = 'E'.
  294. APPEND ls_message TO lt_return.
  295.  
  296. " Transfer the error message(s) into the exception object
  297. lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
  298. RAISE EXCEPTION lr_busi_exc.
  299.  
  300. ENDIF.
  301. ENDIF.
  302. ENDIF.
  303.  
  304. ELSE.
  305. SELECT SINGLE kunnr, name1
  306. INTO ( @<ls_partner>-partn_numb, @<ls_partner>-name )
  307. FROM kna1
  308. WHERE land1 EQ @ls_customerdetail-countryregion
  309. AND ktokd EQ 'CPDA'.
  310. IF sy-subrc <> 0.
  311. " SITE NOT AVAILABLE
  312.  
  313. ls_message-message = 'WERF not found'.
  314. ls_message-type = 'E'.
  315. APPEND ls_message TO lt_return.
  316.  
  317. " Transfer the error message(s) into the exception object
  318. lr_busi_exc->get_msg_container( )->add_messages_from_bapi( it_bapi_messages = lt_return ).
  319. RAISE EXCEPTION lr_busi_exc.
  320.  
  321. ENDIF.
  322. ENDIF.
  323.  
  324. " If ship-to-party = SITE then FE should provide the transport-zone
  325. <ls_partner>-transpzone = ls_customerdetail-shiptotransportzone.
  326.  
  327. " Street number
  328. <ls_partner>-street = ls_customerdetail-street(35).
  329. " City code
  330. <ls_partner>-city = ls_customerdetail-city.
  331. " Country
  332. <ls_partner>-country = ls_customerdetail-countryregion.
  333. <ls_partner>-postl_code = ls_customerdetail-postalcode.
  334. <ls_partner>-telephone = ls_customerdetail-telephone.
  335. <ls_partner>-region = ls_customerdetail-regioncode.
  336.  
  337. MOVE-CORRESPONDING <ls_partner>
  338. TO <ls_addr>.
  339.  
  340. <ls_addr> = CORRESPONDING #( <ls_partner> MAPPING
  341. postl_cod1 = postl_code
  342. tel1_numbr = telephone
  343. ).
  344. <ls_addr>-street = ls_customerdetail-street(40).
  345. <ls_addr>-street_lng = ls_customerdetail-street.
  346.  
  347.  
  348. <ls_partner>-addr_link = '0000000001'.
  349. <ls_addr>-addr_no = '0000000001'.
  350. <ls_addr>-house_no = ls_customerdetail-shiptohousenr.
  351. SELECT SINGLE spras FROM kna1 INTO <ls_addr>-langu WHERE kunnr = ls_customerdetail-shiptoparty.
  352. UNASSIGN <ls_addr>.
  353.  
  354. IF is_request-salesrep <> ''.
  355. " Providing sales representative
  356. APPEND <ls_partner> TO lt_quotation_partners.
  357. CLEAR <ls_partner>.
  358. <ls_partner>-partn_role = c_sales_rep.
  359. <ls_partner>-partn_numb = is_request-salesrep.
  360. ENDIF.
  361.  
  362. " Providing employee responsible
  363. APPEND <ls_partner> TO lt_quotation_partners.
  364. CLEAR <ls_partner>.
  365. <ls_partner>-partn_role = c_employee.
  366. 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
  367. <ls_partner>-partn_numb = |{ <ls_partner>-partn_numb ALPHA = IN }|.
  368.  
  369. ls_quotation_header_in-qt_valid_f = ls_customerdetail-validfrom.
  370. ls_quotation_header_in-qt_valid_t = ls_customerdetail-validto.
  371. ls_quotation_header_in-req_date_h = ls_customerdetail-deliveryuntil.
  372. ls_quotation_header_in-pmnttrms = ls_customerdetail-paymentterms.
  373. ls_quotation_header_in-incoterms1 = ls_customerdetail-incoterms.
  374. ls_quotation_header_in-incoterms2 = ls_customerdetail-incoterms2.
  375. ls_quotation_header_in-name = ls_customerdetail-contactperson.
  376. ls_quotation_header_in-price_list = ls_customerdetail-pricelist.
  377. ls_quotation_header_in-doc_type = c_quotation.
  378. ls_quotation_header_in-sales_org = ls_customerdetail-salesorg.
  379. ls_quotation_header_in-distr_chan = ls_customerdetail-distributionchannel.
  380. ls_quotation_header_in-division = ls_customerdetail-division.
  381. ls_quotation_header_in-purch_no_c = ls_customerdetail-customerref.
  382.  
  383.  
  384. " Get language of sold to party
  385. data lv_sold_to_party_language type spras.
  386. select single SPRAS from kna1
  387. into lv_sold_to_party_language
  388. where KUNNR = ls_customerdetail-soldtoparty.
  389.  
  390.  
  391. " HEADER TEXT
  392. IF is_request-navcustomerdetail-headertext IS NOT INITIAL.
  393. ls_text-text_id = 'Z003'.
  394. ls_text-langu = lv_sold_to_party_language.
  395. ls_text-format_col = '*'.
  396. ls_text-text_line = is_request-navcustomerdetail-headertext.
  397. APPEND ls_text TO lt_quotation_text.
  398. ENDIF.
  399.  
  400. LOOP AT lt_materials ASSIGNING <ls_mat>.
  401.  
  402. READ TABLE lt_mtart ASSIGNING FIELD-SYMBOL(<ls_mtart>) WITH KEY matnr = <ls_mat>-material.
  403. IF <ls_mtart>-mtart IN rt_mtart.
  404. " MTS material
  405. lv_mts = abap_true.
  406. ELSE.
  407. " No MTS material
  408. lv_mts = abap_false.
  409. ENDIF.
  410.  
  411. lv_mat = |{ <ls_mat>-material ALPHA = IN }|.
  412. lv_plant = <ls_mat>-plant.
  413.  
  414. lv_itm_number = <ls_mat>-itemnrlong.
  415.  
  416. " ITEM TEXT
  417. CLEAR ls_text.
  418. IF <ls_mat>-itemtext IS NOT INITIAL.
  419. ls_text-itm_number = lv_itm_number.
  420. ls_text-text_id = 'Z011'.
  421. ls_text-langu = lv_sold_to_party_language.
  422. ls_text-format_col = '*'.
  423. ls_text-text_line = <ls_mat>-itemtext.
  424. APPEND ls_text TO lt_quotation_text.
  425. ENDIF.
  426.  
  427. APPEND INITIAL LINE TO lt_quotation_schedules_in ASSIGNING FIELD-SYMBOL(<lv_qsi>).
  428. <lv_qsi>-itm_number = lv_itm_number.
  429. <lv_qsi>-req_qty = <ls_mat>-quantity.
  430. <lv_qsi>-sched_line = '0001'.
  431.  
  432. APPEND INITIAL LINE TO lt_quotation_items_inx ASSIGNING FIELD-SYMBOL(<lv_updateflag>).
  433. <lv_updateflag> = <ls_mat>-updateflag.
  434.  
  435. IF <ls_mat>-manualprice IS NOT INITIAL.
  436. APPEND INITIAL LINE TO lt_quotation_conditions_in ASSIGNING FIELD-SYMBOL(<lv_qci>).
  437. <lv_qci>-itm_number = lv_itm_number.
  438. <lv_qci>-cond_type = 'PN00'.
  439. <lv_qci>-cond_value = <ls_mat>-manualprice / 10.
  440.  
  441. " TODO: Conversion
  442. " box -> box
  443. " m2 -> m2
  444. " PC -> ST
  445. IF <ls_mat>-manualpriceunit EQ 'PC'.
  446. <lv_qci>-cond_unit = 'ST'.
  447. ELSE.
  448. <lv_qci>-cond_unit = <ls_mat>-manualpriceunit.
  449. ENDIF.
  450.  
  451. APPEND INITIAL LINE TO lt_quotation_conditions_inx ASSIGNING FIELD-SYMBOL(<lv_qcix>).
  452. <lv_qcix>-itm_number = lv_itm_number.
  453. <lv_qcix>-cond_type = 'X'.
  454. <lv_qcix>-cond_value = 'X'.
  455. <lv_qcix>-cond_unit = 'X'.
  456. <lv_qcix>-updateflag = 'U'.
  457.  
  458. ENDIF.
  459.  
  460. APPEND INITIAL LINE TO lt_quotation_items_in ASSIGNING FIELD-SYMBOL(<ls_item>).
  461. <ls_item>-itm_number = lv_itm_number.
  462. <ls_item>-po_itm_no = lv_itm_number.
  463. <ls_item>-poitm_no_s = ls_customerdetail-customerref.
  464. <ls_item>-material = lv_mat.
  465. <ls_item>-plant = lv_plant.
  466. <ls_item>-alt_to_itm = <ls_mat>-alternativeforitem.
  467. <ls_item>-target_qty = <ls_mat>-quantity.
  468.  
  469. lv_iso_code = <ls_mat>-quantityunit.
  470.  
  471. CALL FUNCTION 'UNIT_OF_MEASURE_ISO_TO_SAP'
  472. EXPORTING
  473. iso_code = lv_iso_code " ISO code for the measurement unit
  474. IMPORTING
  475. sap_code = lv_sap_code " SAP code for the measurement unit
  476. EXCEPTIONS
  477. not_found = 1
  478. OTHERS = 2.
  479. IF sy-subrc <> 0.
  480. " PROCEED
  481. ENDIF.
  482.  
  483. IF lv_sap_code <> ''.
  484. <ls_item>-target_qu = lv_sap_code.
  485. <ls_item>-sales_unit = lv_sap_code.
  486. ELSE.
  487. <ls_item>-target_qu = <ls_mat>-quantityunit.
  488. <ls_item>-sales_unit = <ls_mat>-quantityunit.
  489. ENDIF.
  490.  
  491. <ls_item>-short_text = ''.
  492.  
  493.  
  494. " CHARACTERISTICS
  495. lt_chars = <ls_mat>-navvariantvalues.
  496. lv_config_id = lv_config_id + 1.
  497. lv_inst_id = lv_inst_id + 1.
  498.  
  499.  
  500. IF lv_mts EQ abap_false.
  501.  
  502. " ADD entry in configs reference table
  503. APPEND INITIAL LINE TO lt_quotation_cfgs_ref ASSIGNING FIELD-SYMBOL(<ls_ref>).
  504. " external item number
  505. <ls_ref>-posex = lv_itm_number.
  506. " external configuration id
  507. <ls_ref>-config_id = lv_config_id.
  508.  
  509. <ls_ref>-root_id = '00000001'.
  510.  
  511. " ADD entry in configs instance table
  512. APPEND INITIAL LINE TO lt_quotation_cfgs_inst ASSIGNING FIELD-SYMBOL(<ls_inst>).
  513. " External configuration id.
  514. <ls_inst>-config_id = lv_config_id.
  515. " Instance number in configuration.
  516. <ls_inst>-inst_id = '00000001'.
  517. <ls_inst>-obj_type = 'MARA'.
  518. <ls_inst>-class_type = '300'.
  519. <ls_inst>-obj_key = lv_mat.
  520. " Quantity
  521. <ls_inst>-quantity = <ls_item>-target_qty.
  522. " Quantity unit
  523. <ls_inst>-quantity_unit = <ls_item>-target_qu.
  524.  
  525. LOOP AT lt_chars ASSIGNING FIELD-SYMBOL(<ls_char>) where manuallychanged = 'X'.
  526.  
  527. lt_char_values = <ls_char>-navvalues.
  528.  
  529. " CHARACTERISTIC DETAILS
  530. LOOP AT lt_char_values ASSIGNING FIELD-SYMBOL(<ls_char_values>).
  531.  
  532. APPEND INITIAL LINE TO lt_quotation_cfgs_value ASSIGNING FIELD-SYMBOL(<ls_value>).
  533. " External configuration id
  534. <ls_value>-config_id = lv_config_id.
  535. " Instance number in configuration
  536. <ls_value>-inst_id = '00000001'. "lv_inst_id.
  537. " Characteristic name
  538. <ls_value>-charc = <ls_char>-char.
  539. <ls_value>-value = <ls_char_values>-value.
  540.  
  541. ENDLOOP.
  542. ENDLOOP.
  543. ENDIF.
  544.  
  545. ENDLOOP.
  546.  
  547. MOVE-CORRESPONDING ls_quotation_header_in TO quotation_header_in.
  548. MOVE-CORRESPONDING lt_quotation_items_in TO quotation_items_in.
  549. MOVE-CORRESPONDING lt_quotation_items_inx TO quotation_items_inx.
  550. MOVE-CORRESPONDING lt_quotation_partners TO quotation_partners.
  551. MOVE-CORRESPONDING lt_quotation_cfgs_ref TO quotation_cfgs_ref.
  552. MOVE-CORRESPONDING lt_quotation_cfgs_refinst TO quotation_cfgs_refinst.
  553. MOVE-CORRESPONDING lt_quotation_cfgs_inst TO quotation_cfgs_inst.
  554. MOVE-CORRESPONDING lt_quotation_cfgs_value TO quotation_cfgs_value.
  555. MOVE-CORRESPONDING lt_quotation_schedules_in TO quotation_schedules_in.
  556. MOVE-CORRESPONDING lt_quotation_cfgs_part_of TO quotation_cfgs_part_of.
  557. MOVE-CORRESPONDING lt_quotation_conditions_in TO quotation_conditions_in.
  558. MOVE-CORRESPONDING lt_quotation_conditions_inx TO quotation_conditions_inx.
  559. MOVE-CORRESPONDING lt_quotation_text TO quotation_text.
  560. MOVE-CORRESPONDING lt_quotation_addr TO quotation_addr.
  561.  
  562. ENDMETHOD.
  563.  
  564.  
  565. METHOD sales_order_create.
  566.  
  567.  
  568. DATA:
  569. lv_salesdocument TYPE bapivbeln-vbeln,
  570. ls_sold_to_party TYPE bapisoldto,
  571. ls_ship_to_party TYPE bapishipto,
  572. ls_billing_party TYPE bapipayer,
  573. lt_return TYPE TABLE OF bapiret2,
  574. lr_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
  575. lv_error TYPE flag,
  576. ls_quotation_header_in TYPE bapisdhd1,
  577. ls_quotation_header_inx TYPE bapisdhd1x,
  578.  
  579. lt_quotation_items_in TYPE TABLE OF bapisditm,
  580. lt_quotation_items_inx TYPE TABLE OF bapisditmx,
  581.  
  582. lt_quotation_partners TYPE TABLE OF bapiparnr,
  583. lt_quotation_addr TYPE TABLE OF bapiaddr1,
  584. lt_quotation_cfgs_ref TYPE TABLE OF bapicucfg, "BAPICUCFG
  585. lt_quotation_cfgs_refinst TYPE TABLE OF bapicuref,
  586. lt_quotation_cfgs_inst TYPE TABLE OF bapicuins, "BAPICUINS
  587. lt_quotation_cfgs_value TYPE TABLE OF bapicuval, "BAPICUVAL
  588. lt_quotation_cfgs_part_of TYPE TABLE OF bapicuprt,
  589. lt_quotation_schedules_in TYPE TABLE OF bapischdl,
  590. lt_quotation_schedules_inx TYPE TABLE OF bapischdlx,
  591.  
  592. lt_quotation_text TYPE TABLE OF bapisdtext,
  593.  
  594. lt_quotation_conditions_in LIKE lt_bc,
  595. lt_quotation_conditions_inx LIKE lt_bcx,
  596.  
  597. ls_cust LIKE es_request-navcustomerdetail,
  598. lt_mat LIKE es_request-navmaterial,
  599.  
  600. lv_index TYPE i.
  601.  
  602.  
  603. TRY.
  604. " Import input table that will be used by BAPI_QUOTATION_CREATEFROMDATA2
  605. CALL METHOD provide_quotation_tables
  606. EXPORTING
  607. is_request = is_request
  608. IMPORTING
  609. quotation_header_in = ls_quotation_header_in
  610. quotation_items_in = lt_quotation_items_in
  611. quotation_partners = lt_quotation_partners
  612. quotation_cfgs_ref = lt_quotation_cfgs_ref
  613. quotation_cfgs_refinst = lt_quotation_cfgs_refinst
  614. quotation_cfgs_inst = lt_quotation_cfgs_inst
  615. quotation_cfgs_value = lt_quotation_cfgs_value
  616. quotation_cfgs_part_of = lt_quotation_cfgs_part_of
  617. quotation_schedules_in = lt_quotation_schedules_in
  618. quotation_conditions_in = lt_quotation_conditions_in
  619. quotation_conditions_inx = lt_quotation_conditions_inx
  620. quotation_text = lt_quotation_text
  621. quotation_addr = lt_quotation_addr.
  622. CATCH /iwbep/cx_mgw_busi_exception. "/iwbep/cx_mgw_tech_exception.
  623. APPEND INITIAL LINE TO es_request-navmessages ASSIGNING FIELD-SYMBOL(<ls_message>).
  624. <ls_message>-type = 'E'.
  625. <ls_message>-message = 'SITE NOT AVAILABLE'.
  626. <ls_message>-key = '0'.
  627. <ls_message>-char = 'X'.
  628. EXIT.
  629. ENDTRY.
  630.  
  631. CALL METHOD set_x_variable
  632. EXPORTING
  633. i_strucnam = ls_quotation_header_in
  634. CHANGING
  635. e_strucnam = ls_quotation_header_inx.
  636.  
  637. ls_quotation_header_inx-updateflag = ' '.
  638.  
  639.  
  640. LOOP AT lt_quotation_schedules_in ASSIGNING FIELD-SYMBOL(<ls_quotation_si>).
  641. APPEND INITIAL LINE TO lt_quotation_schedules_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_six>).
  642. CALL METHOD set_x_variable
  643. EXPORTING
  644. i_strucnam = <ls_quotation_si>
  645. CHANGING
  646. e_strucnam = <ls_quotation_six>.
  647. <ls_quotation_six>-itm_number = <ls_quotation_si>-itm_number.
  648. <ls_quotation_six>-sched_line = <ls_quotation_si>-sched_line.
  649.  
  650. " I: insert
  651. <ls_quotation_six>-updateflag = 'I'.
  652. ENDLOOP.
  653.  
  654. LOOP AT lt_quotation_items_in ASSIGNING FIELD-SYMBOL(<ls_quotation_item>).
  655. APPEND INITIAL LINE TO lt_quotation_items_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_itemx>).
  656. CALL METHOD set_x_variable
  657. EXPORTING
  658. i_strucnam = <ls_quotation_item>
  659. CHANGING
  660. e_strucnam = <ls_quotation_itemx>.
  661. <ls_quotation_itemx>-itm_number = <ls_quotation_item>-itm_number.
  662.  
  663. " I: insert
  664. <ls_quotation_itemx>-updateflag = 'I'.
  665. ENDLOOP.
  666.  
  667. " Setting Fiori flag in memory > this will trigger user exit ZMV45AFZZ_MOVE_FIELD_TO_VBAK01
  668. CALL FUNCTION 'ZS_SD_SET_SO_ITEM_DATA'
  669. EXPORTING
  670. iv_fiori_flag = abap_true.
  671.  
  672.  
  673. CALL FUNCTION 'BAPI_QUOTATION_CREATEFROMDATA2'
  674. EXPORTING
  675. quotation_header_in = ls_quotation_header_in " Order header
  676. quotation_header_inx = ls_quotation_header_inx
  677. IMPORTING
  678. salesdocument = lv_salesdocument " Sales and Distribution Document Number
  679. TABLES
  680. quotation_items_in = lt_quotation_items_in " Item Data Input
  681. quotation_items_inx = lt_quotation_items_inx
  682. quotation_partners = lt_quotation_partners " Partners
  683. quotation_cfgs_ref = lt_quotation_cfgs_ref " Configuration: Reference data
  684. quotation_cfgs_inst = lt_quotation_cfgs_inst " Configuration: Instances
  685. quotation_cfgs_value = lt_quotation_cfgs_value " Configuration: Characteristic values
  686. quotation_schedules_in = lt_quotation_schedules_in
  687. quotation_schedules_inx = lt_quotation_schedules_inx
  688. quotation_conditions_in = lt_quotation_conditions_in
  689. quotation_conditions_inx = lt_quotation_conditions_inx
  690. quotation_text = lt_quotation_text
  691. partneraddresses = lt_quotation_addr
  692. return = lt_return. " Error Text
  693.  
  694. " ERROR HANDLING
  695. LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_error>).
  696.  
  697. APPEND INITIAL LINE TO es_request-navmessages ASSIGNING <ls_message>.
  698. <ls_message>-type = <fs_error>-type.
  699. <ls_message>-message = <fs_error>-message.
  700. <ls_message>-key = '0'.
  701. <ls_message>-char = 'X'.
  702.  
  703. IF <fs_error>-type CA 'AEX'.
  704. lv_error = abap_true.
  705. es_request-key = '0'.
  706. es_request-action = 'A'.
  707. es_request-salesdocument = 'X'.
  708. ls_cust-key = '0'.
  709. es_request-navcustomerdetail = ls_cust.
  710. APPEND INITIAL LINE TO lt_mat ASSIGNING FIELD-SYMBOL(<ls_mat>).
  711. <ls_mat>-key = '0'.
  712. es_request-navmaterial = lt_mat.
  713. ENDIF.
  714. ENDLOOP.
  715.  
  716. " Disabling Fiori flag in memory
  717. CALL FUNCTION 'ZS_SD_SET_SO_ITEM_DATA'
  718. EXPORTING
  719. iv_fiori_flag = abap_false.
  720.  
  721. UNASSIGN <fs_error>.
  722.  
  723. IF lv_error EQ abap_true.
  724. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  725.  
  726. ELSE.
  727. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  728. EXPORTING
  729. wait = abap_true.
  730.  
  731. " Letter I is send to the FE to indicate the successful creation of a new quotation
  732. es_request-key = 'I'.
  733. es_request-salesdocument = lv_salesdocument.
  734. ENDIF.
  735.  
  736.  
  737.  
  738.  
  739. ENDMETHOD.
  740.  
  741.  
  742. METHOD sales_order_update.
  743. " This method will update a certain quotation with the parameters passed from the my quotation application v2
  744.  
  745. DATA:
  746. lv_salesdocument TYPE bapivbeln-vbeln,
  747. ls_sold_to_party TYPE bapisoldto,
  748. ls_ship_to_party TYPE bapishipto,
  749. ls_billing_party TYPE bapipayer,
  750. lt_return TYPE TABLE OF bapiret2,
  751. lt_return_2 TYPE TABLE OF bapiret2,
  752. lr_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
  753. lv_error TYPE flag,
  754. lt_quotation_conditions_in LIKE lt_bc,
  755. lt_quotation_conditions_inx LIKE lt_bcx,
  756. lt_quotation_addr LIKE lt_qa,
  757. lv_sales_doc_in TYPE bapivbeln-vbeln,
  758. ls_quotation_header_in TYPE bapisdhd1,
  759. ls_quotation_header_inx TYPE bapisdhd1x,
  760. lt_quotation_items_in TYPE TABLE OF bapisditm,
  761. lt_quotation_items_inx TYPE TABLE OF bapisditmx,
  762. lt_quotation_text TYPE TABLE OF bapisdtext,
  763. lt_quotation_partners TYPE TABLE OF bapiparnr,
  764. lt_quotation_cfgs_ref TYPE TABLE OF bapicucfg,
  765. lt_quotation_cfgs_refinst TYPE TABLE OF bapicuref,
  766. lt_quotation_cfgs_inst TYPE TABLE OF bapicuins,
  767. lt_quotation_cfgs_value TYPE TABLE OF bapicuval,
  768. lt_quotation_cfgs_part_of TYPE TABLE OF bapicuprt,
  769. lt_quotation_schedules_in TYPE TABLE OF bapischdl,
  770. lt_quotation_schedules_inx TYPE TABLE OF bapischdlx,
  771. lt_vbap TYPE TABLE OF posnr,
  772. lv_vbap TYPE posnr,
  773. lv_salesdoc TYPE vbeln,
  774. rt_posnr TYPE RANGE OF posnr,
  775. lt_partnerchanges TYPE TABLE OF bapiparnrc,
  776. lt_partneraddresses TYPE TABLE OF bapiaddr1,
  777. ls_quotation_header_inx_2 TYPE bapisdh1x,
  778. ls_cust LIKE es_request-navcustomerdetail,
  779. lt_mat LIKE es_request-navmaterial,
  780. lv_index TYPE i.
  781.  
  782. CREATE OBJECT lr_busi_exc.
  783.  
  784. " import tables for create_quotation BAPI
  785. CALL METHOD provide_quotation_tables
  786. EXPORTING
  787. is_request = is_request
  788. IMPORTING
  789. quotation_header_in = ls_quotation_header_in
  790. quotation_items_in = lt_quotation_items_in
  791. quotation_partners = lt_quotation_partners
  792. quotation_cfgs_ref = lt_quotation_cfgs_ref
  793. quotation_cfgs_refinst = lt_quotation_cfgs_refinst
  794. quotation_cfgs_inst = lt_quotation_cfgs_inst
  795. quotation_cfgs_value = lt_quotation_cfgs_value
  796. quotation_cfgs_part_of = lt_quotation_cfgs_part_of
  797. quotation_schedules_in = lt_quotation_schedules_in
  798. quotation_conditions_in = lt_quotation_conditions_in
  799. quotation_conditions_inx = lt_quotation_conditions_inx
  800. quotation_text = lt_quotation_text
  801. quotation_addr = lt_quotation_addr.
  802.  
  803. lv_sales_doc_in = is_request-salesdocument.
  804. lv_sales_doc_in = |{ lv_sales_doc_in ALPHA = IN }| .
  805.  
  806.  
  807. CALL METHOD set_x_variable
  808. EXPORTING
  809. i_strucnam = ls_quotation_header_in
  810. CHANGING
  811. e_strucnam = ls_quotation_header_inx.
  812. ls_quotation_header_inx-updateflag = 'U'.
  813.  
  814. " I : add new item
  815. " U : update current item
  816. LOOP AT lt_quotation_schedules_in ASSIGNING FIELD-SYMBOL(<ls_quotation_si>).
  817. APPEND INITIAL LINE TO lt_quotation_schedules_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_six>).
  818. CALL METHOD set_x_variable
  819. EXPORTING
  820. i_strucnam = <ls_quotation_si>
  821. CHANGING
  822. e_strucnam = <ls_quotation_six>.
  823. <ls_quotation_six>-itm_number = <ls_quotation_si>-itm_number.
  824. <ls_quotation_six>-sched_line = <ls_quotation_si>-sched_line.
  825. <ls_quotation_six>-updateflag = 'U'.
  826. ENDLOOP.
  827.  
  828. lv_salesdoc = is_request-salesdocument.
  829.  
  830. " Check the existence of item lines for the quotation
  831. " > if the item line is new we need to set the insert flag
  832. " > else we set the update flag
  833. SELECT posnr FROM vbap INTO TABLE @lt_vbap WHERE vbeln = @lv_salesdoc.
  834.  
  835. LOOP AT lt_vbap INTO lv_vbap.
  836. APPEND INITIAL LINE TO rt_posnr ASSIGNING FIELD-SYMBOL(<ls_rt_posnr>).
  837. <ls_rt_posnr>-sign = 'I'.
  838. <ls_rt_posnr>-option = 'EQ'.
  839. <ls_rt_posnr>-low = lv_vbap.
  840. ENDLOOP.
  841.  
  842. LOOP AT lt_quotation_items_in ASSIGNING FIELD-SYMBOL(<ls_quotation_item>).
  843. APPEND INITIAL LINE TO lt_quotation_items_inx ASSIGNING FIELD-SYMBOL(<ls_quotation_itemx>).
  844. CALL METHOD set_x_variable
  845. EXPORTING
  846. i_strucnam = <ls_quotation_item>
  847. CHANGING
  848. e_strucnam = <ls_quotation_itemx>.
  849. <ls_quotation_itemx>-itm_number = <ls_quotation_item>-itm_number.
  850. IF <ls_quotation_item>-itm_number IN rt_posnr.
  851. <ls_quotation_itemx>-updateflag = 'U'.
  852. ELSE.
  853. <ls_quotation_itemx>-updateflag = 'I'.
  854. ENDIF.
  855. ENDLOOP.
  856.  
  857.  
  858. " EXTRACT SHIPTO PARTNER & ADDRESS for PARTNER UPDATE BAPI
  859. MOVE-CORRESPONDING lt_quotation_addr TO lt_partneraddresses.
  860.  
  861. ls_quotation_header_inx_2-updateflag = 'U'.
  862.  
  863. LOOP AT lt_quotation_partners ASSIGNING FIELD-SYMBOL(<ls_partner>) WHERE partn_role EQ 'WE'.
  864. APPEND INITIAL LINE TO lt_partnerchanges ASSIGNING FIELD-SYMBOL(<ls_partner_change>).
  865. <ls_partner_change>-document = lv_sales_doc_in.
  866. <ls_partner_change>-updateflag = 'U'.
  867. <ls_partner_change>-addr_link = <ls_partner>-addr_link.
  868. <ls_partner_change>-partn_role = <ls_partner>-partn_role.
  869. <ls_partner_change>-p_numb_new = <ls_partner>-partn_numb.
  870. <ls_partner_change>-p_numb_new = |{ <ls_partner_change>-p_numb_new ALPHA = IN }| .
  871. ENDLOOP.
  872.  
  873.  
  874.  
  875. " Retrieve the configuration of the quotation
  876.  
  877. DATA:
  878.  
  879. i_bapi_view TYPE order_view,
  880. i_memory_read TYPE order_read-mem_access,
  881. i_with_header_conditions TYPE xfeld,
  882.  
  883. sales_documents TYPE TABLE OF sales_key,
  884. order_headers_out TYPE TABLE OF bapisdhd,
  885. order_items_out TYPE TABLE OF bapisdit,
  886. order_schedules_out TYPE TABLE OF bapisdhedu,
  887. order_business_out TYPE TABLE OF bapisdbusi,
  888. order_partners_out TYPE TABLE OF bapisdpart,
  889. order_address_out TYPE TABLE OF bapisdcoad,
  890. order_statusheaders_out TYPE TABLE OF bapisdhdst,
  891. order_statusitems_out TYPE TABLE OF bapisditst,
  892. order_conditions_out TYPE TABLE OF bapisdcond,
  893. order_cond_head TYPE TABLE OF bapicondhd,
  894. order_cond_item TYPE TABLE OF bapicondit,
  895. order_cond_qty_scale TYPE TABLE OF bapicondqs,
  896. order_cond_val_scale TYPE TABLE OF bapicondvs,
  897. order_contracts_out TYPE TABLE OF bapisdcntr,
  898. order_textheaders_out TYPE TABLE OF bapisdtehd,
  899. order_textlines_out TYPE TABLE OF bapitextli,
  900. order_flows_out TYPE TABLE OF bapisdflow,
  901. order_cfgs_curefs_out TYPE TABLE OF bapicurefm,
  902. order_cfgs_cucfgs_out TYPE TABLE OF bapicucfgm,
  903. order_cfgs_cuins_out TYPE TABLE OF bapicuinsm,
  904. order_cfgs_cuprts_out TYPE TABLE OF bapicuprtm,
  905. order_cfgs_cuvals_out TYPE TABLE OF bapicuvalm,
  906. order_cfgs_cublbs_out TYPE TABLE OF bapicublbm,
  907. order_cfgs_cuvks_out TYPE TABLE OF bapicuvkm,
  908. order_billingplans_out TYPE TABLE OF bapisdbpl,
  909. order_billingdates_out TYPE TABLE OF bapisdbpld,
  910. order_creditcards_out TYPE TABLE OF bapiccardm,
  911. extensionout TYPE TABLE OF bapiparex.
  912.  
  913. i_bapi_view-configure = 'X'.
  914.  
  915. APPEND LV_SALES_DOC_IN TO sales_documents.
  916.  
  917. CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
  918. EXPORTING
  919. i_bapi_view = i_bapi_view " Bapi View for Data Reduction
  920. i_memory_read = ''
  921. i_with_header_conditions = i_with_header_conditions
  922. TABLES
  923. sales_documents = sales_documents " Document Numbers to Be Selected
  924. order_headers_out = order_headers_out " Order Headers for Document Numbers
  925. order_items_out = order_items_out " Order Item Data for Document Numbers
  926. order_schedules_out = order_schedules_out " Order Schedule Lines for Document Numbers
  927. order_business_out = order_business_out " Business Data for Document Numbers
  928. order_partners_out = order_partners_out " Order Partners for Document Numbers
  929. order_address_out = order_address_out
  930. order_statusheaders_out = order_statusheaders_out " Header Status for Document Numbers
  931. order_statusitems_out = order_statusitems_out " Item Status for Document Numbers
  932. order_conditions_out = order_conditions_out " Order Conditions for Document Numbers
  933. order_cond_head = order_cond_head
  934. order_cond_item = order_cond_item
  935. order_cond_qty_scale = order_cond_qty_scale
  936. order_cond_val_scale = order_cond_val_scale
  937. order_contracts_out = order_contracts_out " Contract Data for Document Numbers
  938. order_textheaders_out = order_textheaders_out " Text Header Information for Document Numbers
  939. order_textlines_out = order_textlines_out " Text Lines for Document Numbers
  940. order_flows_out = order_flows_out " Document Flows for Document Numbers
  941. order_cfgs_curefs_out = order_cfgs_curefs_out " Instance in the Configuration for Document Numbers
  942. order_cfgs_cucfgs_out = order_cfgs_cucfgs_out " Configuration Data for Document Numbers
  943. order_cfgs_cuins_out = order_cfgs_cuins_out " Instance Data for Document Numbers
  944. order_cfgs_cuprts_out = order_cfgs_cuprts_out " PartOf Data for Document Numbers
  945. order_cfgs_cuvals_out = order_cfgs_cuvals_out " Characteristic Value Assignment for Document Numbers
  946. order_cfgs_cublbs_out = order_cfgs_cublbs_out " Configuration BLOB for Document Numbers
  947. order_cfgs_cuvks_out = order_cfgs_cuvks_out
  948. order_billingplans_out = order_billingplans_out " Billing Plan for Document Numbers
  949. order_billingdates_out = order_billingdates_out " Billing Plan Deadlines for Document Numbers
  950. order_creditcards_out = order_creditcards_out " Credit Cards for Document Numbers
  951. extensionout = extensionout.
  952.  
  953. * " POSEX > config_id
  954. * " 0010 > 1
  955. * " 0020 > 2
  956. * " 0030 > 3
  957. * " 0040 > 4
  958. * types: begin of gy_posex_mapping,
  959. * posex_new type CU_POSEX,
  960. * posex_old type cu_posex,
  961. * config_id type CUXCFG_ID,
  962. * end of gy_posex_mapping.
  963. * data lt_posex_mapping type table of gy_posex_mapping.
  964. *
  965. * LOOP AT is_request-navmaterial ASSIGNING FIELD-SYMBOL(<ls_mat>).
  966. * append INITIAL LINE TO lt_posex_mapping
  967. * ASSIGNING FIELD-SYMBOL(<ls_posex_mapping>).
  968. * <ls_posex_mapping>-posex_new = <ls_mat>-itemnrlong.
  969. * <ls_posex_mapping>-posex_old = <ls_mat>-itemnrlongold.
  970. * read table order_cfgs_cucfgs_out
  971. * with key posex = <ls_mat>-itemnrlongold
  972. *
  973. * endloop.
  974.  
  975. data lt_quotation_cfgs_value_mc TYPE TABLE OF bapicuval.
  976. lt_quotation_cfgs_value_mc = lt_quotation_cfgs_value.
  977.  
  978. loop at order_cfgs_cuvals_out ASSIGNING FIELD-SYMBOL(<ls_cuvals_out>).
  979. read table lt_quotation_cfgs_value_mc TRANSPORTING NO FIELDS WITH KEY charc = <ls_cuvals_out>-charc config_id = <ls_cuvals_out>-config_id.
  980. if sy-subrc = 0.
  981. * " Entry is found > do nothing
  982. else.
  983. " Append an entry
  984. APPEND INITIAL LINE TO lt_quotation_cfgs_value ASSIGNING FIELD-SYMBOL(<ls_cfg>).
  985. <ls_cfg>-config_id = <ls_cuvals_out>-config_id.
  986. <ls_cfg>-inst_id = <ls_cuvals_out>-inst_id.
  987. <ls_cfg>-charc = <ls_cuvals_out>-charc.
  988. <ls_cfg>-value = <ls_cuvals_out>-value.
  989. <ls_cfg>-author = <ls_cuvals_out>-author.
  990. endif.
  991. endloop.
  992.  
  993. " The partner tables & addresses will be updated by the BAPI_CUSTOMERQUOTATION_CHANGE below
  994. CLEAR lt_quotation_partners.
  995. CLEAR lt_quotation_addr.
  996. CALL FUNCTION 'BAPI_QUOTATION_CREATEFROMDATA2'
  997. EXPORTING
  998. salesdocumentin = lv_sales_doc_in
  999. quotation_header_in = ls_quotation_header_in " Order header
  1000. quotation_header_inx = ls_quotation_header_inx
  1001. IMPORTING
  1002. salesdocument = lv_salesdocument " Sales and Distribution Document Number
  1003. TABLES
  1004. quotation_items_in = lt_quotation_items_in " Item Data Input
  1005. quotation_items_inx = lt_quotation_items_inx
  1006. quotation_partners = lt_quotation_partners " Partners
  1007. quotation_cfgs_ref = lt_quotation_cfgs_ref " Configuration: Reference data
  1008. quotation_cfgs_inst = lt_quotation_cfgs_inst " Configuration: Instances
  1009. quotation_cfgs_value = lt_quotation_cfgs_value " Configuration: Characteristic values
  1010. quotation_schedules_in = lt_quotation_schedules_in
  1011. quotation_schedules_inx = lt_quotation_schedules_inx
  1012. quotation_conditions_in = lt_quotation_conditions_in
  1013. quotation_conditions_inx = lt_quotation_conditions_inx
  1014. partneraddresses = lt_quotation_addr
  1015. quotation_text = lt_quotation_text
  1016. return = lt_return. " Error Text
  1017.  
  1018. " ERROR HANDLING
  1019. LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_error>).
  1020.  
  1021. 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
  1022. 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 ).
  1023.  
  1024. APPEND INITIAL LINE TO es_request-navmessages ASSIGNING FIELD-SYMBOL(<ls_message>).
  1025. <ls_message>-type = <fs_error>-type.
  1026. <ls_message>-message = <fs_error>-message.
  1027. <ls_message>-key = '0'.
  1028. <ls_message>-char = 'X'.
  1029.  
  1030.  
  1031. IF <fs_error>-type CA 'AEX'.
  1032. lv_error = abap_true.
  1033.  
  1034. ls_cust-key = '0'.
  1035. es_request-navcustomerdetail = ls_cust.
  1036. APPEND INITIAL LINE TO lt_mat ASSIGNING FIELD-SYMBOL(<ls_mat>).
  1037. <ls_mat>-key = '0'.
  1038. es_request-navmaterial = lt_mat.
  1039. es_request-salesdocument = 'X'.
  1040. ENDIF.
  1041. ENDLOOP.
  1042.  
  1043. UNASSIGN <fs_error>.
  1044.  
  1045. "COMMIT
  1046. IF lv_error EQ abap_true.
  1047. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  1048. RETURN.
  1049.  
  1050. ELSE.
  1051. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  1052. EXPORTING
  1053. wait = abap_true.
  1054.  
  1055. ENDIF.
  1056.  
  1057.  
  1058. " Separate BAPI is used to update partner & address info
  1059. CALL FUNCTION 'BAPI_CUSTOMERQUOTATION_CHANGE'
  1060. EXPORTING
  1061. salesdocument = lv_sales_doc_in " Sales and Distribution Document Number
  1062. quotation_header_inx = ls_quotation_header_inx_2 " Quotation Header Checkbox
  1063. TABLES
  1064. return = lt_return_2 " Return Code
  1065. partnerchanges = lt_partnerchanges " Partner changes
  1066. partneraddresses = lt_partneraddresses. " BAPI Reference Structure for Addresses (Org./Company)
  1067.  
  1068. APPEND LINES OF lt_return_2 TO lt_return.
  1069.  
  1070.  
  1071. " ERROR HANDLING
  1072. LOOP AT lt_return ASSIGNING <fs_error>.
  1073.  
  1074. 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
  1075. 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 ).
  1076.  
  1077. APPEND INITIAL LINE TO es_request-navmessages ASSIGNING <ls_message>.
  1078. <ls_message>-type = <fs_error>-type.
  1079. <ls_message>-message = <fs_error>-message.
  1080. <ls_message>-key = '0'.
  1081. <ls_message>-char = 'X'.
  1082.  
  1083.  
  1084. IF <fs_error>-type CA 'AEX'.
  1085. lv_error = abap_true.
  1086. ls_cust-key = '0'.
  1087. es_request-navcustomerdetail = ls_cust.
  1088. APPEND INITIAL LINE TO lt_mat ASSIGNING <ls_mat>.
  1089. <ls_mat>-key = '0'.
  1090. es_request-navmaterial = lt_mat.
  1091. es_request-salesdocument = 'X'.
  1092. ENDIF.
  1093. ENDLOOP.
  1094.  
  1095. UNASSIGN <fs_error>.
  1096.  
  1097. "COMMIT
  1098. IF lv_error EQ abap_true.
  1099. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  1100. RETURN.
  1101. ELSE.
  1102. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  1103. EXPORTING
  1104. wait = abap_true.
  1105. ENDIF.
  1106.  
  1107. data lv_sold_to_party_language type spras.
  1108. " Read sold to party language
  1109. select single SPRAS from kna1
  1110. into lv_sold_to_party_language
  1111. where KUNNR = is_request-navcustomerdetail-soldtoparty.
  1112.  
  1113. "handle possible removal of header/item texts
  1114. "header text
  1115. IF is_request-navcustomerdetail-headertext IS INITIAL.
  1116. IF lv_salesdocument IS NOT INITIAL.
  1117. DATA lv_quot TYPE vbeln_va.
  1118. DATA lv_name TYPE tdobname.
  1119. DATA lt_lines TYPE TABLE OF tline.
  1120.  
  1121. lv_quot = |{ lv_salesdocument ALPHA = IN }|.
  1122. lv_name = lv_quot.
  1123. "Retrieve & convert header text
  1124. CALL FUNCTION 'READ_TEXT'
  1125. EXPORTING
  1126. id = 'Z003'
  1127. language = lv_sold_to_party_language
  1128. name = lv_name
  1129. object = 'VBBK'
  1130. TABLES
  1131. lines = lt_lines
  1132. EXCEPTIONS
  1133. id = 1
  1134. language = 2
  1135. name = 3
  1136. not_found = 4
  1137. object = 5
  1138. reference_check = 6
  1139. wrong_access_to_archive = 7
  1140. OTHERS = 8.
  1141. IF sy-subrc EQ 0.
  1142. CALL FUNCTION 'DELETE_TEXT'
  1143. EXPORTING
  1144. id = 'Z003' " Text ID of text to be deleted
  1145. language = lv_sold_to_party_language " Language of text to be deleted
  1146. name = lv_name " Name of text to be deleted
  1147. object = 'VBBK' " Text object of text to be deleted
  1148. savemode_direct = 'X'
  1149. .
  1150. IF sy-subrc <> 0.
  1151. lv_error = abap_true.
  1152. ENDIF.
  1153. ENDIF.
  1154. ENDIF.
  1155. ENDIF.
  1156.  
  1157. "item text
  1158. LOOP AT is_request-navmaterial ASSIGNING FIELD-SYMBOL(<ls_items>).
  1159. IF <ls_items>-itemtext IS INITIAL.
  1160. IF lv_salesdocument IS NOT INITIAL AND <ls_items>-itemnrlong IS NOT INITIAL.
  1161. DATA lv_quot_i TYPE vbeln_va.
  1162. DATA lv_name_i TYPE tdobname.
  1163.  
  1164. lv_name_i = |{ lv_salesdocument ALPHA = IN }{ <ls_items>-itemnrlong ALPHA = IN }|.
  1165. FREE lt_lines.
  1166. "Retrieve & convert header text
  1167. CALL FUNCTION 'READ_TEXT'
  1168. EXPORTING
  1169. id = 'Z011'
  1170. language = lv_sold_to_party_language
  1171. name = lv_name_i
  1172. object = 'VBBP'
  1173. TABLES
  1174. lines = lt_lines
  1175. EXCEPTIONS
  1176. id = 1
  1177. language = 2
  1178. name = 3
  1179. not_found = 4
  1180. object = 5
  1181. reference_check = 6
  1182. wrong_access_to_archive = 7
  1183. OTHERS = 8.
  1184. IF sy-subrc EQ 0.
  1185. CALL FUNCTION 'DELETE_TEXT'
  1186. EXPORTING
  1187. id = 'Z011' " Text ID of text to be deleted
  1188. language = lv_sold_to_party_language " Language of text to be deleted
  1189. name = lv_name_i " Name of text to be deleted
  1190. object = 'VBBP' " Text object of text to be deleted
  1191. savemode_direct = 'X'
  1192. .
  1193. IF sy-subrc <> 0.
  1194. lv_error = abap_true.
  1195. ENDIF.
  1196. ENDIF.
  1197. ENDIF.
  1198. ENDIF.
  1199. ENDLOOP.
  1200.  
  1201. IF lv_error EQ abap_true.
  1202. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  1203. ELSE.
  1204. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  1205. EXPORTING
  1206. wait = abap_true.
  1207.  
  1208. " The letter U is send to FE to indicate a successful sales document update
  1209. es_request-key = 'U'.
  1210. es_request-salesdocument = lv_salesdocument.
  1211. ENDIF.
  1212. ENDMETHOD.
  1213.  
  1214.  
  1215. METHOD set_x_variable.
  1216. DATA: lv_times TYPE i,
  1217. lv_structref TYPE REF TO cl_abap_structdescr,
  1218. lt_comp TYPE abap_compdescr_tab,
  1219. ls_comp TYPE LINE OF abap_compdescr_tab,
  1220. lv_xfield TYPE char40.
  1221. FIELD-SYMBOLS <fs> TYPE any.
  1222. FIELD-SYMBOLS <fs_field> TYPE any.
  1223.  
  1224. lv_structref ?= cl_abap_structdescr=>describe_by_data( i_strucnam ).
  1225. LOOP AT lv_structref->components INTO ls_comp.
  1226. APPEND ls_comp TO lt_comp.
  1227. ENDLOOP.
  1228. DESCRIBE TABLE lt_comp LINES lv_times.
  1229.  
  1230. DO lv_times TIMES.
  1231. ASSIGN COMPONENT sy-index OF STRUCTURE i_strucnam TO <fs>.
  1232. IF sy-subrc <> 0.
  1233. EXIT.
  1234. ELSE.
  1235. IF NOT <fs> IS INITIAL.
  1236. READ TABLE lt_comp INDEX sy-index INTO ls_comp.
  1237. IF sy-subrc = 0.
  1238. CONCATENATE 'e_strucnam' ls_comp-name INTO lv_xfield SEPARATED BY '-'.
  1239. ASSIGN (lv_xfield) TO <fs_field>.
  1240. IF sy-subrc = 0.
  1241. <fs_field> = 'X'.
  1242. ENDIF.
  1243. ENDIF.
  1244. ENDIF.
  1245. ENDIF.
  1246. ENDDO.
  1247. ENDMETHOD.
  1248. ENDCLASS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement