Testing Document For Hanafication With Screenshots
Testing Document For Hanafication With Screenshots
Link : https://blogs.sap.com/2019/08/20/soh-abap-code-remediation-rules-to-be-followed/
Before order by
SELECT * from kna1 INTO TABLE @data(it_kna1_cn) WHERE LAND1 ne 'DE'.
select * from kna1
into table @DATA(itab)
for all entries in @it_kna1_cn
where kunnr = @it_kna1_cn-kunnr.
Results:
SELECT kunnr f1 f2 from kna1 INTO TABLE @data(it_kna1_cn) WHERE LAND1 ne 'DE'
ORDER BY kunnr.
select * from kna1
into table @DATA(itab)
for all entries in @it_kna1_cn
where kunnr = @it_kna1_cn-kunnr
ORDER BY PRIMARY KEY.
Interna
l to
Wipro
ra_route-sign ='I'.
ra_route-option ='BT'.
ra_route-LOW ='20044'.
ra_route-high ='20400'.
APPEND ra_route.
SELECT DISTINCT
store, route INTO TABLE @data(itab)
FROM zdlmta
WHERE store = ' ' "<fs_termin>-kunnr'.
AND route IN @ra_route.
Output:
Interna
l to
Wipro
After code changes
RANGES:
ra_route FOR vbap-route
.
ra_route-sign ='I'.
ra_route-option ='BT'.
ra_route-LOW ='20044'.
ra_route-high ='20400'.
APPEND ra_route.
Interna
l to
Wipro
SELECT DISTINCT
store, route INTO TABLE @data(itab)
FROM zdlmta
WHERE store = ' ' "<fs_termin>-kunnr'.
AND route IN @ra_route
ORDER BY store, route.
Output:
Interna
l to
Wipro
Case 3: Aggregations (Max) with equal to operator and few primary key fields in where condition
Before changes:
* Case 3: aggregations(max)
select max( gueltig_bis )
from zta_ma_035
into @data(lv_max)
where art_nr = '0015768'
and var = '001'
and gebi = '000070'.
write:lv_max.
Interna
l to
Wipro
Output:
After changes:
* Case 3: aggregations(max)
select ART_NR,
VAR,
GEBI,
max( gueltig_bis ) as gueltig_bis
from zta_ma_035
into TABLE @data(itab)
where art_nr = '0015768'
and var = '001'
and gebi = '000070'
GROUP BY ART_NR,
VAR,
GEBI
ORDER BY
ART_NR,
VAR,
GEBI.
read TABLE itab INTO data(wa_tab) INDEX 1.
write: wa_tab-gueltig_bis.
Output:
Interna
l to
Wipro
Case 4: aggregation (max)- random non key fields in where condition
Before changes:
* Case 4: aggregations(max) random non key fields
select
max( gueltig_bis )
from zta_ma_035
into @data(itab)
where IMPORT = '18698'
and AENDER_KZ = '7'.
write: itab.
Output:
After change:
* Case 4: aggregations(max) random non key fields
select
max( gueltig_bis ) as gueltig_bis,
IMPORT,
AENDER_KZ
Interna
l to
Wipro
from zta_ma_035
into TABLE @data(itab)
where IMPORT = '18698'
and AENDER_KZ = '7'
GROUP BY IMPORT,AENDER_KZ
ORDER BY IMPORT,AENDER_KZ.
read TABLE itab INTO data(wa_tab) INDEX 1.
write: wa_tab-gueltig_bis.
Output:
Case 6: aggregation(count)
Before changes:
data t_matnr TYPE TABLE OF marc WITH HEADER LINE.
t_matnr-werks = '8866' .
APPEND t_matnr.
t_matnr-werks = '8868' .
APPEND t_matnr.
IF NOT t_matnr[] IS INITIAL.
SELECT COUNT( * ) FROM marc
into @data(lv_count)
FOR ALL ENTRIES IN @t_matnr
WHERE werks = @t_matnr-werks.
write lv_count.
ENDIF.
Output:
Interna
l to
Wipro
After changes:
Before changes
data t_matnr TYPE TABLE OF marc WITH HEADER LINE.
t_matnr-werks = '8866' .
APPEND t_matnr.
IF NOT t_matnr[] IS INITIAL.
SELECT COUNT(*) FROM marc
into @data(tb_matnr)
WHERE werks = @t_matnr-werks.
write tb_matnr.
ENDIF.
Interna
l to
Wipro
Output:
After changes:
data t_matnr TYPE TABLE OF marc WITH HEADER LINE.
data tb_matnr TYPE TABLE OF marc WITH HEADER LINE.
t_matnr-werks = '8866' .
APPEND t_matnr.
IF NOT t_matnr[] IS INITIAL.
SELECT werks, COUNT(*) as count FROM marc
into CORRESPONDING FIELDS OF TABLE @itab
WHERE werks = @t_matnr-werks
GROUP BY werks
order by werks.
ENDIF.
Output:
Interna
l to
Wipro
Note: for any aggregation functions like MAX,SUM,COUNT its better not to
change code when there is no where condition in statement or when the tables
are there in where condition like (in table or for all entries etc) i.e
multiple values for single field in where . in these 2 conditions it better to
leave the statement unchanged.
Case 8: aggregations(count) with with where condition but non primary key fields
Before changes:
SELECT COUNT(*) FROM marc
into @data(tb_matnr)
WHERE MAABC = 'A'.
write tb_matnr.
Output:
After changes:
SELECT COUNT(*) as count ,MAABC FROM marc
into TABLE @data(tb_matnr)
WHERE MAABC = 'A'
GROUP BY MAABC
ORDER BY MAABC.
Interna
l to
Wipro
Output:
Interna
l to
Wipro