[ABAP] – Dynamic Table Collect

11 10 2010

Hi guys,
For my first article, a little tools for collect a table, based on a dynamic collect field value, contained in a Database Table.

set_aggregazione-method

Check it out the method:

DECLARATION:
class-methods SET_AGGREGAZIONE_DYNAMIC
importing
!IT_COLLECT_FIELD type ANY TABLE
!IT_POSITION type ANY TABLE
exporting
!EV_ESITO type C
!ET_POSITION type ANY TABLE .

Implementation:

METHOD set_aggregazione_dynamic.

DATA: lv_tabix_d       TYPE syst-tabix,
lt_position_type TYPE REF TO data.
FIELD-SYMBOLS: <lt_collect_field> TYPE ANY TABLE,
<ls_collect_field> TYPE ANY,
<ls_position_s>    TYPE ANY,
<ls_position_d>    TYPE ANY,
<lt_position>      type STANDARD TABLE.
*
FIELD-SYMBOLS: <lfs_value1> TYPE ANY.
DATA: lv_key1(40) TYPE c VALUE ‘HKONT’,
lv_value1(40) TYPE c VALUE ‘HKONT’.
*
ASSIGN it_collect_field TO <lt_collect_field>.
CREATE DATA lt_position_type LIKE it_position.
ASSIGN lt_position_type->* to <lt_position>.

LOOP AT <lt_collect_field> ASSIGNING <ls_collect_field>.

lv_key1 = <ls_collect_field>.
LOOP AT it_position ASSIGNING <ls_position_s>.
ASSIGN COMPONENT lv_key1 OF STRUCTURE <ls_position_s> TO <lfs_value1>.
READ TABLE <lt_position> ASSIGNING <ls_position_d> WITH KEY (lv_key1) = <lfs_value1>.
IF sy-subrc NE 0.  “Insert
APPEND <ls_position_s> TO <lt_position>.
ELSE.   “Collect
lv_tabix_d = sy-tabix.
MODIFY <lt_position> FROM <ls_position_d> INDEX lv_tabix_d.
ENDIF.
ENDLOOP.
ENDLOOP.

*
IF NOT <lt_position> IS INITIAL.
et_position[] = <lt_position>.
ev_esito = ga_esito_positivo.
ELSE.
ev_esito = ga_esito_negativo.
ENDIF.

ENDMETHOD.

Annunci

Azioni

Information

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...




%d blogger hanno fatto clic su Mi Piace per questo: