Tips and Tricks for the ABAP® Programming Language

Y9030003: A common area for different information

Possibly a “small macro” called ‘FILL1’ never crossed your way …

For test purposes or “TRANSFER WORK1 TO DSN …” or “APPEND WORK1” or … it is sometimes reasonable to move several different information in one single output area. One solution consists e.g. in the combination of “WRITE …” and “CONDENSE …” in connection with “DEFINE …”.

ABAP-Source-Code

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

REPORT Y9030003 LINE-SIZE 150.       "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: 'A common output area for different fields'
        TO SY-TITLE.
*//////////////////////////////////////////////////////////////////////*
************************************************************************
***************       Declaration of variables    **********************
*
 DATA WORKFELD1(150) TYPE C.
 DATA CFELD2(8) TYPE C VALUE 'XXYYZZWW'.
 DATA NFELD3(6) TYPE N VALUE '123456'.
************************************************************************
*//////////////////////////////////////////////////////////////////////*
*************               Main Section             *******************
*//////////////////////////////////////////////////////////////////////*
*
 PERFORM BISHERIGE-LOESUNG.
 PERFORM CONDENSE-MIT-DEFINE.
*
*//////////////////////////////////////////////////////////////////////*
*************                Subroutines             *******************
*//////////////////////////////////////////////////////////////////////*
************************************************************************
*                 The conventional way ....
************************************************************************
 FORM BISHERIGE-LOESUNG.
*
  BREAK-POINT.
  ULINE. SKIP 2.
  WRITE: /5 'Step 1: Here you can ''calculate and write''' COLOR 5.
*.......................................................................
  MOVE 'Content of CFELD2:'
                   TO WORKFELD1+0(18).
  MOVE CFELD2      TO WORKFELD1+19(8).
  MOVE ', NFELD3:' TO WORKFELD1+28(9).
  MOVE NFELD3      TO WORKFELD1+38(6).
  MOVE '*****'     TO WORKFELD1+45(5).
  MOVE SY-UNAME    TO WORKFELD1+51(12).
  MOVE SY-DATUM    TO WORKFELD1+64(8).
  MOVE SY-UZEIT    TO WORKFELD1+73(6).
  MOVE SY-REPID    TO WORKFELD1+82.
*
* Z.B.
  WRITE: /1 WORKFELD1.
* oder TRANSFER WORKFELD1 TO DSN.
*
 ENDFORM.
************************************************************************
*  Better:   For test purposes look at the following routine
************************************************************************
 FORM CONDENSE-MIT-DEFINE.
*
 BREAK-POINT.
  ULINE. SKIP 2.
  WRITE: /5 'Step 2: Alternative  solution     ' COLOR 6.
************************************************************************
*#######################################################################
  DEFINE FILL1.                          "a small makro ...
    WRITE &1 TO WORKFELD1+100.
*   MOVE &1 TO WORKFELD1+100.  "alternative, e.g. no formatting
    CONDENSE WORKFELD1.
  END-OF-DEFINITION.
************************************************************************
*#######################################################################
  FILL1:
     'Content of CFELD2:', CFELD2, ', NFELD3:', NFELD3, '*****',
     SY-UNAME, SY-DATUM, SY-UZEIT, SY-REPID.
     WRITE: /1 WORKFELD1.
     CLEAR WORKFELD1.
*......................................................................
  FILL1:
  'Here your operation system:', SY-OPSYS, ';','The computer:', SY-HOST.
   WRITE: /1 WORKFELD1.
   CLEAR WORKFELD1.
*.......................................................................
  FILL1:
   'SY-TITLE:', SY-TITLE(30), ',', 'TRANSFER v1 also works            '.
    WRITE: /1 WORKFELD1.
*
 ENDFORM.
************************************************************************
************************************************************************
******************* END OF PROGRAM *************************************