2007 Jul 16 7:58 AM
Hi,
I would like to know which way can I use the structured that I defined somewhere before by passing only the name of the structure. The name of the structure is based on some standardized naming conversion, e.g. 'Zstr_R0001_part1'
Zstr - identifier of customized structure
R0001 - the program name
part1 - the additional information
the components are already provided. However, how can I use the 'Name' to get the structure?
Regards,
Mandy Au
2007 Jul 16 10:07 AM
Hi,
check this example code.
REPORT Z.
TYPES: BEGIN OF STRUCT,
MATNR LIKE MARA-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF STRUCT.
DATA: IT_TABLE TYPE STANDARD TABLE OF STRUCT.
DATA: LR_DATADESCR TYPE REF TO CL_ABAP_DATADESCR,
LR_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR.
FIELD-SYMBOLS: <FS> TYPE ABAP_KEYDESCR.
LR_TABLEDESCR ?= CL_ABAP_TABLEDESCR=>DESCRIBE_BY_DATA( IT_TABLE ).
LOOP AT LR_TABLEDESCR->KEY ASSIGNING <FS>.
LR_DATADESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( <FS>-NAME ).
ENDLOOP.
Kostas
2007 Jul 16 8:08 AM
hi,
YES you can.
use the Class CL_ABAP_TYPEDESCR and method describe_by_name.
Then use CREATE DATA to create data.
Regards,
Sesh
2007 Jul 16 9:07 AM
thanks! I found the class and trying to look into the methods.....
however, when I try to include the class to my program....
there is an error occured:
You cannot generate instatnces of the abstract class "CL_ABAP_TYPEDESCR"
Is that I missed something? or there is another way to call this class?
Here is my code:
data objtypedescr type ref to CL_ABAP_TYPEDESCR .
create object objtypedescr.
and the error occured in line 2.
Thanks.
2007 Jul 16 10:07 AM
Hi,
check this example code.
REPORT Z.
TYPES: BEGIN OF STRUCT,
MATNR LIKE MARA-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF STRUCT.
DATA: IT_TABLE TYPE STANDARD TABLE OF STRUCT.
DATA: LR_DATADESCR TYPE REF TO CL_ABAP_DATADESCR,
LR_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR.
FIELD-SYMBOLS: <FS> TYPE ABAP_KEYDESCR.
LR_TABLEDESCR ?= CL_ABAP_TABLEDESCR=>DESCRIBE_BY_DATA( IT_TABLE ).
LOOP AT LR_TABLEDESCR->KEY ASSIGNING <FS>.
LR_DATADESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( <FS>-NAME ).
ENDLOOP.
Kostas
2007 Jul 16 10:23 AM
Thanks, I can get the structure now.
One more thing I want to ask is about the create data.
DATA: BEGIN OF itab OCCURS 0,
mandt like fkkop-mandt,
vkont like dfkkop-vkont,
OPBEL like dfkkop-OPBEL,
END OF itab.
form get_dynamic_structure_by_name.
Data : lr_rtti_struc TYPE REF TO cl_abap_structdescr.
lr_rtti_struc ?= CL_ABAP_TYPEDESCR=>describe_by_name( 'itab' ).
endform.
I would like to know how can I create a structure which is having the same fields as itab?
I have try this before, but it does not work!
*&---------------------------------------------------------------------*
*& Form get_structure
*&---------------------------------------------------------------------*
* GET THE STRUCTURE OF THE TABLE.
*----------------------------------------------------------------------*
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr,
ref_table_des TYPE REF TO cl_abap_structdescr.
REFRESH : ifc,ifc_char.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( text1 ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
error is about abap_compdescr_tab.
I want to know if this method is workable in my case? or I should use another one?
You guys are really really really helpful!!! Thanks a lot!!!!
2007 Jul 16 10:40 AM
Why don't you use the CREATE DATA statement directly since you have the structure name?
see this code.
REPORT Z1.
TYPES: BEGIN OF struc,
a TYPE i,
b TYPE c LENGTH 8,
END OF STRUC.
DATA: dref TYPE REF TO DATA,
tname TYPE string.
FIELD-SYMBOLS: <f> TYPE any.
tname = 'STRUC'. "
CREATE DATA dref TYPE (tname).
ASSIGN dref->* TO <f>.
2007 Jul 16 10:44 AM
OH!!! THANKS A LOT!!!
This already solved my problem!!!!
Thanks!
Regards,
Mandy
2007 Jul 16 10:31 AM
If u know the structure name then using field-symbols u can access that structure..
field-symbols : <fs> type any.
assign (STR_NAME) to <fs>.
Regards
Prax
2007 Jul 16 10:40 AM