Entering content frame

Procedure documentation Event Handler Locate the document in its SAP Library structure

Use

You need event handlers OnInputProcessing and OnInitialization for the registration page.

Note

For basic information on event handlers, see the section Event Handlers in the Business Server Pages documentation.

OnInitialization

Use event handler OnInitialization to determine your country.This information is evaluated for user data when the page is fragmented.

* event handler for data retrieval

country = 'Germany'.

OnInputProcessing

If the user chooses Done, and if the order executes successfully, the page cnewuser.htm opens (compare with Modifying the Order Confirmation Page). If the user makes an incorrect entry, the current page stays open so that the customer can correct his or her entries.

OnInputProcessingcontains the following code:

DATA wa TYPE bscustomer.

 

s_rc = 1.

 

SELECT SINGLE customerid FROM bscustomer INTO wa-customerid

  WHERE customerid = customerid.

IF sy-subrc = 0.

* user already signed-in

page->messages->add_message(

        condition = 'alreadyexists'

        otr_alias = 'SBOOKSHOP/ALREADYEXISTS'

        severity  = page->messages->CO_SEVERITY_ERROR ).

 

ELSEIF firstname IS INITIAL OR

  pwd IS INITIAL OR

  lastname IS INITIAL OR

  customerid IS INITIAL OR

  street IS INITIAL OR

  city IS INITIAL OR

  zip IS INITIAL OR

  country IS INITIAL.

* missing data

page->messages->add_message(

        condition = 'missingdata'

        otr_alias = 'SBOOKSHOP/MISSINGDATA'

        severity  = page->messages->CO_SEVERITY_ERROR ).

 

ELSEIF pwd <> pwd2.

* Passwords not equal

page->messages->add_message(

        condition = 'passwordnotequal'

        otr_alias = 'SBOOKSHOP/PASSWORDNOTIDENT'

        severity  = page->messages->CO_SEVERITY_ERROR ).

 

ELSE.

* insert user

  wa-customerid = customerid.

  wa-usrpwd = pwd.

  wa-title = title.

  wa-firstname = firstname.

  wa-surname = lastname.

  wa-street = street.

  wa-city = city.

  wa-zip = zip.

  wa-country = country.

  wa-discount = 0.

  INSERT INTO bscustomer VALUES wa.

  IF sy-subrc = 0.

        COMMIT WORK.

        s_rc = 0.

  ELSE.

    page->messages->add_message(

        condition = 'insertfailed'

        message   = 'Insert failed!'

        severity  = page->messages->CO_SEVERITY_ERROR ).

  ENDIF.

ENDIF.

 

CASE event_id.

  WHEN 'newuser'.

    if s_rc = 0.

      navigation->goto_page( 'cnewuser.htm' ).

    endif.

  WHEN OTHERS.

ENDCASE.

First, this code tells the system to check whether an entry for this customer with the given ID (e-mail address) exists in the customer database (table BSCUSTOMER).

If the customer has already logged on, return value s_rc is set to 0. The system displays a message that the customer or the customer identification already exists. The messages object is used for this:

page->messages->add_message(
        condition = 'alreadyexists'
        otr_alias = 'SBOOKSHOP/ALREADYEXISTS'
        severity  = page->messages->CO_SEVERITY_ERROR ).

add_message adds an individual message, below the specified condition (condition). The message itself is implemented as an OTR alias text (see below). Parameter severity specifies the severity of the error: in this case it is a normal error (CO_SEVERITY_ERROR). 

Note

You can find additional information about the use of message objects in the reference documentation in Using Object Messages and Class CL_BSP_MESSAGES.

Next, the system checks whether the user has filled out all mandatory fields.If not, an additional message is displayed, stating that input is missing. This is also an OTR alias text: SBOOKSHOP/MISSINGDATA. The message is: Please fill out all necessary fields. All fields except "title" and "company" must be filled out.

If the password and the password confirmation are not the same, an additional message will be displayed, which is again an OTR alias text.

If all entries are correct (that is, if none of the cases described above occurs), the customer data is written to the table BSCUSTOMER. The customer is now registered.In this case, you navigate to the Confirmation page for Registration cnewuser.htm.

If something goes wrong (for instance if the insert did not work), the system displays an additional error message:

    page->messages->add_message(
        condition = 'insertfailed'
        message   = 'Insert failed!'

        severity  = page->messages->CO_SEVERITY_ERROR ).

This time the error message is not an OTR alias text.

Online Text Repository

In this event handler, some of the messages are declared as alias texts in the Online Text Repository (OTR).As a result, these texts are excluded from the SAP translation system. Since this tutorial is merely a simple example and exists with English interface texts only, in this case it does not make sense to use OTR. It should only give an example of how you can implement your interface elements in different languages. If you want to make your BSP application available in different language versions, then implement all of your interface elements as alias texts or long texts in the OTR.

To display the actual text of the OTR alias texts, in the Web Application Builder Goto  ®  Online Text Repository Browser. The system displays a dialog box with the OTR basic vocabulary and all OTR texts that are contained in your BSP application packet; in this example SBOOKSHOP. For example, the actual text for alias SBOOKSHOP/ALREADYEXISTS is: An account of a person with this e-mail address already exists. If you have forgotten your password, please send us an e-mail and we will reset your password.

You can find additional information about the use of OTR with BSP applications in the reference documentation in Internationalization and Translation.

 

This graphic is explained in the accompanying textCreate the Layout for the Registration Confirmation Page.

 

 

Leaving content frame