Here we tried to summarize some of the basic methods you can use to manipulate BO collections
How To Search in BOL Collection
In order to search for a BO in a collection, the FIND method is used. You can use one of the two input parameters IV_INDEX and IV_ENTITY for the search. However, be aware that only one of these parameters are used for the search so you should provide only one. In case you export both of the parameters, the search will be executed according to the index.
DATA: lr_col TYPE REF TO if_bol_bo_col,
lr_entity TYPE REF TO cl_crm_bol_entity.
lr_entity ?= lr_col->find( iv_index = 1 ).
Another method that is provided for search is FIND_BY_PROPERTY of the iterator interface
DATA: lr_iterator TYPE REF TO if_bol_bo_col_iterator,
lr_entity TYPE REF TO cl_crm_bol_entity.
lr_iterator = lr_col->get_iterator( ).
lr_entity ?= lr_iterator->find_by_property( iv_attr_name = ‘POSTING_DATE’
iv_value = sy-datum ).
How To Sort BOL Collection
You can easily sort a collection with the SORT method. It has one mandatory input parameter IV_ATTR_NAME which indicates the attribute the collection is to be sorted
lr_col->sort( iv_attr_name = ‘POSTING_DATE’
iv_sort_order = if_bol_bo_col=>sort_descending ).
How To Filter BOL Collection
Filtering can be done with iterators. You can have any number of filters on a collection(the same goes for the iterators). Since the filters are applied via iterators, the collection itself is never changed
DATA: lr_iterator TYPE REF TO if_bol_bo_col_iterator,
lr_entity TYPE REF TO cl_crm_bol_entity.
lr_iterator = lr_col->get_iterator( ).
lr_col->filter_by_property( iv_attr_name = ‘POSTING_DATE’
iv_value = sy-datum ).
How To Change BOL Collection Content
IF_BOL_BO_COL~ADD | Append a BO to the collection |
IF_BOL_BO_COL~INSERT | Insert a BO into the collection at the given position |
IF_BOL_BO_COL~REMOVE | Remove a BO from the collection |
IF_BOL_BO_COL~ADD_COLLECTION | Append the content of a collection to another |
IF_BOL_BO_COL~CLEAR | Removes all content of the collection |
How To Use BOL Selection Operators
BOL Collections support two selection modes; single selection and multiple selection. This is set by the collection attribute IF_BOL_BO_COL~MULTI_SELECT. It can have two values ABAP_TRUE and ABAP_FALSE
For the single selection mode, following methods are used
IF_BOL_BO_COL~GET_CURRENT | Returns the selected object |
IF_BOL_BO_COL~GET_CURRENT_INDEX | Returns the index of the selected object |
IF_BOL_BO_COL~GET_NEXT | Returns the next object |
IF_BOL_BO_COL~GET_PREVIOUS | Returns the previous object |
For multi selection mode, following metods are used
IF_BOL_BO_COL_MULTI_SEL~MARK | Marks the object |
IF_BOL_BO_COL_MULTI_SEL~UNMARK | Unmarks the object |
IF_BOL_BO_COL_MULTI_SEL~GET_MARKED | Returns the list marked objects |
Additionally, the metods that are used for single selection mode above have different effects for multi selection mode
IF_BOL_BO_COL~GET_CURRENT | Returns the last selected object |
IF_BOL_BO_COL~GET_CURRENT_INDEX | Returns the index of the last selected object |
IF_BOL_BO_COL~GET_NEXT | Does nothing |
IF_BOL_BO_COL~GET_PREVIOUS | Does nothing |