Application Example 

The BAPI used in this fictitious example reads the standard price of a material:

bapi_material_getprice

importing

material like mara-matnr

exporting

material_price like bapi_material_price.

The external structure bapi_material_price contains the following fields:

Fields in External BAPI Structure

Field

Description

Data Element

Domain

currency_iso

ISO currency code

isocd

isocd

currency

Currency code

waers

waers

amount

Amount

bapimatprice

bapicurr

The application programmer in the R/3 System who intends to use this BAPI uses the internal structure mat_preis in his or her own program. This structure consists of the following fields:

Fields in Internal Working Structure

Field

Description

Data Element

Domain

matnr

Material number

matnr

matnr

waers

Currency code

waers

waers

stprs

Unit price

stprs

strps

The BAPI structure bapi_material_price contains an ISO currency code and a currency amount. After calling the BAPI, the application programmer must convert these fields into the internal format used in R/3 so that the fields can be processed.

Using the function, Generate module to map fields, (see section Converting Between Internal and External Data Formats), the application developer can generate the function module, map2i_bapi_material_price_to_mat_preis, which converts the currency and amount fields. This function module has the following interface:

function map2i_bapi_material_price_to_mat_preis

importing

external structure bapi_material_price

changing

internal structure mat_preis

exceptions

error_during_iso_convertion

error_converting_currency_amount.

 

The application code could be as follows:

...

  data: matnr like mara-matnr,

price like mat_preis,

bapi_price like bapi_material_preis.

...

*BAPI call

Call function bapi_material_getprice

exporting

material = matnr

changing

material_price = bapi_preis.

* Map and convert the result to internal format

call function map2i_bapi_material_price_to_mat_preis

exporting

external = bapi_preis

changing

internal = preis.

* exceptions

* error_during_iso_convertion

* error_during_currency_amount_conversion

preis-matnr = matnr.

...