Pgina 1 de 16
Hi, Guest
Log On Join Us
Products
About SCN
Downloads
Industries
Partnership
Developer Center
Lines of Business
University Alliances
Innovation
Activity
Communications
Actions
Browse
Version 2
created by Nimesh Master on Aug 22, 2012 4:07 PM, last modified by Giriesh Chakaravarthy Mamurugan on Oct 16, 2014 12:12 PM
Share
11
Tweet
6 Like
30
Using the connection SAP with MS Office, users spreads data from SAP application to right
within Microsoft Office desktop applications, including Excel, Outlook, Word and Power point.
With the SAP-MS Office connectivity, end-users can interact with SAP transactions directly
within their Excel spreadsheet, their Outlook e-mail screen, and their Word documents and on
their Power point presentations.
Here we have a simple application to connect SAP with MS-office tools Excel.
But before thatWhy? How? And Use!
Why Data from SAP to MS Office Applications
In spite of large moneys in SAP, most business users continue to be unsatisfied with it
because data from SAP is not easily accessible in their favorite desktop productivity tools -Microsoft Excel, Microsoft Outlook and Microsoft Word. Since Microsoft Office Applications are
not connected to SAP, users are forced to
Use error-prone cut-copy-paste to populate their Excel spreadsheets.
Switch screens from Outlook to gather data and take decisions as they respond to
e-mails.
Manually update data from Excel Spreadsheets to enterprise applications.
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 2 de 16
Who Benefits
Production and Logistics Managers who want to create Excel reports from latest SAP data.
Managers who want to track projects and status automatically as they receive status
e-mails.
Analysts who want to combine data from SAP and other enterprise data stores for
budgeting purposes.
Example:
Here is the main part comes up. We shall take simple scenario for SAP with MS Excel
connectivity. So lets begin!!
Just before start, I would like to give little overview on what we are actually going to do. So,
here are the scenarios!!
Excel File Scenarios
Create a MS excel file for user input.
Create user interface in excel sheet to input data for the customer master and output
cells.
Apply VB code to make connection with SAP.
Read the input data for customer master from the excel file sheet.
Fetch data from SAP using connection code from SAP.
Display output within excel sheet itself.
SAP Scenarios
Create a function module in ABAP that is Remote Enabled.
Create IMPORT, EXPORT and TABLES parameters as per requirement from MS excel.
Write logic to display customer master details based on input from Excel file.
Activate the function module.
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 3 de 16
Wellfilling cell values are simple here but how to add buttons (Get Address and Reset
Output) here? This was also new in my case since new version of MS office.
Just follow following steps for this:
Click MS office button and select Excel Options button from the menu.
Click on Insert and then select Button from the form control. Later on you can double click
on the button and set its properties (Caption, Color, etc.)
Congratulations! Our input screen is finished here. Lets design our output screen now.
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 4 de 16
I have created my output screen just after the input screen. You can create anywhere in the
excel file. Here terms anywhere descries to other worksheet also.
The output screen is simple as you see. Nothing much to do here. I just simple colored the
cells for better look.
Great! Looks like we finished user interface here. (Did we miss something...Naah for now!)
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 5 de 16
sheet.
Note: We have created a Z structure (ZNM_CUST_LIST) for the output list. Here are
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 6 de 16
Here, we are selecting all the customer details from the KNA1 (customer master) table from
the input table (ET_KUNNR) from excel file and return to the table (ET_CUST_LIST).
Now we have all the records in the table ET_CUST_LIST.
So, again congratulation friends! You have completed most of the things. The remaining step
now is to display the list in the excel file.
Lets now connect the SAP and MS Excel.
Go to the Developer tab and click on Visual Basic icon.
The VB editor will be opened and we are going to write the code for connection of excel and
SAP with sending and receiving data.
Here is the variable declaration list. These are the global variables. Lets understand each of
them.
Variable
objBAPIControl
Description
For creating object to access SAP functions.
objgetaddress
http://scn.sap.com/docs/DOC-31015
15/07/2015
vLastRow
vRows
vcount_add
Index_add
objaddress
objkunnr
Variable
LogonControl
Description
Logon control is to make login in SAP.
R3Connection
retcd
Return Code
SilentLogon
Pgina 7 de 16
Perfect!! We have made the connection with SAP R/3. Now we are able to send and receive
the data from MS Excel to SAP R/3 and vice versa.
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 8 de 16
But how to send my customer details and receive? Hmmm..we need to use internal tables
those are created in SAP function module. (Do you remember?....NO?... checkout Tables
parameters in function ZNM_GET_CUSTOMER_DETAILS). So, lets do this.
We are reading here each cell from excel worksheet for input.
Here we have called the FM and passed the input details to process.
Result:
vcount_add returns total number of records from the SAP. And we have already set the loop to
display records in the cells.
Here, R3Connection.Logoff is to sign off from your SAP account.
Here is the output screen:
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 9 de 16
Wow!! We have output result. Good job!! But what is the use of another button Reset Output
here? Yesgood question.
The Reset Output button will clear all the data and messages from the screen. Look at below
code:
-----------------------------------------------------------------------------------------------------------------------
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 10 de 16
End If
returnfunc = objgetaddress.call
If returnfunc = True Then
vcount_add = objaddress.Rows.Count
For index_add = 1 To vcount_add
vRows = 11 + index_add
sht.Cells(vRows, 2) = objaddress.Value(index_add, "KUNNR")
sht.Cells(vRows, 3) = objaddress.Value(index_add, "LAND1")
sht.Cells(vRows, 4) = objaddress.Value(index_add, "NAME1")
sht.Cells(vRows, 5) = objaddress.Value(index_add, "ORT01")
sht.Cells(vRows, 6) = objaddress.Value(index_add, "PSTLZ")
sht.Cells(vRows, 7) = objaddress.Value(index_add, "REGIO")
sht.Cells(vRows, 8) = objaddress.Value(index_add, "KTOKD")
sht.Cells(vRows, 9) = objaddress.Value(index_add, "TELF1")
sht.Cells(vRows, 10) = objaddress.Value(index_add, "TELFX")
Next index_add
End If
' If address not exist then Show error
If vcount_add = "" Then
sht.Cells(10, 11) = "Invalid Input"
Else
'
'
49334 Views
Share
11
Tweet
6 Like
30
35 Comments
Sujeet Kadam Aug 23, 2012 7:44 AM
This is great! Is it possible to integrate date from more than one SAP function module to a single excel
file?
Like (0)
Eddie Woo May 26, 2013 5:54 PM (in response to Dmitry Shipulin)
Hi,
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 11 de 16
Phillip Morgan Dec 15, 2014 10:37 AM (in response to Hari Janpareddy)
Hari,
You could use the generic RFC function module RFC_READ_TABLE.
You give it the table and the selections and it will return the data. Try it in SE37.
Maybe there are some examples if you search.
Like (0)
Giriesh Chakaravarthy Mamurugan Aug 26, 2013 4:01 PM (in response to Praveen Tyagi)
Hi Praveen,
Please Declare the below in VB Sheet1
Option Explicit
Private LogonControl As SAPLogonCtrl.SAPLogonControl
Private R3Connection As SAPLogonCtrl.Connection
Private TableFactory As SAPTableFactory
Public Functions As SAPFunctionsOCX.SAPFunctions
Dim objBAPIControl, objgetaddressn As Object
Dim vLastRow, vRows As Integer
Dim vcount_add, index_add As Integer
Private objaddress, objkunnr As SAPTableFactoryCtrl.Table
It will not give any error.
Like (0)
Jeffrey Quesada Sep 24, 2013 11:58 PM (in response to Giriesh Chakaravarthy Mamurugan)
Hello.
I am still having the error "User defined Type not defined", do I need to select any
reference?
Thank you in advance,
Jeffrey
Like (0)
Hi Rohny,
When I am trying to login the SAP system from Excel it is showing me an error
When I am connecting using remote desktop of my client
SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed and please find the details:
Error Group
RFC_ERROR_COMMUNICATION
Message
SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed
Connect_PM GWHOST=212.78.237.247, GWSERV=sapgw00, SYSNR=00
LOCATION CPIC (TCP/IP) on local host
ERROR
partner '212.78.237.247:3300' not reached
TIME
Mon Aug 26 15:03:37 2013
RELEASE 720
COMPONENT NI (network interface)
VERSION 40
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 12 de 16
RC
-10
MODULE
nixxi.cpp
LINE
3286
DETAIL
NiPConnect2: 212.78.237.247:3300
SYSTEM CALL connect
ERRNO
10060
ERRNO TEXT WSAETIMEDOUT: Connection timed out
COUNTER 1
*******************************************************************************************
When I am trying it from my system:
CMALLC: rc=27 > Connect from SAP Gateway to RFC server failed.
Please find the Details below:
Error Group
RFC_ERROR_COMMUNICATION
Message
CMALLC : rc=27 > Connect from SAP gateway to RFC server failed
Connect_PM GWHOST=212.78.237.247, GWSERV=sapgw00, SYSNR=00
LOCATION SAP-Gateway on host HEXLSVR001.dixons.co.uk / sapgw00
ERROR
timeout during allocate
TIME
Mon Aug 26 15:14:24 2013
RELEASE 720
COMPONENT SAP-Gateway
VERSION 2
RC
242
MODULE
gwr3cpic.c
LINE
2025
DETAIL
no connect of TP sapdp00 from host 212.78.237.247 after 20 sec
COUNTER 2
*******************************************************************
Can you please tell me anything further has to be done other than the mentioned in the blog.
Like (0)
Hello,
Thank you for sharing knowledge
all the best erwin
Like (0)
Good one.
Like (0)
Hello.
I am having the following error "User defined Type not defined", when the system tried to compile line:
Public objaddress, objkunnr As SAPTableFactoryCtrl.Table
Do I need to select any reference?
Thank you in advance,
Jeffrey
Like (0)
Hi Giriesh,
I am getting "User defined Type not defined" error on Public Functions As
SAPFunctionsOCX.SAPFunctions.
After implementing the changes in your comment.
Can you please help me with the issue.
Thanks in advance,
Sidd
Like (0)
Giriesh Chakaravarthy Mamurugan Nov 26, 2013 1:24 PM (in response to Siddharth Patel)
Hi Siddharth,
Paste this code in the sheet1 of your VB Script.
Hope you are doing it in the Module and because of that you are getting the error.
The code below to enter:
Option Explicit
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 13 de 16
Siddharth Patel Nov 27, 2013 8:03 AM (in response to Giriesh Chakaravarthy Mamurugan)
Hi ,
Thanks for your reply but i am still getting the same error.
Error with
Public Functions As SAPFunctionsOCX.SAPFunctions as not defined.
Regards,
Sidd
Like (0)
Siddharth Patel Nov 27, 2013 2:12 PM (in response to Giriesh Chakaravarthy Mamurugan)
Hi Giriesh,
I have tried a lot but nothing works same error everytime.
I wanted to know is there any tools->references needs to be enabled for this.
If not then, please let me know the solution.
Regards,
Sidd
Like (0)
Hi Siddharth,
You dont want to do anything explicit other than mention in this blog. I am
not in the exact position to say what went wrong. Please mention your mail
Id so that I can send the excel which I have done for your reference. (But it
is not completed till the end, as I am facing connectivity issue).
With Regards,
Giriesh M
Like (0)
Hi Giriesh,
Thanks for sharing such a wonderful tutorial and I am trying to
implement the same this, but i am getting error " User defined
type not defined".
If possible can you send me the excel. That will be really help full.
my id id: REMOVED BY SCN MODERATOR
Regards
Neeraj Tiwari
Like (0)
Hi Neeraj,
You can send me a mail. Find my mail Id in my profile.
With Regards,
Giriesh M
Like (0)
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 14 de 16
Indeed...Nicely explained. a step-by-step guide. thank you very much. But now, can you give us stepby-step guide for transferring data from Excel to SAP??? Means....I have data in Excel sheet and I
want to transfer that data in SAP. And one more thing.....Can we connect to sap without code(I mean
not directly through excel.....pls read above comments...lots of people facing "User defined Type not
defined" error on Public Functions As SAPFunctionsOCX.SAPFunctions problem......thats why I am
asking).
Thanks in advance........waiting for your reply with Excel to SAP data transfer tutorial......
Like (0)
Good explanation to read the data, I have also done a similar way but Data Save mode.
Here's the link.
Insert Data Via BAPI Using Excel-VBs
Thanks.
Avirat
Like (0)
Very Informative..
Like (0)
heloo,
nice explanation. everythig seems soothing.
but hardly know anything of vb. just want to know where to write vb code.
do we need to install some another software .
please guide me where to code this vb code.
i mean platform...just like we write abap code in abap editor.
here abap is the language and abap editor is the platform.
Moreover, i dont see DEVELOPER option in our excel. how to enable that.
Like (0)
Giriesh Chakaravarthy Mamurugan Jun 18, 2014 6:39 AM (in response to abhishek bansal)
Hi Abhishek,
You have to make some configuration in Excel for getting the Developer tab. Check in Google
as it varies for MS Office versions. The code used is VB Script.
Cheers!!!
Giriesh M
Like (0)
abhishek bansal Jun 18, 2014 7:01 AM (in response to Giriesh Chakaravarthy Mamurugan)
Hi Giriesh,
I am getting "User defined Type not defined" error on 'Public objaddress, objkunnr As
SAPTableFactoryCtrl.Table ' and can't declared .
Can you please help me with this issue.
Thanks ,
Eli Pai
Like (0)
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 15 de 16
Giriesh Chakaravarthy Mamurugan Oct 16, 2014 12:17 PM (in response to Eli Pai)
Hi Eli,
I have modified some of the codes done by
Nimesh Master. You can have a look and
make changes to the Macro excel. If still you have problem send a mail to me (avail from
business card). I can send you the excel for reference, but before that try from the document
and explore to know much about it.
I don't find any option to attach the file here else I would upload it.
With Regards,
Giriesh M
Like (0)
IBABAP IBABAP Apr 6, 2015 9:07 AM (in response to Giriesh Chakaravarthy Mamurugan)
Dear Giriesh,
I am also getting the same error, "User defined Type not defined". I have send you
mail on your email id, please send me the excel in reply as I am unable to find the
resolution for this error. Or else please specify here what code you have modified so
that we all can be benefited from your learning as well.
Thanks in advance for your help and support.
Regards,
Prameet Gopal Verma
Like (0)
Be careful with building VBA macros using SAP Automation based on remote functions.
This functionality is going out of maintenance and may stop to work in near future. Read the thread
http://scn.sap.com/thread/3445197. I can reccomend the CCo library instead since it uses SAP
NetWeaver RFC API. I used it writing EasyInput tool and it works perfectly.
Like (0)
Anybody having the error " User defined Type not defined" . The solution is to add Three references
to your VBA Project.
- WDTLOG.OCX (non unicode)
- WDTFUNC.OCX (non unicode)
- WDTTAOCX.OCX (non unicode)
or
- WDTLOGU.OCX (unicode)
- WDTFUNCU.OCX (unicode)
- WDTTAOCXU.OCX (unicode)
http://scn.sap.com/docs/DOC-31015
15/07/2015
Pgina 16 de 16
Like (0)
Site Index
Privacy
Contact Us
Terms of Use
http://scn.sap.com/docs/DOC-31015
Copyright
Follow SCN
15/07/2015