Tips and Tricks for the ABAP® Programming Language

Y9030006: IMPORT 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 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 *************************************
pixelstats trackingpixel