SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Report of Sales Order Data by Project



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Tue Sep 09, 2008 4:57 pm    Post subject: Report of Sales Order Data by Project Reply with quote

Report of Sales Order Data by Project

Code:
REPORT ZPRTPROJ MESSAGE-ID ZZ
               NO STANDARD PAGE HEADING
               LINE-SIZE 255 LINE-COUNT 65.
TABLES: PROJ, AFKO, AUFK, VBAP, VBAK, VBPA, PA0002,
        TCJ04, PA0900, VBEP, KNA1, MAKT, VBUP.
SELECT-OPTIONS: VKORG FOR PA0900-VKORG.
*SELTEXT*E*  "Sales Organization"
PARAMETERS:  DAYSOLD TYPE P DEFAULT 10.
*SELTEXT*E*  "Days Old Selection"
SELECT-OPTIONS: PROJECT FOR PROJ-PSPNR MATCHCODE OBJECT PRSM.
*SELTEXT*E*  "Project Number"
SELECT-OPTIONS: VERNR FOR PROJ-VERNR.
*SELTEXT*E*  "Project Engineer"
DATA: BEGIN OF TAB OCCURS 500,
      VKORG LIKE PA0900-VKORG,         "Sales Org
      SALNAME(50),                     "Sales Engineer
      KDAUF LIKE AUFK-KDAUF,           "Sales Ord Number
      KDPOS LIKE AUFK-KDPOS,           "Sales Line Nbr
      PSPNR(30),                       "Project Number
      PS_PSP_PNR(30),                                       "WBS
      WADAT LIKE VBEP-WADAT,           "Planned Ship Date
      VERNR(25),                       "Proj Engineer
      SITENAME LIKE KNA1-NAME1,        "Site Name
      BSTNK    LIKE VBAK-BSTNK,        "P O Number
      ERNAM    LIKE VBAK-ERNAM,        "Entered By
      AEDAT LIKE VBAK-AEDAT,           "Last Changed Dt
      MATNR LIKE VBAP-MATNR,           "Material Number
      MAKTX LIKE MAKT-MAKTX,           "Material Description
      LFGSA LIKE VBUP-LFGSA,           "Overall Item Delivery Status
      NETPR LIKE VBAP-NETPR,           "Net Price
        END OF TAB.
DATA: BEGIN OF OLD.
        INCLUDE STRUCTURE TAB.
DATA:   END OF OLD.
DATA: BEGIN OF PRTTAB.
        INCLUDE STRUCTURE TAB.
DATA:   END OF PRTTAB.
DATA:   SALES-PARTNER1 LIKE VBPA-PARVW VALUE 'ZO'.
DATA:   SALES-PARTNER2 LIKE VBPA-PARVW VALUE 'Z5'.
DATA:   CALC-DAYS TYPE D.
MOVE SY-DATUM TO CALC-DAYS.
CALC-DAYS = CALC-DAYS - DAYSOLD.
SELECT * FROM PROJ WHERE PSPNR IN PROJECT
                     AND VERNR IN VERNR.
  SELECT * FROM AFKO WHERE PRONR EQ PROJ-PSPNR.
    SELECT SINGLE * FROM AUFK WHERE AUFNR EQ AFKO-AUFNR.
    IF SY-SUBRC EQ 0.
      IF NOT AUFK-KDAUF IS INITIAL.
        CLEAR TAB.
        CLEAR VBAK.
        SELECT SINGLE * FROM VBAK WHERE VBELN EQ AUFK-KDAUF.
        MOVE VBAK-BSTNK TO TAB-BSTNK.
        MOVE VBAK-ERNAM TO TAB-ERNAM.
        CLEAR VBAP.
        SELECT SINGLE * FROM VBAP WHERE VBELN EQ AUFK-KDAUF
                                    AND POSNR EQ AUFK-KDPOS.
        WRITE PROJ-PSPNR       TO TAB-PSPNR.
        MOVE AUFK-KDAUF        TO TAB-KDAUF.
        MOVE AUFK-KDPOS        TO TAB-KDPOS.
        WRITE VBAP-PS_PSP_PNR  TO TAB-PS_PSP_PNR.
        MOVE VBAP-MATNR        TO TAB-MATNR.
        MOVE VBAP-NETPR        TO TAB-NETPR.
        CLEAR MAKT.
        SELECT SINGLE * FROM MAKT WHERE MATNR EQ VBAP-MATNR
                                    AND SPRAS EQ SY-LANGU.
        MOVE MAKT-MAKTX         TO TAB-MAKTX.
        CLEAR VBUP.
        SELECT SINGLE * FROM VBUP WHERE VBELN EQ VBAP-VBELN
                                    AND POSNR EQ VBAP-POSNR.
        MOVE VBUP-LFGSA         TO TAB-LFGSA.
        SELECT SINGLE * FROM TCJ04 WHERE VERNR EQ PROJ-VERNR.
        IF SY-SUBRC EQ 0.
          MOVE TCJ04-VERNA   TO TAB-VERNR.
        ELSE.
          MOVE 'Not Assigned' TO TAB-VERNR.
        ENDIF.
        MOVE VBAK-ERDAT        TO TAB-AEDAT.
        IF VBAK-AEDAT > VBAK-ERDAT.
          MOVE VBAK-AEDAT        TO TAB-AEDAT.
        ENDIF.
        SELECT * FROM VBPA WHERE VBELN EQ VBAK-VBELN
                             AND POSNR EQ '000000'
                             AND PARVW EQ SALES-PARTNER1.
          SELECT * FROM PA0002 WHERE PERNR EQ VBPA-PERNR.
            MOVE PA0002-VORNA TO TAB-SALNAME(25).
            MOVE PA0002-NACHN TO TAB-SALNAME+25(25).
            CONDENSE TAB-SALNAME.
            EXIT.
          ENDSELECT.
          EXIT.
        ENDSELECT.
        SELECT * FROM VBPA WHERE VBELN EQ VBAK-VBELN
                             AND POSNR EQ VBAP-POSNR
                             AND PARVW EQ SALES-PARTNER1.
          SELECT * FROM PA0002 WHERE PERNR EQ VBPA-PERNR.
            MOVE PA0002-VORNA TO TAB-SALNAME(25).
            MOVE PA0002-NACHN TO TAB-SALNAME+25(25).
            CONDENSE TAB-SALNAME.
            EXIT.
          ENDSELECT.
          SELECT * FROM PA0900 WHERE PERNR EQ VBPA-PERNR.
            MOVE PA0900-VKORG TO TAB-VKORG.
            EXIT.
          ENDSELECT.
          EXIT.
        ENDSELECT.
        IF TAB-SALNAME IS INITIAL.
          CLEAR: TAB-VKORG, TAB-SALNAME.
          SELECT * FROM VBPA WHERE VBELN EQ VBAK-VBELN
                               AND POSNR EQ '000000'
                               AND PARVW EQ SALES-PARTNER2.
            SELECT * FROM PA0002 WHERE PERNR EQ VBPA-PERNR.
              MOVE PA0002-VORNA TO TAB-SALNAME(25).
              MOVE PA0002-NACHN TO TAB-SALNAME+25(25).
              CONDENSE TAB-SALNAME.
              EXIT.
            ENDSELECT.
            EXIT.
          ENDSELECT.
          SELECT * FROM VBPA WHERE VBELN EQ VBAK-VBELN
                               AND POSNR EQ VBAP-POSNR
                               AND PARVW EQ SALES-PARTNER2.
            SELECT * FROM PA0002 WHERE PERNR EQ VBPA-PERNR.
              MOVE PA0002-VORNA TO TAB-SALNAME(25).
              MOVE PA0002-NACHN TO TAB-SALNAME+25(25).
              CONDENSE TAB-SALNAME.
              EXIT.
            ENDSELECT.
            SELECT * FROM PA0900 WHERE PERNR EQ VBPA-PERNR.
              MOVE PA0900-VKORG TO TAB-VKORG.
              EXIT.
            ENDSELECT.
            EXIT.
          ENDSELECT.
        ENDIF.
        CLEAR TAB-SITENAME.
        SELECT * FROM VBPA WHERE VBELN EQ VBAK-VBELN
                             AND POSNR EQ '000000'
                             AND PARVW EQ 'ZS'.
          SELECT SINGLE * FROM KNA1   WHERE KUNNR EQ VBPA-KUNNR.
          IF SY-SUBRC EQ 0.
            MOVE KNA1-NAME1   TO TAB-SITENAME.
          ENDIF.
          EXIT.
        ENDSELECT.
        SELECT * FROM VBPA WHERE VBELN EQ VBAK-VBELN
                             AND POSNR EQ VBAP-POSNR
                             AND PARVW EQ 'ZS'.
          SELECT SINGLE *  FROM KNA1   WHERE KUNNR EQ VBPA-KUNNR.
          IF SY-SUBRC EQ 0.
            MOVE KNA1-NAME1   TO TAB-SITENAME.
          ENDIF.
          EXIT.
        ENDSELECT.
        SELECT * FROM VBEP WHERE VBELN EQ VBAP-VBELN
                             AND POSNR EQ VBAP-POSNR
                             AND BMENG NE 0.           "Confirmed Qty
          IF TAB-VKORG IN VKORG
            AND VBEP-WADAT > CALC-DAYS.
            MOVE VBEP-WADAT     TO TAB-WADAT.
            IF TAB-VKORG IS INITIAL.
              MOVE '????' TO TAB-VKORG.
            ENDIF.
            IF TAB-SALNAME IS INITIAL.
              MOVE '????' TO TAB-SALNAME.
            ENDIF.
            APPEND TAB.
          ENDIF.
        ENDSELECT.
      ENDIF.
    ENDIF.
  ENDSELECT.
ENDSELECT.
MOVE SPACE TO OLD.
SORT TAB BY   VKORG SALNAME PSPNR KDAUF KDPOS.
LOOP AT TAB.
  IF TAB-VKORG   NE OLD-VKORG.
    MOVE TAB-VKORG TO OLD-VKORG.
    NEW-PAGE.
  ENDIF.
  IF TAB-SALNAME NE OLD-SALNAME.
    MOVE TAB-SALNAME TO OLD-SALNAME.
    NEW-PAGE.
  ENDIF.
  MOVE-CORRESPONDING TAB TO PRTTAB.
  IF TAB-KDAUF EQ OLD-KDAUF.
    CLEAR PRTTAB-KDAUF.
  ENDIF.
  WRITE: /1 PRTTAB-AEDAT,
         12 PRTTAB-ERNAM,
         25 PRTTAB-KDAUF,
         36 PRTTAB-KDPOS,
         43 PRTTAB-MATNR,
         62 PRTTAB-MAKTX,
        103 PRTTAB-SITENAME,
        139 PRTTAB-BSTNK,
        160 PRTTAB-PSPNR,
        191 PRTTAB-VERNR,
        217 PRTTAB-WADAT,
        228 PRTTAB-LFGSA,
        232 PRTTAB-NETPR.
  MOVE-CORRESPONDING TAB TO OLD.
ENDLOOP.
INCLUDE ZCONINC3.
FORMAT INTENSIFIED OFF.
WRITE: /1 'Sales Org=', TAB-VKORG, ' Salesman=', TAB-SALNAME.
WRITE: /1 'OrdDate',
       12 'Entered By',
       25 'Sales Ord',
       36 'ItemNo',
       43 'Material',
       62 'Material Description',
      103 'Site Name',
      139 'PO Number',
      160 'Project',
      191 'Engineer',
      217 'ShipDate',
      228 'Del',
      238 'Net Price'.
FORMAT INTENSIFIED ON.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.