!--a11y-->
Creating Controller search.do for the Search 
Use
This controller accepts data in the search fields, executes the search and then stores the results in an internal table.
Procedure
Create controller
search.do with controller class CL_BSP_TUT_SEARCH.In addition to the mandatory method
DO_REQUEST, you must also overwrite methods DO_HANDLE_EVENT and DO_HANDLE_DATA. The first one determines what should happen when the user clicks on search book, the second one is responsible for processing the data that the user inputs.Furthermore you must create additional attributes for the controller class that it uses for storing the data.
Method DO_REQUEST
This method is very simple, it merely instantiates view
search.htm and calls it up.|
method DO_REQUEST . data: search_view type ref to if_bsp_page. search_view = create_view( view_name = 'search.htm' ). call_view( search_view ). endmethod. |
Method DO_HANDLE_EVENT
This method is called when the user presses on search book.
|
method DO_HANDLE_EVENT . class cl_book_shop definition load. if htmlb_event is bound and htmlb_event->server_event = 'search'. refresh me->isbn_tab . 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. endif. if sy-subrc <> 0. case sy-subrc. when 4. me->messages->add_message( condition = 'isbn' message = 'You entered an invalid ISBN - please try again!' severity = me->messages->CO_SEVERITY_ERROR ). when 2. when others. me->messages->add_message( condition = 'internal' message = 'An internal error occurred - please try again!' severity = me->messages->CO_SEVERITY_FATAL_ERROR ). endcase. else. me->messages->reset( ) . endif. endmethod. |
If the SEARCH button is pressed, this triggers event "search" (see also
Creating View search.htm for the Search). The attributes that were set by method DO_HANDLE_DATA are put in the search method of class CL_BOOK_SHOP (as is the case in all of the tutorials). The result is a table with ISBNs of the books that were found.For error handling the messages object is used, just like in the fourth tutorial (
Further Developing the Bookshop) (see also Modifying the Search Page).Method DO_HANDLE_DATA
The form fields that the user filled out are transferred to this method. They are then available as attributes of the controller class (see below).
|
method DO_HANDLE_DATA . field-symbols: <field> type ihttpnvp. read table form_fields with table key name = 'author' assigning <field>. me->author = <field>-value. read table form_fields with table key name = 'title' assigning <field>. me->title = <field>-value. read table form_fields with table key name = 'publisher' assigning <field>. me->publisher = <field>-value. read table form_fields with table key name = 'keyword' assigning <field>. me->keyword = <field>-value. read table form_fields with table key name = 'isbn' assigning <field>. me->isbn = <field>-value. endmethod. |
Additional Attributes of the Controller Class
With the attributes you must then also specify the input fields as well as the ISBN table that returns the search function.
|
Attribute |
Type |
Visibility |
Reference Type |
Description |
|
AUTHOR |
Instance Attribute |
Public |
STRING |
Name of author |
|
TITLE |
Instance Attribute |
Public |
STRING |
Title of the book |
|
PUBLISHER |
Instance Attribute |
Public |
STRING |
Publisher |
|
ISBN |
Instance Attribute |
Public |
STRING |
ISBN |
|
KEYWORD |
Instance Attribute |
Public |
STRING |
Key words |
|
ISBN_TAB |
Instance Attribute |
Public |
ISBN_TAB |
Table for ISBN numbers |
![]()
You can now create the view for the book search :
Creating View search.htm for the Search