Skip to Content
author's profile photo Former Member
Former Member

Collection Traversing

Hi Experts,

I am getting some records based on condition. Fox example if lv_collection has multiple Records , I need to show only 4 records in WebUi in a table.

I wrote below code but it is not working.

DATA: lv_collection TYPE REF TO if_bol_bo_col,

lv_index type sytabix.


lv_collection->get_first( ).
WHILE lv_collection IS BOUND.
lv_collection->get_current_index( ).
IF lv_index LE 4.
me->collection_wrapper->add_collection( lv_collection ).
lv_collection->get_next( ).
ELSE.
EXIT.
ENDIF.
ENDWHILE.


Please suggest me the solution.


Thanks & regards,

Akhilesh Bhagat.



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Feb 17, 2014 at 07:06 PM

    Hi,


    Try with below code :


    DATA: lv_collection TYPE REF TO if_bol_bo_col,

    lv_entity type ref to cl_crm_bol_entity,

    lv_index type sytabix.

    lv_entity = me->typed_context->Context name->collection_wrapper->get_first( ).
    WHILE lv_entity IS BOUND .

    if lv_collection->Size( ) < 4.
    lv_collection->add( lv_entity ).

    endif.
    lv_entity ?= me->typed_context->Context name->collection_wrapper->get_next( ).
    ELSE.
    EXIT.
    ENDIF.
    ENDWHILE.

    me->typed_context->Context name->collection_wrapper->clear( ).

    me->typed_context->Context name->collection_wrapper->IF_BOL_BO_COL~ADD_COLLECTION( lv_collection ).


    Thanks

    Kumar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2014 at 05:00 AM

    Hi Akhilesh ,

    As I understand your requirement you need to add a maximum of 4 entries in a webui table , to implement this logic you try using the below code .

    DATA: lv_collection TYPE REF TO if_bol_bo_col,

    lv_entity TYPE REF TO cl_crm_bol_entity,

    lv_count TYPE i VALUE 0 . "counter to count the number of entries ..

    lv_entity = me->typed_context->context_node_name->collection_wrapper->get_first( ).

    WHILE lv_entity IS BOUND .

    lv_count = lv_count + 1

    IF lv_count GT 4 .

    EXIT .

    ELSE .

    lv_collection->add( lv_entity ).

    lv_entity ?= me->typed_context->context_node_name->collection_wrapper->get_next( ).

    ENDIF .

    ENDWHILE .

    "Clear the previous entries and add the new set of entries from the collection into the context node as stated above by Gaurav also ..

    me->typed_context->Context_node_name->collection_wrapper->clear( ).

    me->typed_context->Context_nodde_name->collection_wrapper->IF_BOL_BO_COL~ADD_COLLECTION( lv_collection ).

    Please let me know in case of any queries .

    Thanks ,

    Vaibhav

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.