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: 

Create dynamic data type in structure

former_member229026
Participant
0 Kudos

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

Former Member
0 Kudos

Please refer to the [Link|;

14 REPLIES 14

former_member222709
Contributor
0 Kudos

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.

0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

Please refer to the [Link|;

0 Kudos

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

0 Kudos

Hi,

Please can you explain more.

Regards,

BBC

0 Kudos

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.

0 Kudos

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

,

0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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?

0 Kudos

Hi Sandra,

Now it is working fine. Thanks your support.

Regards,

BBC