Tips and Tricks for the ABAP® Programming Language

Y9030013: A macro (DEFINE …) – Definition and processing int. table

A small macro should show that these interesting control statements can be inserted in quite different ways. In this example only scratches the surface of the macro possibilities.

DEFINE VARTAB

  • &1 = The table name of the internal table is determined.
  • &2 = A field name with the length 30 of the type C.
  • &3 = The table structure is specified by the 3rd parameter.
  • E.g. of a macro call: “VARTAB IT100 FIELDNAME T100.”

DEFINE FILLTAB1

  • MOVE &1 TO &2+30. = The content of source field &1 moved to the target field (&2+30)
  • MOVE &3 TO &2-FIELDNAME. = The &2 parameter will be connected with “FIELDNAME”.
  • APPEND &2. = The internal table &2 will be filled. E.g. of a macro call: “FILLTAB1 T100 IT100 ‘T100 …’.”

The parameters of the call of FILLTAB1 must refer to the parameters used in VARTAB call. Consequently the ABAP interpreter “must already know” the real field names of the internal table when calling the macro FILLTAB. The internal table is only effective on internal level. The same memory area is allocated for both tables.

ABAP-Source-Code

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

REPORT Y9030013 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.
* only use with the CT-DEBUG_Simulator
************************************************************************
*BREAK-POINT.
*//////////////////////////////////////////////////////////////////////*
 MOVE: 'Read tables and use a VARTAB (DEFINE-Macro)'
        TO SY-TITLE.
*//////////////////////////////////////////////////////////////////////*
***************         External tables           **********************
 TABLES: YT100.
*
***************         Macro definitions         **********************
DEFINE VARTAB.
  DATA: BEGIN OF &1 OCCURS 0.
  DATA: &2(30) TYPE C.
     INCLUDE STRUCTURE &3.
  DATA: END OF &1.
 END-OF-DEFINITION.
*
 DEFINE FILLTAB1.
   MOVE &1 TO &2+30.
   MOVE &3 TO &2-FIELDNAME.
   APPEND &2.
 END-OF-DEFINITION.
*
*//////////////////////////////////////////////////////////////////////*
*************            -  Main Section             *******************
*//////////////////////////////////////////////////////////////////////*
*
 PERFORM READ-DISPLAY-YT100.
*
*//////////////////////////////////////////////////////////////////////*
*************                Subroutines             *******************
*//////////////////////////////////////////////////////////////////////*
************************************************************************
*           Read and display a few rows of T100
************************************************************************
 FORM READ-DISPLAY-YT100.
*
  ULINE. SKIP 2.
  WRITE: /5 'Step 1: Read and display IT100 ' COLOR 5.
*.......................................................................
*
  VARTAB IT100 FIELDNAME YT100.                                  "macro
*.......................................................................
  SELECT * FROM YT100
    UP TO  50 ROWS
    WHERE ZSPRSL EQ 'E'
     AND  ZARBGB GT 'Z10'.
*
      FILLTAB1 YT100 IT100 'YT100                         '.   "macro
*
  ENDSELECT.
*#######################################################################
      WRITE: /1 'ZSPRSL',
              8 'ZARBGB',
             29 'ZMSGNR',
             36 'Messagetext1',
             77 'Messagetext2'.
      ULINE. SKIP.
*
   LOOP AT IT100.
      WRITE: /1 IT100-ZSPRSL,
              8 IT100-ZARBGB,
             29 IT100-ZMSGNR,
             36(40) IT100-ZTEXT1,
             77(40) IT100-ZTEXT2.
   ENDLOOP.
*
 ENDFORM.
************************************************************************
************************************************************************
******************* END OF PROGRAM *************************************
pixelstats trackingpixel