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 avoid nested loop?

walkerist
Participant
0 Kudos
922
Here is my current situation: 
DATA: T_FCAT1 TYPE slis_fieldcat_alv,
t_fcat TYPE kkblo_t_fieldcat.
LOOP AT T_FCAT1 INTO LX_FCAT1.
LOOP AT LT_FCATALOG INTO LX_FCATALOG.
IF LX_FCAT1-FIELDNAME = LX_FCATALOG-FIELDNAME.
LX_FCAT1-COL_POS = LX_FCATALOG-COL_POS.
APPEND LX_FCAT1 TO T_FCAT1.
CLEAR LX_FCAT1.
ENDIF.
ENDLOOP.
ENDLOOP.

It is possible to eliminate the nested loop here?
My goal is to overwrite the COL_POS from LX_FCATALOG to T_FCAT1 or LX_FCAT1
but the pre-requisite is to map it into correct field.
example: T_FCAT1 OR LX_FCAT1. FIELDNAME COL_POS
EBELN 0


LT_FCATALOG OR LX_FCATALOG. FIELDNAME COL_POS EBELN 23 <-----I want this to overwrite to T_FCAT1 OR LX_FCAT1.
6 REPLIES 6

matt
Active Contributor
849

Looks to me like you've an endless loop (except where there are no shared FIELDNAME between the two internal tables), since you're looping through t_fcat1 you're adding new records into it.

fedaros
Product and Topic Expert
Product and Topic Expert
849

Seems no need of nested loop here. You can loop once T_FCAT1 assigning field symbol, as you want modify COL_POS, read table LT_FCATALOG per field and just set <fs_fcat1>-COL_POS = ls_fcatalog-COL_POS.

BTW: You have many questions unclosed, are it really without valid answers to be closed ?

walkerist
Participant
0 Kudos
849

@All two fieldcatalogs have different types.

raymond_giuseppi
Active Contributor
0 Kudos
849

Try at least something such as

LOOP AT T_FCAT1 ASSIGNING <old>.
  READ TABLE T_FCATALOG WITH KEY FIELDNAME = <old>-FIELDNAME ASSIGNING <new>.     
  IF <new> IS ASSIGNED.
     <old>-COL_POS = <new>-COL_POS.
  ENDIF.
ENDLOOP.

What's your version?

Sandra_Rossi
Active Contributor
849

I guess experience says there's no need to close the questions as people keep answering...

Ryan-Crosby
Active Contributor
849

I stopped answering several months ago when it was obvious that the only thing that would continue was the flow of questions.