Sometimes you may have only a table name and want to retrieve the name of each field of the corresponding table. For example, when you want to use ASSIGN COMPONENT fieldname OF TABLE table. An ABAPer's first reaction is to read the standard ABAP basis tables DD02L, DD03L, etc This way of reading fields is very slow. Use methods from the class CL_ABAP_TYPEDESCR instead. Example: data: descr_struc_ref TYPE REF TO cl_abap_structdescr. descr_struc_ref ?= cl_abap_typedescr=>describe_by_name('SFLIGHT' ). Here is the result of descr_struct_ref after the execution of this piece of code ABSOLUTE_NAME C 200 \TYPE=SFLIGHT TYPE_KIND C 1 u LENGTH I 4 80 DECIMALS I 4 0 KIND C 1 S STRUCT_KIND C 1 F COMPONENTS h 8 Table[14x40] HAS_INCLUDE C 1 The table COMPONENTS is filled with : LENGTH DECIMALS TYPE_KIND NAME 3 | 0 |C |MANDT 3 | 0 |C |CARRID 4 | 0 |N |CONNID 8 | 0 |D |FLDATE etc. You have the fields name and a lot more information about the table. This class can also handle structure, table type, etc. Note that this method is very fast because it uses the database layer directly thanks to SYSTEM CALLs. To have a look at the class, use transaction SE24.
Sometimes you may have only a table name and want to retrieve the name of each field of the corresponding table. For example, when you want to use ASSIGN COMPONENT fieldname OF TABLE table. An ABAPer's first reaction is to read the standard ABAP basis tables DD02L, DD03L, etc This way of reading fields is very slow. Use methods from the class CL_ABAP_TYPEDESCR instead. Example: data: descr_struc_ref TYPE REF TO cl_abap_structdescr. descr_struc_ref ?= cl_abap_typedescr=>describe_by_name('SFLIGHT' ). Here is the result of descr_struct_ref after the execution of this piece of code ABSOLUTE_NAME C 200 \TYPE=SFLIGHT TYPE_KIND C 1 u LENGTH I 4 80 DECIMALS I 4 0 KIND C 1 S STRUCT_KIND C 1 F COMPONENTS h 8 Table[14x40] HAS_INCLUDE C 1 The table COMPONENTS is filled with : LENGTH DECIMALS TYPE_KIND NAME 3 | 0 |C |MANDT 3 | 0 |C |CARRID 4 | 0 |N |CONNID 8 | 0 |D |FLDATE etc. You have the fields name and a lot more information about the table. This class can also handle structure, table type, etc. Note that this method is very fast because it uses the database layer directly thanks to SYSTEM CALLs. To have a look at the class, use transaction SE24.
No comments:
Post a Comment