Application Development and Automation 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: 
Read only

Convert SAP Old code to SAP New Syntax

Sonu786
Discoverer
644

Dear Team,

How to convert the below code into sap new syntax

 LOOP AT it_h1 INTO wa_h1n WHERE regiogroup 'S01' AND supply_division+0(1'W'.
        IF wa_h-langu_corr 'M2'.
          LOOP AT it_swm INTO lv_string WHERE opbel_bi wa_h1n-opbel_bi.
            TRANSFER lv_string TO p_file.
            CLEAR lv_string.
          ENDLOOP.
        ELSE.
          LOOP AT it_swe INTO lv_string WHERE opbel_bi wa_h1n-opbel_bi.
            TRANSFER lv_string TO p_file.
            CLEAR lv_string.
          ENDLOOP.
        ENDIF.
      ENDLOOP.

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
0 Kudos
589

Why do you think it's worth converting?

The only question I see by reading your code, concerning performance, is how many lines are in IT_H1, IT_SWM and IT_SWE, and if they are defined with a sorted key respectively, regiogroup, opbel_bi and opbel_bi.

NB: "lv_string" has a meaningless name and should be renamed + there are also two useless lines "CLEAR lv_string".

Read only

Sonu786
Discoverer
0 Kudos
534

Thank your for your quick reply. All three tables contain more than 1,000 records, and the internal tables are sorted by key. The above code is executed under the OPEN DATASET command to write a file to the application server, which is why we are transferring the table data to p_file, which is of type string.

We are experiencing performance issues, so we are trying to improve performance by using modern inline syntax.

Read only

0 Kudos
426

those are just syntax sugar, code may look succinct, but it doesn't mean high performance.

Read only

345

If the statement "sorted by key" means a standard internal table followed by SORT, then LOOP AT is not optimized at all (only READ TABLE with BINARY SEARCH is optimized).

"LOOP AT" can be optimized only if the internal table has a "sorted index" i.e. it's declared with "TYPE SORTED TABLE" (sorted primary index).

Another alternative is to use a sorted secondary index declared for the internal table via "WITH ... SORTED KEY seckey COMPONENTS", and to use "LOOP AT itab USING KEY seckey WHERE ..."

Note that "supply_division+0(1'W' " cannot be optimized before ABAP 7.58 (maybe needs to be rewritten "supply_division BETWEEN 'W' and 'WZZZ' "), so I hope that using an index for "regiogroup 'S01' " discriminates the lines sufficiently.

Read only

NTeunckens
Active Contributor
0 Kudos
461

Please check out the project "ABAPCleaner" (link) and the power of using it to refactor / modernize your code : 🟢 How to Clean your ABAP code in Seconds with ABA... - SAP Community
Install ABAP Developer Tools (ADT) and use the ABAPCleaner to get hints on how to optimize the code.
If it doesn't offer you a good hint on optimization, it's probably not necessary ..

Hope this helps

Nic T.