08-30-2011 8:21 AM
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
08-30-2011 9:36 AM
08-30-2011 9:15 AM
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.
08-30-2011 9:52 AM
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
08-30-2011 10:05 AM
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.
08-30-2011 9:36 AM
08-30-2011 9:59 AM
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
08-30-2011 11:10 AM
08-30-2011 11:20 AM
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.
08-30-2011 11:30 AM
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
,
08-30-2011 1:15 PM
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
09-02-2011 1:30 PM
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
09-02-2011 1:55 PM
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
09-02-2011 2:39 PM
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
09-02-2011 2:45 PM
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?
09-02-2011 3:04 PM
Hi Sandra,
Now it is working fine. Thanks your support.
Regards,
BBC