Tips and Tricks for the ABAP® Programming Language

Y9020010: Construction of an internal table with “APPEND itab”

In this simple report example a small data base is created for an internal table. After the declaration of the internal table T1, the construction of the table data is undertaken in a subroutine. In a DO-loop, the table header line of T1 is filled with continuously modified values. After that, the header line is added to the data base with “APPEND T1”.

ABAP-Source-Code

You can cut and paste the source code directly into the ABAP-Workbench.

REPORT Y9020010 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.
*//////////////////////////////////////////////////////////////////////*
 MOVE: 'Creation of an internal table with ''APPEND itab ''      '
        TO SY-TITLE.
*//////////////////////////////////////////////////////////////////////*
************************************************************************
***************         Interne Tabellen          **********************
*
 DATA: BEGIN OF T1 OCCURS 30,
        ARTIKELNR(6)  TYPE N,                    "Artikelnummer
        ART_BEZ(16)   TYPE C,                    "Artikelbezeichnung
        ART_GRUPPE(4) TYPE C,                    "Artikelgruppe
        LAGERNR(2)    TYPE P,                    "Lagernummer
        ART_MENGE     TYPE I,                    "Artikelmenge
       END OF T1.
*
 DATA: Z_FELD1(3) TYPE N.                        "Zwischenfeld1
************************************************************************
*--------------------------  Main Section  ----------------------------*
************************************************************************
 PERFORM TABELLENAUFBAU-1.
 PERFORM DISPLAY-T1.
*
************************************************************************
*-------------------------    Subroutines   ---------------------------*
************************************************************************
*
************************************************************************
*           Here the table T1 is filled with 10 elements               *
************************************************************************
 FORM TABELLENAUFBAU-1.
*
  WRITE: /5 'Step 1: Create the internal table T1      ' COLOR 5.
  ULINE. SKIP 2.
*.......................................................................
  DO 10 TIMES.
    ADD 5 TO T1-ARTIKELNR.
    MOVE 'Schuhgroesse ' TO T1-ART_BEZ.
    ADD 3 TO Z_FELD1.
    MOVE Z_FELD1 TO T1-ART_BEZ+13(3).
    ADD 2 TO T1-ART_GRUPPE.
    ADD 8 TO T1-LAGERNR.
    ADD 33 TO T1-ART_MENGE.
*#######################################################################
    APPEND T1.
*#######################################################################
  ENDDO.
*
 ENDFORM.
************************************************************************
*           The content of the table t1 will be displayed              *
************************************************************************
 FORM DISPLAY-T1.
*
  WRITE: /5 'Step 2: The content of T1 will be displayed : ' COLOR 5.
  ULINE. SKIP 2.
*.......................................................................
* ................... Head line (only a test) ..........................
   WRITE: /3 'Warennummer',
          16 'Bezeichnung',
          33 'ArtGrp',
          41 'LOrt',
          51 'Warenmenge'.
          SKIP. ULINE.
*
* ...................... Display of table T1 ...........................
   MOVE SPACE TO T1.
   LOOP AT T1.
     WRITE: /8 T1-ARTIKELNR,
            16 T1-ART_BEZ,
            36 T1-ART_GRUPPE,
            42 T1-LAGERNR,
            51 T1-ART_MENGE.
   ENDLOOP.
*
 ENDFORM.
************************************************************************
********************* END OF PROGRAM ***********************************
************************************************************************
pixelstats trackingpixel