. . .

SAP Module

Introduction

The SAP module enables app developers to access SAP Business Objects using provided BAPI functions.

It performs two major tasks:

  1. Crawling a business object and creating a new module

  2. Performing CRUD operations on that business object using the given BAPI functions

Configuration

Field Name

Field Description

Example

IP/Hostname

Address of your SAP instance

192.168.0.127

Instance Number

Number of your instance

00

System ID

Unique identifier of your system

XYZ

Client

Username used to authenticate against your SAP system

sapuser

Password

Password used to authenticate against your SAP system

secret

Language

Language identifier (e.g. en, de, ..) that SAP should use to communicate with you. Leave blank to use the default of your SAP system.

en

Client ID

Unique identifier of your log-on client used to authenticate against your SAP system

001

Backend

The SAP Module itself contains several meta models which are used internally for saving crawled data.

Note: Please refrain from touching these meta models unless you know what you're doing!

Crawl

In order to access an SAP Business Object, you first have to start a crawling process.

Hover over the added SAP module and click Use. You should be presented with a dialog which will be used to pass the required configuration data to the crawler.

Field

Description

Example

Business Object Name

This should equal the name of the Business Object you want to access. It is used to determine the name of the crawled module and meta model.

USER

Get BAPI

BAPI function that should be used to retrieve data for a single entity of the Business Object

BAPI_USER_GET_DETAIL

GetAll BAPI

BAPI function that should be used to retrieve data for all existing entities of the Business Object

BAPI_USER_GETLIST

GetAll Default Parameters

Since BAPIs happen to often require parameters to restrict their result, you can enter default parameters (using TheJSONmethod) that will be used if no parameters are passed. Thus, you don't have to pass the same parameters each time you want to retrieve the full list of entities. Leave this field empty if you do not wish to set any default parameters,.

{"parameterType": "scalar", "name": "MAXROWS", "value": "10"}

Post BAPI

BAPI function that should be used to create a new entity of the Business Object

BAPI_USER_CREATE1

Put BAPI

BAPI function that should be used to edit an existing entity of the Business Object

BAPI_USER_CHANGE

Delete BAPI

BAPI function that should be used to delete an existing entity of the Business Object

BAPI_USER_DELETE

Re-crawl

Yes - Overwrites previously crawled data if existent

No - Throws an error if previously crawled data exists. This assures that you don't accidentally overwrite data.

No

Clicking the OK button will cause the crawler to create a new module whose name will be formed by "SAP" followed by the Business Object Name (e.g. SAPUSER). When the crawling process has finished (this may take several minutes), add the created module to your backend.

Now you can access the Business Object using the meta model inside of your new module.

Use

In order to perform actions on the Business object, you still have to know the names of the import and export parameters.

We have to differentiate between 5 different SDK actions: getting one object, getting multiple objects, creating a new object, editing an existing object and deleting an object.

Getting one object

To retrieve one object you usually are required to enter an ID or foreignId which identifies the object. Please pass the parameters that are needed to execute the Get BAPI function using TheJSONmethodby inserting the JSON into the foreignId.

You have to know the export parameters of the Get BAPI function in order to call the corresponding get....() methods. There is a NamingPatternconcerningdataobjects.

Getting multiple objects

To retrieve multiple objects you are required to enter query which usually is used to filter the results. Please pass the parameters that are needed to execute the GetAll BAPI using TheJSONmethodby inserting the JSON into the query.

Please do not insert anything else into the query.

You have to know the export parameters of the GetAll BAPI function in order to call the corresponding getAll....() methods. There is a NamingPatternconcerningdataobjects.

Saving a new object

Before you call the save() method, you first have to find out the attributes that correspond with the parameters required by the Post BAPI function by following NamingPatternconcerningdataobjects and then populate them using the set...() methods.

There is no need to save the returned foreignId as it is always the same and you need to pass parameters in order to get object anyway.

Editing an existing object

Once you have got an object of a meta model you can use it to edit the underlying Business Object entity.

Please first find out which BAPI parameters are expected by the Put BAPI function, then look for the corresponding meta model attributes NamingPatternconcerningdataobjects and populate them using the set...() methods.

The meta model attributes which are to be filled in are most likely different from the meta model attributes that originally held the equivalent value when getting the object! The reason for that is that the parameters of the Put BAPI function have different names from the parameters of the Get BAPI function most of the times.

After you are finished setting your parameters, call the save() method and you are done.

Deleting one object

To delete an existing object you usually are required to enter an Id or foreignId which identifies the object.

Please pass the parameters that are needed to execute the Delete BAPI function using TheJSONmethod by inserting the JSON into the foreignId.

BAPI Parameters

In order to perform actions on an Business Object, you need to pass the required arguments to the respective BAPI functions. The way this is done depends on the action you are about to perform.

Also, if you want to retrieve data from a data object, there is a pattern to determine which attributes hold the value for which BAPI parameters.

Naming Pattern concerning data objects

Each parameter will be represented by either exactly one or by multiple meta model attribute, depending on the parameter type:

Accessing Structure Parameters

If there is a structure with the name MY_STRUCTURE which contains two fields FOO and BAR then the meta model will have two corresponding meta model attributes MyStructureFoo and MyStructureBar.

Accessing Table Parameters

If there is a table with the name MY_TABLE which consists of two columns FOO and BAR then the meta model will have two corresponding meta model attributes MyTableFoo and MyTableBar.

Each row of the table is represented by one data model.

Accessing Scalar Parameters

If a function has a scalar parameter called MAX_ROWS, it will be represented by a meta model attribute called MaxRows.

Knowing that, you can set parameters by filling in and retrieve data by reading from the respective meta model attributes.

Please mind that the meta model attributes that you retrieve data from will most likely differ from those meta model attributes that you use to store data since the respective BAPI functions will offer different parameters.

The JSON method

Some functions for retrieving data may nonetheless need import parameters to yield a result. This might be the case when retrieving either one entity of a Business object or a whole list.

Other functions that modify data will be represented by apiomat methods that use a foreignId as their only argument.

In order to pass required arguments, insert an JSON array into the apiomat query or the foreignId which could look like

JSON

Example Parameter JSONArray
[
{
"parameterType": "structure",
"name": "SELOPT_TAB",
"values": {
"COMP_CODE": "SPACE",
"TABNAME": "LFB5",
"FIELDNAME": "LFRMA",
"FIELDVALUE": "*"
}
},
{
"parameterType": "scalar",
"name": "MAX_CNT",
"value": "0"
},
{
"parameterType": "scalar",
"name": "PL_HOLD",
"value": "X"
}
]

. This JSON array should contain a JSON object for each parameter you want to set as follows:

Table parameters

If you need to pass a table parameter, the according JSON object has to have 3 attributes: parameterType, name, and rows.

Attribute

Description

Example

parameterType

Used to determine the type of the parameter and must be set to "table" to work

table

name

The name of the SAP table parameter

IDRANGE

rows

JSON array which contains a JSON object for each row you want the table to possess. These JSONObjects must have keys matching the SAP table column names.

[{"SIGN":"I","OPTION":"GT","LOW":"0"}]

The resulting example JSON object looks like this:

JSON

Example Table Parameter
{
"parameterType": "table",
"name": "IDRANGE",
"rows": [
{
"SIGN": "I",
"OPTION": "GT",
"LOW": "0"
}
]
}

Structure parameters

In case you need to pass a structure parameter, the according JSON object has to have 3 attributes: parameterType, name, and values.

Attribute

Description

Example

parameterType

Used to determine the type of the parameter and must be set to "structure" to work

structure

name

The name of the SAP structure parameter

SELOPT_TAB

values

A JSON that possesses keys matching the SAP structure field names.

{'COMP_CODE': 'SPACE', 'TABNAME': 'LFB5', 'FIELDNAME': 'LFRMA', 'FIELDVALUE': '*'}

The resulting example JSON object looks like this:

JSON

Example Structure Parameter
{
"parameterType": "structure",
"name": "SELOPT_TAB",
"values": {
"COMP_CODE": "SPACE",
"TABNAME": "LFB5",
"FIELDNAME": "LFRMA",
"FIELDVALUE": "*"
}
}

Scalar parameters

If you need to set a parameter that solely exists of a single value, the according JSON object has to have 3 attributes: parameterType, name, and value.

Attribute

Description

Example

parameterType

Used to determine the type of the parameter and must be set to "scalar" to work

scalar

name

The name of the SAP parameter

MAX_CNT

value

The value of the SAP parameter

0

The resulting example JSON object looks like this: { 'parameterType': 'scalar', 'name': 'MAX_CNT', 'value': '0' }

JSON

Example Scalar Parameter
{
"parameterType": "scalar",
"name": "MAX_CNT",
"value": "0"
}

Limitations

  • Unfortunately, most export parameter that can be used to retrieve data will have different names than import parameters which can be used to store data. Having that in mind, you can almost never simply change the value of an meta model attribute, save the data model and expect your data to be stored. In most cases you will need insert your changed data into a different meta model attribute than you retrieved the original data from.

  • Pagination works only slowly. Since SAP doesn't provide a consistent way to query only certain entities, it is impossible to only select the entities according to the pagination. Thus, the whole list is retrieved regardless of the pagination and then filtered according to the pagination.

  • Meta model attributes that represent mandatory (non-optional) BAPI parameters are not marked mandatory. This is because it is not possible to doubtlessly determine mandatory BAPI fields.