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.

8

Business Object Processing Framework (BOPF)

This exception class implements the IF_T100_MESSAGE interface (exception classes

were discussed back in Chapter 7). The BOPF framework likes traditional error

messages and other frameworks (like We b Dynpro) do not, but if our model

sends out a message catering to the lowest common denominator, then the

receiving framework can convert it to whatever it can deal with.

Define the business logic in a method within the monster model (Listing 8.13).

The model is passed the header data, examines it for consistency, and throws an

exception if it does not like what it sees.

METHOD validate_monster_header.

IF is_header_values-hat_size GT 0 AND

is_header_values-no_of_heads EQ 0.

RAISE EXCEPTION TYPE zcx_monster_exceptions

EXPORTING

textid = zcx_monster_exceptions=>head_hat_disparity.

ENDIF.

ENDMETHOD. "Validate Monster Header

Listing 8.13 Validation Method in Main Monster Model

You now have everything you need to code the EXECUTE method in the BOPF generated

validation class. In Listing 8.14, you do five things:

왘 First, you get the data for the node (header row) that you’re interested in.

왘 Then, you hand that data to the model so that it can throw an exception if

something is amiss. If all is fine, then you move straight to the ENDMETHOD statement,

and you’re done.

왘 Next, if it turns out that there’s an error (the model has thrown an exception),

then you add the key of the failed node to a table of nodes that are failures in

life (ET_FAILED_KEY), and this table is exported from the method.

왘 You then create the EXPORTING message parameter (EO_MESSAGE) by means of a

standard BOPF factory method. You can then add one or many error messages

to it.

왘 Finally, you have to create a very specific type of message object (TYPE REF TO /

bobf/cm_frw_core). You are passing into this message object the error message

that the monster model sent out by means of an exception, plus a whole bunch

of constants and the location of the error. Then, add your message to the

exporting parameter, and you’re done.

322

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

Saved successfully!

Ooh no, something went wrong!