How to connect to SAP R/3 and call BAPI from MS Excel VBA



Similar documents
Creating Transaction and Screen Variants

Step by Step Guide How to Copy Flat File from Other Application Server to BI and Load through Info Package

Deleting the User Personalization done on Enterprise Portal

SAP FI - Automatic Payment Program (Configuration and Run)

SAP BW - Excel Pivot Chart and Pivot Table report (Excel)

SAP CRM 7.0 E2C Setup: CRM via Toolset

How to Integrate CRM 2007 WebClient UI with SAP NetWeaver Portal

Step by Step Guide for Language Translation Tool

Configuration of Enterprise Services using SICF and SOA Manager

Creating Web Service from Function Modules/BAPIs & Integrating with SAP Interactive Forms

Connecting to SAP BW with Microsoft Excel PivotTables and ODBO

Display Options in Transaction SE16

Restricting Search Operators in any Search View

How to Generate Stack Xml for Ehp4 and Above Upgrade

SAP CRM System 6.0/7.0. For more information, visit the Customer Relationship Management homepage

Standard SAP Configuration of SMS through HTTP with Third Party SMS Gateway

Table of Contents. Passing Data across Components through Component Controller between Two Value Nodes

Web Application Designer for Beginners

ABAP How To on SQL Trace Analysis

Exposing RFC as Web Service and Consuming Web Service in Interactive Forms in ABAP

LSMW: Upload Master Data using Batch Input Recording

Programming in Access VBA

Forgot or Lock "Administrator or J2EE_ADMIN" Password

Web Dynpro ABAP: ALV and Table in Popup Window

Web Dynpro: Multiple ALV Grids and Layouts in ALV

XSLT Mapping in SAP PI 7.1

Creating Content Using SO10 Objects and Text Symbols

Deploying Crystal Reports on Top of a SAP BI Query

RIT Installation Instructions

How To Create A Powerpoint Intelligence Report In A Pivot Table In A Powerpoints.Com

Release Document Version: User Guide: SAP BusinessObjects Analysis, edition for Microsoft Office

Multi Provider Creation Based on Sales and Planning Info Cubes

Splitting the Custom Container & Display more than one ALV

Creating and Scheduling Publications for Dynamic Recipients on SAP Business Objects Enterprise

SAP CRM Campaign Automation

Data Extraction and Retraction in BPC-BI

How to Schedule Report Execution and Mailing

How to use MS Excel to regenerate a report from the Report Editor

Introduction to Microsoft Access 2003

Creation and Configuration of Business Partners in SAP CRM

How to Define Authorizations

Embedding Crystal Reports inside ECC ALV Reports

Siemens Applied Automation Page 1 11/26/03 9:57 PM. Maxum ODBC 3.11

How to Use Swiftpage for Microsoft Excel

Word 2010: Mail Merge to with Attachments

Creating New Unit of Measure in SAP BW

Quick Viewer: SAP Report Generating Tool

Tips and Tricks SAGE ACCPAC INTELLIGENCE

Applications Development

Creating a Participants Mailing and/or Contact List:

BW Performance Monitoring

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Microsoft Office Access 2007 which I refer to as Access throughout this book

How to Create an ecatt?

Step By Step Procedure to Create Logical File Path and Logical File Name

Step by Step Guide to Extract Batch Master Data via Generic and Classification Datasource to BW

Query OLAP Cache Optimization in SAP BW

Order Split Usage in Production Orders

Reverse Transport Mechanism in SAP BI

Transfer of GL Master from Source SAP System to a Target SAP System through IDOCS

Construction Administrators Work Smart with Excel Programming and Functions. OTEC 2014 Session 78 Robert Henry

ALE Settings, for Communication between a BW System and an SAP System

Organizational Management- Organizational Structure Creation

Excel & Visual Basic for Applications (VBA)

Tutorial - Creating Pop Up Window Using New Features in WebDynpro Java CE 7.1 Ehp1

14.1. bs^ir^qfkd=obcib`qflk= Ñçê=emI=rkfuI=~åÇ=léÉåsjp=eçëíë

Step by Step Procedures to Load Master Data (Attribute and Text) from FlatFile in BI 7.0

Quick Start Guide. Microsoft Access 2013 looks different from previous versions, so we created this guide to help you minimize the learning curve.

Business Explorer (BEx)

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

Table of Content. SAP Query creation and transport Procedure in ECC6

SAP EPM Add-in for Microsoft Office

BEx Analyzer (Business Explorer Analyzer)

Abstract. Introduction. System Requirement. GUI Design. Paper AD

Excel Reports and Macros

1. Go to your programs menu and click on Microsoft Excel.

Getting Started. Tutorial RIT API

WEBFOCUS QUICK DATA FOR EXCEL

Financial Data Access with SQL, Excel & VBA

Deleting the Requests from the PSA and Change Log Tables in Business Intelligence

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Business Portal for Microsoft Dynamics GP. Key Performance Indicators Release 10.0

Understanding BEx Query Designer: Part-2 Structures, Selections and Formulas

ABAP Debugging Tips and Tricks

Microsoft Access 2010 Part 1: Introduction to Access

IENG2004 Industrial Database and Systems Design. Microsoft Access I. What is Microsoft Access? Architecture of Microsoft Access

SAP BI Generic Extraction Using a Function Module

Guidelines for Effective Data Migration

SAP NetWeaver Developer Studio 7.30 Installation Guide

Getting Started Guide

Lesson 07: MS ACCESS - Handout. Introduction to database (30 mins)

Pastel Evolution BIC. Getting Started Guide

Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

SDN Contribution Beginners guide to CRM Interaction Center (IC) Winclient setup

Unit 10: Microsoft Access Queries

Deploying JDBC drivers in PI 7.1x Systems

Quick Start Guide. Microsoft Access 2013 looks different from previous versions, so we created this guide to help you minimize the learning curve.

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

Business Intelligence Overview. BW/BI Security. BW/BI Architecture. Business Explorer (BEx) BW/BI BEx Tools Overview. What is BEx?

Transcription:

How to connect to SAP R/3 and call BAPI from MS Excel VBA Summary This paper describes how to extract data from R/3 and present the results in MS Excel. The paper demonstrates by means of a code sample how easy it is to use VBA as the underlying technology for logon and data extraction. The example allows one to define R/3 systems and to retrieve/present all user locks + types from one individual system. Author(s): Danny De Roovere Company: SAP Belgium Luxemburg Created on: 21 January 2007 Author Bio Danny De Roovere is a senior SAP Netweaver consultant employed at SAP Belgium- Luxemburg. Danny started as a SAP basis consultant (in particular EDI-ALE), and immediately added a new dimension to his career when SAP released it s NetWeaver platform. Today, his main focus is SAP s business-driven software architecture (esoa), including SAP Enterprise Portal, SAP Exchange Infrastructure and Duet. 2007 SAP AG 1

Table of Contents Excel sheet... 3 System Definition and Logon... 3 Lock Overview... 4 Macro... 6 GetUserList... 6 Related Content... 10 Disclaimer and Liability Notice... 11 2007 SAP AG 2

Excel sheet The example is based on the usage of 3 sheets: Logon Data: allows one to select the system of interest and click on the submit button to retrieve the system s user locks Lock Overview: automatically launched after having clicked the submit button: It is the result of the BAPI calls System Definition: contains all system details. Data is copied to the 1 st sheet. This sheet can be protected as it contains userids and passwords. Obviously, you can create your own look-and-feel (change columns and rows) to identify your systems, but be aware that you ll need to modify the sample VBA code in that case. This example is a quick how-to guide that demonstrates the power of VBA. The goal was not to make the winning ultimate UI. System Definition and Logon First of all, you need to declare the systems you want to retrieve data from. To do so, start MS Excel and create the following sheet: Note that I created a separate Tab for System Definition, because I don t want the CPIC user passwords to be visible in the Logon Data Tab in the spreadsheet. In fact I ve hidden the rows (4 and 5) that are referenced in the Logon Data sheet (see below). 2007 SAP AG 3

Lock Overview After having defined your systems, you can call the VBA module by clicking on the button Submit List. To put a button on your worksheet you 1 st have to check that the Forms toolbar is activated (View > Toolbars > Forms). Simply drag-and-drop the button (4 th icon from the left) on your worksheet. To assign a Macro to the button, right-click on it and click on Assign Macro : 2007 SAP AG 4

This button is associated with the macro Locked_Users.xls!GetUserList. 2007 SAP AG 5

Macro GetUserList is the macro used to retrieve the lock information from the system selected in the Logon Data screen. To edit a macro, in the menu bar click on Tools > Macro > Visual Basic Editor). GetUserList The macro executes 2 BAPI calls: one to retrieve the list of users defined for one system (BAPI_USER_GETLIST), and one to retrieve the details (BAPI_USET_GET_DETAIL) for each of the users. Remark that parameters defined as import for the BAPI, are referenced as export parameters for the calling object. Below the full code sample block: Private Sub GetUserList() 2007 SAP AG 6

Declaration Dim Destination_System As Integer Dim objbapicontrol As Object Function Control (Collective object) Dim sapconnection As Object Connection object Set objbapicontrol = CreateObject("SAP.Functions") Set sapconnection = objbapicontrol.connection Logon with initial values ActiveSheet is the sheet calling the Macro / Cells(x, y) refers to the row, column in the spreadsheet Destination_System = ActiveSheet.Cells(11, 2).Value + 2 Add 2 to retrieve the column that contains the definiton sapconnection.client = ActiveSheet.Cells(3, Destination_System).Value sapconnection.user = ActiveSheet.Cells(4, Destination_System).Value sapconnection.language = ActiveSheet.Cells(7, Destination_System).Value sapconnection.hostname = ActiveSheet.Cells(6, Destination_System).Value sapconnection.password = ActiveSheet.Cells(5, Destination_System).Value sapconnection.systemnumber = ActiveSheet.Cells(9, Destination_System).Value sapconnection.system = ActiveSheet.Cells(8, Destination_System).Value sapconnection.destination = ActiveSheet.Cells(8, Destination_System).Value If sapconnection.logon(1, True) <> True Then MsgBox "No connection to R/3!" Exit Sub End program Set objuserlist = objbapicontrol.add("bapi_user_getlist") Set objuserdetail = objbapicontrol.add("bapi_user_get_detail") Prepare output to the EXCEL worksheet Worksheets(2).Select Cells.Clear Range("A1").Font.Italic = True Range("A2:E2").Font.Bold = True ActiveSheet.Cells(2, 1) = "User Name" ActiveSheet.Cells(2, 2) = "Wrong Logon" ActiveSheet.Cells(2, 3) = "Local Lock" ActiveSheet.Cells(2, 4) = "Global Lock" ActiveSheet.Cells(2, 5) = "No UserPwd" 2007 SAP AG 7

Define the import parameters for BAPI_USER_GETLIST objuserlist.exports("max_rows") = "99999" objuserlist.exports("with_username") = "" call the 1st BAPI to retrieve the list of users: BAPI_USER_GETLIST returnfunc = objuserlist.call If returnfunc = True Then Dim objtable As Object Set objtable = objuserlist.tables("userlist") ActiveSheet.Cells(1, 1) = "User count :" & objtable.rowcount For i = 1 To objtable.rowcount Alternate row colors If i Mod 2 = 0 Then For j = 1 To 5 ActiveSheet.Cells(2 + i, j).interior.color = RGB(165, 162, 165) Next j Else For j = 1 To 5 ActiveSheet.Cells(2 + i, j).interior.color = RGB(214, 211, 206) Next j ActiveSheet.Cells(2 + i, 1) = objtable.cell(i, 1) Define the import parameters for BAPI_USER_GET_DETAIL objuserdetail.exports("username") = objtable.cell(i, 1) Cal the 2nd BAPI to retrieve the details for each user returnfunc = objuserdetail.call If returnfunc = True Then Dim islocked As Object Set islocked = objuserdetail.imports("islocked") If islocked.value("wrng_logon") = "L" Then ActiveSheet.Cells(2 + i, 2).Font.Color = RGB(255, 0, 0) ActiveSheet.Cells(2 + i, 2) = "X" If islocked.value("local_lock") = "L" Then ActiveSheet.Cells(2 + i, 3).Font.Color = RGB(255, 0, 0) ActiveSheet.Cells(2 + i, 3) = "X" 2007 SAP AG 8

If islocked.value("glob_lock") = "L" Then ActiveSheet.Cells(2 + i, 4).Font.Color = RGB(255, 0, 0) ActiveSheet.Cells(2 + i, 4) = "X" If islocked.value("no_user_pw") = "L" Then ActiveSheet.Cells(2 + i, 5).Font.Color = RGB(255, 0, 0) ActiveSheet.Cells(2 + i, 5) = "X" Else MsgBox "Error when accessing BAPI_USER_GET_DETAIL in R/3! " Exit Sub Next i Else MsgBox "Error when accessing BAPI_USER_GETLIST in R/3! " Exit Sub Close connection to R/3! objbapicontrol.connection.logoff Release the objects to free storage space Set sapconnection = Nothing Set functionctrl = Nothing MsgBox "Program terminated!", 0, "Exit" End Sub 2007 SAP AG 9

Related Content SAP and VBA: http://abap.mirrorz.com/ Thread: Sample code needed to call BAPI from VB https://www.sdn.sap.com/irj/sdn/thread?threadid=73856 Read any SAP table with Microsoft Excel https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c043d836-166c-2910-b99eae3633dec547 2007 SAP AG 10

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade. SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document. 2007 SAP AG 11