Can Reach program ( 1 d arrray)

 data str_abap_rocks(100) value 'CanRachProgram'. 

WRITE: str_abap_rocks.

data:lt_int type table of i,

    lt_ival type table of i,

    lv_ind type i value 1,

    lv_temp type i,

    lv_target type i value 7.


lt_ival = VALUE #( ( 3 ) ( 4 ) ( 7 ) ).

lt_int = VALUE #( ( 0 ) ).


*perform init_array using lt_int lv_target.

*form init_array using lt_int type table of i lv_target type i.


do lv_target times.

lv_temp = lt_int[ 1 ].

append lv_temp to lt_int.

enddo.

*endform.

*perform can_reach using lt_int lt_ival lv_target.

*form can_reach using lt_int type table of i lt_ival type table of i lv_target type i.


loop at lt_ival into data(wa_ival).

if ( wa_ival <= lv_target ).

lt_int[ wa_ival ] = 1.

endif.

endloop.


while lv_ind <= lv_target.

loop at lt_ival into wa_ival.

if ( wa_ival + lv_ind <= lv_target and lt_int[ lv_ind ] > 0 )

lt_int[ wa_ival + lv_ind ] = 1.

endif.

endloop.

lv_ind = lv_ind + 1.

endwhile.

*endform.

write: lt_int[ lv_target ].

Comments

Popular posts from this blog

Fibonacci - Tabulated 1d array manipulation

Bubble Sort