14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using BOPF to Write a DYNPRO-Style Program 8.2

CLEAR ef_data_in_memory_changed.

* Change Data in Memory

mo_service_manager->modify(

EXPORTING it_modification = it_changes_to_be_made

IMPORTING eo_change = lo_actual_changes_made

eo_message = lo_error_messages ).

ef_data_in_memory_changed =

boolc( lo_actual_changes_made->has_failed_changes( ) = abap_false ).

CHECK lo_error_messages IS BOUND.

CHECK lo_error_messages->check( ) EQ abap_true.

RAISE EXCEPTION TYPE /bobf/cx_dac

EXPORTING

mo_message = lo_error_messages.

ENDMETHOD.

Listing 8.20 Method to Change the BOPF Data in Memory

You now actually want to update the database, so code the method to do so. The

code in Listing 8.21 is almost identical to the code to update the data in memory.

The only difference is that instea d of using the service manager class MODIFY

method, this time you’re using the BOPF transaction manager class SAVE method,

which actually persists the data, so naturally the results are a bit more permanent.

The code in Listing 8.20 and Listing 8.21 is so generic that it can be used for any

type of BOPF business object at all. You could use it in your own applications totally

unchanged, though of course I beg you to understand what’s going on first.

METHOD change_data_in_database.

* Local Variables

DATA: lo_message TYPE REF TO /bobf/if_frw_message,

lf_rejected

TYPE abap_bool.

"Off we go!

mo_transaction_manager->save(

IMPORTING eo_message = lo_message

ev_rejected = lf_rejected ).

CHECK lf_rejected EQ abap_true.

RAISE EXCEPTION TYPE /bobf/cx_dac

EXPORTING

mo_message = lo_message.

339

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

Saved successfully!

Ooh no, something went wrong!