Skip to Content
avatar image
Former Member

code performance problem .

the code gives me data in the debugger can any one tell me why its so slow and dont run .

REPORT ZNEWSALES .



TYPE-POOLS: SLIS.



TABLES :  VBAK  ,VBKD ,  KNA1 .



DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV," WITH HEADER LINE ,

      WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV ,

      LAYOUT      TYPE SLIS_LAYOUT_ALV,

      ERORR LIKE BAPIRETURN ,

      STATUSINFO TYPE TABLE OF BAPISDSTAT .

     DATA STATUSINFO_WA LIKE LINE OF STATUSINFO .







DATA EVENT TYPE SLIS_T_EVENT.

DATA STREVENT TYPE SLIS_ALV_EVENT.





 TYPES: BEGIN OF STR_DATA ,

     SAL_DOC TYPE VBAK-VBELN , "VBAK-AUART = "ZCC1,ZCRC,ZCRS, ZCO1,ZCS1"

    ITEM_NO  type VBAP-POSNR ,

    DESCREPTION type VBAP-ARKTX ,

    VIN_CODE TYPE VBAP-SERNR,

    SOLD_QUANTITY TYPE VBAP-kwmeng, "If  VBAK-AUART = ",ZCRC,ZCRS " then value = '' -1

    SALES_MAN TYPE vbpa-kunnr, "PP

    sman_COD TYPE CHAR10 ,

    SOLD_TO TYPE vbpa-kunnr,"RG

    BIL_TO TYPE vbpa-kunnr, "RE

    FAVOR TYPE VBAP-ZZSALE_TO,

    STATUE TYPE ZORDER_ST,

    REGECTION_REASON TYPE VBAP-abgru,

    COMMENT TYPE VBAP-ZZCOMMENT,

       BIL_COD       TYPE CHAR10,

End OF STR_DATA .



DATA : GT_OUTTAB      TYPE TABLE OF STR_DATA WITH HEADER LINE ,"ZSALESMEN  ,       " DATA TABLE

       WA_DATA_2      LIKE LINE OF GT_OUTTAB.



SELECT-OPTIONS : DOC_ORG   FOR VBAK-VKORG , "ORGANIZATION

                 DOC_CHL   FOR VBAK-VTWEG , " CHANNEL

                 DOC_DIV   FOR VBAK-SPART , "DIVISION

                 DOC_OFF   FOR VBAK-VKBUR , "SALES OFFICE

                 DOC_DAT   FOR VBKD-FKDAT , "DOC. DATE

                 SM        FOR KNA1-KUNNR.  "SALES MAN





* select VBAK~VKORG VBAK~VTWEG VBAK~VKBUR VBKD~FKDAT VBKD~VBELN VBAP~VBELN AS  SAL_DOC VBAP~POSNR AS ITEM_NO VBAP~ARKTX AS DESCREPTION  VBAP~SERNR AS VIN_CODE VBAP~ZZSALE_TO AS FAVOR

*           VBAP~ABGRU AS REGECTION_REASON  VBAP~ZZCOMMENT AS COMMENT VBPA~KUNNR VBPA~POSNR VBPA~VBELN

*    from ( VBRK

*       INNER JOIN VBRP

*       ON VBRK~VBELN = VBRP~VBELN

*       INNER JOIN VBAP

*       ON VBRP~AUBEL = VBAP~VBELN  AND VBRP~AUPOS = VBAP~POSNR

*       INNER JOIN vbak

*       on VBAP~VBELN = vbak~VBELN

*       INNER JOIN LIPS

*       ON  vbap~VBELN = LIPS~vgbel

*       AND vbap~POSNR = LIPS~vgpos

*       INNER JOIN SER02

*       ON  SER02~SDAUFNR = vbap~VBELN

*       AND SER02~POSNR   = vbap~POSNR

*       INNER JOIN OBJK

*       ON  OBJK~OBKNR = SER02~OBKNR

*       INNER JOIN T001W

*       ON  T001W~WERKS = LIPS~WERKS

*       INNER JOIN T001L

*       ON  T001L~WERKS = LIPS~WERKS

*       AND T001L~LGORT = LIPS~LGORT

*       INNER JOIN KNA1

*       ON  KNA1~KUNNR = VBRK~KUNAG

*       INNER JOIN T005U

*       ON T005U~BLAND = KNA1~REGIO AND T005U~LAND1 = 'EG'

*       inner join vbpa

*       on vbpa~vbeln = vbak~vbeln

*       INNER JOIN MARA

*       ON MARA~MATNR = VBAP~MATNR )

*         INTO CORRESPONDING FIELDS OF TABLE  GT_OUTTAB

*        where VBAK~AUART IN ('ZCC1','ZCRC','ZCRS','ZCO1','ZCS1')

*  and  VBPA~PARVW EQ 'SM'

*       AND VBPA~KUNNR IN SM

*   AND VBAK~VKORG IN DOC_ORG

*   AND VBAK~SPART IN DOC_DIV

*   AND VBKD~FKDAT IN DOC_DAT

*   AND VBAK~VKBUR IN DOC_off  .

*  APPEND WA_DATA_2 TO GT_OUTTAB .



* select VBAP~VBELN VBAP~POSNR VBAP~ARKTX VBAP~sernr  VBAP~ZZSALE_TO VBAP~abgru

*    from VBAK

*           inner join VBAP

*           on  VBAP~VBELN = VBAK~VBELN

*           inner join VBKD

*           on  VBKD~POSNR = VBAP~POSNR

*           and VBKD~VBELN = VBAP~VBELN

*           inner join VBPA

*           on  VBPA~POSNR = VBKD~POSNR

*           and VBPA~VBELN = VBKD~VBELN

*

*            INTO CORRESPONDING FIELDS OF TABLE  GT_OUTTAB

*         where VBAK~AUART IN ('ZCC1','ZCRC','ZCRS','ZCO1','ZCS1')

*  and  VBPA~PARVW EQ 'SM'

*   AND VBPA~KUNNR IN SM

*   AND VBAK~VKORG IN DOC_ORG

*   AND VBAK~SPART IN DOC_DIV

*   AND VBKD~FKDAT IN DOC_DAT

*   AND VBAK~VKBUR IN DOC_off .

*           APPEND WA_DATA_2 TO GT_OUTTAB .

 SELECT DISTINCT  vbrk~VBELN  vbrk~FKART  vbrk~FKDAT  VBAK~VBELN as SAL_DOC

   VBAP~POSNR AS ITEM_NO   VBAP~ZZSALE_TO AS FAVOR  KNA1~NAME1 as SOL_PART  VBAP~ARKTX AS DESCREPTION  VBAP~SERNR AS VIN_CODE

         VBAP~ABGRU AS REGECTION_REASON  VBAP~ZZCOMMENT AS COMMENT

FROM ( VBRK

       INNER JOIN VBRP

       ON VBRK~VBELN = VBRP~VBELN

       INNER JOIN VBAP

       ON VBRP~AUBEL = VBAP~VBELN  AND VBRP~AUPOS = VBAP~POSNR

       INNER JOIN vbak

       on VBAP~VBELN = vbak~VBELN

       INNER JOIN KNA1

       ON  KNA1~KUNNR = VBRK~KUNAG

       inner join vbpa

       on vbpa~vbeln = vbak~vbeln )

 INTO CORRESPONDING FIELDS OF TABLE  GT_OUTTAB

     WHERE VBAK~VKORG IN DOC_ORG

       AND VBAK~VTWEG IN DOC_CHL

       AND VBAK~SPART IN DOC_DIV

       AND VBRK~FKDAT IN DOC_DAT

       AND VBRK~FKART IN ( 'ZCC1','ZCRC','ZCRS','ZCO1','ZCS1' )

        and vbpa~PARVW eq 'SM'

       and vbpa~kunnr in sm

      and vbak~VKBUR in DOC_OFF

*       AND VBRK~FKSTO <> 'X'

 ORDER BY VBRK~VBELN  .



LOOP AT GT_OUTTAB into WA_DATA_2 .







*...Bill To

    select single VBPA~KUNNR KNA1~NAME1

      from VBPA

      inner join KNA1

      ON  KNA1~KUNNR = VBPA~KUNNR

      into (WA_DATA_2-BIL_COD , WA_DATA_2-BIL_TO )

      where VBPA~VBELN = WA_DATA_2-SAL_DOC and VBPA~PARVW = 'RE' and VBPA~POSNR = WA_DATA_2-ITEM_NO .

    IF SY-SUBRC = 0 .

    ELSE.

      select single VBPA~KUNNR KNA1~NAME1

        from VBPA

        inner join KNA1

        ON  KNA1~KUNNR = VBPA~KUNNR

        into (WA_DATA_2-BIL_COD , WA_DATA_2-BIL_TO )

        where VBPA~VBELN = WA_DATA_2-SAL_DOC and VBPA~PARVW = 'RE'  .

    ENDIF.





"SALES MAN

          select single VBPA~KUNNR KNA1~NAME1

    from VBPA

    inner join KNA1

    ON  KNA1~KUNNR = VBPA~KUNNR

    into (WA_DATA_2-sman_COD , WA_DATA_2-SALES_MAN )

    where VBPA~VBELN = WA_DATA_2-SAL_DOC and VBPA~PARVW = 'SM' and VBPA~POSNR = WA_DATA_2-ITEM_NO  .

    IF SY-SUBRC = 0 .

    ELSE.

      select single VBPA~KUNNR KNA1~NAME1

      from VBPA

      inner join KNA1

      ON  KNA1~KUNNR = VBPA~KUNNR

      into (WA_DATA_2-sman_COD , WA_DATA_2-SALES_MAN )

      where VBPA~VBELN = WA_DATA_2-SAL_DOC and VBPA~PARVW = 'SM'  .

    ENDIF.

      APPEND WA_DATA_2 TO GT_OUTTAB .



ENDLOOP .



*"SOLDTO

*         select single KNA1~NAME1 AS SOLD_TO

*      from KNA1

*        inner join VBPA

*      ON  KNA1~KUNNR = VBPA~KUNNR

*

*      into  WA_DATA_2-SOLD_TO

*

*      where VBPA~VBELN = WA_DATA_2-SAL_DOC and VBPA~PARVW = 'AG' and VBPA~POSNR = WA_DATA_2-ITEM_NO .

*      APPEND WA_DATA_2 TO GT_OUTTAB .

*

*

*

*      "SOLD QUANTITY

*      SELECT SINGLE VBAP~kwmeng AS SOLD_QUANTITY

*    FROM VBAP

*    INNER JOIN VBFA

*    ON VBFA~VBELN = VBAP~VBELN

*    INTO WA_DATA_2-SOLD_QUANTITY

*    WHERE

*     VBAP~VBELN = WA_DATA_2-SAL_DOC and VBFA~VBTYP_N = 'H' and VBAP~POSNR = WA_DATA_2-ITEM_NO .

































*    CALL FUNCTION 'BAPI_SALESORDER_GETSTATUS'

*     EXPORTING

*       salesdocument       = VBAK-VBELN

*    IMPORTING

*      RETURN              = STATUE

*    TABLES

*      STATUSINFO          = STATUSINFO

*             .

*     READ TABLE STATUSINFO INTO STATUSINFO_WA INDEX 1.

*     IF SY-SUBRC EQ 0.

*      IF STATUSINFO_WA-PRC_STAT_H EQ 'C'.

*       MESSAGE 'billed' TYPE 'M'.

*

*      ENDIF.

*     ENDIF.











    PERFORM GT_FIELDCAT .

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

      I_CALLBACK_PROGRAM = SY-REPID

*     I_CALLBACK_PF_STATUS_SET       = 'PF_STATUS'

     I_CALLBACK_USER_COMMAND        = 'USER_COMMAND'

      IT_FIELDCAT        = GT_FIELDCAT

          IS_LAYOUT          = LAYOUT







    I_BUFFER_ACTIVE    = SPACE

      I_SAVE             = 'X'

    tables

      T_OUTTAB           = GT_OUTTAB

 EXCEPTIONS

     PROGRAM_ERROR      = 1

     OTHERS             = 2

    .

 form GT_FIELDCAT.



  clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = '  SAL_DOC '.

  WA_FIELDCAT-SELTEXT_M = 'Sales order Number'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



   clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'ITEM_NO'.

  WA_FIELDCAT-SELTEXT_M = 'Item Number'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



     clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'DESCREPTION'.

  WA_FIELDCAT-SELTEXT_M = 'Material Description'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT .



     clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'VIN_CODE'.

  WA_FIELDCAT-SELTEXT_M = 'Vin Code'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



     clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'SOLD_QUANTITY'.

  WA_FIELDCAT-SELTEXT_M = 'Sold Quantity'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



    clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'SALES_MAN'.

  WA_FIELDCAT-SELTEXT_M = 'Sales Man'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



    clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'SOLD_TO'.

  WA_FIELDCAT-SELTEXT_M = 'Sold – to Party'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



    clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'BIL_TO'.

  WA_FIELDCAT-SELTEXT_M = 'Bill – to Party'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



    clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'FAVOR'.

  WA_FIELDCAT-SELTEXT_M = 'Sale in favor of'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



    clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'STATUE'.

  WA_FIELDCAT-SELTEXT_M = 'Sales order Status'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



  clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'REGECTION_REASON'.

  WA_FIELDCAT-SELTEXT_M = 'Reason for Rejection'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



  clear WA_FIELDCAT.

  WA_FIELDCAT-FIELDNAME = 'COMMENT'.

  WA_FIELDCAT-SELTEXT_M = 'Comment'.

*  WA_FIELDCAT-KEY = 'X'.

  WA_FIELDCAT-OUTPUTLEN = 15.

  append WA_FIELDCAT to GT_FIELDCAT.



  ENDFORM .
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Nov 10, 2017 at 12:20 AM

    There are whole books on performance analysis available and as a developer, you should have a good baseline understanding of how to identify bottlenecks and hotspots in your code.

    See

    https://wiki.scn.sap.com/wiki/display/ABAP/Single+Transaction+Analysis

    for how to see what takes most of the time in your transactions.

    If it turns out that the database access is the culprit in your code (it doesn't seem to do anything else, really), then check

    https://wiki.scn.sap.com/wiki/display/CPP/Database+Performance+Analysis#DatabasePerformanceAnalysis-MAXDB

    Add comment
    10|10000 characters needed characters exceeded