Tips and Tricks for the ABAP® Programming Language
Y9020022: Relative Addressing of T fields (time)
- Partial association In this example, three T-fields are associated to a field symbol with “ASSIGN”. Each of the three T-fields is associated partially only to the same field symbol.
- T-Fields have a constant field length In the example declaration of the T-fields, a 4 byte field and a 12 byte field are contained. Program-internally, these fields are converted to the valid T-field length of 6 bytes, any other length specification is ignored.
- Relative addressing by numeric values In examples 1 – 3, constant numeric values are used for the addressing of the data field.
- 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.
- 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.
- Addressing other T-fields By specifying an offset that is a multiple of the origin field length other T-fields can be associated (and hence be modified) as well.
ABAP™-Source-Code
You can cut and paste the source code directly into the ABAP™-Workbench.
REPORT Y9020022 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 fuer "ASSIGN TFELD+o(l) TO <fs1>" ' TO SY-TITLE. *//////////////////////////////////////////////////////////////////////* *************** Declaration of variables ********************** FIELD-SYMBOLS <FS1>. *....................................................................... DATA: TFELD4(6) TYPE T VALUE '235046'. "T = always 6 Bytes DATA: TFELD6(6) TYPE T VALUE '201159'. DATA: TFELD12 TYPE T VALUE '060401'. "T = always 6 Bytes * *iiiiiiiiiiiiiii *i Data fiels of the T type (TIME) have a predetermined length of *i 6 bytes: HHMMSS *iiiiiiiiiiiiiii * DATA: OFFX TYPE I VALUE 0. DATA: LENX TYPE I VALUE 2. *//////////////////////////////////////////////////////////////////////* ************* - Main Section ******************* *//////////////////////////////////////////////////////////////////////* * BREAK-POINT. ASSIGN TFELD4+1(5) TO <FS1>. "<-- Assign of variable to <FS1> ****************** bitte ausprobieren ********************************** * ASSIGN TFELD4+12(6) TO <FS1>. "<--The field TFELD12 ! will be assigned * * ASSIGN TFELD4+8(2) TO <FS1>. "<-- No syntax error (middle assign) !!! * ************************************************************************ WRITE: / 'ASSIGN command with TFELD4 (Offset and length constant)' COLOR 6. PERFORM DISPLAY-TFELD USING TFELD4 'TFELD4'. ULINE. SKIP 2. *----------------------------------------------------------------------- BREAK-POINT. ASSIGN TFELD6+2(4) TO <FS1>. "<-- Assign of variable to <FS1> *....................................................................... WRITE: / 'ASSIGN command with TFELD6 (Constant offset and length)' COLOR 6. PERFORM DISPLAY-TFELD USING TFELD6 'TFELD6'. ULINE. SKIP 2. *----------------------------------------------------------------------- BREAK-POINT. ASSIGN TFELD12+4(2) TO <FS1>. "<-- Assign of variable to <FS1> *....................................................................... WRITE: / 'ASSIGN command with TFELD12 (Constant offset and length)' COLOR 6. PERFORM DISPLAY-TFELD USING TFELD12 'TFELD12'. ULINE. SKIP 2. *----------------------------------------------------------------------- *...................................................................... BREAK-POINT. WRITE: / 'ASSIGN command (Offset and length as fields) mit TFELD6' COLOR 6. DO 3 TIMES. WRITE: /5 'DO loop count :' COLOR 5, SY-INDEX. ASSIGN TFELD6+OFFX(LENX) TO <FS1>. PERFORM DISPLAY-TFELD USING TFELD6 'TFELD6'. SKIP 4. ADD 2 TO OFFX. ENDDO. *....................................................................... * *//////////////////////////////////////////////////////////////////////* ************* Subroutines ******************* *//////////////////////////////////////////////////////////////////////* * ************************************************************************ * Display of date fields and field symbols * ************************************************************************ FORM DISPLAY-TFELD USING TFELD FNAME. * WRITE: /10 'Content of', FNAME, ':', TFELD. PERFORM FELDEIGENSCHAFTEN USING TFELD. * WRITE: /10 'Content of <FS1> :', <FS1>. PERFORM FELDEIGENSCHAFTEN USING <FS1>. *----------------------------------------------------------------------- MOVE '15' TO <FS1>. "<-- The field symbol will be used *----------------------------------------------------------------------- WRITE: /10 'MOVE ''15'' TO <FS1>'. ULINE. *....................................................................... WRITE: /10 'Content of', FNAME, 35 ':', TFELD. 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 *************************************