05-18-2011 12:32 PM
Hi Experts,
I have a work area wa_survey with two fields below:
item1 type string,
item2 type string
I have a custom table "ylookup_tab" where I am maintaining some kind of lookup.
I need to populate the wa_survey field based on the lookup value from above table.
For example if the table lookup returned item1 then populate
wa_survey-item1 = some value.
Else if the table returned item2 then populate
wa_survey-item2 = some value.
I tried like below but it does not work:
wa_survey-(wa_lookup_tab-value) = some value.
Is there any way to do this?
Thanks
Gopal
Edited by: kishan P on May 19, 2011 12:18 PM
05-18-2011 12:40 PM
Hi Gopal,
There is a Function Module which will give you the fields at runtime.
Please use this FM 'DDIF_FIELDINFO_GET'.
Hope it clears your requirement.
Thanks,
Bhargav.
05-18-2011 1:31 PM
DATA:wa_struct TYPE REF TO cl_abap_structdescr,
it_table_field TYPE cl_abap_structdescr=>component_table.
wa_struct ?= cl_abap_typedescr=>describe_by_name( 'put your table here' ).
it_table_field = wa_struct->get_components( ).
05-19-2011 4:03 AM
Hi Experts,
I think you did not understand what I want.
Here is what I am doing.
TYPES: BEGIN OF t_survey,
item1 TYPE string,
item2 TYPE string,
END OF t_survey.
Data: i_survey type standard table of t_survey,
wa_survey type t_survey,
i_lookup type table of ylookup_tab,
wa_lookup type ylookup_tab.
select * from ylookup_tab into i_lookup.
i_input table is populated separately and this logic is not given here.
i_input has a field "item" which can have value "item1" or "item2".
loop at i_input into wa_input.
Check if the i_input item value exists in lookup table
read table i_lookup into wa_lookup with key trans_value = wa_input-item.
if sy-subrc = 0.
wa_survey-(wa_input-item) = 'S01'. <-- this does not work
endif.
endloop.
Edited by: gopalkrishna baliga on May 19, 2011 5:15 AM
Edited by: gopalkrishna baliga on May 19, 2011 5:34 AM
05-19-2011 7:33 AM
You can use field symbols , to populate teh table dynamically.
But since you have just 2 fields in your table.try doing the following.
loop at i_input into wa_input.
Check if the i_input item value exists in lookup table
read table i_lookup into wa_lookup with key trans_value = wa_input-item.
if sy-subrc = 0.
If wa_input-item = 'ITEM1'
wa_survey-ITEM1 = 'S01'
ELSE
wa_survey-ITEM2 = 'S01'
endif.
endif.
endloop.
05-19-2011 8:16 AM
Hello,
select * from ylookup_tab into table i_lookup.
loop at i_input into wa_input.
Check if the i_input item value exists in lookup table
read table i_lookup into wa_lookup with key trans_value = wa_input-item.
if sy-subrc = 0.
wa_survey-item1 = wa_lookup-trans_value
endif.
endloop.
05-19-2011 8:19 AM
Hi,
Try like this.....
TYPES: BEGIN OF t_survey,
item1 TYPE string,
item2 TYPE string,
END OF t_survey.
Data: i_survey type standard table of t_survey,
wa_survey type t_survey,
i_lookup type table of ylookup_tab,
wa_lookup type ylookup_tab.
field-symbols: <w_field> type any.
select * from ylookup_tab into i_lookup.
i_input table is populated separately and this logic is not given here.
i_input has a field "item" which can have value "item1" or "item2".
loop at i_input into wa_input.
Check if the i_input item value exists in lookup table
read table i_lookup into wa_lookup with key trans_value = wa_input-item.
if sy-subrc = 0.
assign component wa_input-item OF STRUCTURE wa_survey to <w_field>.
<w_field> = 'S01'.
*wa_survey-(wa_input-item) = 'S01'. <-- this does not work
endif.
endloop.
Hope it will solve the problem....