Skip to Content

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

ABAP code performance issue

Hi experts

it seems in the following code there some costliest statements

can u plz analyse the code and correct the code so that performance improves

*& TABLES

&----


TABLES: AUFK, "Order master data

T001W, "PLANTS/BRANCHES

KNA1, "General Data in Customer Master

T003O, "ORDER TYPES

PMSDO, "PM Organizational data for sales documents

AFKO, "Order header data PP orders

VBAP, "Sales Document Item Data

FPLA, "Billing Plan

FPLT, "Billing Plan Dates

VBRK, "Billing Document Header data

VBAK, "Sales Document Header data

KONV, "Condition-Transaction Data

IHPA, "Plant maintenance

VIQMEL, "Notification

CAUFVD.

&----


*& TYPE POOLS

&----


TYPE-POOLS SLIS. "Global types for generic building blocks

&----


*& PROGRAM VARIABLES

&----


DATA: G_COL TYPE I, "Column position for fieldcat

G_SUM LIKE FPLT-FPROZ, "Billing %

G_TIME LIKE AFKO-GSTRP, "Time Period

G_DATE LIKE FPLT-AFDAT,

G_FKSAF LIKE FPLT-FKSAF,

G_PARNR LIKE IHPA-PARNR,

G_NAME1 LIKE KNA1-NAME1,

G_BSTKD LIKE PMSDO-BSTKD,

g_gltrp LIKE caufvd-gltrp, "Period of end time

g_gstrp LIKE caufvd-gstrp, "Period of start time

lv_lines type i.

&----


*& STRUCTURES

&----


DATA: I_FIELDCATTAB_WA TYPE SLIS_FIELDCAT_ALV, "Fieldcat Work Area for ALV

I_TITLE_WA TYPE SLIS_LISTHEADER. "Title Work Area for ALV

&----


*& INTERNAL TABLES

&----


" Internal table containg data of table VBAP

DATA I_VBAK LIKE VBAK OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF it_plant OCCURS 0,

werks like t001w-werks,

END OF it_plant.

" Internal table containing final data for the Report screen

DATA: BEGIN OF I_FINTAB OCCURS 0,

KUNUM LIKE VIQMEL-KUNUM,

NAME1 LIKE KNA1-NAME1,

AUFNR LIKE AUFK-AUFNR,

KTEXT LIKE AUFK-KTEXT,

BSTKD LIKE PMSDO-BSTKD,

VBELN LIKE VBAK-VBELN,

POSNR LIKE VBAP-POSNR,

KDMAT LIKE VBAP-KDMAT,

ZMENG LIKE VBAP-ZMENG,

KBETR LIKE KONV-KBETR,

NETWR LIKE VBAP-NETWR,

ARKTX LIKE VBAP-ARKTX,

AFDAT LIKE FPLT-AFDAT,

FPROZ LIKE AUFK-USER4,

USER4 LIKE AUFK-USER4,

FKSAF TYPE CHAR30,

WERKS LIKE MARC-WERKS,

AUART LIKE AUFK-AUART,

GSTRP LIKE AFKO-GSTRP,

GLTRP LIKE AFKO-GSTRP,

END OF I_FINTAB.

DATA I_FINALTAB LIKE I_FINTAB OCCURS 0 WITH HEADER LINE.

" Internal table containing AUFK table contents

DATA: I_AUFKTAB LIKE AUFK OCCURS 0 WITH HEADER LINE,

" Internal table containing FPLA table contents

I_FPLATAB LIKE FPLA OCCURS 0 WITH HEADER LINE,

" Internal table containing FPLT table contents

I_FPLTTAB LIKE FPLT OCCURS 0 WITH HEADER LINE,

" Internal table containing VBAPtable contents

I_VBAP LIKE VBAP OCCURS 0 WITH HEADER LINE,

" Fieldcat Internal table for ALV

I_FIELDCATTAB TYPE SLIS_T_FIELDCAT_ALV ,

" Title Internal table for ALV

I_TITLE TYPE SLIS_T_LISTHEADER,

I_FPLA LIKE FPLA OCCURS 0 WITH HEADER LINE.

DATA I TYPE N.

&----


*& SELECT-OPTIONS

&----


SELECT-OPTIONS: S_WERKS FOR T001W-WERKS, "Plant

S_AUART FOR AUFK-AUART, "Order Type

S_GSTRP FOR CAUFVD-GSTRP, "Period of Time

S_KUNUM FOR VIQMEL-KUNUM, "Customer Number

S_NAME1 FOR KNA1-NAME1, "Customername

S_AUFNR FOR AUFK-AUFNR MATCHCODE OBJECT ORDP, "Job Number

S_KTEXT FOR AUFK-KTEXT, "Job Description

S_BSTKD FOR PMSDO-BSTKD. "Purchase order no

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

  • AT SELECTION-SCREEN

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

  • Event which occurs each time the user hits enter on the selection

  • screen.

AT SELECTION-SCREEN.

perform plant_authorization_check.

perform validate_select_options.

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

  • START-OF-SELECTION

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

START-OF-SELECTION.

"Retrieves the data from the table AUFK,VBAP,VBAK,FPLT into internal table I_AUFKTAB

PERFORM SUB_SELECTION_TAB.

"Internal table containing the report fields

PERFORM SUB_SELECTION_FINALTAB1.

"Defining the fieldcatalog to be used for the report

PERFORM SUB_FIELDCAT_BUILD.

"Define the Top-Of-Page contents

PERFORM SUB_FIELDCAT_TITLE.

"Mapping the internal table I_FINALTAB with fieldcat

PERFORM SUB_FIELDCAT_DISPLAY.

&----


*& Form SUB_SELECTION_TAB

&----


  • Retrieves the data from the table AUFK into internal table I_AUFKTAB

----


FORM SUB_SELECTION_TAB.

SELECT AUFNR KTEXT OBJNR USER4 WERKS AUART INTO CORRESPONDING FIELDS OF TABLE

I_AUFKTAB FROM AUFK

FOR ALL ENTRIES in it_plant

WHERE AUFNR IN S_AUFNR

AND KTEXT IN S_KTEXT

  • AND WERKS IN S_WERKS

AND AUART IN S_AUART

AND werks = it_plant-werks.

  • AND ERDAT IN S_GSTRP.

IF SY-SUBRC <> 0.

MESSAGE S017.

ENDIF.

ENDFORM. "SUB_SELECTION_TAB

&----


*& Form SUB_SELECTION_FINALTAB1

&----


  • Final Internal table containing the report fields

----


FORM SUB_SELECTION_FINALTAB1.

" Retrieve the sales line items from the table VBAK

*IF NOT I_AUFKTAB[] IS INITIAL.

*loop at i_aufktab.

IF S_AUFNR IS INITIAL.

SELECT * FROM VBAK INTO TABLE I_VBAK

WHERE AUFNR = I_AUFKTAB-AUFNR.

ELSE.

*LOOP AT I_AUFKTAB.

SELECT * FROM VBAK INTO TABLE I_VBAK FOR ALL ENTRIES IN I_AUFKTAB

WHERE AUFNR = I_AUFKTAB-AUFNR.

  • APPEND I_VBAK.

  • ENDSELECT.

*ENDLOOP.

ENDIF.

IF I_VBAK IS INITIAL.

SELECT * FROM VBAK INTO TABLE I_VBAK.

  • WHERE AUFNR = I_AUFKTAB-AUFNR.

ENDIF.

*ENDIF.

*LOOP AT I_AUFKTAB.

LOOP AT I_VBAK.

" Retrieve the sales line items from the table VBAP

SELECT * INTO TABLE I_VBAP FROM VBAP

WHERE VBELN = I_VBAK-VBELN.

  • AND AUFNR = I_AUFKTAB-AUFNR.

" Retrieve the billing plan dates from the table FPLA

SELECT * FROM FPLA INTO TABLE I_FPLA

WHERE VBELN = I_VBAK-VBELN.

I = 1.

LOOP AT I_FPLA.

" Retrieve the billing plan dates from the table FPLT

SELECT AFDAT FPROZ FKSAF INTO CORRESPONDING FIELDS OF TABLE I_FPLTTAB

FROM FPLT

WHERE FPLNR = I_FPLA-FPLNR.

LOOP AT I_FPLTTAB.

AT END OF FPLNR.

SUM.

MOVE I_FPLTTAB-FPROZ TO G_SUM.

ENDAT.

I_FINTAB-FPROZ = G_SUM.

ENDLOOP.

IF I_FPLTTAB-FKSAF = 'A'.

CONCATENATE TEXT-001 '(' I_FPLTTAB-FKSAF ')' INTO I_FINTAB-FKSAF.

ELSEIF I_FPLTTAB-FKSAF = 'B'.

CONCATENATE TEXT-002 '(' I_FPLTTAB-FKSAF ')' INTO I_FINTAB-FKSAF.

ELSEIF I_FPLTTAB-FKSAF = 'C'.

CONCATENATE TEXT-003 '(' I_FPLTTAB-FKSAF ')' INTO I_FINTAB-FKSAF.

ELSEIF I_FPLTTAB-FKSAF = ' '.

CONCATENATE ' ' '(' I_FPLTTAB-FKSAF ')' INTO I_FINTAB-FKSAF.

ENDIF.

SORT I_FPLTTAB BY AFDAT DESCENDING .

READ TABLE I_FPLTTAB INDEX 1.

IF SY-SUBRC = 0.

I_FINTAB-AFDAT = I_FPLTTAB-AFDAT.

ENDIF.

READ TABLE I_VBAP INDEX I.

IF SY-SUBRC = 0.

MOVE : I_VBAP-VBELN TO I_FINTAB-VBELN,

I_VBAP-POSNR TO I_FINTAB-POSNR,

I_VBAP-KDMAT TO I_FINTAB-KDMAT,

I_VBAP-ZMENG TO I_FINTAB-ZMENG,

I_VBAP-NETPR TO I_FINTAB-KBETR,

I_VBAP-NETWR TO I_FINTAB-NETWR,

I_VBAP-AUFNR TO I_FINTAB-AUFNR,

I_VBAP-ARKTX TO I_FINTAB-ARKTX.

CLEAR I_AUFKTAB.

READ TABLE I_AUFKTAB WITH KEY AUFNR = I_VBAP-AUFNR.

IF SY-SUBRC = 0.

I_FINTAB-KTEXT = I_AUFKTAB-KTEXT.

I_FINTAB-USER4 = I_AUFKTAB-USER4.

I_FINTAB-WERKS = I_AUFKTAB-WERKS.

I_FINTAB-AUART = I_AUFKTAB-AUART.

"Retrieving customer number from VIQMEL into final internal table

SELECT SINGLE PARNR FROM IHPA INTO G_PARNR WHERE OBJNR = I_AUFKTAB-OBJNR

AND PARVW = TEXT-110

AND PARNR IN S_KUNUM.

IF SY-SUBRC = 0.

I_FINTAB-KUNUM = G_PARNR.

ENDIF.

"Retrieving customer name from KNA1 into final internal table

SELECT SINGLE NAME1 FROM KNA1 INTO G_NAME1 WHERE KUNNR = G_PARNR.

IF SY-SUBRC = 0.

I_FINTAB-NAME1 = G_NAME1.

ENDIF.

"Retrieving purchase order number from PMSDO into final internal table

SELECT SINGLE BSTKD FROM PMSDO INTO G_BSTKD WHERE OBJNR = I_AUFKTAB-OBJNR .

IF SY-SUBRC = 0.

I_FINTAB-BSTKD = G_BSTKD.

ENDIF.

" Retrieving Required end date from AFKO into final internal table

SELECT SINGLE gltrp gstrp FROM afko INTO (g_gltrp,g_gstrp) WHERE aufnr = i_aufktab-aufnr.

IF sy-subrc = 0. "AFKO

i_fintab-gltrp = g_gltrp.

i_fintab-gstrp = g_gstrp.

endif.

ENDIF. "AUFKTAB

ENDIF. "VBAP

APPEND I_FINTAB.

CLEAR I_FINTAB.

I = I + 1.

ENDLOOP. "FPLA

ENDLOOP. "I_VBAK

*DELETE I_FINTAB WHERE NOT AUFNR IN S_AUFNR.

*DELETE I_FINTAB WHERE NOT KUNUM IN S_KUNUM.

LOOP AT i_fintab WHERE kunum IN s_kunum

AND gstrp IN s_gstrp

AND gltrp IN s_gstrp

AND werks IN s_werks

AND auart IN s_auart

AND name1 IN s_name1

AND aufnr IN s_aufnr

AND ktext IN s_ktext

AND bstkd IN s_bstkd.

i_finaltab = i_fintab.

APPEND i_finaltab.

CLEAR i_finaltab.

ENDLOOP.

  • I_FINALTAB[] = I_FINTAB[].

  • IF ( I_FINALTAB[] IS INITIAL ).

  • MESSAGE S010.

  • ENDIF.

SORT I_FINALTAB BY AUFNR.

*endloop.

ENDFORM. "SUB_SELECTION_FINALTAB1

&----


*& Form SUB_FIELDCAT_BUILD

&----


  • Defining the fieldcatalog to be used for the report

----


FORM SUB_FIELDCAT_BUILD.

PERFORM SUB_FIELDCAT USING '' 'KUNUM' TEXT-004 G_COL 'X'.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'NAME1' TEXT-005 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'AUFNR' TEXT-006 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'KTEXT' TEXT-007 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'BSTKD' TEXT-008 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'VBELN' TEXT-009 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'POSNR' TEXT-010 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'KDMAT' TEXT-011 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'ZMENG' TEXT-012 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'KBETR' TEXT-013 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'NETWR' TEXT-014 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'ARKTX' TEXT-015 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'AFDAT' TEXT-016 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'FPROZ' TEXT-017 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'USER4' TEXT-018 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'FKSAF' TEXT-019 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'WERKS' TEXT-020 G_COL ''.

ADD 1 TO G_COL.

PERFORM SUB_FIELDCAT USING '' 'AUART' TEXT-021 G_COL ''.

ADD 1 TO G_COL.

ENDFORM. "SUB_FIELDCAT_BUILD

&----


*& Form SUB_FIELDCAT

&----


  • Defining the fields in the fieldcatalog used for the report

----


  • --> L_TABNAME : Table name for the fieldcat

  • --> L_FNAME : Field name for the fieldcat

  • --> L_SEL : Field Description for the fieldcat

  • --> L_COL : Column position for the fieldcat

  • --> L_KEY : Key for the fieldcat

----


FORM SUB_FIELDCAT USING L_TABNAME TYPE SLIS_TABNAME

L_FNAME TYPE SLIS_FIELDNAME

L_SEL TYPE DD03P-SCRTEXT_L

L_COL TYPE I

L_KEY TYPE C.

I_FIELDCATTAB_WA-REF_TABNAME = L_TABNAME.

I_FIELDCATTAB_WA-FIELDNAME = L_FNAME.

I_FIELDCATTAB_WA-SELTEXT_L = L_SEL.

I_FIELDCATTAB_WA-COL_POS = L_COL.

I_FIELDCATTAB_WA-KEY = L_KEY.

APPEND I_FIELDCATTAB_WA TO I_FIELDCATTAB.

ENDFORM. " SUB_FIELDCAT

&----


*& Form SUB_FIELDCAT_DISPLAY

&----


  • Mapping the internal table I_FINALTAB with fieldcat

----


FORM SUB_FIELDCAT_DISPLAY.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'ZPSPAR11_SCHD_RATES'

IT_FIELDCAT = I_FIELDCATTAB

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_SAVE = 'A'

TABLES

T_OUTTAB = I_FINALTAB.

ENDFORM. "SUB_FIELDCAT_DISPLAY

&----


*& Form SUB_FIELDCAT_TITLE

&----


  • Define the Top-Of-Page contents

----


FORM SUB_FIELDCAT_TITLE.

I_TITLE_WA-TYP = TEXT-023.

I_TITLE_WA-INFO = TEXT-022.

APPEND I_TITLE_WA TO I_TITLE.

I_TITLE_WA-TYP = TEXT-024.

I_TITLE_WA-KEY = TEXT-025.

I_TITLE_WA-INFO = SY-UNAME.

APPEND I_TITLE_WA TO I_TITLE.

I_TITLE_WA-TYP = TEXT-024.

I_TITLE_WA-KEY = TEXT-026.

CONCATENATE SY-DATUM6(2) TEXT-027 SY-DATUM4(2) TEXT-027 SY-DATUM+0(4) INTO I_TITLE_WA-INFO.

APPEND I_TITLE_WA TO I_TITLE.

I_TITLE_WA-TYP = TEXT-024.

I_TITLE_WA-KEY = TEXT-028.

CONCATENATE S_GSTRP9(2) TEXT-027 S_GSTRP7(2) TEXT-027 S_GSTRP+3(4) INTO I_TITLE_WA-INFO.

IF NOT ( S_GSTRP-HIGH IS INITIAL ).

CONCATENATE S_GSTRP-LOW6(2) TEXT-027 S_GSTRP-LOW4(2) TEXT-027 S_GSTRP-LOW+0(4) TEXT-029

S_GSTRP-HIGH6(2) TEXT-027 S_GSTRP-HIGH4(2) TEXT-027 S_GSTRP-HIGH+0(4) INTO I_TITLE_WA-INFO.

ENDIF.

APPEND I_TITLE_WA TO I_TITLE.

ENDFORM. "SUB_FIELDCAT_TITLE

&----


*& Form TOP_OF_PAGE

&----


  • TOP-OF-PAGE

----


FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = I_TITLE.

ENDFORM. "TOP_OF_PAGE

INCLUDE ZPSPAR11_INCLUDE_AF01.

thank u in advance .max points will be awarded since this is very urgent.

regards

siri

Tags:

Helpful Answer

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