06/08/2010

Insert Data into Hashed Table


REPORT ZRRSAMPLE.

TYPES: BEGIN OF t_foo,
field1 TYPE char2,
field2 TYPE char2,
field3 TYPE char2,
field4 TYPE i,
END OF t_foo.

DATA: lt_foo TYPE HASHED TABLE OF t_foo WITH UNIQUE KEY field1 field2 field3.

DATA: ls_foo LIKE LINE OF lt_foo.

FIELD-SYMBOLS: LIKE LINE OF lt_foo.

* Must assign it to use it.
ASSIGN ls_foo TO .

CLEAR .

-field1 = 'AB'.
-field2 = 'CD'.
-field3 = 'EF'.
-field4 = '2'.

INSERT INTO TABLE lt_foo.

CLEAR .

-field1 = 'AB'.
-field2 = 'CD'.
-field3 = 'EF'.
-field4 = '2'.

INSERT INTO TABLE lt_foo.

IF sy-subrc NE 0.

WRITE:/ ' this is the duplidate key'.

ENDIF.

Nenhum comentário:

Postar um comentário