cancel
Showing results for 
Search instead for 
Did you mean: 

How to manage DO_PREPARE_OUTPUT

merveguel
Participant
0 Kudos


Hi All,


I added the following code into DO_PREPARE_OUTPUT method of my custom assigment block's IMPL class.

As you see, I am looking if it is the first time in the request for change order or not.

If it is first time in the order then I am gonna add lines into the assignment block otherwise I wont.

But when I click the standart 'Notes' assignment block in the same order and add a note and go back to the order page, the page triggers DO_PREPARE_OUTPUT again and it acts like its the first time in the order and adds 2 more lines too!! 


How can I handle if its second time in the same page but DO_PREPARE_OUTPUT thinks its the first time?

   if iv_first_time eq abap_true.

* Populate the lines of the assignment block

     me->mv_min_empty_lines = 2.


    else.

     me->mv_min_empty_lines = 2.

    

     endif.

Accepted Solutions (0)

Answers (2)

Answers (2)

merveguel
Participant
0 Kudos

Thank you Pural for your response.

I have changed the code with creating a global variable and using it as iv_first_time. It helped me to figure the problem out.

Regards,

Merve

navn_metts
Active Participant
0 Kudos

Hello,

Instead of using do_prepare_output method use do_init_context method.

This method will trigger only once.

Br,

Navn

merveguel
Participant
0 Kudos

Hello Naveen,

Thanks for your quick reply. I already tried in DO_INIT_CONTEXT method.

But the problem my sample code doesnt work in the method. The iterator throws error.

How should I change my code for DO_INIT_CONTEXT?

My sample code:

datalo_iterator     type ref to if_bol_bo_col_iterator,

          lo_current      type ref to if_bol_bo_property_access,

          rt_buttons      type crmt_thtmlb_button_t,

          it_zmodul       type table of zmodul,

          ls_zmodul       like line of it_zmodul,

          lv_lines        type i,

          ls_value        TYPE string.

   if iv_first_time eq abap_true.

     me->mv_min_empty_lines = 2.

     call method super->do_prepare_output

       exporting

         iv_first_time = iv_first_time.

     lo_iterator ?= me->typed_context->TABLE_CONTEXT_NODE->collection_wrapper->get_iterator( ).

     if lo_iterator is bound.

* Get the first line

       lo_current ?= lo_iterator->get_first( ).

       while lo_current is bound.

             lo_current->set_property_as_string( iv_attr_name = 'ZZABC'  iv_value = 'ABC'  ).

* Get the next line

             lo_current ?= lo_iterator->get_next( ).

       endwhile.

     endif.

   else.

     me->mv_min_empty_lines = 0.

     call method super->do_prepare_output

       exporting

         iv_first_time = abap_false.

   endif.

navn_metts
Active Participant
0 Kudos

Hello,

Can you show me what is the error you are getting in do_init_context method.

you can write below code in do_init_context method.

me->mv_min_empty_lines = 2.

lo_iterator ?= me->typed_context->TABLE_CONTEXT_NODE->collection_wrapper->get_iterator( ).

     if lo_iterator is bound.

* Get the first line

       lo_current ?= lo_iterator->get_first( ).

       while lo_current is bound.

             lo_current->set_property_as_string( iv_attr_name = 'ZZABC'  iv_value = 'ABC'  ).

* Get the next line

             lo_current ?= lo_iterator->get_next( ).

       endwhile.

     endif.


Br,

Navn

former_member541649
Active Participant
0 Kudos

Hi Merve,

I noticed you have the line:

if iv_first_time eq abap_true. in your do_init_context method - there is no such parameter in the method. Perhaps you copied the code here from do_prepare_output?


Also, try this for getting the iterator instance:

lo_iterator ?= me->typed_context->TABLE_CONTEXT_NODE->collection_wrapper-> if_bol_bo_col~get_iterator( ).


And the right placeholder for this code will be do_init_context.


Regards,

Parul