Entering content frame

Procedure documentation OnInitialization Locate the document in its SAP Library structure

OnInitialization runs after OnRequest. It retrieves and prepares data for the layout and can also perform calculations.

In our example, OnInitialization contains the following program code:

DATA: line_item TYPE bsbasket,

      item_detail TYPE bsbookdata,

      catid_tab TYPE catid_tab,

      psubtotal TYPE bscurr.

 

IF application->m_basket IS NOT INITIAL.

  LOOP AT application->m_basket INTO line_item.

    IF line_item-qty > 0.

      append line_item-catid to catid_tab.

  ELSE.

      DELETE application->m_basket.

  ENDIF.

  ENDLOOP.

 

  SORT catid_tab.

  DELETE ADJACENT DUPLICATES from catid_tab.

 

  CALL METHOD cl_book_shop=>get_items

      EXPORTING catid_tab = catid_tab

      IMPORTING bookdata = bookcat_tab.

 

* calculate total price

  LOOP AT bookcat_tab INTO item_detail.

    READ TABLE application->m_basket

      WITH KEY catid = item_detail-cata_id INTO line_item.

    psubtotal = psubtotal + ( item_detail-our_price * line_item-qty ).

  ENDLOOP.

  totalamount = psubtotal.

  ENDIF.

If the shopping basket contains items, the catalog IDs of the items are stored in the table catid_tab. This table uses the method cl_book_shop=>get_items to get the required book data and write the data to the internal table bookcat_tab (see Page Attributes).

Next, the application calculates the total price of the books in the basket. This figure is then output in the Layout.

This graphic is explained in the accompanying textOnInputProcessing

 

 

Leaving content frame