Tips and Tricks for the ABAP® Programming Language

Y9020027 – Relative Addressing of F fields / Problems (floating point)

  1. Partial association In this example, three N-fields are associated to a field symbol with “ASSIGN”. Each of the three N-fields is associated partially only to the same field symbol.
  2. Partial association In this example, the FFELD8 is used with different relative addressing. The offset is always divisible by 8, the field length is 8 bytes constantly. The following informations are somewhat difficult to integrate for “beginners”.
  3. Relative addressing of a F-field The same logic applies analogically as with the I-fields. Here, some elementary informations once more: Basically, it can be said that F-fields must be relatively addressed and be associated to a field symbol, except when using the same field length of the origin field as length and a multiple of the length as offset. This way, e.g. a field string with F-fields of equal length can be processed quite simple by a field symbol. The drawback: Uninvolved fields can e.g. be modified unintentionally by addressing errors. So, if an F-field is relatively addressed for an association to a field symbol, only other F-fields, being declared immediately after the origin field, should be addressed by this.
  4. Example 1 – Here, a relative addressing was chosen, that would cause a runtime error if being activated.
  5. Example 2 – FFELD8 is addressed with “FFELD8+8(8)” and associated to the field symbol . This way, the field FFELDX, following next in the declaration, is addressed however. So, with a modification of , FFELDX is modified. The declaration of ZFELD1 would imply, that padding bytes are inserted internally. This way, the relative addressing of FFELD8 points right into other F-fields. The wrong results are processed without any error message from the SP processor. So, ZFELD1 should remain in the program just as a comment.
  6. Example 3 – FFELD4 is addressed with “FFELD8+16(8)” and associated to the field symbol . This way, the field FFELDA, following next in the declaration, is addressed. So, with a modification of , FFELDA is modified. Because of the fixed length of F-fields, the modification of does not produce any “trash” (like in the case of PFELD6). A prerequisite is, however, that the respective F-fields were declared contiguously (avoid padding bytes).
  7. Example 4 – FFELD8 is relatively addressed by the two variables OFFX and LENX. The addressing points right into the data field NFELDX (because in our example 4, the address variable OFFX contains a “wrong” value). The addition of 111 to the field symbol is not performed, instead, something like a “MOVE” is made. The SP processor displays no error message. However, the target field NFELDX is modified.
  8. Summary: Caution is recommended also with relative addressing of F-fields. If addressing fields (e.g. OFFX or LENX) receive a wrong content, this causes errors. Sometimes, these errors are hard to localize (… the rest is known)

ABAP-Source-Code

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

REPORT Y9020027 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  FFeld+o(l)  TO  <fs1>"        '
        TO SY-TITLE.
*//////////////////////////////////////////////////////////////////////*
***************       Declaration of variables    **********************
 FIELD-SYMBOLS <FS1>.
*.......................................................................
 DATA: FFELD8(8)   TYPE F VALUE '1022333'.   "Unusual: Explicit 8 bytes
*DATA: ZFELD1(2)    TYPE N.            "Here slack bytes are (DW border)
*                                      "necessary
*               "If you like computing error, please uncomment the above
 DATA: FFELDX(8)   TYPE F VALUE '7777777'.
 DATA: FFELDA(8)   TYPE F VALUE '7333213'.
 DATA: NFELDX(400) TYPE N.
*
 DATA: OFFX(4) TYPE I VALUE 160.
 DATA: LENX(4) TYPE I VALUE 8.
*//////////////////////////////////////////////////////////////////////*
*************               Main Section             *******************
*//////////////////////////////////////////////////////////////////////*
*
    SKIP.
    WRITE: /5  'Example 1   **** inadmissible ASSIGN ***' COLOR 6.
    WRITE: /10 'Inadmissible ASSIGN: ''ASSIGN FFELD4+1(3) TO <FS1>'' '.
*   ASSIGN FFELD4+1(3) TO <FS1>.
    ULINE.
    SKIP 2.
*-----------------------------------------------------------------------
    SKIP.
 ASSIGN FFELD8+8(8) TO <FS1>.     "<-- Assigning of variable  FFELDX  !!
*.......................................................................
    BREAK-POINT.
    WRITE: / 'ASSIGN command with FFELD8, but FFELDX will be assigned'
              COLOR 3.
    WRITE: /5 'Example 2'.
    PERFORM DISPLAY-FFELD USING FFELD8 'FFELD8'.
    WRITE: /10 'Content of   FFELDX      :', FFELDX.
    ULINE. SKIP 2.
*-----------------------------------------------------------------------
    SKIP.
 ASSIGN FFELD8+16(8) TO <FS1>.    "<-- Assiging a few FFELDA to <FS1>
*.......................................................................
    BREAK-POINT.
    WRITE: / 'ASSIGN with FFELD8, but instead FFELDA is assigned'
              COLOR 3.
    WRITE: /5 'Example 3'.
    WRITE: /10 'Content of   FFELDA      :', FFELDA.
    PERFORM DISPLAY-FFELD USING FFELD8 'FFELD8'.
    WRITE: /10 'Content of   FFELDA      :', FFELDA.
    ULINE. SKIP 2.
*-----------------------------------------------------------------------
*.......................................................................
 BREAK-POINT.
   DO 4 TIMES.
     ASSIGN FFELD8+OFFX(LENX) TO <FS1>.     "Zuordnung auf OFFX zu <FS1>
        WRITE: / 'ASSIGN command with FFELD8, es wird NFELDX zugeordnet'
                  COLOR 5.
         WRITE: /5 'Example 4', 'DO-Schleife Nr.:', SY-INDEX.
         PERFORM DISPLAY-FFELD USING FFELD8 'FFELD8'.
         WRITE: /10 'Content of NFELDX+145(40)  :', NFELDX+145(40).
         ULINE. SKIP 2.
         ADD 8 TO OFFX.
   ENDDO.
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
*
*//////////////////////////////////////////////////////////////////////*
*************                Subroutines             *******************
*//////////////////////////////////////////////////////////////////////*
*
************************************************************************
*            Display of data fields and field symbols                  *
************************************************************************
 FORM DISPLAY-FFELD USING FFELD FNAME.
*
 WRITE: /10 'Content of', FNAME, ':', FFELD.
 PERFORM FELDEIGENSCHAFTEN USING FFELD.
*
 WRITE: /10 'Content of <FS1> :', <FS1>.
 PERFORM FELDEIGENSCHAFTEN USING <FS1>.
*-----------------------------------------------------------------------
 ADD   111    TO <FS1>.               "<-- Das Feldsybmol wird verwendet
*-----------------------------------------------------------------------
 WRITE: /10 'ADD 111 TO <FS1>'.
 ULINE.
*.......................................................................
 WRITE: /10 'Content of', FNAME, 35 ':', FFELD.
 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 *************************************