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.

Backend Tasks: Creating the Model Using SAP Gateway 13.3

Figure 13.23 Monster with One Head

Coding Error Handling

Now you need to redefine all the other methods of both entities (create, delete,

and so forth), but because all that involves is passing the call on to the equivalent

method in your monster model class, there’s no need to go through each one here

in any detail.

This example puts a small piece of code in the delete method for you to see how

to pass back exceptions to the calling application. It also sets things up so that trying

to delete a monster always fails, so that you can see an error message in your

SAPUI5 application later on. The code for this is shown in Listing 13.4.

METHOD monsterset_delete_entity.

* Local Variables

DATA: lo_message_container

TYPE REF TO /iwbep/if_message_container.

lo_message_container =

/iwbep/if_mgw_conv_srv_runtime~get_message_container( ).

lo_message_container->add_message_text_only(

EXPORTING

iv_msg_type

= /iwbep/if_message_container=>gcs_message_type-error

iv_msg_text = `This monster does not want to be deleted` ).

RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception

591

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

Saved successfully!

Ooh no, something went wrong!