Posted: Sun Nov 04, 2007 2:59 pm Post subject: EXPORT, IMPORT, DELETE of Data in table INDX
Report Y9030005 until Y9030007 - A small data base application with "IMPORT", "EXPORT" and "DELETE" The following 3 reports belong together. 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
EXPORT of Data to table INDX
Code:
REPORT Y9030005 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.
*
************************************************************************
MOVE: 'TESTREPORT for "SELECT * FROM etab" with "EXPORT" '
TO SY-TITLE.
************************************************************************
*
PARAMETERS: P_KDNR(6) TYPE C DEFAULT '100007', "= customer ID
*................Time line from.........................................
P_DATVON TYPE D DEFAULT '19960101', "jhjjmmtt !!
P_TIMVON TYPE T DEFAULT '000001',
*................Time line until........................................
P_DATBIS TYPE D DEFAULT '20011231', "jhjjmmtt !!
P_TIMBIS TYPE T DEFAULT '234500',
*................Only text examples.....................................
P_EXPORT TYPE C DEFAULT 'J',
TEXT1(40) TYPE C DEFAULT
'That should be only be a T e s t'.
************************************************************************
*
TABLES: INDX.
************************************************************************
*--DB-area and work area must be of the same structure ------*
* e.g. fields, field string, table
DATA: BEGIN OF TEXTINDX, "DB-area of INDX
UZEIT LIKE SY-UZEIT, " = 6 Bytes
TEXT(80) TYPE C, " = 80 Bytes
END OF TEXTINDX.
*.......................................................................
DATA: BEGIN OF INP1, "work area
UZEIT LIKE SY-UZEIT, " = 6 Bytes
TEXT(80) TYPE C, " = 80 Bytes
END OF INP1.
************************************************************************
*.......................................................................
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.
*............... INDX has a primary key of 22 digits....................
DATA: KEY_LOW(22) VALUE '0000000000000000000000'.
DATA: KEY_HIGH(22) VALUE '9999999999999999999999'.
*.......................................................................
DATA: BEGIN OF IMPKEY, "Import key INDX
SRTFD LIKE INDX-SRTFD,
SRTF2 LIKE INDX-SRTF2,
END OF IMPKEY.
*................. Clear speration of the keys would be better..........
DATA: BEGIN OF EXPKEY, "Export key INDX
SRTFD LIKE INDX-SRTFD,
SRTF2 LIKE INDX-SRTF2,
END OF EXPKEY.
************************************************************************
****************** work fields ***************
DATA: INDX_VORHANDEN(1) TYPE N. "1 = content available
************************************************************************
*//////////////////////////////////////////////////////////////////////*
************* Main Section *******************
*//////////////////////////////////////////////////////////////////////*
*
END-OF-SELECTION.
*#######################################################################
* 1. In the database "INDX" data (or text) up to a length of today
* 2886 bytes per key can be inserted
* 2. The key length of the DB "INDX" is 22 chars in total
* which can be expanded with an the addition field (INDX-SRTF2)
*#######################################################################
PERFORM KEY-FUELLEN-INDX-LESEN.
PERFORM LESEN-INDX.
*................. If a dataset should be exported .................
IF P_EXPORT EQ 'J'.
PERFORM KEY-FUELLEN-INDX-EXPORT.
PERFORM UEBERNAHME-TEXT.
PERFORM EXPORT-INDX.
*#######################################################################
* The generated data will now transfered to the INDX
* The data wihtin int cluster can be organized in a variable way.
* Important: The EXPORT and the IMPORT command must use the
* same structure.
*#######################################################################
ENDIF.
*
************************************************************************
************************************************************************
*//////////////////////////////////////////////////////////////////////*
************* Subroutines *******************
*//////////////////////////////////////////////////////////////////////*
*
************************************************************************
* Format the key to read from the INDX *
************************************************************************
FORM KEY-FUELLEN-INDX-LESEN. " fill the KEY of INDX
*
*.......... Fill key .............................................
MOVE KEY_LOW TO KEY_VON. "all 0
MOVE P_KDNR TO KEY_VON+0(6). "Text number acc. to parameter
MOVE P_DATVON TO KEY_VON+6(8). "Date of acc. to parameter
MOVE P_TIMVON TO KEY_VON+14(6). "Time of acc. to parameter
*.......................................................................
MOVE KEY_HIGH TO KEY_BIS. "all 9
MOVE P_KDNR TO KEY_BIS+0(6). "Text number (s.o.)
MOVE P_DATBIS TO KEY_BIS+6(8). "Date of acc. to parameter
MOVE P_TIMBIS TO KEY_BIS+14(6). "Time of acc. to parameter
*
ENDFORM.
************************************************************************
*- THE FILE INDX WILL BE READ SEQUENTIELL -*
************************************************************************
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. "if mass data should be processed
*
MOVE INDX-SRTFD TO IMPKEY-SRTFD .
MOVE INDX-SRTF2 TO IMPKEY-SRTF2 .
*#######################################################################
PERFORM LESENINDX-IMPORT.
*#######################################################################
IF INDX_VORHANDEN EQ 1.
CLEAR INDX_VORHANDEN.
PERFORM DRUCKEN-INDX. "print out the found text
ELSE.
ENDIF.
*
ENDSELECT.
IF INDX-SRTFD IS INITIAL.
WRITE: /1 'No data'No data in INDX available, RELID/Key: YT'.
WRITE: /10 'KEY_VON:', KEY_VON, 'KEY_BIS:', KEY_BIS.
ENDIF.
*
ENDFORM.
************************************************************************
* Read the Clusters YT of the DB INDX *
************************************************************************
FORM LESENINDX-IMPORT.
*
IMPORT TEXTINDX TO INP1 FROM DATABASE INDX(YT) ID IMPKEY.
IF SY-SUBRC EQ 0.
INDX_VORHANDEN = 1.
ELSE.
PERFORM FEHLER-BEIM-IMPORT.
ENDIF.
*
ENDFORM.
************************************************************************
* Error message, if the Cluster YT is not in INDX *
* .. although Index set display it. (= DB not consistent)
************************************************************************
FORM FEHLER-BEIM-IMPORT.
*= rare case
WRITE: / '*****************************************************'.
WRITE: / 'ATTENTION, ERROR THROUGH READING INDX IN CLUTSER YT:'.
WRITE: / ' KEY: ', IMPKEY-SRTFD, IMPKEY-SRTF2.
WRITE: / ' DB INDX (Cluster YT) not consistent '.
WRITE: / '*****************************************************'.
STOP.
ENDFORM.
************************************************************************
* Print (not prepared) form Cluster YT out of INDX *
************************************************************************
FORM DRUCKEN-INDX.
*
WRITE: /1 'Key:', INDX-SRTFD COLOR 5.
WRITE: /1 'Data value:', INP1-UZEIT, INP1-TEXT.
ULINE.
ENDFORM.
************************************************************************
* Create key for the Export in INDX *
************************************************************************
FORM KEY-FUELLEN-INDX-EXPORT. "Determine key for EXPORT
*
MOVE KEY_LOW TO EXPKEY-SRTFD. "all 0
MOVE P_KDNR TO EXPKEY+0(6). "text number from parameter
MOVE SY-DATUM TO EXPKEY+6(8). "todays date
MOVE SY-UZEIT TO EXPKEY+14(6). "current time
MOVE 0 TO EXPKEY-SRTF2. "additional key Zusatzkey is 0
*.......................................................................
ENDFORM.
************************************************************************
* Arbitrary text can be placed in the data area ... *
************************************************************************
FORM UEBERNAHME-TEXT.
*
MOVE SY-UZEIT TO INP1-UZEIT.
MOVE TEXT1 TO INP1-TEXT.
*
ENDFORM.
************************************************************************
* EXPORT OF INP1 OVER TEXTINDX IN DB INDX (YT) *
************************************************************************
FORM EXPORT-INDX.
*
LOCAL INDX. "The EXPORT changes only the local copy of INDX.
"After the form is left, the origin will be reestablished
"The source key will be used for a possible forward
"reading with SELECT.
*.......................................................................
MOVE INP1 TO TEXTINDX.
EXPORT TEXTINDX TO DATABASE INDX(YT) ID EXPKEY.
*. . . . . . . . . . . . . . . . . . . . . . . .*
IF SY-SUBRC NE 0.
WRITE: / 'Attention, Error on EXPORT in INDX'.
WRITE: / 'KEY:', EXPKEY.
ELSE.
WRITE: / 'The export was carried out:' COLOR 6.
PERFORM DRUCKEN-INDX.
ENDIF.
*......................................................................*
*
ENDFORM.
Report Y9030006: EXPORT of Data to table INDX
Code:
REPORT Y9030006 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.
*
************************************************************************
MOVE: 'TESTREPORT for "SELECT * FROM etab" with "IMPORT" '
TO SY-TITLE.
************************************************************************
PARAMETERS: P_KDNR(6) TYPE C DEFAULT '100007', "= Text number
*................Time line from ........................................
P_DATVON TYPE D DEFAULT '19950101', "jhjjmmtt !!
P_TIMVON TYPE T DEFAULT '000001',
*................Time line to ..........................................
P_DATBIS TYPE D DEFAULT '20011231', "jhjjmmtt !!
P_TIMBIS TYPE T DEFAULT '234500'.
************************************************************************
TABLES: INDX.
************************************************************************
*-- DB-area and work area must be of the same structure ------*
* e.g. fields, field string, table
DATA: BEGIN OF TEXTINDX, "DB area auf der INDX
UZEIT LIKE SY-UZEIT, " = 6 Bytes
TEXT(80) TYPE C, " = 80 Bytes
END OF TEXTINDX.
*.......................................................................
DATA: BEGIN OF INP1, "work area
UZEIT LIKE SY-UZEIT, " = 6 Bytes
TEXT(80) TYPE C, " = 80 Bytes
END OF INP1.
************************************************************************
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.
*............... INDX has a primary key of 22 digits....................
DATA: KEY_LOW(22) VALUE '0000000000000000000000'.
DATA: KEY_HIGH(22) VALUE '9999999999999999999999'.
*.......................................................................
DATA: BEGIN OF IMPKEY, "Import-key INDX
SRTFD LIKE INDX-SRTFD,
SRTF2 LIKE INDX-SRTF2,
END OF IMPKEY.
************************************************************************
****************** work fields ***************
*
DATA: INDX_VORHANDEN(1) TYPE N. "1 = content available
************************************************************************
*//////////////////////////////////////////////////////////////////////*
************* - Main Section *******************
*//////////////////////////////////////////////////////////////////////*
*
END-OF-SELECTION.
*#######################################################################
* 1. In the database "INDX" data (or text) up to a length of today
* 2886 bytes per key can be inserted
* 2. The key length of the DB "INDX" is 22 chars in total
* which can be expanded with an the addition field (INDX-SRTF2)
*#######################################################################
PERFORM KEY-FUELLEN-INDX-LESEN.
PERFORM LESEN-INDX.
*//////////////////////////////////////////////////////////////////////*
************* Subroutines *******************
*//////////////////////////////////////////////////////////////////////*
*
************************************************************************
* Format the key to read from INDX *
************************************************************************
FORM KEY-FUELLEN-INDX-LESEN. " fill the KEY of INDX
*
*.......... Key fuellen .............................................
MOVE KEY_LOW TO KEY_VON. "initialize all with 0
MOVE P_KDNR TO KEY_VON+0(6). "Text number behind
MOVE P_DATVON TO KEY_VON+6(8). "Date is placed behind
MOVE P_TIMVON TO KEY_VON+14(6). "Time is placed behind
*.......................................................................
MOVE KEY_HIGH TO KEY_BIS. "initialize all with 9
MOVE P_KDNR TO KEY_BIS+0(6). "Text number behind
MOVE P_DATBIS TO KEY_BIS+6(8). "Date is placed behind
MOVE P_TIMBIS TO KEY_BIS+14(6). "Time is places behind
*
ENDFORM.
************************************************************************
*- THE FILE INDX WILL BE READ SEQUENTIELL -*
************************************************************************
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. "in the case of mass data
*
MOVE INDX-SRTFD TO IMPKEY-SRTFD .
MOVE INDX-SRTF2 TO IMPKEY-SRTF2 .
*#######################################################################
PERFORM LESENINDX-IMPORT. "Import of data
*#######################################################################
IF INDX_VORHANDEN EQ 1.
CLEAR INDX_VORHANDEN.
PERFORM DRUCKEN-INDX. "print out the found text
ELSE.
ENDIF.
*
ENDSELECT.
*
IF INDX-SRTFD IS INITIAL.
WRITE: /1 'No data in INDX available, RELID/Key: YT'.
WRITE: /10 'KEY_VON:', KEY_VON, 'KEY_BIS:', KEY_BIS.
ENDIF.
*
ENDFORM.
************************************************************************
* Read the Clusters YT of the DB INDX *
************************************************************************
FORM LESENINDX-IMPORT.
*
IMPORT TEXTINDX TO INP1 FROM DATABASE INDX(YT) ID IMPKEY.
IF SY-SUBRC EQ 0.
INDX_VORHANDEN = 1.
ELSE.
PERFORM FEHLER-BEIM-IMPORT.
ENDIF.
*
ENDFORM.
************************************************************************
* Error message, if the Cluster YT is not in INDX *
************************************************************************
FORM FEHLER-BEIM-IMPORT.
*
WRITE: / '*****************************************************'.
WRITE: / 'ATTENTION, ERROR WHILE READING INDX IN CLUSTER YT: '.
WRITE: / ' KEY: ', IMPKEY-SRTFD, IMPKEY-SRTF2.
WRITE: / '*****************************************************'.
STOP.
ENDFORM.
************************************************************************
* Print a not formated form of Cluster YT out of INDX *
************************************************************************
FORM DRUCKEN-INDX.
*
WRITE: /1 'Key:', INDX-SRTFD.
WRITE: /1 'Data value:', INP1-UZEIT COLOR 5, INP1-TEXT COLOR 4.
ULINE.
ENDFORM.
************************************************************************
******************* END OF PROGRAM *************************************
Report Y9030007: ...... EXPORT of Data to table INDX
Code:
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 ****************************************
************************************************************************
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.