SlideShare a Scribd company logo
1 of 24
1
SAP integration with Excel -
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.
SAP Excel Integration
2
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
SAP Excel Integration
3
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.
Base on the above, we will design a simple proof of concept.
Step 1: This is the Excel Sales Order Creation screen, with Sales Order information that will be posted.
Step 2: This is the Excel Screen after successful posting into SAP. SAP Sales Order number will be shown.
SAP Excel Integration
4
Step 3: This is the Sales Order created in SAP.
SAP Excel Integration
5
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)
3-Tier Model-View-Controller Framework
In the 3-Tier MVC Framework, there are
 View/ Interface:The role focuseson userinteraction;collectinganddisplayinginformation.Inour
specificcase,thiswill be ourExcel anditsembeddedVBA.
 Controller:The role focusesontransmittingandmanipulationof information.Inourspecificcase,
thiswill be ourSAPRFC FunctionModule.
 Model:The role focusesondata storage and itsrelatedprocesses. Inourspecificcase,thiswillbe
the underlyingDatabase.
This document will now be divided into 2 sections:
 Preparatory work in RFC FM – this explains how the Controller of the architecture is coded.
 Preparatory work in Excel VBA – this explains how the View/Interface of the architecture is
scripted.
SAP Excel Integration
6
Preparatory work in RFC FM
The purpose of RFC FM/BAPI is to populate sales header and line items data into SAP backend.
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.
SAP Excel Integration
7
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).
SAP Excel Integration
8
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.
Note: full code at appendix.
SAP Excel Integration
9
Definition of sales header data (i.e. SO_HEADER of type ZZSOHEADER)
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).
SAP Excel Integration
10
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.
Processing messages are as below:
SAP Excel Integration
11
Actual Sales Order as per below:
SAP Excel Integration
12
Preparatory work in Excel VBA
To be able to perform scripting in Excel VBA, the Developer Tab needs to be turned on. (This is documented
in the Basic Guide)
The start of the script is to instantiate ActiveX Components “SAP LogonControl.1” and “SAP.Functions” as
per below.
SAP Excel Integration
13
The actual function call to “ZZZ_SO_BAPI_CREATE_N” is as per below.
Note: full script at appendix.
SAP Excel Integration
14
Integration & Testing
With both the Excel VBA scripting and SAP RFC FM coding completed, we can perform end-to-end testing.
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.
SAP Excel Integration
15
We can view the Sales Order #13309, in SAP Screen, as per below:
SAP Excel Integration
16
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.
SAP Excel Integration
17
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.
PERFORM add_header TABLES t_order_partners
CHANGING l_order_header_in
so_header.
PERFORM add_items TABLES t_order_items_in
t_order_schedules_in
t_order_schedules_inx
CHANGING so_items1.
PERFORM add_items TABLES t_order_items_in
t_order_schedules_in
t_order_schedules_inx
CHANGING so_items2.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = l_order_header_in
IMPORTING
salesdocument = sd_doc_number
TABLES
return = return
order_items_in = t_order_items_in
order_partners = t_order_partners
order_schedules_in = t_order_schedules_in
order_schedules_inx = t_order_schedules_inx.
PERFORM return_op TABLES return
CHANGING sd_doc_number
so_header-purch_no_c
e_info.
IF e_info+0(2) = 'S:'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
ENDFUNCTION.
SAP Excel Integration
18
*----------------------------------------------------------------------*
***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.
CHECK so_item IS NOT INITIAL.
DATA l_order_items_in LIKE bapisditm.
DATA l_order_schedules_in LIKE bapischdl.
DATA l_order_schedules_inx LIKE bapischdlx.
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
SAP Excel Integration
19
CHANGING l_order_header_in TYPE bapisdhd1
so_header TYPE zssoheader.
DATA l_order_partners LIKE bapiparnr.
MOVE-CORRESPONDING so_header TO l_order_header_in.
l_order_partners-partn_numb = so_header-partn_numb_sp.
l_order_partners-partn_role = 'AG'.
APPEND l_order_partners TO t_order_partners.
IF so_header-partn_numb_sh IS NOT INITIAL.
l_order_partners-partn_numb = so_header-partn_numb_sh.
l_order_partners-partn_role = 'WE'.
APPEND l_order_partners TO t_order_partners.
ENDIF.
ENDFORM. " ADD_HEADER
*&---------------------------------------------------------------------*
*& Form RETURN_OP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_RETURN text
* <--P_SD_DOC_NUMBER text
* <--P_E_INFO text
*----------------------------------------------------------------------*
FORM return_op TABLES return STRUCTURE bapiret2
CHANGING sd_doc_number
sd_po_number
e_info.
SHIFT sd_doc_number LEFT DELETING LEADING '0'.
DATA is_error TYPE boolean VALUE 0.
LOOP AT return.
IF return-type = 'E'.
is_error = 1.
CONCATENATE 'E:-' return-message
' (' sd_po_number ') '
INTO e_info.
EXIT.
ENDIF.
ENDLOOP.
IF is_error = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
CONCATENATE 'S:-Sales Order (' sd_doc_number ')'
' Created Successfully'
INTO e_info.
ENDIF.
ENDFORM. " RETURN_OP
SAP Excel Integration
20
Full Excel VBA Scripting
Sub Button1_Click()
'---------------------------------
' Declaration.
'---------------------------------
Dim LogonControl As SAPLogonCtrl.SAPLogonControl
Dim R3Connection As SAPLogonCtrl.Connection
Dim TableFactory As SAPTableFactory
Dim Functions As SAPFunctionsOCX.SAPFunctions
Dim objBAPIControl As Object
Dim oWB As Workbook
Dim oST As Worksheet
Set oWB = Application.ActiveWorkbook
Set oST = oWB.Worksheets(1)
'---------------------------------
' Initialize SAP ActiveX Control.
'---------------------------------
Set LogonControl = CreateObject("SAP.LogonControl.1")
Set R3Connection = LogonControl.NewConnection
Set objBAPIControl = CreateObject("SAP.Functions")
'--------------------
' Logon with prompt.
'--------------------
R3Connection.Client = "100" 'as per SAP Logon Pad
R3Connection.System = "SID" 'as per SAP Logon Pad
R3Connection.SystemNumber = "00" 'as per SAP Logon Pad
R3Connection.ApplicationServer = "XX.XX.XX.XX" 'as per SAP Logon Pad
R3Connection.User = "sapidx" 'as per SAP Logon Pad
R3Connection.Password = "sapid-passwdx" 'as per SAP Logon Pad
Application.StatusBar = "Start of Logging in"
SY_Subrc = R3Connection.Logon(0, SilentLogon)
If SY_Subrc <> True Then MsgBox "Logon failed": Exit Sub
Application.StatusBar = "Login Successful"
Set objBAPIControl.Connection = R3Connection
'---------------------------------
' Prepare a sales order.
'---------------------------------
Dim SO_Header As Object
SAP Excel Integration
21
Dim SO_Item1 As Object
Dim SO_Item2 As Object
Dim SO_Number As Object
Dim SO_Info As Object
Dim vRow, vCol As Integer
Set oBAPI = objBAPIControl.Add("ZZZ_SO_BAPI_CREATE_N")
Set SO_Header = oBAPI.Exports.Item("SO_HEADER")
Set SO_Item1 = oBAPI.Exports.Item("SO_ITEMS1")
Set SO_Item2 = oBAPI.Exports.Item("SO_ITEMS2")
Set SO_Number = oBAPI.Imports("SD_DOC_NUMBER")
Set SO_Info = oBAPI.Imports("E_INFO")
SO_Header.Value("DOC_TYPE") = "OR"
SO_Header.Value("SALES_ORG") = "3090"
SO_Header.Value("DISTR_CHAN") = "01"
SO_Header.Value("DIVISION") = "01"
SO_Header.Value("PURCH_NO_C") = Trim(oST.Cells(7, 4))
SO_Header.Value("PARTN_NUMB_SP") = Trim(oST.Cells(6, 4))
vRow = 10: vCol = 3
SO_Item1.Value("ITM_NUMBER") = Trim(oST.Cells(vRow, vCol + 0))
SO_Item1.Value("MATERIAL") = Trim(oST.Cells(vRow, vCol + 1))
SO_Item1.Value("QUANTITY") = Trim(oST.Cells(vRow, vCol + 2))
SO_Item1.Value("PLANT") = Trim(oST.Cells(vRow, vCol + 3))
SO_Item1.Value("SHORT_TEXT") = Trim(oST.Cells(vRow, vCol + 4))
vRow = 11: vCol = 3
SO_Item2.Value("ITM_NUMBER") = Trim(oST.Cells(vRow, vCol + 0))
SO_Item2.Value("MATERIAL") = Trim(oST.Cells(vRow, vCol + 1))
SO_Item2.Value("QUANTITY") = Trim(oST.Cells(vRow, vCol + 2))
SO_Item2.Value("PLANT") = Trim(oST.Cells(vRow, vCol + 3))
SO_Item2.Value("SHORT_TEXT") = Trim(oST.Cells(vRow, vCol + 4))
'---------------------------------
' Make the sales order.
'---------------------------------
Application.StatusBar = "Perform SAP Call"
SY_Subrc = oBAPI.Call
If SY_Subrc <> True Then MsgBox "Call failed!!": Exit Sub
If Left(SO_Info, 2) = "E:" Then MsgBox "Call failed: " & SO_Info: Exit Sub
MsgBox SO_Info
Application.StatusBar = "Perform SAP Call Successful"
Cells(4, 4).Value = SO_Number
SAP Excel Integration
22
Cells(4, 4).Interior.Color = vbGreen
'-----------------------------------
' Logoff SAP and close the control.
'-----------------------------------
R3Connection.Logoff
Set LogonControl = Nothing
Set objBAPIControl = Nothing
End Sub
SAP Excel Integration
23
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).
He holds a Bachelor of Management and a Diploma in IT. He has worked in Banking,
Retail and Manufacturing industries, playing both in-house and external consultant
role.
He is situated in Singapore and is bilingual in English and Mandarin. He can be
contacted at benytx@gmail.com.
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
SAP Excel Integration
24
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
3. SAP SDN – Common export parameter issues
https://blogs.sap.com/2014/04/27/activex-component-sapfunctions-with-export-parameter-string/
https://answers.sap.com/questions/529288/datatype-problem-with-sap-gui-75-pl5-unicode-activ.html
https://answers.sap.com/questions/10222185/activex-component-sapfunctions-with-export-
paramet.html

More Related Content

What's hot

0104 abap dictionary
0104 abap dictionary0104 abap dictionary
0104 abap dictionary
vkyecc1
 
Copa configuration
Copa configurationCopa configuration
Copa configuration
Mithun Roy
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
Kranthi Kumar
 
IDOC , ALE ,EDI
IDOC , ALE ,EDIIDOC , ALE ,EDI
IDOC , ALE ,EDI
Amit Khari
 

What's hot (20)

SAP S_4HANA Migration Cockpit - Migrate your Data to SAP S_4HANA.pdf
SAP S_4HANA Migration Cockpit - Migrate your Data to SAP S_4HANA.pdfSAP S_4HANA Migration Cockpit - Migrate your Data to SAP S_4HANA.pdf
SAP S_4HANA Migration Cockpit - Migrate your Data to SAP S_4HANA.pdf
 
0104 abap dictionary
0104 abap dictionary0104 abap dictionary
0104 abap dictionary
 
Introduction Into SAP Fiori
Introduction Into SAP FioriIntroduction Into SAP Fiori
Introduction Into SAP Fiori
 
Sapui5 & Fiori
Sapui5 & FioriSapui5 & Fiori
Sapui5 & Fiori
 
Architecture overview
Architecture  overviewArchitecture  overview
Architecture overview
 
S4 HANA Finance Contents
S4 HANA Finance Contents S4 HANA Finance Contents
S4 HANA Finance Contents
 
Abap Objects for BW
Abap Objects for BWAbap Objects for BW
Abap Objects for BW
 
FS for FICO
FS for FICOFS for FICO
FS for FICO
 
SAP Integration: Best Practices | MuleSoft
SAP Integration: Best Practices | MuleSoftSAP Integration: Best Practices | MuleSoft
SAP Integration: Best Practices | MuleSoft
 
Functional specification doc Gst purcahse register
Functional specification doc Gst purcahse registerFunctional specification doc Gst purcahse register
Functional specification doc Gst purcahse register
 
Beginner's Guide: Programming with ABAP on HANA
Beginner's Guide: Programming with ABAP on HANABeginner's Guide: Programming with ABAP on HANA
Beginner's Guide: Programming with ABAP on HANA
 
Copa configuration
Copa configurationCopa configuration
Copa configuration
 
Fiori Presentation
Fiori PresentationFiori Presentation
Fiori Presentation
 
1000 solved questions
1000 solved questions1000 solved questions
1000 solved questions
 
SAP S/4HANA Cloud
SAP S/4HANA CloudSAP S/4HANA Cloud
SAP S/4HANA Cloud
 
Sap Purchase Order Workflow
Sap Purchase Order WorkflowSap Purchase Order Workflow
Sap Purchase Order Workflow
 
Funds management configuration sap ag
Funds management configuration sap agFunds management configuration sap ag
Funds management configuration sap ag
 
“Migration to Suite of HANA”
“Migration to Suite of HANA”“Migration to Suite of HANA”
“Migration to Suite of HANA”
 
Central Finance Configuration.pdf
Central Finance Configuration.pdfCentral Finance Configuration.pdf
Central Finance Configuration.pdf
 
IDOC , ALE ,EDI
IDOC , ALE ,EDIIDOC , ALE ,EDI
IDOC , ALE ,EDI
 

Similar to SAP Integration With Excel - Advanced Guide

Fi enhancement technique how-to-guide on the usage of business transaction ...
Fi enhancement technique   how-to-guide on the usage of business transaction ...Fi enhancement technique   how-to-guide on the usage of business transaction ...
Fi enhancement technique how-to-guide on the usage of business transaction ...
Kranthi Kumar
 
XLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & TricksXLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & Tricks
guest92a5de
 
XLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksXLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & Tricks
Earl Grau
 
SAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdfSAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdf
KoushikGuna
 
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Alkis Vazacopoulos
 
Docslide.net how ale-and-idocs-affect-sap-in-house-cash-configuration
Docslide.net how ale-and-idocs-affect-sap-in-house-cash-configurationDocslide.net how ale-and-idocs-affect-sap-in-house-cash-configuration
Docslide.net how ale-and-idocs-affect-sap-in-house-cash-configuration
Shailendra Surana
 

Similar to SAP Integration With Excel - Advanced Guide (20)

SYSTEM APPLICATION PRODUCTS AND DATA PROCESING
SYSTEM APPLICATION PRODUCTS AND DATA PROCESINGSYSTEM APPLICATION PRODUCTS AND DATA PROCESING
SYSTEM APPLICATION PRODUCTS AND DATA PROCESING
 
Sap alv excel inplace with macro recording sapignite
Sap alv excel inplace with macro recording sapigniteSap alv excel inplace with macro recording sapignite
Sap alv excel inplace with macro recording sapignite
 
SAP performance testing & engineering courseware v01
SAP performance testing & engineering courseware v01SAP performance testing & engineering courseware v01
SAP performance testing & engineering courseware v01
 
325546_adding fields in CJI3 & CJI5.pdf
325546_adding fields in CJI3 & CJI5.pdf325546_adding fields in CJI3 & CJI5.pdf
325546_adding fields in CJI3 & CJI5.pdf
 
Integrating SAP and Low-Code Plaforms
Integrating SAP and Low-Code PlaformsIntegrating SAP and Low-Code Plaforms
Integrating SAP and Low-Code Plaforms
 
Fi enhancement technique how-to-guide on the usage of business transaction ...
Fi enhancement technique   how-to-guide on the usage of business transaction ...Fi enhancement technique   how-to-guide on the usage of business transaction ...
Fi enhancement technique how-to-guide on the usage of business transaction ...
 
Fi enhancement technique how-to-guide on the usage of business transaction ...
Fi enhancement technique   how-to-guide on the usage of business transaction ...Fi enhancement technique   how-to-guide on the usage of business transaction ...
Fi enhancement technique how-to-guide on the usage of business transaction ...
 
How to find user exits
How to find user exitsHow to find user exits
How to find user exits
 
Sap integration by mule esb
Sap integration by mule esbSap integration by mule esb
Sap integration by mule esb
 
ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1 ERP Magazine April 2018 Issue 1
ERP Magazine April 2018 Issue 1
 
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP ProfessionalsERP Magazine April 2018 - The magazine for SAP ABAP Professionals
ERP Magazine April 2018 - The magazine for SAP ABAP Professionals
 
XLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & TricksXLS PE How To Tutorials Tips & Tricks
XLS PE How To Tutorials Tips & Tricks
 
XLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & TricksXLS Processor Engine How To, Tutorials, Tips & Tricks
XLS Processor Engine How To, Tutorials, Tips & Tricks
 
Custom Development of Enterprise Services
Custom Development of Enterprise ServicesCustom Development of Enterprise Services
Custom Development of Enterprise Services
 
Mule sap connector
Mule sap connectorMule sap connector
Mule sap connector
 
SAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdfSAP BI Generic Extraction Using a Function Module.pdf
SAP BI Generic Extraction Using a Function Module.pdf
 
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
Quick Development and Deployment of Industrial Applications using Excel/VBA, ...
 
MD04 Report in BW
MD04 Report in BWMD04 Report in BW
MD04 Report in BW
 
Docslide.net how ale-and-idocs-affect-sap-in-house-cash-configuration
Docslide.net how ale-and-idocs-affect-sap-in-house-cash-configurationDocslide.net how ale-and-idocs-affect-sap-in-house-cash-configuration
Docslide.net how ale-and-idocs-affect-sap-in-house-cash-configuration
 
Beginner's guide create a custom 'copy' planning function type
Beginner's guide  create a custom 'copy' planning function typeBeginner's guide  create a custom 'copy' planning function type
Beginner's guide create a custom 'copy' planning function type
 

More from Benedict Yong (杨腾翔)

More from Benedict Yong (杨腾翔) (17)

Phillip Securities - Prime US REIT Corporate Presentation.pdf
Phillip Securities - Prime US REIT Corporate Presentation.pdfPhillip Securities - Prime US REIT Corporate Presentation.pdf
Phillip Securities - Prime US REIT Corporate Presentation.pdf
 
ERP Made Simple (preview)
ERP Made Simple (preview)ERP Made Simple (preview)
ERP Made Simple (preview)
 
SAP Asset Accounting in 1-Pager
SAP Asset Accounting in 1-PagerSAP Asset Accounting in 1-Pager
SAP Asset Accounting in 1-Pager
 
ABAP/4 Mindmap!! - for busy functional consultants
ABAP/4 Mindmap!! - for busy functional consultantsABAP/4 Mindmap!! - for busy functional consultants
ABAP/4 Mindmap!! - for busy functional consultants
 
Practitioner perspective-erp-on-hana-and-fi-analytics 2015
Practitioner perspective-erp-on-hana-and-fi-analytics 2015Practitioner perspective-erp-on-hana-and-fi-analytics 2015
Practitioner perspective-erp-on-hana-and-fi-analytics 2015
 
SAP with Banking
SAP with BankingSAP with Banking
SAP with Banking
 
SAP PS Certification Overview (mindmap edition)
SAP PS Certification Overview (mindmap edition)SAP PS Certification Overview (mindmap edition)
SAP PS Certification Overview (mindmap edition)
 
SAP PP Certification Overview (mindmap edition)
SAP PP Certification Overview (mindmap edition)SAP PP Certification Overview (mindmap edition)
SAP PP Certification Overview (mindmap edition)
 
SAP S4 HANA Innovations
SAP S4 HANA InnovationsSAP S4 HANA Innovations
SAP S4 HANA Innovations
 
SAP MTS-To-COPA Flow Diagram
SAP MTS-To-COPA Flow DiagramSAP MTS-To-COPA Flow Diagram
SAP MTS-To-COPA Flow Diagram
 
SAP Account Determination Diagram
SAP Account Determination DiagramSAP Account Determination Diagram
SAP Account Determination Diagram
 
SAP COPA Integration overview
SAP COPA Integration overviewSAP COPA Integration overview
SAP COPA Integration overview
 
Highlevel Overview of S4 Improvements
Highlevel Overview of S4 ImprovementsHighlevel Overview of S4 Improvements
Highlevel Overview of S4 Improvements
 
SAP S4 HANA MM 1709 Overview (mindmap edition) Final
SAP S4 HANA MM 1709 Overview (mindmap edition) FinalSAP S4 HANA MM 1709 Overview (mindmap edition) Final
SAP S4 HANA MM 1709 Overview (mindmap edition) Final
 
SAP S4 HANA SD 1709 Overview (mindmap edition) Final
SAP S4 HANA SD 1709 Overview (mindmap edition) FinalSAP S4 HANA SD 1709 Overview (mindmap edition) Final
SAP S4 HANA SD 1709 Overview (mindmap edition) Final
 
SAP S4 HANA CO 1709 Overview (mindmap edition)
SAP S4 HANA CO 1709 Overview (mindmap edition)SAP S4 HANA CO 1709 Overview (mindmap edition)
SAP S4 HANA CO 1709 Overview (mindmap edition)
 
SAP S4 HANA FI 1610 Overview (mindmap edition)
SAP S4 HANA FI 1610 Overview (mindmap edition)SAP S4 HANA FI 1610 Overview (mindmap edition)
SAP S4 HANA FI 1610 Overview (mindmap edition)
 

Recently uploaded

Powerpoint showing results from tik tok metrics
Powerpoint showing results from tik tok metricsPowerpoint showing results from tik tok metrics
Powerpoint showing results from tik tok metrics
CaitlinCummins3
 
Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312
LR1709MUSIC
 
Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...
Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...
Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...
Klinik kandungan
 
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di PasuruanObat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Jakarta Wa 085176963835 Apotek Jual Obat Cytotec Di Jakarta
 

Recently uploaded (20)

PALWAL CALL GIRL ❤ 8272964427❤ CALL GIRLS IN PALWAL ESCORTS
PALWAL CALL GIRL ❤ 8272964427❤ CALL GIRLS IN PALWAL ESCORTSPALWAL CALL GIRL ❤ 8272964427❤ CALL GIRLS IN PALWAL ESCORTS
PALWAL CALL GIRL ❤ 8272964427❤ CALL GIRLS IN PALWAL ESCORTS
 
Home Furnishings Ecommerce Platform Short Pitch 2024
Home Furnishings Ecommerce Platform Short Pitch 2024Home Furnishings Ecommerce Platform Short Pitch 2024
Home Furnishings Ecommerce Platform Short Pitch 2024
 
Powerpoint showing results from tik tok metrics
Powerpoint showing results from tik tok metricsPowerpoint showing results from tik tok metrics
Powerpoint showing results from tik tok metrics
 
How does a bike-share company navigate speedy success? - Cyclistic
How does a bike-share company navigate speedy success? - CyclisticHow does a bike-share company navigate speedy success? - Cyclistic
How does a bike-share company navigate speedy success? - Cyclistic
 
Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312Shots fired Budget Presentation.pdf12312
Shots fired Budget Presentation.pdf12312
 
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
 
The Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and UncertaintyThe Art of Decision-Making: Navigating Complexity and Uncertainty
The Art of Decision-Making: Navigating Complexity and Uncertainty
 
Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...
Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...
Jual obat aborsi Hongkong ( 085657271886 ) Cytote pil telat bulan penggugur k...
 
WAM Corporate Presentation May 2024_w.pdf
WAM Corporate Presentation May 2024_w.pdfWAM Corporate Presentation May 2024_w.pdf
WAM Corporate Presentation May 2024_w.pdf
 
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptxThompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
Thompson_Taylor_MBBS_PB1_2024-03 (1)- Project & Portfolio 2.pptx
 
UJJAIN CALL GIRL ❤ 8272964427❤ CALL GIRLS IN UJJAIN ESCORTS SERVICE PROVIDE
UJJAIN CALL GIRL ❤ 8272964427❤ CALL GIRLS IN UJJAIN ESCORTS SERVICE PROVIDEUJJAIN CALL GIRL ❤ 8272964427❤ CALL GIRLS IN UJJAIN ESCORTS SERVICE PROVIDE
UJJAIN CALL GIRL ❤ 8272964427❤ CALL GIRLS IN UJJAIN ESCORTS SERVICE PROVIDE
 
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR ESCORTS SERVICE PROVIDE
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR  ESCORTS SERVICE PROVIDEJAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR  ESCORTS SERVICE PROVIDE
JAJPUR CALL GIRL ❤ 8272964427❤ CALL GIRLS IN JAJPUR ESCORTS SERVICE PROVIDE
 
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di PasuruanObat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
Obat Aborsi Pasuruan 0851\7696\3835 Jual Obat Cytotec Di Pasuruan
 
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON ESCORTS SERVICE PROVIDE
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON  ESCORTS SERVICE PROVIDEGURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON  ESCORTS SERVICE PROVIDE
GURGAON CALL GIRL ❤ 8272964427❤ CALL GIRLS IN GURGAON ESCORTS SERVICE PROVIDE
 
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
10 Influential Leaders Defining the Future of Digital Banking in 2024.pdf
 
WheelTug Short Pitch Deck 2024 | Byond Insights
WheelTug Short Pitch Deck 2024 | Byond InsightsWheelTug Short Pitch Deck 2024 | Byond Insights
WheelTug Short Pitch Deck 2024 | Byond Insights
 
Progress Report - Oracle's OCI Analyst Summit 2024
Progress Report - Oracle's OCI Analyst Summit 2024Progress Report - Oracle's OCI Analyst Summit 2024
Progress Report - Oracle's OCI Analyst Summit 2024
 
HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024HomeRoots Pitch Deck | Investor Insights | April 2024
HomeRoots Pitch Deck | Investor Insights | April 2024
 
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptxGoal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
Goal Presentation_NEW EMPLOYEE_NETAPS FOUNDATION.pptx
 
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAIGetting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
Getting Real with AI - Columbus DAW - May 2024 - Nick Woo from AlignAI
 

SAP Integration With Excel - Advanced Guide

  • 1. 1 SAP integration with Excel - 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.
  • 2. SAP Excel Integration 2 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
  • 3. SAP Excel Integration 3 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. Base on the above, we will design a simple proof of concept. Step 1: This is the Excel Sales Order Creation screen, with Sales Order information that will be posted. Step 2: This is the Excel Screen after successful posting into SAP. SAP Sales Order number will be shown.
  • 4. SAP Excel Integration 4 Step 3: This is the Sales Order created in SAP.
  • 5. SAP Excel Integration 5 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) 3-Tier Model-View-Controller Framework In the 3-Tier MVC Framework, there are  View/ Interface:The role focuseson userinteraction;collectinganddisplayinginformation.Inour specificcase,thiswill be ourExcel anditsembeddedVBA.  Controller:The role focusesontransmittingandmanipulationof information.Inourspecificcase, thiswill be ourSAPRFC FunctionModule.  Model:The role focusesondata storage and itsrelatedprocesses. Inourspecificcase,thiswillbe the underlyingDatabase. This document will now be divided into 2 sections:  Preparatory work in RFC FM – this explains how the Controller of the architecture is coded.  Preparatory work in Excel VBA – this explains how the View/Interface of the architecture is scripted.
  • 6. SAP Excel Integration 6 Preparatory work in RFC FM The purpose of RFC FM/BAPI is to populate sales header and line items data into SAP backend. 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.
  • 7. SAP Excel Integration 7 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).
  • 8. SAP Excel Integration 8 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. Note: full code at appendix.
  • 9. SAP Excel Integration 9 Definition of sales header data (i.e. SO_HEADER of type ZZSOHEADER) 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).
  • 10. SAP Excel Integration 10 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. Processing messages are as below:
  • 11. SAP Excel Integration 11 Actual Sales Order as per below:
  • 12. SAP Excel Integration 12 Preparatory work in Excel VBA To be able to perform scripting in Excel VBA, the Developer Tab needs to be turned on. (This is documented in the Basic Guide) The start of the script is to instantiate ActiveX Components “SAP LogonControl.1” and “SAP.Functions” as per below.
  • 13. SAP Excel Integration 13 The actual function call to “ZZZ_SO_BAPI_CREATE_N” is as per below. Note: full script at appendix.
  • 14. SAP Excel Integration 14 Integration & Testing With both the Excel VBA scripting and SAP RFC FM coding completed, we can perform end-to-end testing. 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.
  • 15. SAP Excel Integration 15 We can view the Sales Order #13309, in SAP Screen, as per below:
  • 16. SAP Excel Integration 16 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.
  • 17. SAP Excel Integration 17 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. PERFORM add_header TABLES t_order_partners CHANGING l_order_header_in so_header. PERFORM add_items TABLES t_order_items_in t_order_schedules_in t_order_schedules_inx CHANGING so_items1. PERFORM add_items TABLES t_order_items_in t_order_schedules_in t_order_schedules_inx CHANGING so_items2. CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING order_header_in = l_order_header_in IMPORTING salesdocument = sd_doc_number TABLES return = return order_items_in = t_order_items_in order_partners = t_order_partners order_schedules_in = t_order_schedules_in order_schedules_inx = t_order_schedules_inx. PERFORM return_op TABLES return CHANGING sd_doc_number so_header-purch_no_c e_info. IF e_info+0(2) = 'S:'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. ENDIF. ENDFUNCTION.
  • 18. SAP Excel Integration 18 *----------------------------------------------------------------------* ***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. CHECK so_item IS NOT INITIAL. DATA l_order_items_in LIKE bapisditm. DATA l_order_schedules_in LIKE bapischdl. DATA l_order_schedules_inx LIKE bapischdlx. 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
  • 19. SAP Excel Integration 19 CHANGING l_order_header_in TYPE bapisdhd1 so_header TYPE zssoheader. DATA l_order_partners LIKE bapiparnr. MOVE-CORRESPONDING so_header TO l_order_header_in. l_order_partners-partn_numb = so_header-partn_numb_sp. l_order_partners-partn_role = 'AG'. APPEND l_order_partners TO t_order_partners. IF so_header-partn_numb_sh IS NOT INITIAL. l_order_partners-partn_numb = so_header-partn_numb_sh. l_order_partners-partn_role = 'WE'. APPEND l_order_partners TO t_order_partners. ENDIF. ENDFORM. " ADD_HEADER *&---------------------------------------------------------------------* *& Form RETURN_OP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_RETURN text * <--P_SD_DOC_NUMBER text * <--P_E_INFO text *----------------------------------------------------------------------* FORM return_op TABLES return STRUCTURE bapiret2 CHANGING sd_doc_number sd_po_number e_info. SHIFT sd_doc_number LEFT DELETING LEADING '0'. DATA is_error TYPE boolean VALUE 0. LOOP AT return. IF return-type = 'E'. is_error = 1. CONCATENATE 'E:-' return-message ' (' sd_po_number ') ' INTO e_info. EXIT. ENDIF. ENDLOOP. IF is_error = 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. CONCATENATE 'S:-Sales Order (' sd_doc_number ')' ' Created Successfully' INTO e_info. ENDIF. ENDFORM. " RETURN_OP
  • 20. SAP Excel Integration 20 Full Excel VBA Scripting Sub Button1_Click() '--------------------------------- ' Declaration. '--------------------------------- Dim LogonControl As SAPLogonCtrl.SAPLogonControl Dim R3Connection As SAPLogonCtrl.Connection Dim TableFactory As SAPTableFactory Dim Functions As SAPFunctionsOCX.SAPFunctions Dim objBAPIControl As Object Dim oWB As Workbook Dim oST As Worksheet Set oWB = Application.ActiveWorkbook Set oST = oWB.Worksheets(1) '--------------------------------- ' Initialize SAP ActiveX Control. '--------------------------------- Set LogonControl = CreateObject("SAP.LogonControl.1") Set R3Connection = LogonControl.NewConnection Set objBAPIControl = CreateObject("SAP.Functions") '-------------------- ' Logon with prompt. '-------------------- R3Connection.Client = "100" 'as per SAP Logon Pad R3Connection.System = "SID" 'as per SAP Logon Pad R3Connection.SystemNumber = "00" 'as per SAP Logon Pad R3Connection.ApplicationServer = "XX.XX.XX.XX" 'as per SAP Logon Pad R3Connection.User = "sapidx" 'as per SAP Logon Pad R3Connection.Password = "sapid-passwdx" 'as per SAP Logon Pad Application.StatusBar = "Start of Logging in" SY_Subrc = R3Connection.Logon(0, SilentLogon) If SY_Subrc <> True Then MsgBox "Logon failed": Exit Sub Application.StatusBar = "Login Successful" Set objBAPIControl.Connection = R3Connection '--------------------------------- ' Prepare a sales order. '--------------------------------- Dim SO_Header As Object
  • 21. SAP Excel Integration 21 Dim SO_Item1 As Object Dim SO_Item2 As Object Dim SO_Number As Object Dim SO_Info As Object Dim vRow, vCol As Integer Set oBAPI = objBAPIControl.Add("ZZZ_SO_BAPI_CREATE_N") Set SO_Header = oBAPI.Exports.Item("SO_HEADER") Set SO_Item1 = oBAPI.Exports.Item("SO_ITEMS1") Set SO_Item2 = oBAPI.Exports.Item("SO_ITEMS2") Set SO_Number = oBAPI.Imports("SD_DOC_NUMBER") Set SO_Info = oBAPI.Imports("E_INFO") SO_Header.Value("DOC_TYPE") = "OR" SO_Header.Value("SALES_ORG") = "3090" SO_Header.Value("DISTR_CHAN") = "01" SO_Header.Value("DIVISION") = "01" SO_Header.Value("PURCH_NO_C") = Trim(oST.Cells(7, 4)) SO_Header.Value("PARTN_NUMB_SP") = Trim(oST.Cells(6, 4)) vRow = 10: vCol = 3 SO_Item1.Value("ITM_NUMBER") = Trim(oST.Cells(vRow, vCol + 0)) SO_Item1.Value("MATERIAL") = Trim(oST.Cells(vRow, vCol + 1)) SO_Item1.Value("QUANTITY") = Trim(oST.Cells(vRow, vCol + 2)) SO_Item1.Value("PLANT") = Trim(oST.Cells(vRow, vCol + 3)) SO_Item1.Value("SHORT_TEXT") = Trim(oST.Cells(vRow, vCol + 4)) vRow = 11: vCol = 3 SO_Item2.Value("ITM_NUMBER") = Trim(oST.Cells(vRow, vCol + 0)) SO_Item2.Value("MATERIAL") = Trim(oST.Cells(vRow, vCol + 1)) SO_Item2.Value("QUANTITY") = Trim(oST.Cells(vRow, vCol + 2)) SO_Item2.Value("PLANT") = Trim(oST.Cells(vRow, vCol + 3)) SO_Item2.Value("SHORT_TEXT") = Trim(oST.Cells(vRow, vCol + 4)) '--------------------------------- ' Make the sales order. '--------------------------------- Application.StatusBar = "Perform SAP Call" SY_Subrc = oBAPI.Call If SY_Subrc <> True Then MsgBox "Call failed!!": Exit Sub If Left(SO_Info, 2) = "E:" Then MsgBox "Call failed: " & SO_Info: Exit Sub MsgBox SO_Info Application.StatusBar = "Perform SAP Call Successful" Cells(4, 4).Value = SO_Number
  • 22. SAP Excel Integration 22 Cells(4, 4).Interior.Color = vbGreen '----------------------------------- ' Logoff SAP and close the control. '----------------------------------- R3Connection.Logoff Set LogonControl = Nothing Set objBAPIControl = Nothing End Sub
  • 23. SAP Excel Integration 23 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). He holds a Bachelor of Management and a Diploma in IT. He has worked in Banking, Retail and Manufacturing industries, playing both in-house and external consultant role. He is situated in Singapore and is bilingual in English and Mandarin. He can be contacted at benytx@gmail.com. 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
  • 24. SAP Excel Integration 24 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 3. SAP SDN – Common export parameter issues https://blogs.sap.com/2014/04/27/activex-component-sapfunctions-with-export-parameter-string/ https://answers.sap.com/questions/529288/datatype-problem-with-sap-gui-75-pl5-unicode-activ.html https://answers.sap.com/questions/10222185/activex-component-sapfunctions-with-export- paramet.html