Entering content frame

Example Programs with Asynchronous BAPI Calls Locate the document in its SAP Library structure

The following example programs show how receivers are determined with asynchronous BAPI calls.

Note

The function ALE_BAPI_GET_FILTEROBJECTS must be used if the application's filter object types are not known at runtime.

Caution

A COMMIT WORK must be executed in the program after the outbound function module of the generated BAPI-ALE interface has been called. The database commit at the end of the transaction is not sufficient. If a COMMIT WORK is not executed, the IDoc is created with the correct status but it will not be dispatched.

The IDocs created are locked until the called transaction has been completed. If you want to unlock them earlier, you can call the function module:

DEQUEUE_ALL releases all locked objects

EDI_DOCUMENT_DEQUEUE_LATER releases individual IDocs whose numbers have been transferred to the function module as parameter values.

Filter Object Types Are Not Known at Runtime

* data declaration

data:
filterobj_values like bdi_fobj occurs 0,
filterobj_types like bdi_fobjtype occurs 0,
bapi_logsys like bdi_logsys occurs 0.

constants:
c_objtype_plant type c value ‘WERKS’,
c_objtype_langu type c value ‘SPRAS’.

* get filterobjects from ALE distribution model

call function ‘ALE_BAPI_GET_FILTEROBJECTS’
exporting
object = ‘BUS1001’
method = ‘REPLICATEDATA’
tables
filterobjects = filterobj_types
exceptions
error_in_ale_customizing = 1.

* fill filterobject values into table

loop at filterobj_types.
case filterobj_values-objtype.
when c_objtype_plant.
filterobj_values-objtype = c_objtype_plant.
filterobj_values-objvalue = ‘0002’.
when c_objtype_langu.
filterobj_values-objtype = c_objtype_langu.
filterobj_values-objvalue = ‘D’.
when others.
endcase.
append filterobj_values.
endloop.

* get receiver from ALE distribution model

call function ‘ALE_ASYNC_BAPI_GET_RECEIVER’
exporting
object = ‘BUS1001’
method = ‘REPLICATEDATA’
tables
receivers = bapi_logsys
filterobject_values = filterobj_values
exceptions
error_in_filterobjects = 1
error_in_ale_customizing = 2.

* call generated ALE interface function module

if sy-subrc <> 0.
if not bapi_logsys[] is initial.
call function ‘ALE_MATERIAL_REPLICATE_DATA’
tables
receivers = bapi_logsys
...

commit work.
endif.
endif.

Receiver determination with business add-in

Form routine implemented by SAP

*-------------------------------------------------------------------

* FORM ALE_BFA_TEST_RECEIVERS

*-------------------------------------------------------------------

FORM ale_bfa_test_receivers TABLES receivers STRUCTURE bdi_logsys

USING object TYPE swo_objtyp

method TYPE swo_method

key1 LIKE tbbfatest-key1

key2 LIKE tbbfatest-key2

return_info LIKE syst.

* key1 and key2 are parameters regarding receiver determination

* 2 filter object types were defined by SAP:

* TEST_KEY1

* TEST_KEY2

 

* variables definition

DATA: w_filter_object_type TYPE bdi_flttyp,

t_filter_object_type TYPE bdi_flttyp_tab,

w_filter_object_value TYPE bdi_fobj,

t_filter_object_value TYPE bdi_fobj_tab,

receivers_output LIKE bdi_logsys OCCURS 0 WITH HEADER LINE.

CLASS: cl_ex_customer_filter DEFINITION LOAD.

DATA: my_exit TYPE REF TO if_ex_customer_filter.

*> Step 1) get filter object types for a BAPI

CALL FUNCTION 'ALE_BAPI_GET_FILTEROBJECTS'

EXPORTING

object = object

method = method

TABLES

receiver_input = receivers

filterobjects = t_filter_object_type

EXCEPTIONS

error_in_ale_customizing = 1

OTHERS = 2.

IF sy-subrc <> 0.

return_info = syst.

EXIT.

ENDIF.

 

*> Step 2) evaluate SAP filter objects

LOOP AT t_filter_object_type INTO w_filter_object_type.

CASE w_filter_object_type-objtype.

* evaluate delivered filter objects

WHEN 'TEST_KEY1'.

MOVE-CORRESPONDING w_filter_object_type

TO w_filter_object_value.

w_filter_object_value-objvalue = key1.

APPEND w_filter_object_value TO t_filter_object_value.

WHEN 'TEST_KEY2'.

MOVE-CORRESPONDING w_filter_object_type

TO w_filter_object_value.

w_filter_object_value-objvalue = key2.

APPEND w_filter_object_value TO t_filter_object_value.

* customers defined filter objects

WHEN OTHERS.

ENDCASE.

ENDLOOP.

*> Step 3) evaluate customer-defined filter objects

CREATE OBJECT my_exit TYPE cl_ex_customer_filter.

CALL METHOD my_exit->filtering

EXPORTING

object = object

method = method

key1 = key1

key2 = key2

filterobjtype = t_filter_object_type

CHANGING

filterobjvalue = t_filter_object_value.

*> Step 4) determine receivers for all filter objects

CALL FUNCTION 'ALE_ASYNC_BAPI_GET_RECEIVER'

EXPORTING

object = object

method = method

TABLES

receiver_input = receivers

receivers = receivers_output

filterobject_values = t_filter_object_value

EXCEPTIONS

error_in_filterobjects = 1

error_in_ale_customizing = 2

OTHERS = 3.

IF sy-subrc <> 0.

return_info = syst.

EXIT.

ENDIF.

receivers[] = receivers_output[].

ENDFORM.

 

Methods Implemented by Customers

* The following method was implemented by a customer with
* Business Add-In

* 1 filter object type was defined by customer:

* ZTEST_KEYS

 

METHOD if_ex_customer_filter~filtering.

* ...

DATA: w_filterobjtype TYPE bdi_flttyp,

w_filterobjvalue TYPE bdi_fobj.

LOOP AT filterobjtype INTO w_filterobjtype.

CASE w_filterobjtype-objtype.

WHEN 'ZTEST_KEYS'.

MOVE-CORRESPONDING w_filterobjtype TO w_filterobjvalue.

w_filterobjvalue-objvalue+0(3) = key1.

w_filterobjvalue-objvalue+3(3) = key2.

APPEND w_filterobjvalue TO filterobjvalue.

WHEN OTHERS.

ENDCASE.

ENDLOOP.

ENDMETHOD.

 

#

 

Filter Object Types are Known at Runtime

* data declaration

data: filterobj_values like bdi_fobj occurs 0,
filterobj_types like bdi_fobjtype occurs 0,
bapi_logsys like bdi_logsys occurs 0.

filterobj_values-objtype = ‘KKBER’.
filterobj_values-objvalue = ‘0002’.
append filterobj_values.

* get receiver from ALE distribution model

call function ‘ALE_ASYNC_BAPI_GET_RECEIVER’
exporting
object = ‘BUS1010’
method = ‘REPLICATESTATUS’
tables
receivers = bapi_logsys
filterobject_values = filterobj_values
exceptions
error_in_filterobjects = 1
error_in_ale_customizing = 2.

* call generated ALE interface function module

if sy-subrc <> 0.
if not bapi_logsys[] is initial.
call function ‘ALE_DEBITOR_CREDITACC_REPLICATESTATUS’
tables
receivers = bapi_logsys
...

commit work.
endif.
endif.

 

 

 

Leaving content frame