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

Defining a local type dynamically



 
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: Sun Nov 25, 2007 10:17 pm    Post subject: Defining a local type dynamically Reply with quote

You can now define a local type dynamically.

This is only supported in 6.40. Here's how it goes:

Code:
REPORT ZDANY_DYN_LOCAL_TYPES.
 
****************** hardcoded "old style" local type *******************
* This is a normal hardcoded local type
 types : begin of typ_hardcoded,
         l_count type i,
         lt_sflight type sflight.
 types : end of typ_hardcoded.
* create a table based on hardcoded type
 data : lt_hardcoded type table of typ_hardcoded.
 
****************** dynamic "new wave" local type *******************
 types: typ_count type i.
 
 field-symbols : <lt_dynamic> type any table.
 data: dref type ref to data,
       itab_type type ref to cl_abap_tabledescr,
       struct_type type ref to cl_abap_structdescr,
       elem_type type ref to cl_abap_elemdescr,
       comp_tab type cl_abap_structdescr=>component_table,
       comp_fld type cl_abap_structdescr=>component.
 
* We read information about each fields of SFLIGHT (see ABAP FAQ #2)
struct_type ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT' ).
 
* We also need the information about the type "typ_count", note that
* we should use class cl_abap_elemdescr instead of cl_abap_typedescr
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'TYP_COUNT' ).
 
* we read all fleids of SFLIGHT and create a component table
comp_tab = struct_type->get_components( ).
 
* We add manually the counter
comp_fld-name = 'L_COUNT'.
comp_fld-type = elem_type.
insert comp_fld into comp_tab index 1.
 
* we create the structure
struct_type = cl_abap_structdescr=>create( comp_tab ).
 
* ... and the internal table
itab_type = cl_abap_tabledescr=>create( struct_type ).
 
* The new thing here is the "type handle" which create a pointer to a
* handle
create data dref type handle itab_type.
 
* we finally assign a field symbol to the pointer because we cannot
* directly access a pointer.
assign dref->* to <lt_dynamic>.
 
* At the end of this small program, internal table lt_hardcoded and
* lt_dynamic are the same
break-point.
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.