0% found this document useful (0 votes)
33 views3 pages

Delete 3

The DELETE statement in ABAP is used to delete lines from internal tables. It can delete a single line using the INDEX addition or multiple lines using the WHERE clause. When used with INDEX or WHERE, SY-SUBRC is set to 0 if deletion is successful. DELETE can also be used inside a loop to delete the current line.

Uploaded by

Vikram Bigamudre
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Delete 3

The DELETE statement in ABAP is used to delete lines from internal tables. It can delete a single line using the INDEX addition or multiple lines using the WHERE clause. When used with INDEX or WHERE, SY-SUBRC is set to 0 if deletion is successful. DELETE can also be used inside a loop to delete the current line.

Uploaded by

Vikram Bigamudre
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

DELETE is the statement to delete one or more lines from an ABAP Internal Table.

Use the INDEX addition to delete a single line. If we use the INDEX addition and the operation is successful, SY-SUBRC will be set to zero, the line with the corresponding index in the internal table will be deleted and the indexes of the subsequent lines will be reduced by one.
DELETE <internal table> [INDEX <index>].

We can also use the above DELETE statement without INDEX addition inside LOOP. Inside LOOP if we do not specify the INDEX, then the current loop line will be deleted. We can use the WHERE clause to delete single or multiple lines. All the lines that meet the logical condition will be deleted. If at least one line is deleted, the system sets SYSUBRC to 0, otherwise to 4.
DELETE <internal table> [FROM <n1>] [TO <n2>] [WHERE <condition>].

With WHERE clause we can also specify the lines between certain indices that we want to delete by specifying indexes in FROM and TO additions.
*--------------------------------------------------------------* *Data Types *--------------------------------------------------------------* TYPES: BEGIN OF ty_student, id(5) TYPE n, name(10) TYPE c, place(10) TYPE c, age TYPE i, END OF ty_student. *--------------------------------------------------------------* *Data Declaration *--------------------------------------------------------------* DATA: gwa_student TYPE ty_student. DATA: it TYPE TABLE OF ty_student. gwa_student-id gwa_student-name gwa_student-place gwa_student-age INSERT gwa_student gwa_student-id gwa_student-name gwa_student-place gwa_student-age INSERT gwa_student gwa_student-id gwa_student-name gwa_student-place gwa_student-age INSERT gwa_student = 1. = 'JOHN'. = 'London'. = 20. INTO TABLE it. = 2. = 'JIM'. = 'New York'. = 21. INTO TABLE it. = 3. = 'JACK'. = 'Bangalore'. = 20. INTO TABLE it.

gwa_student-id gwa_student-name gwa_student-place gwa_student-age INSERT gwa_student

= 4. = 'ROB'. = 'Bangalore'. = 22. INTO TABLE it.

WRITE:/ 'Values in IT before DELETE' COLOR 4. WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5, 37 'Age' COLOR 5. LOOP AT it INTO gwa_student. WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place, gwa_student-age. ENDLOOP. SKIP. WRITE:/ 'Values in IT after DELETE' COLOR 4. *Delete second line from IT DELETE it INDEX 2. WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5, 37 'Age' COLOR 5. LOOP AT it INTO gwa_student. WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place, gwa_student-age. ENDLOOP. SKIP. WRITE:/ 'Values in IT after DELETE using WHERE Clause' COLOR 4. *Delete entries from IT where place is Bangalore DELETE it WHERE place = 'Bangalore'. WRITE:/ 'ID' COLOR 5,7 'Name' COLOR 5, 18 'Place' COLOR 5, 37 'Age' COLOR 5. LOOP AT it INTO gwa_student. WRITE:/ gwa_student-id, gwa_student-name, gwa_student-place, gwa_student-age. ENDLOOP.

Output

You might also like