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: 

How to dynamically determine work area field?

gopalkrishna_baliga
Participant
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

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.

Former Member
0 Kudos

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( ).

0 Kudos

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

0 Kudos

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.

0 Kudos

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.

0 Kudos

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....