Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

problem : ALV report taking a lot of time to execute

hii

Am facing problem in my ALV report which is taking a lot of Time to execute

Below is my Code :

START-OF-SELECTION.

  • Retrieving data from table

PERFORM sub_fill_itab.

************************************************************************

  • END-OF-SELECTION EVENT *

************************************************************************

END-OF-SELECTION.

PERFORM sub_fill_final.

  • Prepare fieldcatalog

PERFORM sub_prepare_fieldcat.

  • prepare layout

PERFORM sub_layout.

  • Display data in the output

PERFORM sub_display_data.

&----


*& Form sub_fill_itab

&----


  • text

----


FORM sub_fill_itab .

SELECT bukrs

gjahr

budat

belnr

INTO TABLE it_bkpf

FROM bkpf

WHERE budat IN s_budat AND bukrs EQ p_bukrs

AND gjahr IN s_gjahr .

IF sy-subrc EQ 0.

  • SORT it_bkpf BY bukrs gjahr belnr.

ELSE.

MESSAGE i007(zwb).

LEAVE LIST-PROCESSING.

ENDIF.

SELECT bukrs

belnr

xref3

gjahr

buzid

hkont

matnr

menge

dmbtr

lifnr

ebeln

shkzg

buzei

INTO TABLE it_bseg

FROM bseg

FOR ALL ENTRIES IN it_bkpf

WHERE bukrs = it_bkpf-bukrs AND gjahr = it_bkpf-gjahr

AND belnr = it_bkpf-belnr AND hkont IN s_hkont AND

ebeln IN s_ebeln.

IF sy-subrc EQ 0.

SORT it_bseg BY bukrs xref3 ebeln hkont gjahr.

ENDIF.

SELECT bukrs

xref3

gjahr

lifnr

belnr

ebeln

INTO TABLE it_bseg1

FROM bseg

FOR ALL ENTRIES IN it_bkpf

WHERE bukrs = it_bkpf-bukrs AND gjahr = it_bkpf-gjahr

AND belnr = it_bkpf-belnr . " AND hkont IN s_hkont AND ebeln IN s_ebeln.

IF sy-subrc EQ 0.

DELETE it_bseg1 WHERE lifnr = ''.

ENDIF.

SELECT lifnr

name1

INTO TABLE it_lfa1

FROM lfa1

FOR ALL ENTRIES IN it_bseg1

WHERE lifnr = it_bseg1-lifnr.

IF sy-subrc EQ 0.

DELETE ADJACENT DUPLICATES FROM it_lfa1 .

ENDIF.

&----


*& Form sub_fill_final

&----


  • text

----


FORM sub_fill_final .

LOOP AT it_bseg INTO wa_bseg.

*v_year1 = wa_bseg-xref3+0(4).

MOVE: wa_bseg-bukrs TO wa_bseg2-bukrs,

wa_bseg-belnr TO wa_bseg2-belnr,

  • wa_bseg-xref3

wa_bseg-gjahr TO wa_bseg2-gjahr,

  • wa_bseg-buzid

wa_bseg-hkont TO wa_bseg2-hkont,

wa_bseg-matnr TO wa_bseg2-matnr,

  • wa_bseg-menge

wa_bseg-dmbtr TO wa_bseg2-dmbtr,

  • wa_bseg-lifnr TO wa_bseg2-lifnr,

wa_bseg-ebeln TO wa_bseg2-ebeln,

wa_bseg-shkzg TO wa_bseg2-shkzg.

READ TABLE it_bseg1 INTO wa_bseg1 WITH KEY bukrs = wa_bseg-bukrs

gjahr = wa_bseg-gjahr

belnr = wa_bseg-belnr.

IF sy-subrc EQ 0.

MOVE: wa_bseg1-lifnr TO wa_bseg2-lifnr.

  • wa_bseg1-ebeln TO wa_bseg2-ebeln.

ENDIF.

APPEND wa_bseg2 TO it_bseg2.

CLEAR: wa_bseg2,

wa_bseg1,

wa_bseg.

ENDLOOP.

REFRESH: it_bseg,

it_bseg1.

IF sy-subrc EQ 0.

DELETE it_bseg2 WHERE lifnr NOT IN s_lifnr.

ENDIF.

LOOP AT it_bseg2 INTO wa_bseg2.

IF wa_bseg2-shkzg EQ 'H'.

v_val = - wa_bseg2-dmbtr.

ELSE.

v_val = wa_bseg2-dmbtr.

ENDIF.

MOVE: wa_bseg2-bukrs TO wa_final-bukrs,

wa_bseg2-belnr TO wa_final-belnr,

  • wa_bseg-xref3

wa_bseg2-gjahr TO wa_final-gjahr,

  • wa_bseg-buzid

wa_bseg2-hkont TO wa_final-hkont,

wa_bseg2-matnr TO wa_final-matnr,

  • wa_bseg-menge

v_val TO wa_final-dmbtr,

wa_bseg2-lifnr TO wa_final-lifnr,

wa_bseg2-ebeln TO wa_final-ebeln,

wa_bseg2-shkzg TO wa_final-shkzg.

READ TABLE it_bkpf INTO wa_bkpf WITH KEY bukrs = wa_bseg2-bukrs

gjahr = wa_bseg2-gjahr

belnr = wa_bseg2-belnr.

IF sy-subrc EQ 0.

MOVE: wa_bkpf-budat TO wa_final-budat.

ENDIF.

READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_bseg2-lifnr.

IF sy-subrc EQ 0.

MOVE: wa_lfa1-name1 TO wa_final-name1.

ENDIF.

APPEND wa_final TO it_final.

CLEAR: wa_bseg2,

wa_bkpf,

wa_final,

wa_lfa1.

ENDLOOP.

REFRESH: it_bseg2,

it_bkpf,

it_lfa1.

FREE: it_bseg2,

it_bkpf,

it_lfa1.

IF sy-subrc EQ 0.

SORT it_final BY ebeln.

ENDIF.

ENDFORM. " sub_fill_final

*******************************************************************

The Sub-Routine "sub_fill_final" taking a lot of Time as there are lakhs of Records getting populated in Internal table "it_bseg" .

Plz guide me up in Improvimg the codeing part so that it will take less time to execute .

Thanks in Advance

Jack

Not what you were looking for? View more on this topic or Ask a question