Tips and Tricks for the ABAP® Programming Language
ABAP® Program – Y9030007 – DELETE Data from table INDX
A small data base application with “IMPORT”, “EXPORT” and “DELETE” The following 3 reports belong together [Y9030005 until Y9030007 ]. It should be demonstrated that heterogeneous data e.g. from a subsystem, can be relatively simple transferred to the R/3(r) system and later administrated there.
Any data list (e.g. addresses, birthday, hobbies and so forth) is complemented with date and time and saved as a data cluster in the table INDX with the command “EXPORT …” . Through “IMPORT …” the data saved in the INDX are selected and displayed again. Here, any period of time can be selected on the basis of the time axis (DATE, TIME). Via “DELETE …” the possibility exists to delete no more required data from the respective cluster. The examples only use the field “TEXT1” as “useful information”, any other data contents can be used alternatively here in the reports.
Parameters:
The total keyword in the INDX consists of 22 bytes (in release 3.1), where 20 bytes are used. A time window can be used for the precise selection of an up/to area:
- MOVE P_KDNR TO KEY_VON+0(6). “e.g. customer number
- MOVE P_DATVON TO KEY_VON+6(8). “Date of
- MOVE P_TIMVON TO KEY_VON+14(6). “Time of
ABAP™-Source-Code
You can cut and paste the source code directly into the ABAP™-Workbench.
REPORT Y9030007 LINE-SIZE 130. "Release 3.1G, 4.5A ************************************************************************ * Copyright (c) 1999 by CT-Team, 33415 Verl, http://www.ct-software.com * * You can use or modify this report for your own work as long * as you don't try to sell or republish it. * In no event will the author be liable for indirect, special, * Incidental, or consequental damages (if any) arising out of * the use of this report. * ************************************************************************ BREAK-POINT. *####################################################################### * 1. Attention the report deletes data from the INDX DB (Cluster YT) * * 2. The deletion will be carried out if the paramter (P_DELETE) * is settet to "J" ("N" is default). On "N" only the keys which * would be deleted are displayed (but not deleted). *####################################################################### MOVE: 'TESTREPORT for "SELECT * FROM etab" with "D E L E T E" ' TO SY-TITLE. ************************************************************************ * PARAMETERS: P_KDNVON(6) TYPE C DEFAULT '100007', "= Customer-VON P_KDNBIS(6) TYPE C DEFAULT '100007', "= Customer-BIS *................Zeitachse-Von.......................................... P_DATVON TYPE D DEFAULT '19950101', "jhjjmmtt !! P_TIMVON TYPE T DEFAULT '000001', *................Zeitachse-Bis.......................................... P_DATBIS TYPE D DEFAULT SY-DATUM, "jhjjmmtt !! P_TIMBIS TYPE T DEFAULT SY-UZEIT, *................DELETE-Schalter ....................................... P_DELETE TYPE C DEFAULT 'N'. ************************************************************************ * TABLES: INDX. ************************************************************************ *....................................................................... DATA: BEGIN OF KEY_VON, "key CT-CLUSTER of TEXTVON(22), END OF KEY_VON. *....................................................................... DATA: BEGIN OF KEY_BIS, "key CT-CLUSTER up to TEXTBIS(22), END OF KEY_BIS. *...............The INDX has primary key of 22 chars ................... DATA: KEY_LOW(22) VALUE '0000000000000000000000'. DATA: KEY_HIGH(22) VALUE '9999999999999999999999'. *....................................................................... ************************************************************************ *//////////////////////////////////////////////////////////////////////* ************* Main Section ******************* *//////////////////////////////////////////////////////////////////////* * END-OF-SELECTION. PERFORM KEY-FUELLEN-INDX-LESEN. PERFORM LESEN-INDX. *####################################################################### * To delete a cluster "bunch of data" from the INDX, * the index record must be read (with "SELECT .."). * If the index was found, the corresponding cluster can be * deleted with "DELETE INDX" . *####################################################################### SKIP. *//////////////////////////////////////////////////////////////////////* ************* Subroutines ******************* *//////////////////////////////////////////////////////////////////////* * ************************************************************************ * Preparing the key to read from the INDX * ************************************************************************ FORM KEY-FUELLEN-INDX-LESEN. "the KEY of INDX will be filled * *.......... Key fuellen ............................................. MOVE KEY_LOW TO KEY_VON. "All 0 MOVE P_KDNVON TO KEY_VON+0(6). "Text number from MOVE P_DATVON TO KEY_VON+6(8). "Date from MOVE P_TIMVON TO KEY_VON+14(6). "Date from *....................................................................... MOVE KEY_HIGH TO KEY_BIS. "All 9 MOVE P_KDNBIS TO KEY_BIS+0(6). "Text number until MOVE P_DATBIS TO KEY_BIS+6(8). "Date until MOVE P_TIMBIS TO KEY_BIS+14(6). "Time until * ENDFORM. ************************************************************************ *- THE FILE INDX IS SEQUENTIALLY READED -* ************************************************************************ FORM LESEN-INDX. *......................................................................* SELECT * FROM INDX WHERE RELID EQ 'YT' AND SRTFD BETWEEN KEY_VON AND KEY_BIS ORDER BY PRIMARY KEY. "ascending please * Commit work. "when deleting mass data IF P_DELETE EQ 'J'. *####################################################################### PERFORM DELETE-INDX. *####################################################################### ELSE. WRITE: / 'Key found, ''P_DELETE'' auf ''N'' '. WRITE: / 'If really delete then set ''P_DELETE'' to ''J'' ' COLOR 6, INDX-SRTFD. ENDIF. * ENDSELECT. * IF INDX-SRTFD IS INITIAL. WRITE: /1 'No data available in the INDX , RELID/Key: YT'. WRITE: /10 'KEY_VON:', KEY_VON, 'KEY_BIS:', KEY_BIS. ENDIF. * ENDFORM. ************************************************************************ * Deletion of the Cluster YT from the INDX * ************************************************************************ FORM DELETE-INDX. * *####################################################################### * For the Deletion of cluster "SELECT SINGLE ..." is used, * here only the cluster specified in the key should be deleted. *####################################################################### SELECT SINGLE FOR UPDATE * FROM INDX "= Locking for other USER WHERE RELID EQ 'YT' AND SRTFD EQ INDX-SRTFD AND SRTF2 EQ INDX-SRTF2. DELETE INDX. * "only the current key of the INDX will be deleted * " not the whole DB (... all-clear ...) IF SY-SUBRC EQ 0. WRITE: / 'Clusterdata YT from INDX will be deleted', 'Key:', INDX-SRTFD. ELSE. PERFORM FEHLER-BEIM-DELETE. ENDIF. * ENDFORM. ************************************************************************ * Error message, if YT is not available in the INDX * ************************************************************************ FORM FEHLER-BEIM-DELETE. * WRITE: / '*****************************************************'. WRITE: / 'ERROR WHILE DELETING DB INDX(YT): '. WRITE: / ' KEY: ', INDX. WRITE: / '*****************************************************'. ENDFORM. ************************************************************************ *************** END OF PROGRAM **************************************** ************************************************************************