Show TOC

Iteration Through Element ContentLocate this document in the navigation structure

Use

Activate this option in the Attributes display for the BSP element if this element is to run through its own content repeatedly, that is, it should implement a loop.

Procedure

In addition to activating this option, you must also redefine the interface method DO_AT_ITERATION of the element handler class.

This method is called each time at the end of an iteration. Using the return parameter , you control whether the loop is ended ( RC=CO_ELEMENT_DONE ) or run through once again ( RC=CO_ELEMENT_CONTINUE).

Example

Let us assume that you wish to have a repeated text call with a simple <do>-Element. The number of iterations is set through the corresponding attribute howOften.

Example:

<loops:do howOften = "10">
   Hello World !
</loops:do>
         

The value of the attribute howOften is used at the beginning of the element call in the method DO_AT_BEGINNING in order to initialize the loop counter count:

method IF_BSP_ELEMENT~DO_AT_BEGINNING .
  if howOften > 0.
    count = howOften - 1.
    rc = CO_ELEMENT_CONTINUE.
  else.
    rc = CO_ELEMENT_DONE.
endmethod.
         
Note

The method DO_AT_BEGINNING should have already checked whether the element content is to be evaluated at all. If this not the case, DO_AT_ITERATION is skipped and afterwards the method DO_AT_END is called.

The implementation of DO_AT_ITERATION could look like this:

method IF_BSP_ELEMENT~DO_AT_ITERATION .
  if count <> 0.
    count = count - 1.
    rc = CO_ELEMENT_CONTINUE.
  else.
    rc = CO_ELEMENT_DONE.
  endif.
endmethod.
         
Note

Note that the method DO_AT_ITERATION is only called if the operation Iteration Through Element Content has been explicitly assigned as element attribute. See also Defining BSP Elements.

DO_AT_ITERATION is called as soon as the element content has been processed. The method DO_AT_END, on the other hand, is called whatever the case, but only once; in this case, the call takes place after the iteration has closed.