14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Troubleshooting 14.4

* updated, so we have to use the sledgehammer approach and

* delete everything. That's better than the slighest risk of

* having wrong data in shared memory

zcl_material_master_shmo=>invalidate_area( ).

ENDFUNCTION.

Listing 14.8 Remote-Enabled Function for Shared Memory

Finally, add some code known as a business transaction event to the user exit; this

code fires whenever a materi al is saved. In this user exit, the added code looks

like Listing 14.9.

DATA: lt_application_servers TYPE STANDARD TABLE OF rfchosts

WITH HEADER LINE,

ld_message TYPE char80 ##needed.

"If certain data gets changed, notify shared memory of this fact

CHECK upd_mara IS NOT INITIAL.

* Obtain a list of all active servers in the system.

CALL FUNCTION 'RFC_GET_LOCAL_DESTINATIONS'

TABLES

localdest = lt_application_servers[]

EXCEPTIONS

not_available = 1

error_message = 2

OTHERS = 3.

IF sy-subrc <> 0.

"At least remove the material on this server

CALL FUNCTION 'ZMM_SHM_INVALIDATE_MATERIAL'

EXPORTING

id_material = i_mara_new-matnr.

RETURN.

ENDIF.

* Make sure material is invalidated on all application servers

* Call the function in a new task to avoid an implicit database

* COMMIT

LOOP AT lt_application_servers.

CALL FUNCTION 'ZMM_SHM_INVALIDATE_MATERIAL'

STARTING NEW TASK i_mara_new-matnr

DESTINATION lt_application_servers-rfcdest

EXPORTING

id_material

= i_mara_new-matnr

EXCEPTIONS

system_failure = 16 MESSAGE ld_message

communication_failure = 17 MESSAGE ld_message.

651

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!