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: 

Change value of fields of an internal table without loop

Pier_1973
Participant
0 Kudos

Hello Everyone,

Please can you help me with new abap code?
I need to change values of some fields of an internal table depending other tables but i would achieve it without loop, because i have lots of record in my internal table.

With old abap code I would do:

Loop at Internal_tableA.

read table Internal_tableB with key fieldA-xx = fieldB-xx fieldA-zz = fieldB-zz.

if sy-subrc = 0.

Read Internal_tableC wiht key fieldC-kk = fieldB-kk.

IF sy-subrc = 0.

fieldA-NNN = fieldC-XXX.

fieldA-WWW = fieldC-HHH.

MODIFY Internal_tableA.

ENDIF.

ENDIF.

ENDLOOP.

I should do the same but without loop.

Thank you in advance

 

 

fieldA-NNN = fieldC-XXX.

 

11 REPLIES 11

Sandra_Rossi
Active Contributor
0 Kudos

Do you think that a constructor expression has better performance?

That's a wrong assertion. The goal of constructor expressions is to clarify the ABAP code.

0 Kudos

Sorry but I didn’t understand you wrote.

You say "I should do the same but without loop." It means you probably want to use what newbies call incorrectly "new ABAP", which is without "LOOP AT" (but in fact it remains a loop with only a different syntax), its real name is a Constructor Expression. Newbies incorrectly think that it has a better performance, that's completely wrong. I hope you understand now.

0 Kudos

Sandra, I apologize for my errors but my intentions were to ask an help to avoid the use of loop because i have lots of records into internal table.

Whit for iteraction, actually the loop is by-passed but I don't know how to write code to obtain my goal.

Basically, i have to fill fields of first internal table getting data from two other internal tables, with read table.

If i use loop i have problems for perfomance 

0 Kudos

You can fix performance on READ TABLE. It could be the same performance issue with constructor expressions.

The first thing to do is to use SORTED or HASHED tables instead of STANDARD. By default, you should never use STANDARD tables (use them only in the rare cases of doing a unique loop at all the lines).

0 Kudos

Sandra,

yes my internal tables are Sorted tables.

Please tell me the syntax for constructor expressions (If you can)

There should be no performance issue with your current code if you have sorted tables with the right fields. Constructor expressions are useless to solve your performance issue. Especially because you have a MODIFY. Constructor expressions should never be used if you have MODIFY. You desperately want to use constructor expressions, I tell you to not use them, but it seems you don't want to understand my arguments. Good luck.

PS: you can find in the forum all my answers about constructor expressions.

Siri_88
Discoverer
0 Kudos

How about select directly from the SQL without performing a loop?

Below is an example to get NAME_TEXT by BNAME (SAP ID).

 

SELECT A~BNAME C~NAME_TEXT
  INTO CORRESPONDING FIELDS OF TABLE GT_USR02
    FROM USR02 AS A
    INNER JOIN USR21 AS B
    ON A~BNAME = B~BNAME
    INNER JOIN ADRP AS C
    ON B~PERSNUMBER = C~PERSNUMBER.

0 Kudos

Hi Siri i cannot because I need to work with these 3 internal tables. 😞

raymond_giuseppi
Active Contributor
0 Kudos

You didn't provide a 'why' answer... Nevertheless read this answer 

VaraPrasadT
Explorer
0 Kudos

To get better performance, SAP is suggested to go with CDS view. Try this approach and see if your problem can solve 

Vara Prasad Thatikonda