Application Development and Automation 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: 
Read only

Create dynamic data type in structure

Former Member
0 Likes
2,848

Hi Experts,

I am new to ABAP.

In my scenario data type is varying for the field. for that I need to create dynamic data type in structure, this structure I am using for internal table for OVS search input.

Please suggest the solution for this.

Advance thanks,

Regards,

BBC

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,653

Please refer to the [Link|;

14 REPLIES 14
Read only

former_member222709
Contributor
0 Likes
2,653

Hi Achari,

If you are not defining the structure in the Data Dictionary (SE11) and only want to define a dynamic data type structure in the ABAP Editor (SE38), then you can use Field Symbols.

FIELD-SYMBOLS v_struc TYPE ANY.

Regards,

Pranav.

Read only

0 Likes
2,653

Hi,

I need to create dynamic data type for field while declaring structure.

like this:

BEGIN OF lty_stru_input,

FIELD1 TYPE <dynamic data type>.

END OF lty_stru_input.

here <dynamic data type> is varying like either LIFNR or WERKS or etc.,

Please suggest the solution?

Regards,

BBC

Edited by: BBC Achari on Aug 30, 2011 10:53 AM

Read only

0 Likes
2,653

Hi,

If you can use a complete dynamic structure at requirement, then, Field Symbols can be used. It will adopt the complete structure from which data is passed.

FIELD-SYMBOLS <v_struc> TYPE ANY.

But, if you want only a single field amongst multiple fields within a structure, then, it is tricky.

Regards,

Pranav.

Read only

Former Member
0 Likes
2,654

Please refer to the [Link|;

Read only

0 Likes
2,653

just replace the call to method DESCRIBE_BY_DATA by a call to DESCRIBE_BY_NAME and provide paramater P_NAME with a table (or structure) and field name

example: P_NAME = 'T001-BUKRS' will create a field corresponding to company code

it is often easier to remember what a field is when you see where it comes from

Read only

0 Likes
2,653

Hi,

Please can you explain more.

Regards,

BBC

Read only

0 Likes
2,653

You can refer the following links for detailed explanations with exampes.

[http://wiki.sdn.sap.com/wiki/display/ABAP/Workingwithdynamictablesusingfieldsymbols]

[http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]

If you still have some doubt, then, do let us know.

Regards,

Pranav.

Read only

0 Likes
2,653

Hi ,

I have declared like this.

TYPES:

BEGIN OF lty_stru_input,

  • add fields for the display of your search input here

FIELD1 TYPE (dynamic data type),

END OF lty_stru_input.

same structure I am using in internal table.

DATA: ls_search_input TYPE lty_stru_input.

  • pass the values to the OVS component

ovs_callback_object->set_input_structure(

input = ls_search_input ).

Here (dynamic data type) is the dynamic data type is required for me.

Please tell me a example for how to create dynamic data type?.

Regards,

BBC

,

Read only

0 Likes
2,653

Hi,

For instance:


 data:
ls_component type abap_componentdescr,
lt_component type abap_component_tab.

*... (1) define structure components :

clear ls_component.
ls_component-name = 'FIELD1'.
ls_component-type ?= cl_abap_typedescr=>describe_by_name( 'SFLIGHT-CARRID' ).
insert ls_component into table lt_component.

clear ls_component.
ls_component-name = 'FIELD2'.
ls_component-type ?= cl_abap_elemdescr=>get_n( 4 ).
insert ls_component into table lt_component.

*... (2) create structure
data lr_strucdescr type ref to cl_abap_structdescr.
data lr_data_struc type ref to data.

lr_strucdescr = cl_abap_structdescr=>create( lt_component ).
create data lr_data_struc type handle lr_strucdescr.

field-symbols <fs> TYPE any.
assign lr_data_struc->* to <fs>.

ovs_callback_object->set_input_structure(
input = <fs> ).

Sandra

Read only

0 Likes
2,653

Hi Sandra,

Thanks for sending the logic.

Here I need to refer structure name to query parameter,

FIELD-SYMBOLS: <ls_query_params> TYPE <structure name>,

Please can you suggest how to refer the structure name.

Regards,

BBC

Read only

0 Likes
2,653

Hi,

what is <structure name> exactly? is it a DDic structure?

If so, then do like this (here DDic "structure" is SFLIGHT):


data lr_data_struc type ref to data.
create data lr_data_struc type ('SFLIGHT').
 
field-symbols <fs> TYPE any.
assign lr_data_struc->* to <fs>.
 
ovs_callback_object->set_input_structure(
input = <fs> ).

Sandra

Read only

0 Likes
2,653

Thanks for your quick reply,

I used your logic like this.

data:

ls_component type abap_componentdescr,

lt_component type abap_component_tab.

*... (1) define structure components :

clear ls_component.

ls_component-name = 'NVALUE'.

ls_component-type ?= cl_abap_typedescr=>describe_by_name( <fs_seg_v>-fieldname ).

insert ls_component into table lt_component.

*... (2) create structure

data lr_strucdescr type ref to cl_abap_structdescr.

data lr_data_struc type ref to data.

lr_strucdescr = cl_abap_structdescr=>create( lt_component ).

create data lr_data_struc type handle lr_strucdescr.

field-symbols <fs> TYPE any.

assign lr_data_struc->* to <fs>.

your logic is working fine.

here I am getting feild name (<fs_seg_v>-fieldname) from internal table.

But I need to assign same field name structure to query parameter.

FIELD-SYMBOLS: <ls_query_params> TYPE lty_stru_input.

Please can you suggest how I can refer the field name structure?

Regards,

BBC

Read only

0 Likes
2,653

here I am getting feild name (<fs_seg_v>-fieldname) from internal table.

But I need to assign same field name structure to query parameter.

FIELD-SYMBOLS: <ls_query_params> TYPE lty_stru_input.

Please can you suggest how I can refer the field name structure?

I don'tunderstand what you want to do, could you please explain with an example?

Read only

0 Likes
2,653

Hi Sandra,

Now it is working fine. Thanks your support.

Regards,

BBC