Created
January 14, 2014 07:46
-
-
Save weiserman/8414651 to your computer and use it in GitHub Desktop.
Create a vendor in SAP using the Vendor API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| *&---------------------------------------------------------------------* | |
| *& Report Creating a vendor, sample API coding | |
| *& | |
| *&---------------------------------------------------------------------* | |
| *& Test for creation of vendor | |
| *& | |
| *&---------------------------------------------------------------------* | |
| REPORT ydemo. | |
| * Local data structure | |
| DATA: lo_vendor TYPE REF TO cl_erp_vendor_api. | |
| DATA: lv_ktokk TYPE ktokk VALUE 'COMP', | |
| lt_messages TYPE bapiret2_t, | |
| ls_message TYPE bapiret2, | |
| ls_error TYPE cvis_message, | |
| lv_activity TYPE tcode VALUE 'XK01', | |
| lv_guid TYPE guid, | |
| lv_general_data TYPE vmds_ei_vmd_central, | |
| ls_central_data TYPE vmds_ei_vmd_central_data, | |
| ls_central_datax TYPE vmds_ei_vmd_central_data_xflag, | |
| lv_postal TYPE cvis_ei_1vl, | |
| ls_address TYPE bapiad1vl, | |
| ls_addressx TYPE bapiad1vlx. | |
| * Instantiate an API object | |
| CREATE OBJECT lo_vendor. | |
| * Initialise the vendor with account group | |
| CALL METHOD lo_vendor->initialize_vendor | |
| EXPORTING | |
| iv_ktokk = lv_ktokk | |
| * iv_lifnr = | |
| iv_activity = lv_activity | |
| IMPORTING | |
| et_messages = lt_messages | |
| ev_guid = lv_guid | |
| EXCEPTIONS | |
| internal_error = 1 | |
| parameter_error = 2 | |
| vendor_already_initialized = 3 | |
| process_error = 4 | |
| OTHERS = 5. | |
| * Set the basic vendor information up | |
| CLEAR ls_central_data. | |
| MOVE 'Test1' TO ls_central_data-pson1. | |
| MOVE 'Test2' TO ls_central_data-pson2. | |
| MOVE 'Name' TO ls_central_data-psovn. | |
| MOVE 'Name' TO ls_central_data-psotl. | |
| MOVE '4050229840' TO ls_central_data-stcd1. | |
| MOVE 'COMP' TO ls_central_data-ktokk. | |
| MOVE 'X' TO ls_central_datax-pson1. | |
| MOVE 'X' TO ls_central_datax-pson2. | |
| MOVE 'X' TO ls_central_datax-psovn. | |
| MOVE 'X' TO ls_central_datax-psotl. | |
| MOVE 'X' TO ls_central_datax-stcd1. | |
| MOVE 'X' TO ls_central_datax-ktokk. | |
| lv_general_data-data = ls_central_data. | |
| lv_general_data-datax = ls_central_datax. | |
| * Add the basic information for the vendor (using GUID) | |
| CALL METHOD lo_vendor->maintain_general_data | |
| EXPORTING | |
| iv_instance_guid = lv_guid | |
| iv_country = 'ZA' | |
| is_general_data = lv_general_data | |
| IMPORTING | |
| et_messages = lt_messages | |
| EXCEPTIONS | |
| parameter_error = 1 | |
| process_error = 2 | |
| internal_error = 3 | |
| OTHERS = 4. | |
| * Set up the address data | |
| MOVE 'Warren Demo' TO ls_address-name. | |
| MOVE 'Warren Demo' TO ls_address-sort1. | |
| MOVE 'ZA' TO ls_address-countryiso. | |
| MOVE 'X' TO ls_addressx-name. | |
| MOVE 'X' TO ls_addressx-sort1. | |
| MOVE 'X' TO ls_addressx-countryiso. | |
| lv_postal-data = ls_address. | |
| lv_postal-datax = ls_addressx. | |
| CALL METHOD lo_vendor->maintain_gen_address | |
| EXPORTING | |
| iv_instance_guid = lv_guid | |
| is_postal = lv_postal | |
| IMPORTING | |
| et_messages = lt_messages | |
| EXCEPTIONS | |
| parameter_error = 1 | |
| process_error = 2 | |
| internal_error = 3 | |
| OTHERS = 4. | |
| * Write response to screen | |
| LOOP AT lt_messages INTO ls_message. | |
| WRITE: / ls_message-type, ls_message-message. | |
| ENDLOOP. | |
| * Where any errors detected? | |
| READ TABLE lt_messages TRANSPORTING NO FIELDS WITH KEY type = 'E'. | |
| IF sy-subrc = 0. | |
| WRITE: / 'Error detected, vendor processing not possible'. | |
| EXIT. "Do not try and save | |
| ELSE. | |
| CLEAR lt_messages[]. " Clear message table already written out | |
| ENDIF. | |
| * Call the save function in commit mode | |
| CALL METHOD lo_vendor->save_single | |
| EXPORTING | |
| iv_instance_guid = lv_guid | |
| iv_testrun_indicator = ' ' | |
| IMPORTING | |
| et_messages = lt_messages. | |
| * Commit the changes | |
| READ TABLE lt_messages TRANSPORTING NO FIELDS WITH KEY type = 'E'. | |
| IF sy-subrc <> 0. | |
| COMMIT WORK AND WAIT. | |
| ENDIF. | |
| LOOP AT lt_messages INTO ls_message. | |
| WRITE: / ls_message-type, ls_message-message. | |
| ENDLOOP. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working