Hi,
I am developing a report in ALV but report is too slow, as its using three loops(Loop inside a loop), kindly suggest how to make the report fast, as I have tried using Read statement for 2 loops but data is not coming correctly, One of my friend suggested to u use field symbol, But I don't have much knowledge about the field symbols, kindly suggest how to modify the report to make it faster.
Here's the code ...
FORM FETCH_DATA .
IFNOT P_CHECK ISINITIAL.
if it_vttk[] isNOTINITIAL.
SELECT ROUTE KNANF KNEND
FROM TVRAB
INTOTABLE IT_ROUTE
FORALL ENTRIES IN IT_VTTK
WHERE ROUTE = IT_VTTK-ROUTE.
IF SY-SUBRC ISINITIAL.
SELECT VBELN TKNUM
FROM VTTP
INTOTABLE IT_VTTP
FORALL ENTRIES IN IT_VTTK
WHERE TKNUM = IT_VTTK-TKNUM.
IF SY-SUBRC ISINITIAL.
SELECT VBELN KUNNR PARVW
FROM VBPA
INTOTABLE IT_KUNNR
FORALL ENTRIES IN IT_VTTP
WHERE VBELN = IT_VTTP-VBELN
AND ( PARVW = 'AG'
OR PARVW = 'SL' ).
if it_kunnr[] isNOTINITIAL. "added by Sonam
SELECT KUNNR NAME1
FROM KNA1
INTOTABLE IT_KNA1
FORALL ENTRIES IN IT_KUNNR
WHERE KUNNR = IT_KUNNR-KUNNR.
ENDIF.
SELECT VBELN POSNR matnr VGBEL VGPOS mtart AESKD
FROM LIPS
INTOTABLE IT_LIPS
FORALL ENTRIES IN IT_VTTP
WHERE VBELN = IT_VTTP-VBELN.
IF SY-SUBRC ISINITIAL.
SELECT VBAP~VBELN VBAP~POSNR VBAK~KNUMV vbak~auart "vbap~matnr
FROM VBAK INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN
INTOTABLE IT_VBAK
FORALL ENTRIES IN IT_LIPS
WHERE VBAP~VBELN = IT_LIPS-VGBEL
AND VBAP~POSNR = IT_LIPS-VGPOS
and vbak~auart in so_auart.
if sy-subrc isINITIAL.
SELECT KNUMV KPOSN KSCHL KWERT
FROM KONV
INTO TABLE IT_KONV
* FOR ALL ENTRIES IN IT_VBRP
FORALL ENTRIES IN IT_VBAK
WHERE KNUMV = IT_VBAK-KNUMV.
endif.
select vbeln posnr vgbel vgpos aubel NETWR NTGEW BRGEW MVGR1 PRODH
from vbrp
intotable it_vbrp
forall entries in IT_LIPS
where vgbel = IT_LIPS-VBELN
AND VGPOS = IT_LIPS-POSNR.
if it_vbrp[] isnotINITIAL.
SELECT vbeln bstnk_vf
FROM vbrk
intoTABLE it_vbrk
FORALL ENTRIES IN it_vbrp
WHERE vbeln = IT_VBRP-VBELN
AND SFAKN eq SPACE
AND FKSTO NE'X'.
endif.
ENDIF.
ENDIF.
ENDIF.
else.
MESSAGE'NO RELEVANT VALUE EXIST FOR THIS'TYPE'E'.
endif.
DATA: L_TEU TYPEI,
LV_PRODH TYPEC LENGTH 10,
LINESTYPETABLEOF TLINE,
WA_LINE TYPE TLINE,
L_NAME TYPE THEAD-TDNAME.
SORT: IT_VTTP[] BY TKNUM," VBELN,
IT_VTTK[] BY TKNUM ,"ROUTE,
IT_LIPS[] BY VBELN," POSNR, "VGBEL VGPOS,
IT_VBRP[] BY VGBEL VGPOS,
IT_VBRK[] BY VBELN,
IT_VBAK[] BY VBELN POSNR," POSNR KNUMV,
* IT_VBKD[] BY VBELN,
IT_ROUTE[] BY ROUTE,
IT_KUNNR[] BY VBELN,
IT_KNA1[] BY KUNNR,
IT_KONV[] BY KNUMV KPOSN KSCHL.
LOOPAT IT_VTTK INTO WA_VTTK.
LOOPAT IT_VTTP INTO WA_VTTP WHERE TKNUM = WA_VTTK-TKNUM.
LOOPAT IT_LIPS INTO WA_LIPS WHERE VBELN = WA_VTTP-VBELN.
READTABLE IT_VBRP INTO WA_VBRP WITHKEY VGBEL = WA_LIPS-VBELN VGPOS = WA_LIPS-POSNR BINARYSEARCH.
IF SY-SUBRC ISINITIAL.
READTABLE IT_VBRk INTO WA_VBRk WITHKEY vbeln = WA_VBRP-vbeln BINARYSEARCH.
endif.
READTABLE IT_VBAK INTO WA_VBAK WITHKEY VBELN = WA_LIPS-VGBEL POSNR = WA_LIPS-VGPOS BINARYSEARCH.
IF SY-SUBRC ISINITIAL.
READTABLE IT_ROUTE INTO WA_ROUTE WITHKEY ROUTE = WA_VTTK-ROUTE BINARYSEARCH.
READTABLE IT_KUNNR INTO WA_KUNNR WITHKEY VBELN = WA_VTTP-VBELN PARVW = 'AG'BINARYSEARCH.
if sy-subrc isINITIAL.
READTABLE IT_KNA1 INTO WA_KNA1 WITHKEY KUNNR = WA_KUNNR-KUNNR BINARYSEARCH.
endif.
READTABLE IT_KUNNR INTO WA_KUNNR1 WITHKEY VBELN = WA_VTTP-VBELN PARVW = 'SL'BINARYSEARCH.
if sy-subrc isINITIAL.
READTABLE IT_KNA1 INTO WA_SL WITHKEY KUNNR = WA_KUNNR1-KUNNR BINARYSEARCH.
endif.
CONCATENATE WA_VBAK-VBELN WA_VBAK-POSNR INTO L_NAME.
REFRESH: lines.
CALLFUNCTION'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = '0001'
LANGUAGE = 'E'
NAME = L_NAME
OBJECT = 'VBBP'
TABLES
LINES = LINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
else.
MESSAGE'NO RELEVANT VALUE EXIST FOR THIS'TYPE'E'.
LEAVETO LIST-PROCESSING.
endif.
READTABLELINESINTO WA_LINE INDEX1.
"Loop for every Billing Condition Number and
READTABLE IT_KONV INTO WA_KONV WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZFR0'BINARYSEARCH . "Freight Charges
if sy-subrc ne0.
READTABLE IT_KONV INTO WA_KONV WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZFR1' BINARYSEARCH . "Freight Charges
endif.
* IF ls_konv-kschl = 'ZFR0'. "FOR FREIGHT CHARGES
READTABLE IT_KONV INTO WA_KONV_ZD01
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZD01'BINARYSEARCH.
if sy-subrc ne0.
READTABLE IT_KONV INTO WA_KONV_ZD01
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZD03'BINARYSEARCH.
endif.
READTABLE IT_KONV INTO WA_KONV_ZD02
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZD02'BINARYSEARCH.
if sy-subrc ne0.
READTABLE IT_KONV INTO WA_KONV_ZD02
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZD04'BINARYSEARCH.
endif.
READTABLE IT_KONV INTO WA_KONV_ZSTB
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZSTB'BINARYSEARCH.
*Discounted Total = Frieight - Discount1 - Discount2
WA_FINAL-ZFR0 = WA_KONV-KWERT
+ WA_KONV_ZD01-KWERT "Added as it is a -ve amt
+ WA_KONV_ZD02-KWERT.
*Tax = Ser.Tax basis Reven
WA_FINAL-TAX = WA_KONV_ZSTB-KWERT.
LOOPAT IT_KONV INTO WA_KONV_THC WHERE KNUMV = WA_VBAK-KNUMV
AND KPOSN = WA_VBAK-POSNR
AND ( KSCHL = 'ZTH0'OR KSCHL = '0ZTH' "Ter. HandlINGg ChrgES
OR KSCHL = 'ZTH1'OR KSCHL = '1ZTH'
OR KSCHL = 'ZTH3'OR KSCHL = 'ZTH4') .
IF ( WA_KONV_THC-KSCHL = 'ZTH0'OR WA_KONV_THC-KSCHL = '0ZTH'
OR WA_KONV_THC-KSCHL = 'ZTH4'). "FOR TER handling CHARGES - ZTH0 and 0ZTH
WA_FINAL-ZTH0 = WA_KONV_THC-KWERT.
WA_FINAL-NON_TAX = WA_KONV_THC-KWERT.
* gs_invoice-total = WA_KONV-kwert.
ELSE. "FOR TER handling CHARGES - ZTH1 and 1ZTH
WA_FINAL-TAX = WA_FINAL-TAX + WA_KONV_THC-KWERT.
WA_FINAL-ZTH0 = WA_FINAL-ZTH0 + WA_KONV_THC-KWERT.
READTABLE IT_KONV INTO WA_KONV_ZSR1 "added by Sonam Singh on dated 19th july'12 (zsr1,zec1,zsh1)
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZSR1'BINARYSEARCH.
WA_FINAL-ZSR1 = WA_KONV_ZSR1-KWERT.
READTABLE IT_KONV INTO WA_KONV_ZEC1
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZEC1'BINARYSEARCH.
WA_FINAL-ZEC1 = WA_KONV_ZEC1-KWERT.
READTABLE IT_KONV INTO WA_KONV_ZSH1
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZSH1'BINARYSEARCH.
WA_FINAL-ZSH1 = WA_KONV_ZSH1-KWERT.
ENDIF.
ENDLOOP.
*Abate = Discounted Total - Ser.Tax basis Reven
WA_FINAL-ABATE = WA_FINAL-ZFR0
- WA_FINAL-TAX . "WA_KONV_ZSTB-KWERT (CHANGED FOR TAX) .
*Service taxes ,ECS and SHE taxes...
READTABLE IT_KONV INTO WA_KONV_ZSRT
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZSRT'BINARYSEARCH.
WA_FINAL-ZSRT = WA_FINAL-ZSR1 + WA_KONV_ZSRT-KWERT. "added by Sonam Singh on dated 19th july'12
READTABLE IT_KONV INTO WA_KONV_ZECS
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZECS'BINARYSEARCH.
WA_FINAL-ZECS = WA_FINAL-ZEC1 + WA_KONV_ZECS-KWERT.
READTABLE IT_KONV INTO WA_KONV_ZSHE
WITHKEY KNUMV = WA_VBAK-KNUMV
KPOSN = WA_VBAK-POSNR
KSCHL = 'ZSHE'BINARYSEARCH.
WA_FINAL-ZSHE = WA_FINAL-ZSH1 + WA_KONV_ZSHE-KWERT.
CLEAR: WA_KONV,WA_KONV_THC,WA_KONV_ZD01,WA_KONV_ZD02,WA_KONV_ZSTB,WA_KONV_ZSRT,WA_KONV_ZECS,WA_KONV_ZSHE.
"Loop for every Billing Condition Number and
IF WA_lips-MTART = 'C20'. "changes by Sonam
L_TEU = 1.
ELSEIF WA_lips-MTART = 'C40'OR WA_lips-MTART = 'CPK' .
L_TEU = 2.
else.
clear l_teu.
ENDIF.
LV_PRODH = WA_VBRP-PRODH+5(5).
CASE LV_PRODH.
WHEN'00001'. "REEFER
WA_FINAL-CONTNER_TY = 'REEFER'.
WHEN'00002'. "DRY
WA_FINAL-CONTNER_TY = 'DRY'.
WHEN'00003'. "TANK
WA_FINAL-CONTNER_TY = 'TANK'.
WHEN'00004'. "OTHERS
WA_FINAL-CONTNER_TY = 'OTHERS'.
ENDCASE.
wa_final-tpbez = wa_vttk-tpbez.
WA_FINAL-VBELN = WA_VBRP-VBELN.
WA_FINAL-AUBEL = WA_VBAK-VBELN."WA_VBRP-AUBEL.
WA_FINAL-VGBEL = WA_LIPS-VBELN."WA_VBRP-VGBEL.
WA_FINAL-AESKD = WA_LIPS-AESKD.
WA_FINAL-NETWR = WA_FINAL-ZSRT + WA_FINAL-ZECS +
WA_FINAL-ZSHE + WA_FINAL-ZFR0 +
WA_FINAL-ZTH0. "WA_VBRP-NETWR .
WA_FINAL-NTGEW = WA_VBRP-NTGEW .
WA_FINAL-BRGEW = WA_VBRP-BRGEW .
WA_FINAL-MVGR1 = WA_VBRP-MVGR1 .
if wa_lips-mtart = 'C00'. "changes by Sonam
WA_FINAL-MATNR = 'FLAT WAGON'.
else.
WA_FINAL-MATNR = WA_lips-MATNR .
endif.
WA_FINAL-MTART = WA_lips-MTART .
WA_FINAL-TDLNR = WA_VTTK-TDLNR.
WA_FINAL-TKNUM = WA_VTTK-TKNUM.
WA_FINAL-ROUTE = WA_VTTK-ROUTE.
WA_FINAL-KNANF = WA_ROUTE-KNANF.
WA_FINAL-KNEND = WA_ROUTE-KNEND.
WA_FINAL-SIGNI = WA_VTTK-SIGNI.
WA_FINAL-BSTNK_VF = WA_VBRk-BSTNK_VF. "changes by Sonam
WA_FINAL-KUNNR = WA_KUNNR-KUNNR.
WA_FINAL-NAME1 = WA_KNA1-NAME1.
WA_FINAL-KUNNR_SL = WA_KUNNR1-KUNNR.
WA_FINAL-NAME_SL = WA_SL-NAME1.
WA_FINAL-CONSIN = WA_LINE-TDLINE.
WA_FINAL-DATBG = WA_VTTK-DATBG.
WA_FINAL-DATEN = WA_VTTK-DATEN.
WA_FINAL-TEU = L_TEU.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_LINE-TDLINE.
CLEAR: WA_LIPS, WA_VBRP, WA_VBRK, WA_VBAK, WA_KUNNR,WA_FINAL, WA_KNA1, WA_ROUTE, L_TEU,WA_KONV. "WA_MARA.
* ENDIF.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDFORM. " FETCH_DATA