SAP Business One SDK DI API Samples.htm

21
SAP Business One SDK DI API Samples Applies to: Business One For more information, visit the Business One homepage . Summary This article includes several samples of code for SAP® Business One Software Development Kit (SDK) for Visual Basic 6.0 and Visual Basic .NET development environments. The samples demonstrate typical work with the Data Interface API (DI API), which is a set of development tools that enable SAP Business Partners to enhance and extend SAP Business One as well as integrate external solutions. Author: SAP Business One Product Management Company: SAP Created on: 13 May 2009 SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 1

Transcript of SAP Business One SDK DI API Samples.htm

Page 1: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Applies to: Business One For more information, visit the Business One homepage.

Summary This article includes several samples of code for SAP® Business One Software Development Kit (SDK) for Visual Basic 6.0 and Visual Basic .NET development environments. The samples demonstrate typical work with the Data Interface API (DI API), which is a set of development tools that enable SAP Business Partners to enhance and extend SAP Business One as well as integrate external solutions.

Author: SAP Business One Product Management

Company: SAP

Created on: 13 May 2009

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 1

Page 2: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Table of Contents Purpose of DI API ...............................................................................................................................................3

Where Applicable ............................................................................................................................................3 Developer Audience........................................................................................................................................3

Requirement ................................................................................................................................................................3 Basic Operations ................................................................................................................................................3

To Run the Basic Operations Sample.............................................................................................................4 Connecting to the Company Database Using the Company Object...............................................................4 Selecting Information Using the Recordset Object .........................................................................................4 Selecting Information Using the Recordset and Data Browser Objects .........................................................5

Meta Data Operations.........................................................................................................................................6 To Run the Meta Data Operations Sample.....................................................................................................6 Adding a User Table .......................................................................................................................................6 Adding User Fields..........................................................................................................................................7 Adding a Private Key.......................................................................................................................................7

Using SBObob Functions ...................................................................................................................................8 To Run the SBObob Sample ..........................................................................................................................9 Get Business Partners List .............................................................................................................................9 Get Due Date ................................................................................................................................................10 Currency Bobs ..............................................................................................................................................11 Conversion Bobs...........................................................................................................................................12 Get Index Rate ..............................................................................................................................................13 Get Item Price ...............................................................................................................................................14 Get Item List..................................................................................................................................................15 Get User List .................................................................................................................................................15 Get Warehouse List ......................................................................................................................................16 Get Contact Employees ................................................................................................................................16

Formatting Bobs ...............................................................................................................................................17 Get Object Key By Single Value ...................................................................................................................18

Related Contents ..............................................................................................................................................20 Copyright...........................................................................................................................................................21

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 2

Page 3: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Introduction

The DI API projects samples demonstrate implementations and code of mainly non-business objects.

Purpose of DI API The SAP Business One Data Interface API (DI API) is a set of development tools that enable SAP Business Partners to enhance and extend SAP Business One as well as integrate external solutions.

Where Applicable

The SAP Business One DI API can be used to access the SAP Business One application on the database level, to extend its functionality, to link with third-party solutions, and to adapt the functionality of SAP Business One to fit customers' needs.

Developer Audience

The SAP Business One DI API is implemented as a Component Object Model (COM) Dynamic Link Library (DLL), and is designed primarily for Microsoft Visual C/C++® and Microsoft Visual Basic®. Familiarity with the SAP Business One application standards and the business logic concepts are required.

The following projects samples are provided:

• Basic operations - Demonstrate the most common objects: Company, Recordset, and DataBrowser.

• Meta Data Operations - Demonstrate the objects: UserTablesMD, UserFieldsMD, UserKeysMD, and UserKeysMD_Elements.

• Using SBObob Functions - Demonstrate the accessory functions of the SBObob object.

The project samples in this article are also found in the SAP Business One SDK installation folder (default: C:\Program Files\SAP Manage\SAPBusinessOneSDK65\DI API\Samples). You can open this directory through: Start->Programs->SAP Business One->DI API->Samples.

The project samples are presented both in VB6 and VB.NET and also include code descriptions integrated within the code.

Requirement

Visual Basic version 6 or later is needed to run the sample project.

Basic Operations The Basic Operations sample is a Microsoft® Visual Basic® program included with SAP Business One SDK - DI API. The sample uses Company, Recordset, and DataBrowser objects, which are commonly used in SAP Business One add-on solutions.

The Basic Operations sample demonstrates the following:

• Connecting to the company database using the Company object.

• Selecting information from the database using the Recordset object.

• Selecting information from the database using the Recordset and DataBrowser objects.

The Basic Operations sample also presents illustrations of the user interface.

Basic Operations Sample VB6 source files

Basic Operations Sample VB.NETsource files

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 3

Page 4: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

To Run the Basic Operations Sample

In Visual Basic, open the BasicOperations.vbp project file and run the project. The Basic Operations window opens.

Connecting to the Company Database Using the Company Object

To connect to the company database:

1. In the Basic Operations window, click Choose Company DB. The Choose Company DB dialog box opens.

2. From the Company DB box, select the company database.

3. In the User Name field, type a valid user name (default: manager).

4. In the Password field, type a valid password (default: manager).

1. Click Connect. A confirmation message appears.

2. Click OK and then close the Choose Company DB dialog box. The inactive buttons, Recordset Operations and Data Browser Operations, become active.

Selecting Information Using the Recordset Object

The Recordset object is used for selecting information from the database. This sample runs an SQL query (DoQuery method) for two properties (cardcode and cardname).

This sample also demonstrates the SaveXML mothod, which saves the results in an XML file in a fixed directory as follows: C:\Program Files\SAP Manage\XML\. Make sure to create this directory on your machine, or you may modify the code according to your requirements.

To select information from the database using the Recordset object:

1. In the Basic Operations window, click Recordset Operations. The Recordset Operations dialog box opens.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 4

Page 5: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

2. In the DoQuery area, click Execute. The query results, Card Code and Card Name from the Business Partners table (OCRD), appear in the results area.

3. To view more records of the query results, click the left or right arrows.

1. To save the query results in XML format, in File Name box of the XML area, enter a file name without

a path, and then click Save.

The XML file is saved in a directory specified in the sample code (you must create this directory prior to saving to the XML file).

Selecting Information Using the Recordset and Data Browser Objects

The Data Browser object enables you to navigate between records that are selected from the database (or from XML formatted data - not shown in the sample. Load from XML Sample source code).

All business objects can call the Data Browser object using the Browser property. Use a Recordset object to initialize the Data Browser object.

To select information from the database using the Recordset and Data Browser objects:

1. In the Basic Operations window, click Data Browser Operations. The Data Browser dialog box opens.

2. In Query Data Browser area, click Execute. The query results, Card Code and Card Name where their Card Type is 'C', appear in the results area.

1. To view more records of the query results, click the left or right arrows.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 5

Page 6: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Meta Data Operations The Meta Data Operations sample is a Microsoft® Visual Basic® program included with SAP Business One SDK - DI API. The sample uses UserTablesMD, UserFieldsMD, UserKeysMD, and UserKeysMD_Elements objects.

The Meta Data Operations sample demonstrates the following:

• Adding a user table to the database.

• Adding a user field to a table.

• Adding a private key to a user table.

The Meta Data Operations sample also presents illustrations of the user interface.

Meta Data Operations Sample VB6 source files

Meta Data Operations Sample VB.NET source files

To Run the Meta Data Operations Sample

1. In Visual Basic, open the MetaDataOperations.vbp project file and run the project.

After connecting to the database, the Meta Data Operations window opens.

Adding a User Table

The UserTablesMD object is used for adding a user defined tables to the database. After adding the user table, you can add fields to the user table.

To add a user table to the database:

1. In the Meta Data Operations window, click Add User Table. Add User Table dialog box opens.

2. In Table Name box, type a name for the new user table.

3. In Table Description, type a short description.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 6

Page 7: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

4. Click Add Table. A confirmation message appears. Click OK.

Adding User Fields

The UserFieldsMD object is used, in this sample, for adding fields to a table. The table type can be user table or system table. After adding the user table, you can add private keys to the user fields.

To add a field to a table:

1. In the Meta Data Operations window, click Add User Fields. The Add User Fields dialog box opens.

2. In Table Name box, type a name for an existing user/system table.

3. In Field Name, type a name for the field.

4. In Field Description, type a short description.

5. From Field Type box, select the type.

6. In Field Size, type the field size.

7. Click Add Field. A confirmation message appears. Click OK.

Adding a Private Key

The UserKeysMD and UserKeysMD_Elements objects are used, in this sample, for adding private keys (user keys) to a user defined table. You can add private keys only to user tables.

To add a private key to a user table:

1. In the Meta Data Operations window, click Add Private Key. The Add Private Key dialog box opens.

2. In Table Name box, type a name for an existing user table.

3. In Key Name, type a name for the key.

4. In Column Alias, specify the field name for which the added key relates to.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 7

Page 8: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

5. Click Add Column (Field) To Key. The function adds the field name to list in the Key Columns (Fields) box.

6. Repeat steps 4-5 for all your required fields.

7. In the Add Key as Unique box, select Yes for unique or No for not unique.

8. Click Add Key To Table. A confirmation message appears. Click OK.

Using SBObob Functions The SBObob (SAP Business One Business Object Bridge) sample is a Microsoft® Visual Basic® program included with SAP Business One SDK - DI API. The SBObob object is an accessory that helps you retrieve commonly used information directly from the database without using the business objects and their properties. This sample demonstrates all SBObob functions.

The SBObob sample also presents illustrations of the user interface.

SBObob includes the following functions:

• Get Business Partners List

• Get Due Date

• Currency Bobs

• Conversion Bobs

• Get Index Rate

• Get Item Price

• Get Item List

• Get User List

• Get Warehouse List

• Get Contact Employees

• Formatting Bobs

• Get Object Key By Single Value

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 8

Page 9: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Using SBObob Functions Sample VB6 source files

Using SBObob Functions Sample VB.NET source files

To Run the SBObob Sample

In Visual Basic, open the UsingSBObob.vbp project file and run the project. After connecting to the database, the Using SBObob window opens.

Get Business Partners List

This sample uses the GetBPList method that retrieves the Business Partners list of a specified BP Type (Business Partner Type: Customer, Supplier, or Lead). The sample applies a loop to retrieve a list of the first 10 results.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 9

Page 10: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

To get a Business Partners list:

1. In Using SBObob window, click Get Business Partners List.

The GetBPList bob dialog box opens.

2. In the Select BP Type box, select the type of the Business Partner.

3. Click Execute. The function returns the first 10 results, including Business Partner code and name.

Get Due Date

This sample uses the GetDueDate method that retrieves the due date for a specified business partner based on the business partner's code and a reference date.

To get the due date for a business partner :

1. In Using SBObob window, click Get Due Date.

The GetDueDate bob dialog box opens.

2. In Select a Business Partner box, select the code of the Business Partner.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 10

Page 11: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

3. In Reference Date box, type the reference date.

4. Click Execute. The function returns the due date.

Currency Bobs

This sample uses the following four methods:

• GetLocalCurrency - Gets the local currency defined in the company database.

• GetSystemCurrency - Gets the system currency defined in the company database.

• GetCurrencyRate - Gets the exchange rate for a specified date and currency from the company database.

• SetCurrencyRate - Sets the exchange rate for a specified date and currency in the company database.

To use Currency bobs:

1. In Using SBObob window, click Currency bobs.

Currency bobs dialog box opens (local and system currencies are retrieved automatically).

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 11

Page 12: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

To get the currency rate:

1. In the Choose Currency box, select the currency you want.

2. In the Date box, type the date you want.

3. Click Execute. The function returns the exchange rate.

To set the currency rate:

1. In the Choose Currency box, select the currency you want.

2. In the Date box, type the date you want.

3. In the Value box, type the exchange rate.

4. In the Update Current box, select True or False to specify whether or not to update the currency.

5. Click Execute. The function sets the exchange rate.

Conversion Bobs

This sample uses the following two methods:

• ConvertEnumValueToValidValue - Converts a specified enumeration value of an enumeration name to the valid value defined in the company database.

• ConvertValidValueToEnumValue - Converts a specified valid value of an enumeration name to the enumeration value defined in the company database.

To use Conversion bobs:

1. In Using SBObob window, click Conversion bobs.

A Conversion bobs dialog box opens.

To convert an enumeration value to a valid value:

1. In the Enumeration Name box, type the enumeration name you want.

2. In the Enumeration Value box, type the enumeration value to convert.

3. Click Execute. The function returns the required valid value.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 12

Page 13: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

To convert a valid value to an enumeration value:

1. In the Enumeration Name box, type the enumeration name you want.

2. In the Valid Value box, type the valid value to convert.

3. Click Execute. The function returns the required enumeration value.

Get Index Rate

This sample uses the GetIndexRate method that retrieves the index rate value for a specified date and price index code.

To get the index rate value:

1. In the Using SBObob window, click GetIndexRate bob.

The GetIndexRate bob dialog box opens.

2. In the Price Index Code box, type the price index code.

3. In the Date box, type a reference date.

4. Click Execute. The function returns the index rate value.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 13

Page 14: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Get Item Price

This sample uses the GetItemPrice method that retrieves the item price for a specified Business Partner and item, based on the amount and transaction date.

To get the item price:

1. In Using SBObob window, click Get Item Price.

The GetItemPrice bob dialog box opens.

2. In Business Partner Name box, type the name of the required business partner.

3. In the Item Name box, type the name of the required item.

4. In the Amount box, type the required value.

5. In the Transaction Date box, type the due date.

6. Click Execute. The function returns the item price.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 14

Page 15: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Get Item List

This sample uses the GetItemList method that retrieves a Recordset object that contains an item code and item name. The sample applies a loop to retrieve a list of the first 10 results.

To get an item list:

1. In the Using SBObob window, click the Get Item List.

The GetItemList bob returns the first 10 results, including item code and name.

Get User List

This sample uses the GetUserList method that retrieves a Recordset object that contains the application user name. The sample applies a loop to retrieve a list of the first 10 results.

To get a users list:

1. In the Using SBObob window, click Get User List.

The GetUserList bob returns the first 10 user names.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 15

Page 16: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Get Warehouse List

This sample uses the GetWarehouseList method that retrieves a Recordset object that contains the warehouse code and name defined in the company database.

The sample applies a loop to retrieve a list of the first 10 results.

To get a warehouse list:

1. In the Using SBObob window, click the Get Warehouse List.

The GetWarehouseList bob returns the first 10 warehouse codes and names.

Get Contact Employees

This sample uses the GetContactEmployees method that retrieves a Recordset object that contains a list of contact employees for a specified Business Partner.

The sample applies a loop to retrieve a list of the first 10 results.

To get a Contact Employees list of a Business Partner:

1. In the Using SBObob window, click the Get Contact Employees.

The GetContactEmployees bob dialog box opens.

2. In the Select Card Code box, select the card code of the Business Partner.

3. Click Execute. The function returns the first 10 employees.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 16

Page 17: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Formatting Bobs This sample uses the following two methods:

• Format_DateToString - Converts the system date to a string.

• Format_MoneyToString - Converts a specified amount of money to a string according to a specified precision.

To use Formatting bobs:

1. In the Using SBObob window, click Formatting bobs.

The Formatting bobs dialog box opens.

To convert the system date to a string:

1. In the Date To String area, Click Execute.

The function returns the system date as a string.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 17

Page 18: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

To convert money to string:

1. In the Amount box, type the value of money you want to convert.

2. From the Precision box, select the required precision type that defines the number of decimal places (up to 6).

3. Click Execute. The function returns the amount as a string in the Results box.

Get Object Key By Single Value

This sample uses the GetObjectKeyBySingleValue method that retrieves a Recordset object that contains the object key according to the following inputs:

• Object type - Business object name (BusinessPartners or Items only in this sample).

• Property name of the selected object.

• Condition - Equal, Not Equal, or Like.

• Value for the specified property.

The sample applies a loop to retrieve a list of the first 10 results.

To get the business object list:

1. In the Using SBObob window, click Get Object Key By Single Value.

The GetObjectKeyBySingleValue bob dialog box opens.

2. From Select ObjectType box, select an object type.

3. In the Property Name box, type the required property name.

4. From Condition box, select the required condition.

5. In Value box, type a value.

6. Click Execute. The function returns the first 10 results.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 18

Page 19: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 19

Page 20: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

Related Contents

• Documentation for SAP Business One SDK DI API • Documentation for SAP Business One DI Objects, Methods, Properties, Events and Enumerations.

• Documentation for SAP Business One SDK UI API

• Documentation for SAP Business One UI Objects, Methods, Properties and Events.

• For more information, visit the Business One homepage.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 20

Page 21: SAP Business One SDK DI API Samples.htm

SAP Business One SDK DI API Samples

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 21

Copyright © Copyright 2009 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.