0% found this document useful (0 votes)
186 views

Code For Bapi So Create

This document contains the code for a function that creates a sales order using SAP BAPI functions. It searches for a customer by email, gets the associated sales areas, and then uses that information to populate header and item tables that are passed to the BAPI_SALESORDER_CREATEFROMDAT2 function to generate the sales order document. Any error messages are returned and the transaction is committed if successful. The function returns the sales document number and transaction on success.

Uploaded by

kenguva_tirupati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
186 views

Code For Bapi So Create

This document contains the code for a function that creates a sales order using SAP BAPI functions. It searches for a customer by email, gets the associated sales areas, and then uses that information to populate header and item tables that are passed to the BAPI_SALESORDER_CREATEFROMDAT2 function to generate the sales order document. Any error messages are returned and the transaction is committed if successful. The function returns the sales document number and transaction on success.

Uploaded by

kenguva_tirupati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

FUNCTION zbapi_sales_order_create1.

*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(I_CONTACT_EMAIL) LIKE BAPIKNA101_1-E_MAIL
*" REFERENCE(I_ACCOUNT_NAME) TYPE NAME1_GP OPTIONAL
*" VALUE(I_ITEM) LIKE ZIMPORT STRUCTURE ZIMPORT OPTIONAL
*" EXPORTING
*" REFERENCE(E_ITEM) TYPE ZEXPORT_ITEM
*" REFERENCE(E_RESULT) TYPE STRING
*" REFERENCE(E_RESPONSE) TYPE I
*" REFERENCE(E_TRANSACTION) TYPE VBTYP
*"----------------------------------------------------------------------
DATA: ls_header TYPE bapisdhd1,
ls_headerx TYPE bapisdhd1x,
ls_partner TYPE bapiparnr,
ls_item TYPE bapisditm,
ls_schedule TYPE bapischdl,
ls_return TYPE bapiret2,
ls_address TYPE bapiaddr1,
ls_text TYPE bapisdtext,
lt_text TYPE TABLE OF bapisdtext,
lt_partner TYPE TABLE OF bapiparnr,
lt_item TYPE TABLE OF bapisditm,
lt_schedule TYPE TABLE OF bapischdl,
lt_address TYPE TABLE OF bapiaddr1,
lt_return TYPE TABLE OF bapiret2,
ls_return_e TYPE bapireturn1,
lt_return_e TYPE TABLE OF bapireturn1,
ls_salesarea TYPE bapiknvvky,
lt_salesarea TYPE TABLE OF bapiknvvky,
ls_return_c TYPE bapireturn,
lt_return_c TYPE TABLE OF bapireturn,
ls_partnerfs TYPE E1KNVPM,
lt_partnerfs TYPE TABLE OF E1KNVPM
.
CONSTANTS:lc_auart TYPE auart VALUE 'QT' .
DATA:lv_customer TYPE bapikna103-customer,
e_salesdocument_ex TYPE bapivbeln-vbeln .
CALL FUNCTION 'BAPI_CUSTOMER_SEARCH1'
EXPORTING
pi_e_mail = i_contact_email
pi_salesorg = lc_auart
IMPORTING
customerno = lv_customer
return = ls_return_e.
IF lv_customer IS INITIAL.
e_result = 'Respective email not found'.
e_response = 1 .
ELSE.
CALL FUNCTION 'BAPI_CUSTOMER_GETSALESAREAS'
EXPORTING
customerno = lv_customer
IMPORTING
return = ls_return_c
TABLES
salesareas = lt_salesarea.
ENDIF.
IF lt_salesarea IS INITIAL.
e_result = 'Customer not defined for Sales details ' .
e_response = 1 .
ELSE.
LOOP AT lt_salesarea INTO ls_salesarea
WHERE customer = lv_customer .
ls_header-doc_type = lc_auart .
ls_header-sales_org = ls_salesarea-salesorg.
ls_header-distr_chan = ls_salesarea-distrchn.
ls_header-division = ls_salesarea-division .
ls_header-qt_valid_f = sy-datum.
CLEAR LS_SALESAREA.
ENDLOOP.
ENDIF.
ls_item-material = i_item-material.
ls_item-target_qty = i_item-target_qty.
ls_item-purch_no_c = i_item-target_qu.
APPEND ls_item TO lt_item.
CLEAR ls_item.
CALL FUNCTION 'CUSTOMER_PARTNERFS_GET'
EXPORTING
iv_kunnr = lv_customer
iv_vkorg = ls_header-sales_org
iv_vtweg = ls_header-distr_chan
iv_spart = ls_header-division
TABLES
et_e1knvpm = lt_partnerfs
.
IF LT_PARTNERFS IS NOT INITIAL.
.
LOOP AT LT_PARTNERFS INTO LS_PARTNERFS.
ls_partner-partn_role = LS_PARTNERFS-PARVW.
ls_partner-partn_numb = lv_customer.
APPEND ls_partner TO lt_partner.
CLEAR ls_partner.
ENDLOOP.
ELSE.
e_result = 'Partner Function Details Not Found' .
e_response = 1 .
ENDIF.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = ls_header
IMPORTING
salesdocument = e_salesdocument_ex
TABLES
return = lt_return
order_items_in = lt_item
* order_schedules_in = lt_schedule
order_partners = lt_partner.
* order_text = lt_text.
* partneraddresses = lt_address.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WRITE: / 'Dear Customer Your Sales Order', e_transaction ,e_salesdocument_ex
, 'has been created'.
ENDIF.
ENDFUNCTION.

You might also like