This is the code I use for my BDC for Component Allocation in Routing
Basically this code page down as long as the item is not in the page yet.
If you want to make your BDC Data Table Shorter, you can uncomment the v_first_page_sel section.
DATA : v_page_top(5) type c default '0',
v_int_page_top type i,
v_field_name(20) type c,
v_first_page_sel type c default 'X'.
DESCRIBE TABLE t_item LINES v_total_item.
Loop at t_item into w_item.
DO.
v_page_index = w_item-index - v_page_top.
IF v_page_index<= 15. "If the
EXIT. "The page have displayed the item so proceed with the process
ELSE.
v_page_top = v_page_top + 15. "The counter to count where last of previous page is
MOVE v_page_top TO v_int_page_top.
IF v_int_page_top > ( v_total_item - 15 ). "If the counter exceed the last page, adjust the counter
v_page_top = v_total_item - 15.
ENDIF.
PERFORM bdc_dynpro USING 'SAPLCMDI' '1000'.
PERFORM bdc_field USING 'BDC_CURSOR' 'STPOB-DUMPS1(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=P+'.
* v_page_first_sel = 'X'.
ENDIF.
ENDDO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' "To make sure index always 2 Digits
EXPORTING INPUT = v_page_index
IMPORTING OUTPUT = v_page_index.
* IF v_page_first_sel = 'X'.
PERFORM bdc_dynpro USING 'SAPLCMDI' '1000'.
PERFORM bdc_field USING 'BDC_CURSOR' 'STPOB-DUMPS1(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
* v_page_first_sel = ' '.
* ENDIF.
CONCATENATE 'RC27X-FLG_SEL(' v_page_index ')' INTO v_field_name.
PERFORM bdc_field USING v_field_name 'X'.
ENDLOOP.
The concept of this thing is the item per page if 15 (in my case of default screen, default screen parameter for the transaction option is a must to avoid errors)
The 16th item is in the 2nd page index 1. so we must page down then select the first item
and so on.
Then for the last page, your last item will be in the 15th index, so you must adjust the counter of top page to the last item
This code only works if the item was sorted by index ascending.
Hope this help,
Please let me know if there are some errors because i edited the code in this post
Regards,
Wendi Gunawan