Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Identify the TYPE using CL_ABAP_DATADESCR

abhishek_nms
Participant
0 Kudos
2,809

we have a custom field ROLE with the Data element as ZDOA_ROLE in a table ZTABLE.

CODE SAMPLE 1

data gs_comp TYPE abap_componentdescr.

gs_comp-type ?= cl_abap_datadescr=>describe_by_data( 'ROLE' ).

gs_comp-name = gs_comp-type->get_relative_name( ).

when i write the above code, the name is blank.

CODE SAMPLE 2

do_type = cl_abap_datadescr=>describe_by_name( 'ROLE' ).

it dumps, stating ROLE type is not available

CODE SAMPLE 3

do_type = cl_abap_datadescr=>describe_by_name( 'ZDOA_ROLE' ).

it returns the type is ZDOA_ROLE.

"--NOT USEFUL because i cannot pass the Data element, I can only pass Field name

Priority is to find the type from the Field.

Can any body suggest me, a better way to get the Type of the Field and not by the Data element ?

5 REPLIES 5

alex_campbell
Contributor
0 Kudos
584

You should pass the field itself to describe_by_data, and not the name of the field. Like so:


data l_role type ztable-role.
gs_comp-type ?= cl_abap_datadescr=>describe_by_data( l_role ).
gs_comp-name = gs_comp-type->get_relative_name( ).

I think if you don't actually have an instance of the field, you might be able to do this:


gs_comp-type ?= cl_abap_datadescr=>describe_by_name( 'ZTABLE-ROLE' ).
gs_comp-name = gs_comp-type->get_relative_name( ).

0 Kudos
584

Any work around ? because i cannot mention the table name,

Requirement: based on the tab delimited file upload in Web Dynpro, I need to identify which table data (mostly our Custom ZDOA tables which are around 10) was uploaded and updated the corresponding table .

since we have customized field ROLE with data element ZDOA_ROLE, the type is not identified.

Basically trying to figure out the structure dynamically of the tab delimited File (data would be in accordance with the structure of the Table in Data Dictionary) uploaded !!

ONE more thing, the uploaded tab delimited file would have Table Field name ( HEADER ) as well .

0 Kudos
584

Any work around ? because i cannot mention the table name,

Requirement: based on the tab delimited file upload in Web Dynpro, I need to identify which table data (mostly our Custom ZDOA tables which are around 10) was uploaded and updated the corresponding table .

These two statements seem contradictory. If you know that the file must be one of your ZDOA tables, than you can get the table name(s) by finding all tables that match the pattern ZDOA*

Once you know the possible tables, you can determine the structure of each table like this:


lo_structdescr ?= cl_abap_structdescr=>describe_by_name( 'ZDOA_TABLE' ).
li_components = lo_structdescr->get_components( ).

li_components is a table of the names and type descriptors for each field in the structure. You can loop through this table, comparing the names of each field to the field names given in the header of the tab-delimited file.

former_member184611
Active Participant
0 Kudos
584

Hi abishek,

Try this code....

DATA: v_tydescr_ref TYPE REF TO cl_abap_datadescr.

v_tydescr_ref ?= cl_abap_datadescr=>describe_by_data( 'ROLE' ).

****You will get the type in v_tydescr_ref->type_kind.

WRITE: / 'Typename:', v_tydescr_ref->absolute_name,

/ 'Kind :', v_tydescr_ref->type_kind,

/ 'Length :', v_tydescr_ref->length,

/ 'Decimals:', v_tydescr_ref->decimals.

Thanks

0 Kudos
584

Hey ,

I did try the same code in CODE SAMPLE 1 in my First Posting. It returns a Blank value for the Name and Absolute Type is not

ZDOA_ROLE. it has some thing like this \TYPE=%_T00006S00000000O0000000289

Thanks

Abhi