Rule Definition
If possible, avoid raising an exception in a supply function or in a method called by a supply function. Since supply functions are often called during rendering, these exceptions cannot be processed efficiently. This can impact the error handling and the performance of the component.
Remediation
Since runtime controls when the supply function is called (and not the code created by the application developer), it is especially important that no errors occur when the data is retrieved. For this reason, use the supply function only if you know that the data is available and correct in the back end.
Violation Code Sample
method BOOKINGS_READ .
data:
Stru_flight type IF_COMPONENTCONTROLLER=>Element_Flightinfo,
Itab_Booking type IF_COMPONENTCONTROLLER=>Elements_Bookingtab.
* Get Parent Element
CALL METHOD parent_element->get_static_attributes
IMPORTING
STATIC_ATTRIBUTES = Stru_flight.
* read bookings
select * from sbook
into corresponding fields of table Itab_Booking
where carrid = Stru_flight-carrid
and connid = Stru_flight-connid
and fldate = Stru_flight-fldate.
if sy-subrc NE 0.
RAISE NO_DATA_FOUND.
else.
* bind all the elements
Node->Bind_Table(
New_Items = Itab_Booking
Set_Initial_Elements = Abap_True ).
endif.
endmethod.
Fixed Code Sample
method BOOKINGS_READ .
data:
Stru_flight type IF_COMPONENTCONTROLLER=>Element_Flightinfo,
Itab_Booking type IF_COMPONENTCONTROLLER=>Elements_Bookingtab.
* Get Parent Element
CALL METHOD parent_element->get_static_attributes
IMPORTING
STATIC_ATTRIBUTES = Stru_flight.
* read bookings
select * from sbook
into corresponding fields of table Itab_Booking
where carrid = Stru_flight-carrid
and connid = Stru_flight-connid
and fldate = Stru_flight-fldate.
if sy-subrc = 0.
* bind all the elements
Node->Bind_Table(
New_Items = Itab_Booking
Set_Initial_Elements = Abap_True ).
endif.
endmethod.
Reference
NetWeaver Web Dynpro for Abap
http://help.sap.com/saphelp_nw2004s/helpdata/en/f1/177741adb7167de10000000a155106/frameset.htm
Related Technologies
Technical Criterion
Programming Practices - Error and Exception Handling
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.