How to Implement Staging BAPI

download How to Implement Staging BAPI

of 19

Transcript of How to Implement Staging BAPI

  • 7/30/2019 How to Implement Staging BAPI

    1/19

  • 7/30/2019 How to Implement Staging BAPI

    2/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    1 Business Scenario

    Your company wants to load data from various external (Non SAP) sources. You want to avoid the

    multi-step approach of transferring the legacy data first into a comma separated (CSV) or ASCII file,and subsequently uploading these files via the flat file interface into the BW system.

    The sample program is supposed to provide ideas about how a custom defined program uses thestaging BAPIs. It does not replace the existing ETL (Extraction Transformation Loading) tools whichuse also the staging BAPIs in their implementation, yet comprise of a much bigger set of features,e.g. transformation, mapping, scheduling, etc. than the sample program.

    2 The Result

    The SAP BW-ODBC Connector is a sample solution (running on Visual Basic) for the data uploadfrom different ODBC (Open Database Connectivity) data sources to the SAP BW system. It isworking as a connection between the SAP BW system and the ODBC drivers. Therefore, it ispossible to upload data from every data source supported by ODBC.

    The SAP BW-ODBC Connector is working like a server program based on the Business ObjectInfoSource Data Provider (BUS6107). It registers itself at a specified SAP BW system and waits for information and data extraction requests from the BW systen. The extracted data are transferred tothe BW system via BAPI calls according to their type (Transaction data, Master data, Texts or Hierarchies). Communication is realised by a Remote Function Call mechanism. The extraction istriggered from the BW system (Pull mechanism). It is also possible to implement a Push mechanism,whereby the extraction process is triggered from outside of the BW system.

    ODBC data sources and tables are managed using providers and layouts structures. As long as an Active-X Control is provided for a data source it is possible to launch a macro prior to the dataupload. An Active-X Control is automatically available for all Microsoft data sources, whereas it is

    needed for all Non-Microsoft data sources. All requests are processed in the background and parallelprocessing of multiple requests is also supported.

    3 The Step By Step Solution

    3.1 Prerequisites Installation of the sample program

    Before you install the SAP BW-ODBC Connector, please make sure that

    A valid license of Visual Basic, version > 6.0, SAP BW 2.0 and higher

    The most recent version of the SAP GUI (> 4.6D) and

    The most recent version of the Microsoft Data Access Controls (MDAC) is installed. Theinstallation of the program includes the MDAC. The most recent version of MDAC isavailable at http://www.microsoft.com/data

    2001 SAP A MERICA , INC. AND SAP AG

    http://www.microsoft.com/datahttp://www.microsoft.com/data
  • 7/30/2019 How to Implement Staging BAPI

    3/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    1. Copy the files Connector.CAB,setup.exe and SETUP.LST in adirectory and executesetup.exe. The Installation isperformed by a wizard, where

    the user can either use defaultsettings or specify the desiredsettings manually, e.g. for theprogram path and programgoup name.

    2. After the installation hasfinished, the executableprogram Connector.exe isavailable in the specifiedprogram group. In addition, asample layout file(sample.dsp) and data file (DSSample Data.xls) is available inthe same directory. Thesamples are based on sales anddistribution (SD) InfoSources.

    2001 SAP A MERICA , INC. AND SAP AG

  • 7/30/2019 How to Implement Staging BAPI

    4/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    3. You have to maintain also thesaprfc.ini file. This file isresponsible for theconfiguration of the RFCconnection to the SAP BW

    system.Note:

    1. The PROGID has to be thesame as specified in themaintenance of the RFCDestination in the BWsystem (Source systemcreation in Adminstratorworkbench or TCODE SM59)

    2. The host name can be

    retrieved from the entry in TCODE SM51 in your BWsystem. The service name of the SAP Gateway isassembled by sapgw andthe service number of theBW system, e.g. 41. If theBW system has multipleapplication servers, youhave to make sure that youspecify the one you aretriggering the upload from.

    Otherwise, you will get anerror after you have startedthe upload process, e.g.from the InfoPackage.

    Sample entry for BW system in saprfc.ini:

    /* Name of the RFC Destination */DEST=BAPIJ11/* R = Registration mode (mandatory) */

    TYPE=R

    /* Program ID */PROGID=ODBC_CONNECTOR/* Host name of the SAP Gateway */GWHOST=hs0041.wdf.sap-ag.de/* Service name of the SAP Gateway */GWSERV=sapgw41/* 1 = Trace on, 0 = Trace off */RFC_TRACE=1

    2001 SAP A MERICA , INC. AND SAP AG

  • 7/30/2019 How to Implement Staging BAPI

    5/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    3.2 Starting the RFC server

    The RFC server is part of the SAP BW-ODBC Connector. It waits for data requests from the BWsystem.

    1. Start the SAP BW-ODBCConnector via the menu entry inthe specified program group orby executing theConnector.exe file in therespective directory path.

    2. The data provider string and thelayout information have to bespecified. When no layout isspecified, a generic fieldstructure is assumed. There aredifferent options to customizethe RFC server. Loading of the necessary

    information from a file :For the SD example the filesample.dsp, which comeswith the installation,contains provider strings andlayout definitions. For adetailed description of thefile, please refer to AppendixA Profile file

    Defining settingsmanually : You have tospecify the Data LinkProperties for the providerstring (please see AppendixB Creation of a ProviderString for a detaileddescription) and the layoutinformation based on the

    2001 SAP A MERICA , INC. AND SAP AG

  • 7/30/2019 How to Implement Staging BAPI

    6/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    Data Source provider and asource table for the fielddefinition (please see Appendix C Creation of aLayout for a detailed

    description).

    3. In addition to the settings, youhave multiple menu optionsavailable on the initial window.

    2001 SAP A MERICA , INC. AND SAP AG

    Save profilein file

    Create new profile

    Load profile file

    RFC Server options

    Start RFC Server

    Exit program

  • 7/30/2019 How to Implement Staging BAPI

    7/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    4. The most important menuoption is the RFC Serveroptions button. There areseveral settings that you canmaintain on this popup: RFC Destination

    Host of the BW system asdefined in the saprfc.ini file.

    Package SizeSize of every data packagethat is transmitted to the BWsystem.

    Save log automatically The log file is automaticallysaved in the directory folderwhere the executable of theSAP BW-ODBC Connector resides.

    Show thread windowsShows a new window forevery new thread that isopened.

    Automatically open thisfile and start RFC ServerOpens the named profile fileand start the RFC server. If you choose this option, thenext start of the SAP BW-ODBC Connector will readthe profile file and kick off the RFC Server.

    RFC_INI fileSpecify the location of thesaprfc.ini file.

    2001 SAP A MERICA , INC. AND SAP AG

  • 7/30/2019 How to Implement Staging BAPI

    8/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    5. After all the settings have beendefined, you can start the RFCServer by pressing the Startbutton.

    The RFC Server is started andwaits for request from the BWsystem. If you want to stop theRFC Server, press the Stopbutton, which becomesavailable after the Start buttonhas been used, or close thewindow with -F4.

    The second tab strip in the SAPBW-ODBC Connector windowprovides a log about allactivities of the server, i.e.threads started, data requestshandled, error messages, etc..

    2001 SAP A MERICA , INC. AND SAP AG

    RFC Server started

    Refreshpressed inInfoPackage

    Error inrequest

    Send datapackages

  • 7/30/2019 How to Implement Staging BAPI

    9/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    3.3 Scheduling the data upload from BW

    After the RFC Server has been configured and started, you can trigger the data upload via anInfoPackage. This happens in a similar fashion than the definition of an InfoPackage for a R/3system or a PC flat file . There are some settings particular to ODBC interface, like the name of theprovider, table name and layout name, which have to be specified in the InfoPackage.

    1. When the source system is notdefined yet, this has to be donefirst. Select Ext Sytem, dataand meta data transfer -staging BAPIs.

    2. Provide a desired name anddescription for the sourcesystem.

    3. Press the Registration buttonand specify the name of theprogram. This name has to beidentical with the Program IDyou have specified in thesaprfc.ini file entry for theactual BW system.

    Save your entry and return tothe Administrator workbench.

    2001 SAP A MERICA , INC. AND SAP AG

  • 7/30/2019 How to Implement Staging BAPI

    10/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    4. In order to upload the data, youhave to assign the data sourceto an InfoSource. In our samplescenario, we want to uploadcompany code texts.

    5. Choose previously definedsource system (in our exampleBAPI_SAMPL), press enter andaccept the saving of changesfor the assignments that youwant to use (attributes, texts,hierarchies or transaction data).

    6.Perform changes to the transferrules if needed and activatethem.

    2001 SAP A MERICA , INC. AND SAP AG

    Activate

  • 7/30/2019 How to Implement Staging BAPI

    11/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    7. As the last step, you have todefine an InfoPackage for thescheduling of the upload.

    NOTE:

    The RFC Server has to bestarted in order be able toprocess incoming requests,i.e. before the upload can bestarted

    8. Most of the settings are thesame as for the other sourcesystem types. In addition, theBAPI source system specific tabstrip 3 rd party selections has tobe maintained.

    The following parameters areavailable (when the parametersare not visible press theRefresh button first): Provider Name (required)

    Name of the provider (casesensitive !!).

    Table name (required) The name of the table thatcontains the data. This namehas to be in quotation marks( ). In order to enter thecorrect value, copy and pastethe table name from thedialog when adding a newlayout (after pressing Gettables and choosing therespective table; see Appendix C Creation of aLayout ).

    Layout Name (optional)Name of the layout to beused. If none is specified theprogram assuming a genericlayout.

    Macro name (optional)

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    12/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    Not used in the scenario of this paper.

    .

    4 FAQs

    Program supportThe program is designed as a sample solution. Therefore, SAP is not offering any support inenhancing or correcting this solution in case of occurring problems. The productive usage of theprogram is at the responsibility of the customer.

    Program limitations It is possible to have only one profile file at a time. Hence, it is not possible to define a

    separate profile file for each logical ODBC data source and then use all of them together.

    There is a significant problem with memory consumption. For the package size of 2000records, the program needs more than 400MB of memory. Therefore the packet size is limitedto small values.

    The maximum number of layouts and providers is limited to 20. This can be easily extended inthe source code.

    Although the program runs with multiple threads, a single request is not processed in parallel,e.g. sending several packages of one request at the same time is not supported.

    Additional feature to integrate data from web pagesIn the scenario described in this paper, an EXCEL web template has been integrated. This allows theretrieval of data from an Internet website and the needed conversion of this data into a formatsuitable for the upload into the BW. Since this feature is not based on the BAPI interface, detailedinformation about it is not provided in this paper. For a description of this feature and how to use it,please refer to the technical documentation enclosed in the ZIP file of the sample program.

    Detailed documentation of the implemented source codePlease refer to the technical documentation enclosed in the ZIP file of the sample program. You candisplay the various source code files for the basic modules with the Notepad. The files reside after the installation in the Source subfolder.

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    13/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    Information about the staging BAPI interfaceIf you want to implement your own requirement or extend the sample program, you might have touse other BAPIs of the staging BAPI interface to the BW system. For further information, please usethe TCODE BAPI in the BW system and lookup the information (documentation) for the respectivebusiness object (or look for the documentation of the Staging BAPIs on the public BusinessInformation Warehouse web page http://wwwint01.wdf.sap-ag.de/solutions/compsoft/scenarios/bi/bwsta.htm ).

    Usage of ODBC datasources other than EXCELNo changes have to be performed in the source code of the program. Only a new provider string hasto be assembled for the desired datasource.

    Implementation in programming languages other than Visal BasicVisual Basic has only been selected for the implementation of the sample program due to thewidespread usage of Visual Basic. This should provide a comprehensible template for the realizationof own requirements. Other programming languages can be used, too.

    5 Appendix A Profile file

    The structure of the profile file is similar to the windows ini files. It is a text file divided into sections.In each section, specified variables are assigned a value.

    Comments

    Each line starting with # character is treated as a comment and is ignored.Labels

    Lines containing a string in brackets (e.g. [Provider]) begin a new section, and are supposed to befollowed by variable assignments. Only two sections are defined [Provider] and [Layout] . There canbe none, one or more sections of the same type in one profile file.

    Variable assignment

    Each section contains variable assignments. If the variable is a structure, than the attributes can beseparated with coma.

    Provider string

    The provider string contains information about the OLE DB Provider, the location of the data(directory path to the file containing the data), and some intialization properties depending on theselected provider.

    Layout

    The layout consists of a name and a corresponding field structure. The field within the structure isdefined by its position (field index) within in the structure, its name, and its length.

    2001 SAP A MERICA , INC. AND SAP AG 1

    http://wwwint01.wdf.sap-ag.de/solutions/compsoft/scenarios/bi/bwsta.htmhttp://wwwint01.wdf.sap-ag.de/solutions/compsoft/scenarios/bi/bwsta.htmhttp://wwwint01.wdf.sap-ag.de/solutions/compsoft/scenarios/bi/bwsta.htmhttp://wwwint01.wdf.sap-ag.de/solutions/compsoft/scenarios/bi/bwsta.htm
  • 7/30/2019 How to Implement Staging BAPI

    14/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    #

    # SAP BW-ODBC Connector - data source profile

    # ProviderStrings and Layouts

    #

    # Editing is not recommended. No data consistency check.

    [ProviderString]

    Name=BAPI

    Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="DSN=ExcelFiles;DBQ=.\BAPI SD SampleData.xls;DefaultDir=.\;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"

    [ProviderString]

    Name=dane.xls

    Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="DSN=Excel

    Files;DBQ=.\dane.xls;DefaultDir=.\;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"

    [Layout]Name=TransDataField=0,0D_CO_CODE,4Field=1,0D_DIS_CHAN,2Field=2,0D_DIV,2Field=3,0D_MATERIAL,18Field=4,0D_PLANT,4Field=5,0D_SALE_GRP,3Field=6,0D_SALE_ORG,4

    Field=7,0D_SOLD_TO,10Field=8,0D_SHIPTO,10Field=9,0D_PAYER,10Field=10,0D_VERSION,3Field=11,0D_VTYPE,3Field=12,0D_DOCCLASS,1Field=13,0D_DEBCRED,1Field=14,0CALMONTH,7Field=15,0FISCVARNT,2Field=16,0D_OORQTYBM,17Field=19,0BASE_UOM,3Field=17,0D_OORVALSC,17Field=22,0STAT_CURR,5Field=18,0D_QUANT_B,17Field=20,0D_NETVAL_S,17Field=21,0D_COSTVALS,17Field=23,0D_DOCUMENT,17Field=24,0D_DOCITEMS,17Field=25,0D_GR_WT_KG,17Field=26,0D_NT_WT_KG,17

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    15/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    Field=27,0D_VOLUMCDM,17Field=28,0CALYEAR,4Field=29,0D_COUNTRY,3Field=30,0D_REGION,3

    [Layout]Name=CompCodeTextField=0,Company Code,4Field=1,Description,20

    6 Appendix B Creation of a Provider String

    The definition of the provider string can also be performed manually.

    1. Press the Add push button tostart the definition of a newdatasource provider, whichconsists of a provider name andthe provider string. When aprovider name is alreadyspecified, the provider stringcan be built separately.

    2. Specify a name for the DataProvider.

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    16/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    3. Select an OLE DB provider. Thisstep is also the first popup thatyou get after you press BuildProvider String on the initialpopup. In our example screen

    shots we assume an EXCEL fileas data source, and thereforeselect Microsoft OLE DBProviders for ODBC Drivers.

    4. Press Next to get to the nexttab strip of the popup, whereyou have to define theconnection (path to the data).Switch on the Use connectionstring and press the Buildbutton.

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    17/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    5. Select a Data Source Name onthe Machine Data Source tabstrip, and press OK.

    6. Locate and select a data source.In our example this is an EXCELfile.

    7. After the completion of thisprocess you return to theconnection tab strip, where afurther pressing of the OK

    button completes the definitionof the provider string (additionalinitialization settings can bespecified in the All tab stripbefore pressing OK). Theprovider string is thendisplayed.

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    18/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    7 Appendix C Creation of a Layout

    The definition of the layout can also be performed manually. If done so, the layout should match(especially the sequence of the fields) the definition of the transfer structure of the respectiveInfoSource.

    1. Start the definition of a newlayout by pressing the Addlayout button.

    2. Specify a name for the layout. If you have not retrieved the tabledefinition for an earlier createdlayout, press Get tables todetermine the availablestructures for the specifieddatasource provider. In case of EXCEL, the first row of everysheet of the workbook is read todetermine the structure. Selectone of the source tables fromthe pull-down list.

    2001 SAP A MERICA , INC. AND SAP AG 1

  • 7/30/2019 How to Implement Staging BAPI

    19/19

    HOW TO U SE THE S TAGING BAPI S IN VISUAL BASIC

    3. After the initial definition of thelayout, you have severaloptions to change the layoutdefinition. Up and Down buttons:

    With these buttons you canchange the order of thefields within the structure.

    Currently selected field: For the currently selectedfield, you can change thefield name and the field size.

    The modification of the fieldsize is particular importantwhen a generic layout isused. In this case, all fieldsare considered as of typeString with a default lengthof 255 for a string. To makethe changes effective, youhave to press the Applybutton.

    2001 SAP A MERICA , INC. AND SAP AG 1