Sap Integration With Excel Advanced Guide PDF Free
Sap Integration With Excel Advanced Guide PDF Free
Advanced Guide
Summary
This document is a follow-up of ‘SAP integration with Excel - Basic Guide’. It documents how Excel can be
made to interface with SAP and perform data posting activities.
Perquisites:
Basic SAP ABAP knowledge is required. SAP terminologies and jargons are applied for brevity.
Review ‘SAP integration with Excel - Basic Guide, by Benedict Yong’, as it is the part 1 of this two-part
series.
Disclaimers:
Although the author and publisher have made every reasonable attempt to achieve complete accuracy of the
content, they assume no responsibility for errors or omissions. You should use this information as you see fit,
and at your own risk.
This publication is not affiliated with, sponsored by, or approved by SAP. Any trademarks, service marks,
product names or named features are assumed to be the property of their respective owners, and are used
only for reference.
1
SAP Excel Integration
Table of Contents
Business Requirements.................................................................................................................................... 3
System Architecture.......................................................................................................................................... 5
Preparatory work in RFC FM............................................................................................................................ 6
Preparatory work in Excel VBA....................................................................................................................... 12
Integration & Testing....................................................................................................................................... 14
Conclusion...................................................................................................................................................... 16
Appendix......................................................................................................................................................... 17
Author Bio....................................................................................................................................................... 23
Reference....................................................................................................................................................... 24
2
SAP Excel Integration
Business Requirements
In an enterprise with SAP, there can be business units where sales order creation is minimal. Hence, there is
a requirement to create a streamlined user entry/retrieval interface.
It would be a dream come true to have sales order data input in Excel and have these data posted into SAP
at a click of a button and review them back again in Excel. In this document, we will go through how to create
a SAP RFC Function Module that can be called by an Excel VBA.
Step 2: This is the Excel Screen after successful posting into SAP. SAP Sales Order number will be shown.
3
SAP Excel Integration
4
SAP Excel Integration
System Architecture
As the Excel Integration process comprises of various components and interactions, a 3-Tier Model-View-
Controller Framework should be applied to manage the complexity. (This is also applied in the Basic Guide)
5
SAP Excel Integration
This can be achieved by creating a wrapper RFC FM as “ZZZ_SO_BAPI_CREATE_N”. This RFC FM will
perform appropriate coordination and relay information to/from the standard BAPI
“BAPI_SALESORDER_CREATEFROMDAT2” & “BAPI_TRANSACTION_COMMIT”. The standard BAPI
“BAPI_SALESORDER_CREATEFROMDAT2” will generate a new sales order number after all checking is done;
while the “BAPI_TRANSACTION_COMMIT” actually post the document. In the case, where BAPI
“BAPI_SALESORDER_CREATEFROMDAT2” is ran but “BAPI_TRANSACTION_COMMIT” is not, the sales order
number will be exhausted.
6
SAP Excel Integration
At the specific mapping level, it is required for us to understand what are the fields required from the frontend
(i.e. Excel) and what are the variables to transfer to at the backend (i.e. Standard BAPI).
7
SAP Excel Integration
The wrapper RFC FM is designed to take in minimal data from its incoming interfaces (i.e. Excel VBA). This
is a good practice. The incoming parameters (imports) will take in flat type structures instead of table types.
The flat type structures include sales header data (i.e. SO_HEADER of type ZZSOHEADER) and line items
data (i.e. SO_ITEM1 and SO_ITEM2 of type ZSSOITEM). Once successfully posted, the system generated
Sales Order number will be relay back to the call interface.
8
SAP Excel Integration
Definition of line items data (i.e. SO_ITEM1 and SO_ITEM2 of type ZSSOITEM)
Note: there is more than one way to implement RFC Sales Order Creation. The above is one of the
possibilities. It should also be noted that Table objects transferring can be cumbersome between SAP and
VBA (it might be better with JAVA/C++/C#), to be safe we have chosen to transfer line items as flat type
structure instead of collection type table (i.e. in the TABLE parameter | the IMPORT paramater for Table-type
Structure).
9
SAP Excel Integration
Function Module Unit Testing is as per expectation. A Sales Order header and two line items information is
entered, and Sales Order number 13308 is generated.
10
SAP Excel Integration
11
SAP Excel Integration
The start of the script is to instantiate ActiveX Components “SAP LogonControl.1” and “SAP.Functions” as
per below.
12
SAP Excel Integration
13
SAP Excel Integration
We start with data entry to the customer code cell (=D6), customer reference cell (=D7), line item 1 row
(=C10:G10) and line item 2 row (=C11:G11).
Note that Sales Order number cell (=D4) will be updated by the system upon successful update.
Once the ‘Submit SO’ button is pressed, the Excel VBA will make connection with SAP RFC FM via the
ActiveX components. The SAP RFC FM (custom), will populate appropriate information to various structures
required by the standard BAPI, and invoke the BAPI. The SAP RFC FM finally relay the generated Sales
Order number back to the VBA. The VBA projects the returned information in the Sales Order number cell
(=D4), with a message box notification. Noting the Sales Order number is #13309.
14
SAP Excel Integration
We can view the Sales Order #13309, in SAP Screen, as per below:
15
SAP Excel Integration
Conclusion
The standard way of access SAP is via SAP GUI. However, it is technically possible to access SAP using
ActiveX control delivered by SAP. This greatly enriches the developer toolset to provide user a wide array of
connectivity options (such as Excel VBA, JAVA, C++, ASP/C#, JavaScript). From a business perspective, an
intuitive user interface greatly enhances user experiences and potentially reduces user training cost.
Based on this two-part series, we can observe the feasibility of writing and retrieving SAP information using
intuitive interfaces – which can then be further scaled into enterprise-level. However, one needs to be
mindful, integration always takes two parts to work: one part SAP; one part third-party.
16
SAP Excel Integration
Appendix
Full RFC FM ABAP
FUNCTION zzz_so_bapi_create_n.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(SO_HEADER) TYPE ZSSOHEADER
*" VALUE(SO_ITEMS1) TYPE ZSSOITEM
*" VALUE(SO_ITEMS2) TYPE ZSSOITEM
*" EXPORTING
*" VALUE(SD_DOC_NUMBER) LIKE BAPIVBELN-VBELN
*" VALUE(E_INFO) TYPE CHAR256
*" TABLES
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
DATA l_order_header_in LIKE bapisdhd1.
DATA t_order_partners TYPE STANDARD TABLE OF bapiparnr.
DATA t_order_items_in TYPE STANDARD TABLE OF bapisditm.
DATA t_order_schedules_in TYPE STANDARD TABLE OF bapischdl.
DATA t_order_schedules_inx TYPE STANDARD TABLE OF bapischdlx.
IF e_info+0(2) = 'S:'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDFUNCTION.
17
SAP Excel Integration
*----------------------------------------------------------------------*
***INCLUDE LZZZ_MDF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form ADD_ITEMS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM add_items TABLES t_order_items_in STRUCTURE bapisditm
t_order_schedules_in STRUCTURE bapischdl
t_order_schedules_inx STRUCTURE bapischdlx
CHANGING so_item TYPE zssoitem.
l_order_items_in-itm_number = so_item-itm_number.
IF so_item-item_categ IS NOT INITIAL.
l_order_items_in-item_categ = so_item-item_categ.
ENDIF.
l_order_items_in-target_qty = so_item-quantity.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = so_item-material
IMPORTING
output = l_order_items_in-material.
l_order_items_in-plant = so_item-plant.
l_order_items_in-short_text = so_item-short_text.
APPEND l_order_items_in TO t_order_items_in.
l_order_schedules_in-itm_number = so_item-itm_number.
l_order_schedules_in-sched_line = '0001'.
l_order_schedules_in-req_qty = so_item-quantity.
APPEND l_order_schedules_in TO t_order_schedules_in.
l_order_schedules_inx-itm_number = so_item-itm_number.
l_order_schedules_inx-sched_line = so_item-sched_line.
l_order_schedules_inx-updateflag = 'X'.
l_order_schedules_inx-req_qty = 'X'.
APPEND l_order_schedules_inx TO t_order_schedules_inx.
ENDFORM. " ADD_ITEMS
*&---------------------------------------------------------------------*
*& Form ADD_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_ORDER_PARTNERS text
* <--P_L_ORDER_HEADER_IN text
* -->P_SO_HEADER text
*----------------------------------------------------------------------*
FORM add_header TABLES t_order_partners STRUCTURE bapiparnr
18
SAP Excel Integration
19
SAP Excel Integration
20
SAP Excel Integration
21
SAP Excel Integration
22
SAP Excel Integration
Author Bio
Benedict Yong is a PMP/ITIL trained Project Consultant with 9+ years Finance domain experience (FICO,
COPA, BPC) and 3+ years of Logistics experiences (SD, MM, PS, CS). He holds four SAP® Functional
Certifications (Financial Accounting, Management Accounting, Sales, Procurement) and three Technical
Certifications (S/4 HANA Implementation Architect, S/4 Cloud Onboarding with SAP Activate, SAP
Business Intelligence 7.0).
For people who are interested to have a holistic understanding of ERP, a PDF document will not be
enough. “ERP Made Simple” at Amazon might prove to be useful.
https://www.amazon.com/dp/B083C3X8YY
23
SAP Excel Integration
Reference
1. SAP Help - BAPI Framework
https://help.sap.com/doc/saphelp_46c/4.6C/en-
US/d8/44ca02ac3c11d189c60000e829fbbd/content.htm
2. SAP OSS – note 2256415 - Adaptation of RFC controls (Logon, Function, Table and BAPI) to use
SAP NetWeaver RFC Library
https://launchpad.support.sap.com/#/notes/2256415
24