‎2006 Aug 18 2:25 PM
hi all,
selection-screen is
year
period
I need to get wbs elemets(ps_psp_pnr) from GLPCA table where user enters year and period and activ = sd00.
cast of sales = for each wbs elment we must add all amounts where account nos 831501 or 831201.
for this requirement i wrote the program like this. but the program taking too much time to get the out put,
if any body know different way to write these program to increase performance.
&----
*& Report ZFRSGDD1 *
*& *
&----
*& *
*& *
&----
REPORT ZFRSGDD1 .
TABLES: ZGLPCA.
PARAMETERS: RYEAR LIKE ZGLPCA-RYEAR.
PARAMETERS: POPER LIKE ZGLPCA-POPER.
DATA: BEGIN OF ITAB OCCURS 0,
ACTIV LIKE ZGLPCA-ACTIV,
RYEAR LIKE ZGLPCA-RYEAR,
POPER LIKE ZGLPCA-POPER,
REFDOCNR LIKE ZGLPCA-REFDOCNR,
RPRCTR LIKE ZGLPCA-RPRCTR,
RACCT LIKE ZGLPCA-RACCT,
KUNNR LIKE ZGLPCA-KUNNR,
MATNR LIKE ZGLPCA-MATNR,
PS_PSP_PNR LIKE ZGLPCA-PS_PSP_PNR,
HSL LIKE ZGLPCA-HSL,
END OF ITAB.
DATA: BEGIN OF JTAB OCCURS 0,
ACTIV LIKE ZGLPCA-ACTIV,
RYEAR LIKE ZGLPCA-RYEAR,
POPER LIKE ZGLPCA-POPER,
REFDOCNR LIKE ZGLPCA-REFDOCNR,
RPRCTR LIKE ZGLPCA-RPRCTR,
RACCT LIKE ZGLPCA-RACCT,
KUNNR LIKE ZGLPCA-KUNNR,
MATNR LIKE ZGLPCA-MATNR,
PS_PSP_PNR LIKE ZGLPCA-PS_PSP_PNR,
HSL LIKE ZGLPCA-HSL,
CSALE LIKE ZGLPCA-HSL.
END OF JTAB.
SELECT ACTIV RYEAR POPER HSL REFDOCNR RPRCTR RACCT KUNNR MATNR
PS_PSP_PNR INTO TABLE ITAB FROM ZGLPCA WHERE RYEAR = RYEAR AND
POPER = POPER.
LOOP AT ITAB WHERE ACTIV = 'SD00'.
MOVE-CORRESPONDING ITAB TO JTAB.
APPEND JTAB.
ENDLOOP.
SORT ITAB BY REFDOCNR.
LOOP AT JTAB.
LOOP AT ITAB.
CHECK JTAB-PS_PSP_PNR = ITAB-PS_PSP_PNR.
CHECK ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'.
JTAB-CSALE = JTAB-CSALE + ITAB-HSL.
MOVE-CORRESPONDING ITAB TO JTAB.
MODIFY JTAB.
ENDIF.
ENDLOOP.
LOOP AT JTAB.
WRITE: / JTAB-ACTIV,JTAB-RYEAR,JTAB-POPER,JTAB-HSL,JTAB-REFDOCNR,
JTAB-RPRCTR,JTAB-RACCT,JTAB-KUNNR,JTAB-MATNR,JTAB-PS_PSP_PNR,JTAB-HSL,
JTAB-CSALE.
ENDLOOP.
‎2006 Aug 18 2:39 PM
Hello Praveen
I guess on ENDLOOP is missing in you code sample.
LOOP AT JTAB.
LOOP AT ITAB.
CHECK JTAB-PS_PSP_PNR = ITAB-PS_PSP_PNR.
CHECK ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'.
JTAB-CSALE = JTAB-CSALE + ITAB-HSL.
MOVE-CORRESPONDING ITAB TO JTAB.
MODIFY JTAB.
ENDIF.
ENDLOOP. " entries in JTAB ENDLOOP. " entries in ITAB <- missingWhy don't you put your conditions into the LOOPs?
LOOP AT JTAB.
LOOP AT ITAB
WHERE ( ps_psp_pnr = JTAB-ps_psp_pnr ) AND
( racct = '0000831201' OR
racct = '0000831501' ).
* CHECK JTAB-PS_PSP_PNR = ITAB-PS_PSP_PNR. " DEL
* CHECK ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'. " DEL
JTAB-CSALE = JTAB-CSALE + ITAB-HSL.
MOVE-CORRESPONDING ITAB TO JTAB.
MODIFY JTAB.
ENDIF.
ENDLOOP. " entries in JTAB
ENDLOOP. " entries in ITAB If you don't need ITAB anymore you could delete the obsolete entries before entering the LOOPs in order to fasten looping.
DELETE ITAB
WHERE ( racct <> '0000831201' AND
racct <> '0000831501' ).Regards
Uwe
‎2006 Aug 18 2:39 PM
Hello Praveen
I guess on ENDLOOP is missing in you code sample.
LOOP AT JTAB.
LOOP AT ITAB.
CHECK JTAB-PS_PSP_PNR = ITAB-PS_PSP_PNR.
CHECK ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'.
JTAB-CSALE = JTAB-CSALE + ITAB-HSL.
MOVE-CORRESPONDING ITAB TO JTAB.
MODIFY JTAB.
ENDIF.
ENDLOOP. " entries in JTAB ENDLOOP. " entries in ITAB <- missingWhy don't you put your conditions into the LOOPs?
LOOP AT JTAB.
LOOP AT ITAB
WHERE ( ps_psp_pnr = JTAB-ps_psp_pnr ) AND
( racct = '0000831201' OR
racct = '0000831501' ).
* CHECK JTAB-PS_PSP_PNR = ITAB-PS_PSP_PNR. " DEL
* CHECK ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'. " DEL
JTAB-CSALE = JTAB-CSALE + ITAB-HSL.
MOVE-CORRESPONDING ITAB TO JTAB.
MODIFY JTAB.
ENDIF.
ENDLOOP. " entries in JTAB
ENDLOOP. " entries in ITAB If you don't need ITAB anymore you could delete the obsolete entries before entering the LOOPs in order to fasten looping.
DELETE ITAB
WHERE ( racct <> '0000831201' AND
racct <> '0000831501' ).Regards
Uwe
‎2006 Aug 18 2:43 PM
Try these:
1. Check the order of fields in the select statement , it should be same as the order in which they appear in the table ZGLPCA.
Similarly , check the where conditions.
2. Optionally u may create a secondary index on the table with fields RYEAR and POPER
3. Replace the statements
LOOP AT JTAB.
LOOP AT ITAB.
CHECK JTAB-PS_PSP_PNR = ITAB-PS_PSP_PNR.
CHECK ITAB-RACCT = '0000831201' OR
ITAB-RACCT = '0000831501'.
By following points
LOOP AT JTAB
LOOP AT ITAB WHERE PS_PSP_PNR = JTAB-PS_PSP_PNR
AND (RACCT = '0000831201' OR
RACCT = '0000831501')
4. Instead of move-corresponding u may explicitly name the fields to be moved , before the append statement.
‎2006 Aug 18 3:13 PM
Hi Praveen,
1. make sure that the fields that you are passing on to your select statement are in table order ...
SELECT ACTIV RYEAR POPER HSL REFDOCNR RPRCTR RACCT KUNNR MATNR
PS_PSP_PNR INTO TABLE ITAB FROM ZGLPCA WHERE RYEAR = RYEAR AND
POPER = POPER.
2. Avoid using loop statemnet within a loop statement use Read table statement for the same...
3. Avoid using Check statements ..
Regards,
Santosh
‎2006 Aug 18 3:21 PM
Please check the below code for changes
REPORT ZFRSGDD1 .
TABLES: ZGLPCA.
PARAMETERS: RYEAR LIKE ZGLPCA-RYEAR.
PARAMETERS: POPER LIKE ZGLPCA-POPER.
DATA: BEGIN OF ITAB OCCURS 0,
ACTIV LIKE ZGLPCA-ACTIV,
PS_PSP_PNR LIKE ZGLPCA-PS_PSP_PNR,
RYEAR LIKE ZGLPCA-RYEAR,
POPER LIKE ZGLPCA-POPER,
REFDOCNR LIKE ZGLPCA-REFDOCNR,
RPRCTR LIKE ZGLPCA-RPRCTR,
RACCT LIKE ZGLPCA-RACCT,
KUNNR LIKE ZGLPCA-KUNNR,
MATNR LIKE ZGLPCA-MATNR,
HSL LIKE ZGLPCA-HSL,
END OF ITAB.
DATA: BEGIN OF JTAB OCCURS 0,
ACTIV LIKE ZGLPCA-ACTIV,
PS_PSP_PNR LIKE ZGLPCA-PS_PSP_PNR,
RYEAR LIKE ZGLPCA-RYEAR,
POPER LIKE ZGLPCA-POPER,
REFDOCNR LIKE ZGLPCA-REFDOCNR,
RPRCTR LIKE ZGLPCA-RPRCTR,
RACCT LIKE ZGLPCA-RACCT,
KUNNR LIKE ZGLPCA-KUNNR,
MATNR LIKE ZGLPCA-MATNR,
HSL LIKE ZGLPCA-HSL,
CSALE LIKE ZGLPCA-HSL.
END OF JTAB.
SELECT ACTIV RYEAR POPER HSL REFDOCNR RPRCTR RACCT KUNNR MATNR
PS_PSP_PNR INTO TABLE ITAB FROM ZGLPCA WHERE RYEAR = RYEAR AND
POPER = POPER.
LOOP AT ITAB.
check itab-ACTIV = 'SD00'.
AT new PS_PSP_PNR.
ltot = 0.
endat.
if ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'.
ltot = ltot + ITAB-HSL.
endif.
MOVE-CORRESPONDING ITAB TO JTAB.
move ltot to jtab-csale.
append jtab.
at end of ps_psp_pnr.
loop at jtab where ps_pnp_pnr = itab-ps_psp_pnr.
move ltot to jtab-csale.
modify jtab.
endloop.
endat.
ENDLOOP.
SORT ITAB BY REFDOCNR.
LOOP AT JTAB.
WRITE: / JTAB-ACTIV,JTAB-RYEAR,JTAB-POPER,JTAB-HSL,JTAB-REFDOCNR,
JTAB-RPRCTR,JTAB-RACCT,JTAB-KUNNR,JTAB-MATNR,JTAB-PS_PSP_PNR,JTAB-HSL,
JTAB-CSALE.
ENDLOOP.
Other solution can also be to update the CSALE vaule in another table with the key as PS_PSP_PNR and you can read the value during the write loop as illustrated below.
Loop at itab.
check itab-activ = 'SD0O'.
check ITAB-RACCT = '0000831201' OR ITAB-RACCT = '0000831501'.
at new ps_psp_pnr.
ltot = 0.
endat.
ltot = ltot + itab-hsl.
at end of ps_psp_pnr.
move itab-ps_psp_pnr to xtab-ps_psp_pnr.
move ltot to xtab-csale.
modify xtab.
endat.
endloop.
loop at jtab.
write jtab
read table xtab with key ps_psp_pnr = jtab-ps_psp_pnr.
write xtab-csale.
endloop.