SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Field Symbol Sample Source



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Tue Sep 11, 2007 8:54 pm    Post subject: Field Symbol Sample Source Reply with quote

1. Field Symbols
Code:
  DATA int TYPE i VALUE 15.
  FIELD-SYMBOLS <fs_int> TYPE i.
  ASSIGN int TO <fs_int>.
  WRITE: / int, <fs_int>.
  <fs_int> = 17.
  WRITE: / int, <fs_int>.
  UNASSIGN <fs_int>.
  IF <fs_int> IS ASSIGNED.
    WRITE: / int, <fs_int>.
  ELSE.
    WRITE: / 'field symbol not assigned'(fna).
  ENDIF.


Quote:
15 15
17 17
field symbol not assigned


2. References and Field Symbols
Code:
  DATA int TYPE i VALUE 15.
  FIELD-SYMBOLS <fs_int> LIKE int.
  DATA d_ref1 TYPE REF TO data.
  DATA d_ref2 LIKE d_ref1.
  GET REFERENCE OF int INTO d_ref1.
  d_ref2 = d_ref1.
  ASSIGN d_ref2->* TO <fs_int>.
  WRITE: / int, <fs_int>.


Quote:
15 15


3.
Code:
DATA: BEGIN OF STR,
        A VALUE 'a',
        B VALUE 'b',
        C VALUE 'c',
        D VALUE 'd',
      END   OF STR,
      CN(5) VALUE 'D'.
FIELD-SYMBOLS <FS> TYPE ANY.
DO 3 TIMES.
  ASSIGN COMPONENT SY-INDEX OF
         STRUCTURE STR TO <FS>.
  IF SY-SUBRC <> 0. EXIT. ENDIF.
  WRITE <FS>.
ENDDO.
ASSIGN COMPONENT CN OF STRUCTURE STR TO <FS>.
WRITE <FS>.


Quote:
Output: a b c d


4.
Code:
DATA: BEGIN OF LINE,
        COL1 TYPE I VALUE '11',
        COL2 TYPE I VALUE '22',
        COL3 TYPE I VALUE '33',
      END OF LINE.

DATA COMP(5) VALUE 'COL3'.

FIELD-SYMBOLS: <F1>, <F2>, <F3>.

ASSIGN LINE TO <F1>.
ASSIGN COMP TO <F2>.

DO 3 TIMES.
  ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
  WRITE <F3>.
ENDDO.

ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
WRITE / <F3>.


The output is:
Quote:
11 22 33

33


5. Example of Dynamic Type Casting -> Bad !
Code:
  PARAMETERS: pa_dbtab TYPE dd02l-tabname.
  DATA dummy TYPE i. "address of line mod 4 has to be zero !!!
  DATA: line(65535).
  FIELD-SYMBOLS: <fs_wa> TYPE ANY, <fs_comp> TYPE ANY.
  SELECT * FROM (pa_dbtab) INTO line.
    ASSIGN line TO <fs_wa> CASTING TYPE (pa_dbtab).
    DO.
      ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <fs_comp>.
      IF sy-subrc NE 0.
        SKIP.
        EXIT.
      ENDIF.
      WRITE <fs_comp>.
    ENDDO.
  ENDSELECT.


** Suppose pa_dbtab's value is SFLIGHT

Quote:
100 UA 0941 15.03.2002 3.313,30 USD A310-300 280 1 0,00

100 UA 0941 16.03.2002 3.313,30 USD A310-300 280 43 134.586,23

100 UA 3504 09.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 10.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 11.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 12.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 13.03.2002 3.313,30 USD RJ115 128 43 134.586,23


6. Declaring Data Object Dynamically -> Good !
Code:
PARAMETERS: pa_dbtab(30) DEFAULT 'SFLIGHT'.
DATA: d_ref TYPE REF TO data.
FIELD-SYMBOLS: <fs_wa> TYPE ANY, <fs_comp> TYPE ANY.
CREATE DATA d_ref TYPE (pa_dbtab).
ASSIGN d_ref->* TO <fs_wa>.
SELECT * FROM (pa_dbtab) INTO <fs_wa>.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <fs_comp>.
    IF sy-subrc NE 0.
      SKIP.
      EXIT.
    ENDIF.
    WRITE <fs_comp>.
  ENDDO.
ENDSELECT.


Quote:
100 UA 0941 15.03.2002 3.313,30 USD A310-300 280 1 0,00

100 UA 0941 16.03.2002 3.313,30 USD A310-300 280 43 134.586,23

100 UA 3504 09.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 10.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 11.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 12.03.2002 3.313,30 USD RJ115 128 43 134.586,23

100 UA 3504 13.03.2002 3.313,30 USD RJ115 128 43 134.586,23
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.