Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos


Every developer is always confronted with handling application messages as well as maintaining these messages, for example, in databases for evaluation at a later stage or simply to display them in another framework. This may become complicated in a Web-based scenario. To solve this problem, developers create their own tools to manage and control the application message handling. But the developer's motivation is long gone when he comes to known that such a tool long ago exits.




In his excellent Web log BSP: Using the observer design pattern for error handling, Thomas Ritter describes an interesting way to handle messages in Business Server Page (BSP) applications using design patterns. Unlike to it, we will take a look inside of the SAP mechanisms for message handling in the “application log”.






Introduction




 


This Web log introduces some of the SAP’s own message handling tool concepts and its possible usage in a BSP-based scenario. This tool is actually used in almost every ABAP application and is highly-valued by experienced ABAP developers.





The application log is used to gather messages easily within an application and to maintain them in a log and then save them to the database. It provides additional functions such as saving, reading and deleting logs as well as editing and making changes to log messages. Error and warning messages are normally packed into a message class and read via the application log functions such as T100 Messages. This helps to make the developer’s life a little easier.





Another great feature of the application log tool is the capability to display messages within reports and dynpros and this feature is used in most ABAP-based applications. However, this functionality is not available for BSP applications.





By implementing a very simple (not MVC) BSP application, it will be demonstrated how to use the log to handle messages generated by a user search. The example above shows an application that requests user information. The first screenshot contains an input field labeled as User ID, five text views labeled ‘First name’, ‘Last name’, ‘Street’, ‘City’, and ‘Telephone’, a checkbox labeled ‘Saved log’, a button labeled ‘Go’, and a table view to display the messages.




!https://weblogs.sdn.sap.com/weblogs/images/17564/Log_handle_appl0.jpg|height=178|alt=image|width=290...!

 


The search application retrieves the User ID as input and requests the user data from the logic. Each time a User ID is not found, a new application log is created and the messages are added to the log.




!https://weblogs.sdn.sap.com/weblogs/images/17564/Log_handle_appl3.jpg|height=222|alt=image|width=361...!

 


Then the messages are displayed in a table view that is embedded in a tray and, therefore, excludes the necessity of a roundtrip to obtain the messages. If no messages were found, the tray is hidden. If the checkbox “save log” is checked, the log is saved in the database.




!https://weblogs.sdn.sap.com/weblogs/images/17564/display_log.jpg|height=203|alt=image|width=540|src=...!

 


It is important to mention that a log is always recorded by an application log object and sub-object. This allows a better classification of the log protocols. In this example, we set our log by default to a test object “BCT1” (first test object).


 


As shown above, the saved log protocol can be displayed in transaction SGL1 “Evaluate Application Log”. It is very useful if the user wants critical messages to remain accessible. When a log is first created it is also possible to set an expiration date for the log and set the flag for deletion after expiration.




Implementation



 


This application consists of a default.htm page, two event handlers and an application log class. The function modules of the application log are contained in the function group SBAL and for an easy usage in BSP application we encapsulate its functionality in class. We create the class cl_applog containing all the methods required to create, initialize and save an application log as well as a method to add messages to the log. As mentioned before, we are only using the basic functionality of the application log. The BSP application includes three pages of attributes:




!https://weblogs.sdn.sap.com/weblogs/images/17564/Pageatributte.jpg|height=151|alt=image|width=386|sr...!

 


The class cl_applog has tree private attributes: lt_messages: A table of type BSPMSG containing the messages with its type and icon. Log_handle: is a GUID used to identify a log. You can access this log using this handle. The last one log_handle_tab provide. When a user search is started, the event handler ‘on InputProcessing’ try to create a new application log using the method cl_applog=>create_log( ).of our class. This method encapsulates only the function module BAL_LOG_CREATE of SBAL, which sets the log handle GUID to the class attribute Log_handle. If a log handle already exists, the messages a
are only refreshed.



 


If the user ID is not matched or some user items are not customized, such as the telephone number or city, the method add_message( ) is executed and a message is added to the log. This method reads the parameters (MSGTY, MSGID, MSGNO, MSGV1 - 4) of the system structure where the message information is contained.





Now we need to create our message class Z_LOG and write the message text into it. A message class can be created using the transaction se91. The messages of this class consists of a Message ID (here 000 to 010), a message short text and if need a long text (self explanaty). We restrict this example only for the usage of short texts.




!https://weblogs.sdn.sap.com/weblogs/images/17564/message_class.jpg|height=235|alt=image|width=483|sr...!

 


Messages are raised using the message command, which reads them from message class and then sends them to the SAPGUI. Using the option INTO of the message command, the messages texts can be moved into text variables.



 



 


After all the messages have been collected, the application calls the method cl_applog=>read_log( ). This method uses the function module BAL_LOG_MSG_READ to move all the messages below to the referenced log and the messages are moved to a structure of type BSPMSG (Business Server Pages Messages).





 


As mentioned above, the display functionality is not provided for BSP application, so we have to assign the corresponding icon and message type to the structure. The messages are displayed in a default.htm page with a table view.




!https://weblogs.sdn.sap.com/weblogs/images/17564/structure.jpg|height=60|alt=image|width=542|src=htt...!

 


A table iterator class is used to display the message text correctly and there is an icon in the table view. This was implemented as a local class of cl_applog.





If the option ‘Save log’ was checked, the application calls the method cl_applog=>save_log which saves the log to a persistent object and then to the function module BAL_DB_SAVE.





 

Conclusion



 


The application log is a powerful tool to handle messages in BSP applications. It can be easily integrated into an application as well as into a class hierarchy.




 

Coding




 



class-pool .

" class pool for class CL_APPLOG

" local type definitions

*" local classes for public class CL_LOG_PPF

*" use this source file for any type declarations you need

*" in your method implementation

----


  •       CLASS CL_MY_ITERATOR DEFINITION

----


*

----


class cl_my_iterator definition.

  public section.

    interfaces if_htmlb_tableview_iterator.

    methods: constructor.

  private section.

    data: m_rowref type ref to bspmsg.                      "#EC NEEDED

endclass.                    "CL_MY_ITERATOR DEFINITION

" class CL_APPLOG definition

" public declarations

class CL_APPLOG definition

  public

  create public .

" public components of class CL_APPLOG

" do not include other source files here!!!

public section.

  class CL_OS_SYSTEM definition load .

  class-methods ITERATOR

    returning

      value(LT_ITERATOR) type ref to IF_HTMLB_TABLEVIEW_ITERATOR .

  class-methods READ_LOG

    returning

      value(LT_MESSAGES) type TBSPMSG

    exceptions

      LOG_NOT_FOUND

      MSG_NOT_FOUND .

  class-methods CREATE_LOG

    importing

      !IP_OBJECT type BALOBJ_D default 'BCT1'

      !IP_SUBOBJECT type BALSUBOBJ optional

    exceptions

      LOG_HEADER_INCONSISTENT

      INTERNAL_ERROR

      LOG_NOT_FOUND .

  class-methods ADD_MESSAGE

    exceptions

      LOG_NOT_FOUND

      MSG_INCONSISTENT

      LOG_IS_FULL

      INTERNAL_ERROR .

  class-methods SAVE_LOG

    importing

      !IP_UPDATE_TASK type CHAR1 default SPACE

    returning

      value(RP_LOGNO) type BALOGNR

    exceptions

      INTERNAL_ERROR

      LOG_NOT_FOUND

      NO_MESSAGES_FOUND .

  class-methods DELETE_LOG

    exceptions

      LOG_NOT_FOUND

      INTERNAL_ERROR

      MSG_NOT_FOUND .

  type-pools SPPF .

" protected declarations

*" protected components of class CL_LOG_PPF

*" do not include other source files here!!!

protected section.

" private declarations

" private components of class CL_APPLOG

" do not include other source files here!!!

private section.

  class-data LT_MESSAGES type TBSPMSG .

  class-data LOG_HANDLE type BALLOGHNDL .

  class-data:

    log_handle_tab type table of balloghndl .

  type-pools SPPF .

endclass. "CL_APPLOG definition

" macro definitions

" use this source file for any macro definitions you need

" in the implementation part of the class

" local class implementation

" local class implementation for public class

" use this source file for the implementation part of

" local helper classes

class cl_my_iterator implementation.

  method constructor.

  •    me->m_messages = it_messages.

  endmethod.                    "constructor

  method if_htmlb_tableview_iterator~get_column_definitions.

    data: tv_column type tableviewcontrol.

    clear tv_column.

    tv_column-columnname = 'CONDNAME'.

    tv_column-title = 'Type'(001).

    tv_column-horizontalalignment = 'center'.

    append tv_column to p_column_definitions.

    clear tv_column.

    tv_column-columnname = 'MESSAGE'.

    tv_column-horizontalalignment = 'left'.

    tv_column-title = 'Message'(002).

    append tv_column to p_column_definitions.

  endmethod.                    "IF_HTMLB_TABLEVIEW_ITERATOR~GET_COLUMN_DEFINITIONS

  method if_htmlb_tableview_iterator~render_row_start.

    m_rowref ?= p_row_data_ref.

  endmethod.                    "IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_ROW_START

  method if_htmlb_tableview_iterator~render_cell_start.

    data:

            row_index         type string,                  "#EC NEEDED

            lv_onclientclick  type string,

            ls_message        type bspmsg.                  "#EC *

    field-symbols:      type     bspmsg.

*----


get current row

    assign m_rowref->* to height = 15.

        p_replacement_bee = col1_image.

    endcase.

  endmethod.                    "IF_HTMLB_TABLEVIEW_ITERATOR~RENDER_CELL_START

endclass.                    "CL_MY_ITERATOR IMPLEMENTATION

class CL_APPLOG implementation.

" method's implementations

METHOD add_message .

  • ---------------------------------------------*

  • Add a message to the application log         *

----


*----Declarations

  DATA:

  ls_msg   TYPE bal_s_msg.

  IF NOT log_handle IS INITIAL.

*---- Build up message

    MOVE-CORRESPONDING sy TO ls_msg.

*----Add the message

    CALL FUNCTION 'BAL_LOG_MSG_ADD'

      EXPORTING

        i_log_handle     = log_handle

        i_s_msg          = ls_msg

      EXCEPTIONS

        log_not_found    = 1

        msg_inconsistent = 2

        log_is_full      = 3

        OTHERS           = 4.

  •   Error Processing

    CASE sy-subrc.

*----->Log has been not found

      WHEN 1.

        MESSAGE ID     sy-msgid

                TYPE   sy-msgty

                NUMBER sy-msgno

                WITH   sy-msgv1

                       sy-msgv2

                       sy-msgv3

                       sy-msgv4

               RAISING log_not_found.

*---->Message is incosistent

      WHEN 2.

        MESSAGE ID     sy-msgid

                TYPE   sy-msgty

                NUMBER sy-msgno

                WITH   sy-msgv1

                       sy-msgv2

                       sy-msgv3

                       sy-msgv4

              RAISING msg_inconsistent.

*----->Log is full

      WHEN 3.

        MESSAGE ID     sy-msgid

                TYPE   sy-msgty

                NUMBER sy-msgno

                WITH   sy-msgv1

                       sy-msgv2

                       sy-msgv3

                       sy-msgv4

               RAISING log_is_full.

*---->An internal error is ocurred

      WHEN 4.

        MESSAGE ID     sy-msgid

                TYPE   sy-msgty

                NUMBER sy-msgno

                WITH   sy-msgv1

                       sy-msgv2

                       sy-msgv3

                       sy-msgv4

               RAISING internal_error.

    ENDCASE.

  ENDIF.

ENDMETHOD.

METHOD create_log .

----


  • Create a new application log               *

----


*----Deklarationen

  DATA:

  ls_log      TYPE bal_s_log,

  ls_mdef     TYPE bal_s_mdef.

*----If log exits, just delete messages

  IF   log_handle IS NOT INITIAL.

    CALL FUNCTION 'BAL_LOG_MSG_DELETE_ALL'

      EXPORTING

        i_log_handle  = log_handle

      EXCEPTIONS

        log_not_found = 1

        OTHERS        = 2.

  • Error processing

    CASE sy-subrc.

      WHEN 1.

*----> LOG_HEADER_INCONSISTENT

        MESSAGE ID      sy-msgid

                TYPE    sy-msgty

                NUMBER  sy-msgno

                WITH    sy-msgv1

                        sy-msgv2

                        sy-msgv3

                        sy-msgv4

                RAISING log_not_found.

      WHEN 2.

*---->INTERNAL_ERROR

        MESSAGE ID     sy-msgid

               TYPE    sy-msgty

               NUMBER  sy-msgno

               WITH    sy-msgv1

                       sy-msgv2

                       sy-msgv3

                       sy-msgv4

               RAISING internal_error.

    ENDCASE.

  ELSE.

*----Set application log header

  ls_log-object     = ip_object.

  ls_log-subobject  = ip_subobject.

  ls_log-aldate     = sy-datum .

  ls_log-altime     = sy-uzeit.

  ls_log-aluser     = sy-uname.

  ls_log-del_before = 'X'.

*----Create application log (processing log)

    CALL FUNCTION 'BAL_LOG_CREATE'

      EXPORTING

        i_s_log                 = ls_log

      IMPORTING

        e_log_handle            = log_handle

      EXCEPTIONS

        log_header_inconsistent = 1

        OTHERS                  = 2.

  • Error processing

    CASE sy-subrc.

      WHEN 1.

*----> LOG_HEADER_INCONSISTENT

        MESSAGE ID      sy-msgid

                TYPE    sy-msgty

                NUMBER  sy-msgno

                WITH    sy-msgv1

                        sy-msgv2

                        sy-msgv3

                        sy-msgv4

                RAISING log_header_inconsistent.

      WHEN 2.

*---->INTERNAL_ERROR

        MESSAGE ID     sy-msgid

               TYPE    sy-msgty

               NUMBER  sy-msgno

               WITH    sy-msgv1

                       sy-msgv2

                       sy-msgv3

                       sy-msgv4

               RAISING internal_error.

    ENDCASE.

  ENDIF.

ENDMETHOD.

METHOD save_log .

----


  • Save application log                            *

----


*---- Declarations

  DATA:

    lt_handles       TYPE bal_t_logh,

    ls_statistics    TYPE bal_s_scnt,

    lt_longnumbers   TYPE bal_t_lgnm,

    ls_longnumbers   TYPE bal_s_lgnm.

  IF log_handle IS INITIAL.

*-->Error message -> Log not specified

    MESSAGE 'Log not specified'

    TYPE 'E'

    RAISING log_not_found.

  ENDIF.

*----Search for messages

  CALL FUNCTION 'BAL_LOG_HDR_READ'

    EXPORTING

      i_log_handle  = log_handle

    IMPORTING

      e_statistics  = ls_statistics

    EXCEPTIONS

      log_not_found = 1

      OTHERS        = 2.

  • Error processing

  IF sy-subrc = 1.

*-->Log has been not found

    MESSAGE ID       sy-msgid

            TYPE     sy-msgty

            NUMBER   sy-msgno

            WITH     sy-msgv1

                     sy-msgv2

                     sy-msgv3

                     sy-msgv4

           RAISING  log_not_found .

  ELSEIF sy-subrc = 2.

*-->An internal error ocurred

    MESSAGE ID sy-msgid

        TYPE   sy-msgty

        NUMBER sy-msgno

        WITH   sy-msgv1

               sy-msgv2

               sy-msgv3

               sy-msgv4

       RAISING internal_error .

  ENDIF.

*----Any Messages found?

  IF ls_statistics-msg_cnt_al = 0.

    MESSAGE 'No messages found'

    TYPE 'E'

    RAISING no_messages_found.

  ENDIF.

  APPEND log_handle TO lt_handles.

*-----Update task?

  IF ip_update_task is not initial.

*----Save log in update task

    CALL FUNCTION 'BAL_DB_SAVE'

      EXPORTING

        i_in_update_task = 'X'

        i_save_all       = ' '

        i_t_log_handle   = lt_handles

      IMPORTING

        e_new_lognumbers = lt_longnumbers

      EXCEPTIONS

        log_not_found    = 1

        save_not_allowed = 2

        OTHERS           = 3.

  •   Error processing

    IF sy-subrc <> 0.

*-->An internal error ocurred

      MESSAGE ID sy-msgid

          TYPE   sy-msgty

          NUMBER sy-msgno

          WITH   sy-msgv1

                 sy-msgv2

                 sy-msgv3

                 sy-msgv4

         RAISING internal_error .

    ENDIF.

    APPEND LINES OF lt_handles TO log_handle_tab.

*----Return protocoll value

    READ TABLE lt_longnumbers INDEX 1

    INTO ls_longnumbers.

    rp_logno = ls_longnumbers-lognumber..

  ELSE.

*----Just save

    CALL FUNCTION 'BAL_DB_SAVE'

      EXPORTING

        i_in_update_task = ' '

        i_save_all       = ' '

        i_t_log_handle   = lt_handles

      IMPORTING

        e_new_lognumbers = lt_longnumbers

      EXCEPTIONS

        log_not_found    = 1

        save_not_allowed = 2

        OTHERS           = 3.

  •   Error processing

    IF sy-subrc <> 0.

*-->An internal error ocurred

      MESSAGE ID sy-msgid

          TYPE   sy-msgty

          NUMBER sy-msgno

          WITH   sy-msgv1

                 sy-msgv2

                 sy-msgv3

                 sy-msgv4

         RAISING internal_error .

    ENDIF.

*----Return protocoll value

    READ TABLE lt_longnumbers INDEX 1

    INTO ls_longnumbers.

    rp_logno = ls_longnumbers-lognumber.

  ENDIF.

ENDMETHOD.                    "SAVE_LOG

METHOD read_log .

----


  • Read Application Logs                    *

----


*-----Declarations

  DATA:

        lt_lghdl           TYPE          bal_t_logh,

        ls_message         TYPE          bspmsg,

        lt_msghdl          TYPE          bal_t_msgh,

        ls_msghdl          TYPE          balmsghndl,

        ls_hgl_message     TYPE          bal_s_msg,

        lv_message         TYPE          bapi_msg.

*---- Init message table

  REFRESH lt_messages.

  APPEND log_handle TO lt_lghdl.

*-----Find all application logs

  CALL FUNCTION 'BAL_GLB_SEARCH_MSG'

    EXPORTING

      i_t_log_handle = lt_lghdl

    IMPORTING

      e_t_msg_handle = lt_msghdl

    EXCEPTIONS

      msg_not_found  = 1

      OTHERS         = 2.

  IF sy-subrc = 0.

*----Read all mesages of all applications log

    LOOP AT lt_msghdl INTO ls_msghdl.

      CLEAR ls_message.

      CALL FUNCTION 'BAL_LOG_MSG_READ'

        EXPORTING

          i_s_msg_handle = ls_msghdl

          i_langu        = sy-langu

        IMPORTING

          e_s_msg        = ls_hgl_message

          e_txt_msg      = lv_message

        EXCEPTIONS

          log_not_found  = 1

          msg_not_found  = 2

          OTHERS         = 3.

  •     Error processing

      IF sy-subrc = 2.

*------> Log has been not found

        MESSAGE ID       sy-msgid

                TYPE     sy-msgty

                NUMBER   sy-msgno

                WITH     sy-msgv1

                         sy-msgv2

                         sy-msgv3

                         sy-msgv4

                RAISING  log_not_found .

*-----> No messages found for this application log

      ELSEIF sy-subrc = 3.

        MESSAGE ID       sy-msgid

                TYPE     sy-msgty

                NUMBER   sy-msgno

                WITH     sy-msgv1

                         sy-msgv2

                         sy-msgv3

                         sy-msgv4

                RAISING  msg_not_found .

      ENDIF.

*-----Build up error message table

  •     Add Icon to message structur

  • ERROR/WARNING/OK/STOP/LOADING/NONE/TEXT

      CASE ls_hgl_message-msgty.

        WHEN 'E'.

          ls_message-condname = '@8O@'.

        WHEN 'S'.

          ls_message-condname = '@8O@'.

        WHEN 'I'.

          ls_message-condname = '@8P@'.

        WHEN 'W'.

          ls_message-condname = '@8R@'.

        WHEN 'A'.

          ls_message-condname = '@8N@'.

        WHEN 'E'.

          ls_message-condname = '@8O@'.

      ENDCASE.

      ls_message-message  = lv_message.

      ls_message-severity = ls_hgl_message-msgno.

*-----Build Messages Output Table

      APPEND ls_message TO  lt_messages.

    ENDLOOP.

  ENDIF.

*-----Add log handle to log handle table

  APPEND log_handle TO log_handle_tab.

ENDMETHOD.                    "READ_LOG

METHOD iterator.

----


  • This Iterator formats the output of the table

  • view user to show the messages

----


  CREATE OBJECT lt_iterator TYPE cl_my_iterator.

ENDMETHOD.

METHOD DELETE_LOG .

----


  • Initialize application log    *

----


  • Declaration

  DATA: ls_handle   TYPE balloghndl.

  LOOP AT log_handle_tab INTO ls_handle.

*----Clear protocol (in memory)

    CALL FUNCTION 'BAL_LOG_REFRESH'

      EXPORTING

        i_log_handle  = ls_handle

      EXCEPTIONS

        log_not_found = 1

        OTHERS        = 2.

  •   Error processing

*--->Log has been not found

    IF sy-subrc =  1.

      MESSAGE ID     sy-msgid

              TYPE   sy-msgty

              NUMBER sy-msgno

              WITH   sy-msgv1

                     sy-msgv2

                     sy-msgv3

                     sy-msgv4

             RAISING log_not_found .

    ELSEIF sy-subrc =  2.

*-----> An internal error ocurred

      MESSAGE ID     sy-msgid

           TYPE   sy-msgty

           NUMBER sy-msgno

           WITH   sy-msgv1

                  sy-msgv2

                  sy-msgv3

                  sy-msgv4

          RAISING internal_error.

    ENDIF.

  ENDLOOP.

*-----Clear logs

  CLEAR log_handle_tab.

  CLEAR log_handle.

  clear lt_messages.

ENDMETHOD.

endclass. "CL_APPLOG implementation

BSP Application

Default.htm

<%@page language="abap" %>

<%@extension name="htmlb" prefix="htmlb" %>

<%@extension name="phtmlb" prefix="phtmlb" %>

<htmlb:content design="design2003" >

  <htmlb:page title="User Info" >

    <htmlb:form>

      <%

         if lt_messages is not initial.

      %>

      <htmlb:tray id          = "auf1"

                  title       = "<%= lv_text %>"

                  isCollapsed = "true" >

        <htmlb:tableView id              = "errormessages"

                         table           = "<%= lt_messages %>"

                         design          = "alternating"

                         width           = "100%"

                         footerVisible   = "false"

                         selectionMode   = "none"

                         fillUpEmptyRows = "false"

                         iterator        = "<%= cl_applog=>iterator( ) %>" />

      </htmlb:tray>

      <%

        endif.

      %>

      <htmlb:label id       = "lbl_id"

                   for      = "USERID"

                   text     = "User ID"

                   required = "TRUE" />

      <htmlb:inputField id      = "inp_id"

                        visible = "true"

                        value   = "<%= ls_user-bname %>" />

      <htmlb:button id      = "but_id"

                    onClick = "FIND_USER"

                    text    = "Go" />

      <htmlb:gridLayout columnSize  = "2"

                        rowSize     = "1"

                        cellSpacing = "3" >

        <htmlb:gridLayoutCell columnIndex = "1"

                              rowIndex    = "1" >

          <% if ls_user-bname is not initial. %>

         <htmlb:image src="../PUBLIC/BC/Icons/s_b_cust.gif"  tooltip="User found"/>

         <% endif. %>

        </htmlb:gridLayoutCell>

        <htmlb:gridLayoutCell columnIndex = "2"

                              rowIndex    = "1" >

          <htmlb:gridLayout columnSize = "2"

                            rowSize    = "7" >

            <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "1" />

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "1" >

              <htmlb:textView id     = "USERID"

                              text   = "<%= ls_user-bname %>"

                              design = "EMPHASIZED" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "2" >

              <htmlb:label for  = "FNAME"

                           text = "First name" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "2" >

              <htmlb:textView id     = "FNAME"

                              text   = "<%= ls_user-name1 %>"

                              design = "EMPHASIZED" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "3" >

              <htmlb:label for  = "LNAME"

                           text = "Last name" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "3" >

              <htmlb:textView id     = "LNAME"

                              text   = "<%= ls_user-name2 %>"

                              design = "EMPHASIZED" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "4" >

              <htmlb:label for  = "STREET"

                           text = "Street" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "4" >

              <htmlb:textView id     = "STREET"

                              text   = "<%= ls_user-stras %>"

                              design = "EMPHASIZED" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "5" >

              <htmlb:label for  = "CITY"

                           text = "City" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "5" >

              <htmlb:textView id     = "CITY"

                              text   = "<%= ls_user-ort01 %>"

                              design = "EMPHASIZED" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "6" >

              <htmlb:label for  = "TELE"

                           text = "Telephone" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "6" >

              <htmlb:textView id     = "TELE"

                              text   = "<%= ls_user-telnr %>"

                              design = "EMPHASIZED" />

            </htmlb:gridLayoutCell>

                <htmlb:gridLayoutCell columnIndex = "1"

                                  rowIndex    = "7" >

                <htmlb:label for  = "SAVE_LOG"

                           text = "Save log" />

            </htmlb:gridLayoutCell>

            <htmlb:gridLayoutCell columnIndex = "2"

                                  rowIndex    = "7" >

              <htmlb:checkbox id="SAVE_LOG" checked="FALSE" />

            </htmlb:gridLayoutCell>

          </htmlb:gridLayout>

        </htmlb:gridLayoutCell>

      </htmlb:gridLayout>

    </htmlb:form>

  </htmlb:page>

</htmlb:content>

Event Handler ‘onInputProcessing’

-


Declarations

data: lv_dummy          type string,

      data              type ref to cl_htmlb_inputfield,

      event             type ref to cl_htmlb_event,

      checkbox          type ref to cl_htmlb_checkbox,

      lv_bname          type bname,

      lv_log_number     type balognr,

      lv_count          type i,

      lv_help           type c,

      lv_checked        type string.

*---- Initialize User data and Messages

clear   ls_user.

refresh lt_messages.

*-----Create log

cl_applog=>create_log( ).

*---- Read Event

class cl_htmlb_manager definition load.

event ?= cl_htmlb_manager=>get_event( runtime->server->request ).

if event is initial.

  exit.

endif.

if event->id ='but_id' and event->event_type = 'click'.

*-----Read Inputfield data

  data ?= cl_htmlb_manager=>get_data( request = runtime->server->request

                                         name = 'inputField'

                                         id   = 'inp_id'  ).

  if data->value is initial.

*-----Insert a user ID

    message e003(z_log)

    into lv_dummy.

    cl_applog=>add_message( ).

  else.

    lv_bname      = data->value.

    ls_user-bname = lv_bname .

    condense ls_user-bname.

  endif.

*-----Read Checkbox input

  checkbox ?= cl_htmlb_manager=>get_data(

                                        request = runtime->server->request

                                        name    = 'checkbox'

                                        id      = 'SAVE_LOG' ).

  if checkbox is not initial.

    lv_checked  = checkbox->checked.

  endif.

  if ls_user-bname is not initial.

    translate ls_user-bname to upper case.

*-----Request user details

    call function 'SUSR_SHOW_USER_DETAILS'

      exporting

        bname      = ls_user-bname

        mandt      = sy-mandt

        no_display = 'X'

      changing

        user_usr03 = ls_user.

    if   ls_user-name1 is initial

    and  ls_user-name2 is initial.

*-----User &1 not found

      message e000(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( ).

    else.

*-----User: &1

      message i010(z_log)

      with lv_bname into lv_dummy.

      cl_applog=>add_message( ).

    endif.

    if   ls_user-name1 is not initial

    and  ls_user-name2 is initial

    and  ls_user-bname is not initial.

*-----Last name not found

      message e005(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( )..

    endif.

    if   ls_user-name2 is not initial

    and  ls_user-name1 is initial

    and  ls_user-bname is not initial.

*-----First name not found

      message w004(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( ).

    endif.

    if ls_user-stras is initial

  and  ls_user-bname is not initial.

*-----Street not found

      message w001(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( ).

    endif.

    if ls_user-ort01 is initial

  and  ls_user-bname is not initial.

*-----City not found

      message w002(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( ).

    endif.

    if ls_user-pstlz is initial

  and  ls_user-bname is not initial.

*-----Zip code not found

      message w006(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( ).

    endif.

    if ls_user-telnr is initial

  and  ls_user-bname is not initial.

*-----Telefon code not found

      message w007(z_log)

      with lv_bname into lv_dummy.

*----Add message to log

      cl_applog=>add_message( ).

    endif.

*-----Save Log if user has been not found

    if lv_checked is not initial.

      call method cl_applog=>save_log

        receiving

          rp_logno          = lv_log_number

        exceptions

          internal_error    = 1

          log_not_found     = 2

          no_messages_found = 3

          others            = 4.

*-----Log saved

      if sy-subrc = 0.

        message w008(z_log)

        with'BCT1' into  lv_dummy.

*----Add message to log

        cl_applog=>add_message( ).

*----- See protocoll with the TA SLG1

        message w009(z_log)

        into lv_dummy.

*----Add message to log

        cl_applog=>add_message( ).

      else.

*----Log not found

*----Add message to log

        cl_applog=>add_message( ).

      endif.

    endif.

endif.

*-----Read Log Messages

    lt_messages =  cl_applog=>read_log( ).

    if lt_messages is not initial.

*-----Count messages

      describe table lt_messages lines lv_count.

      move lv_count to lv_help.

*---- Build text messages found

      concatenate

       lv_help

      'Messages founds'

       into lv_text

       separated by space.

    endif.

  endif.

Event Handler ‘onDestroy’

  • this handler is called once the page reference is destroyed

*----Delete log from memory

call method cl_applog=>delete_log

  exceptions

    log_not_found  = 1

    internal_error = 2

    msg_not_found  = 3

    others         = 4

        .

if sy-subrc <> 0.

endif.

Message class texts

Message     Message short text

000          User: &1 not found

001          Street: not found

002          City:   not found

003          Telephone Nr: not found

004          First name: not found

005          Last name: not found

006          Zip code: not found

007          Telephone: not found

008          A message protocoll was saved ( Object & )

009          See protocoll with the TA SLG1

010          User: &1 found

</textarea>

</p>

2 Comments