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: 

Performance hit with 'ASSIGN COMPONENT'

Former Member
0 Kudos

Hi,

I am using 'Assign Component' to pass values between 2 dynamically created tables. However it seems the subroutine where this is occuring is taking long to run.

Is ASSIGN COMPONENT abc of STRUCTURE .... statement Performance intensive ?

Thanks

1 ACCEPTED SOLUTION

franois_henrotte
Active Contributor
0 Kudos

be sure to do ASSIGN only once, not each pass in your LOOP

7 REPLIES 7

franois_henrotte
Active Contributor
0 Kudos

be sure to do ASSIGN only once, not each pass in your LOOP

0 Kudos

Thanks. The component to assign is inside a Loop.

Loop at itab

Assign Component itab-comp of structure struc..

Endloop.

itab has the name of the components (fields) of the structure.

0 Kudos

I'm not sure if using the INDEX of the field of the structure is faster than using the name of the field or not. Maybe you can try it.

Regards,

Rich Heilman

franois_henrotte
Active Contributor
0 Kudos

if you can give the complete code between LOOP and ENDLOOP we could see if optimization is possible...

0 Kudos

Hi Francois... Here is the code

Loop at <it_select_tab> assigning <ls_select_tab>.

INSERT INITIAL LINE INTO <it_select_global> index cnt assigning

<ls_select_global>.

Loop at ifc_local into xfc.

assign component xfc-fieldname of structure <ls_select_tab> to

<ls_select_field>.

read table itg_map into itl_map with key

zsyst = lv_syst

zmapfield = xfc-fieldname

binary search.

if sy-subrc = 0.

assign component itl_map-fieldname of structure

<ls_select_global> to

<ls_select_global_field>.

<ls_select_global_field> = <ls_select_field>.

endif.

Endloop.

Unassign: <ls_select_field>,

<ls_select_global_field>.

Endloop.

0 Kudos

OK in this case you cannot do it else, but you should try to remove nested loops. For example, why don't you do the loop directly on itg_map in place of xfc ?

but anyway beware your UNASSIGN statements are not placed well, they should be placed like this:

Loop at ifc_local into xfc.

assign component xfc-fieldname of structure <ls_select_tab> to

<ls_select_field>.

read table itg_map into itl_map with key

zsyst = lv_syst

zmapfield = xfc-fieldname

binary search.

if sy-subrc = 0.

assign component itl_map-fieldname of structure

<ls_select_global> to

<ls_select_global_field>.

<ls_select_global_field> = <ls_select_field>.

UNASSIGN <ls_select_global_field>.

endif.

UNASSIGN <ls_select_field>.

Endloop.

Endloop.

0 Kudos

Thanks Francois. It helped with the performance.