!--a11y-->
Use
You must still make a few small changes to the third tutorial:
Layout
On the start page add statements to the layout for displaying error messages using the
messages object:|
<%@ page language="abap" %> <%@include file="head.htm" %> <h3>Search</h3> <p> Fill out one or more of the fields below to search for a book. You can use the wildcard character '+' to replace just one letter and '*' to replace any number of letters. <p> <font color="red"> <%= page->messages->assert_message( 'isbn' ) %></font><font color="red"> <%= page->messages->assert_message( 'internal' ) %></font><font color="blue"> <%= page->messages->assert_message( 'noresults' ) %></font><form method="POST"> <table> <tr><td width="180"> Author (last name) </td> <td> <input type="text" name="author" size="80"></td> </tr> <tr><td>Title </td> <td> <input type="text" name="title" size="80"></td></tr> <tr><td>Publisher </td> <td> <input type="text" name="publisher" size="40"></td></tr> <tr><td>Keyword </td> <td> <input type="text" name="keyword" size="20"</td></tr> <tr><td>ISBN </td> <td> <input type="text" name="isbn" size="13"></td></tr> </table> <p> <input type=submit name="onInputProcessing(search)" value="Search for Book"> <input type="reset" value="Reset" name="B2"> </form> </body> </html> |
The following errors can occur at this point:

In all error cases, the
Page Attributes
You need the additional page attribute
isbn_tab for this tutorial. This is the table for the ISBNs with the reference type ISBN_TAB.Event Handler OnInputProcessing
Create the search for using class
CL_BOOK_SHOP (see also Data Models for the Bookshop Tutorialsas well as the following error cases in this event handler:|
class CL_BOOK_SHOP definition load. case event_id. when 'search'. *look for matching books for user query CALL METHOD cl_book_shop=>search_book EXPORTING author = author title = title publisher = publisher ISBN = ISBN keyword = keyword IMPORTING isbn_tab = isbn_tab EXCEPTIONS no_search_parameter = 2 invalid_isbn = 4.
* error handling if sy-subrc <> 0. case sy-subrc. when 4. page->messages->add_message( condition = 'isbn' message = 'You entered an invalid ISBN - please try again!' severity = page->messages->CO_SEVERITY_ERROR ). when 2. when others. page->messages->add_message( condition = 'internal' message = 'An internal error occurred - please try again!' severity = page->messages->CO_SEVERITY_FATAL_ERROR ). endcase. else. * no books found * if sy-subrc = 0. if isbn_tab is initial. page->messages->add_message( condition = 'noresults' message = 'No books were found that match your query.' severity = page->messages->CO_SEVERITY_INFO ). * something found and no error else. navigation->next_page( 'TORESULTS' ). endif. endif.
navigation->set_parameter( 'author' ). navigation->set_parameter( name = 'isbn_tab' value = isbn_tab ).
when others.
endcase. |
Specify a message for each of the error cases stated in the layout.
If the internal return value
sy-subrc does not equal 0, it can have values 2 or 4. Value 4 means that the ISBN that was entered is an incorrect ISBN and the messages object outputs a corresponding error message: page->messages->add_message(
condition = 'isbn'
message = 'You entered an invalid ISBN - please try again!'
add_message
adds an individual message, below the specified condition (condition). This message or the message text itself is specified directly and not implemented as an OTR alias text. Parameter severity specifies the severity of the error: in this case it is a normal error (CO_SEVERITY_ERROR).
You can find additional information about the use of message objects in the reference documentation in
Value
2 means that a serious internal error occured: page->messages->add_message(
condition = 'internal'
message = 'An internal error occurred - please try again!'
If no results were found because of the user’s search query, internal value
sy_subrc is set to 0 and the following message is displayed as information (this time not using the OTR): page->messages->add_message(
condition = 'noresults'
message = 'No books were found that match your query.'
Only if no errors occur and the results are found for the search query is the results page displayed using navigation request
TORESULTS.
Now modify the