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

Example: Generating Data Objects at Runtime



 
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: 1639

PostPosted: Tue Sep 11, 2007 8:52 pm    Post subject: Example: Generating Data Objects at Runtime Reply with quote

Code:
PARAMETERS pa_dbtab TYPE dd02l-tabname DEFAULT 'SFLIGHT'.
DATA d_ref TYPE REF TO data.
 
FIELD-SYMBOLS: <fs_wa> TYPE ANY, <fs_comp> TYPE ANY.
 
START-OF-SELECTION.
  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.

 This example displays the content of a transparent table. You can make the FROM clause of the SELECT statement dynamic. For the INTO clause, you will need a data object that has a line type compatible with that of the table being displayed. Since the name - and thus the line type of the table is not known until runtime, you should not create the data object until then.
 Unlike conventional data objects, you can specify the type of a data object created at runtime dynamically. The TYPE addition of the CREATE DATA statement contains the name of the table, so that the system creates the appropriate structure.
 The statement ASSIGN d_ref->* TO <fs_wa> assigns the data object to the field symbol. The data type of the table is inherited by the field symbol, so type casting is no longer necessary.
 You can now write each data record from the SELECT statement into the compatibly-typed data object using the field symbol <fs_wa>.
 If you knew the component names, you could display the fields directly using WRITE <fs_wa>-... .
However, you will not normally know the names of the components, nor how many of them there are. For this reason, you must display the components using the ASSIGN-COMPONENT variant: The components of the structure <fs_wa are assigned one-by-one to the field symbol <fs_comp> and then displayed. When the loop runs out of components, the program reads the next data record.
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.