Tips and Tricks for the ABAP® Programming Language

Y9020024 – Relative Addressing of X fields (hexadecimal)

  1. Partial association In this example, three X-fields are associated to a field symbol with “ASSIGN”. Each of the three X-fields is associated partially only to the same field symbol.
  2. Relative addressing by numeric values In examples 1 – 3, constant numeric values are used for the addressing of the data field.
  3. Relative addressing by addressing fields In example 4, the addressing is modified continuously in a do-loop. The thus addressed part of the data field is associated to the field symbol and evaluated.
  4. Modification only in the addressed part If only a part of a data field was associated to a field symbol and the field symbol is used in a memory modifying command, the effects are constrained to the addressed part of the origin field.

ABAP-Source-Code

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

REPORT Y9020024 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: 'TESTREPORT for    "ASSIGN  XFELD+o(l)   TO  <fs1>"        '
        TO SY-TITLE.
*//////////////////////////////////////////////////////////////////////*
***************       Declaration of variables    **********************
 FIELD-SYMBOLS <FS1>.
 FIELD-SYMBOLS <FS2>.
*.......................................................................
 DATA: XFELD4(4)   TYPE X VALUE 'ABF13320'.
 DATA: XFELD8(8)   TYPE X VALUE '2020203132333030'.
 DATA: XFELD12(12) TYPE X VALUE '2020ABACBF323335BFCF'.
*
 DATA: OFFX    TYPE I VALUE 0.
 DATA: LENX    TYPE I VALUE 2.
*//////////////////////////////////////////////////////////////////////*
*************               Main Section             *******************
*//////////////////////////////////////////////////////////////////////*
*
 SKIP.
 ASSIGN XFELD4+1(3) TO <FS1>.
************************************************************************
*  At this place the last 3 bytes of the XFELD4 field will be assigned
*  to the field symbols <FS1>. The first byte can not be addressed
*  through <FS1> (e.g. changed).
************************************************************************
*.......................................................................
    BREAK-POINT.
    WRITE: / 'ASSIGN command with XFELD4 (Constant offset and length)'
              COLOR 6.
    PERFORM DISPLAY-XFELD USING XFELD4 'XFELD4'.
    ULINE. SKIP 2.
*-----------------------------------------------------------------------
 ASSIGN XFELD8+4(3) TO <FS1>.     "<-- Assign of variable to <FS1>
*.......................................................................
    BREAK-POINT.
    WRITE: / 'ASSIGN command with XFELD8 (Constant offset and length)'
              COLOR 6.
    PERFORM DISPLAY-XFELD USING XFELD8 'XFELD8'.
    ULINE. SKIP 2.
*-----------------------------------------------------------------------
 ASSIGN XFELD12+6(4) TO <FS1>.    "<-- Assign of variable to <FS1>
*.......................................................................
    BREAK-POINT.
    WRITE: / 'ASSIGN command with XFELD12 (Constant offset and length)'
              COLOR 6.
    PERFORM DISPLAY-XFELD USING XFELD12 'XFELD12'.
    ULINE. SKIP 2.
*-----------------------------------------------------------------------
*......................................................................
   BREAK-POINT.
   WRITE: / 'ASSIGN-Befehl (Offset and length as fields) mit XFELD12'
             COLOR 6.
     DO 5 TIMES.
       WRITE: /5 'DO loop count :' COLOR 5, SY-INDEX.
       ASSIGN XFELD12+OFFX(LENX) TO <FS1>.
       PERFORM DISPLAY-XFELD USING XFELD12 'XFELD12'.
       SKIP 4.
       ADD 2 TO OFFX.
     ENDDO.
*
*//////////////////////////////////////////////////////////////////////*
*************                Subroutines             *******************
*//////////////////////////////////////////////////////////////////////*
*
************************************************************************
*            Display of data fields and field symbols                  *
************************************************************************
 FORM DISPLAY-XFELD USING XFELD FNAME.
*
 WRITE: /10 'Content of', FNAME, ':', XFELD.
 PERFORM FELDEIGENSCHAFTEN USING XFELD.
*
 WRITE: /10 'Content of <FS1> :', <FS1>.
 PERFORM FELDEIGENSCHAFTEN USING <FS1>.
*-----------------------------------------------------------------------
 MOVE 'BF20' TO <FS1>.     "<-- The field symbols will be used
*-----------------------------------------------------------------------
 WRITE: /10 'MOVE ''BF20'' TO <FS1>'.
 ULINE.
*.......................................................................
 WRITE: /10 'Content of', FNAME, 35 ':', XFELD.
 WRITE: /10 'Content of <FS1>',  35 ':', <FS1>.
*.......................................................................
 ENDFORM.
************************************************************************
*    Determination of field properties (only for information)          *
************************************************************************
 FORM FELDEIGENSCHAFTEN USING ALLG.
*
 DATA: FLAENGE(2) TYPE N.
 DATA: FTYP(1) TYPE C.
 DATA: FOUT(2) TYPE N.
 DATA: FDEZ(2) TYPE N.
*.......................................................................
  ULINE.
  DESCRIBE FIELD ALLG LENGTH FLAENGE.
  WRITE: /10 'Field length  :', FLAENGE.
*
  DESCRIBE FIELD ALLG TYPE FTYP.
  WRITE: /10 'Field type    :', FTYP.
*
  DESCRIBE FIELD ALLG OUTPUT-LENGTH FOUT.
  WRITE: /10 'Output length :', FOUT.
*
  DESCRIBE FIELD ALLG DECIMALS FDEZ.
  WRITE: /10 'Decimals      :', FDEZ.
  SKIP 1.
*.......................................................................
 ENDFORM.
************************************************************************
************************************************************************
******************* END OF PROGRAM *************************************
pixelstats trackingpixel