Compare Production Confirmation against Planned by Work Centre

*
* Compare Production Confirmation against Planned by Work Centre
*
REPORT ZASSEMBLY_EFFICIENCY  LINE-SIZE 255 NO STANDARD PAGE HEADING
                    LINE-COUNT 065(001).

TABLES: AFKO,   "Order header data PP orders
        AFPO,   "Order item
        AFRU,   "Order completion confirmations
        AUFM,   "Goods movements for order
        AFVV,   "DB structure of the quantities/dates/values in the oper
        MARA.   "General Material Data

DATA: BEGIN OF INT_EFF OCCURS 100,
        MATNR     TYPE AFKO-STLBEZ,
        MTART     TYPE MARA-MTART,
        AUFNR     TYPE AFKO-AUFNR,
        GSTRI     TYPE AFKO-GSTRI,
        GLTRI     TYPE AFKO-GLTRI,
        GAMNG(9)  TYPE C,
        MENGE(9)  TYPE C,
        PLN01(9)  TYPE C,
        ISM01(7)  TYPE P DECIMALS 2,
        DAUAT     TYPE AFPO-DAUAT,
      END OF INT_EFF.

DATA: FDATE LIKE SY-DATUM,
      LDATE LIKE SY-DATUM.

DATA: YGAMNG(7)   TYPE P DECIMALS 2,
      YMENGE(7)   TYPE P DECIMALS 2,
      YPLN01(7)   TYPE P DECIMALS 2,
      XMENGE(7)   TYPE P DECIMALS 0,
      XSTDRATE(7) TYPE P DECIMALS 2,
      XACTRATE(7) TYPE P DECIMALS 2,
      XLINEEFF(7) TYPE P DECIMALS 2,
      XUTILISA(7) TYPE P DECIMALS 2.

SELECT-OPTIONS XWERKS  FOR AFRU-WERKS DEFAULT 'SAP'.
SELECT-OPTIONS XBUDAT  FOR AFRU-BUDAT.
SELECT-OPTIONS XAUFNR  FOR AFRU-AUFNR.

START-OF-SELECTION.
SELECT * FROM AFRU WHERE BUDAT IN XBUDAT
                     AND WERKS IN XWERKS
                     AND AUFNR IN XAUFNR.
  CLEAR AFPO.
  SELECT SINGLE * FROM AFPO WHERE AUFNR = AFRU-AUFNR.

  CLEAR AFKO.
  SELECT SINGLE * FROM AFKO WHERE AUFNR = AFRU-AUFNR.

  CLEAR MARA.
  SELECT SINGLE * FROM MARA WHERE LVORM = ''
                              AND MATNR = AFKO-STLBEZ.

  CLEAR AFVV.
  SELECT SINGLE * FROM AFVV WHERE AUFPL = AFRU-AUFPL
                              AND APLZL = AFRU-APLZL.

  IF AFVV-VGE01 = 'MIN'.
     AFVV-VGW01 = AFVV-VGW01 / 60.
  ENDIF.

  PERFORM GET_DATA_AUFM.
  PERFORM GET_DATA.

ENDSELECT.

PERFORM LOOP_INT_EFF.
END-OF-SELECTION.

FORM GET_DATA.
* Reverse Confirmation
     IF AFRU-STOKZ = 'X'.
        MULTIPLY AFRU-LMNGA  BY    -1.
        MULTIPLY AFRU-ISM01  BY    -1.
        MULTIPLY AFRU-ISM02  BY    -1.
        MULTIPLY AFRU-ISM03  BY    -1.
        MULTIPLY AFRU-ISM04  BY    -1.
        MULTIPLY AFKO-GAMNG  BY    -1.
        MULTIPLY AFVV-BMSCH  BY    -1.
        MULTIPLY AFVV-VGW01  BY    -1.
        MULTIPLY AFVV-VGW02  BY    -1.
        MULTIPLY AFVV-VGW03  BY    -1.
     ENDIF.
* Plan Activities
     IF AFVV-BMSCH <> 0.
        INT_EFF-PLN01 = ( AFKO-GAMNG / AFVV-BMSCH ) * AFVV-VGW01 * 60.
     ENDIF.
* Actual Activities
     INT_EFF-ISM01 = AFRU-ISM01.
* Material No.
     IF AFKO-PLNBEZ = SPACE.
        INT_EFF-MATNR = AFKO-STLBEZ.
     ELSE.
        INT_EFF-MATNR = AFKO-PLNBEZ.
     ENDIF.
     INT_EFF-MTART = MARA-MTART.
     INT_EFF-AUFNR = AFKO-AUFNR.
     INT_EFF-GSTRI = AFKO-GSTRI.
     INT_EFF-GLTRI = AFKO-GLTRI.
     INT_EFF-GAMNG = AFKO-GAMNG.
     INT_EFF-MENGE = XMENGE.
     INT_EFF-DAUAT = AFPO-DAUAT.

     COLLECT INT_EFF.
     CLEAR   INT_EFF.

ENDFORM.

FORM GET_DATA_AUFM.
     CLEAR XMENGE.
     SELECT * FROM AUFM WHERE AUFNR = AFKO-AUFNR
                          AND BWART IN ('101', '102').
          IF AUFM-SHKZG = 'H'.
             MULTIPLY AUFM-MENGE BY -1.
          ENDIF.
          ADD AUFM-MENGE  TO XMENGE.
     ENDSELECT.
ENDFORM.

FORM LOOP_INT_EFF.
     LOOP AT INT_EFF.
        CLEAR: XSTDRATE, XACTRATE, XLINEEFF, XUTILISA.

        IF INT_EFF-PLN01 <> 0.
           XSTDRATE = INT_EFF-MENGE / INT_EFF-PLN01.
        ENDIF.
        IF INT_EFF-ISM01 <> 0.
           XACTRATE = INT_EFF-MENGE / INT_EFF-ISM01.
           XUTILISA = INT_EFF-PLN01 - INT_EFF-ISM01.
        ENDIF.
        IF XSTDRATE <> 0.
           XLINEEFF = XACTRATE / XSTDRATE.
        ENDIF.
        YGAMNG = INT_EFF-GAMNG.
        YMENGE = INT_EFF-MENGE.
        YPLN01 = INT_EFF-PLN01.
        WRITE:/ INT_EFF-MATNR UNDER '      Material',
                INT_EFF-MTART UNDER ' Matl',
                INT_EFF-AUFNR UNDER 'Production',
                INT_EFF-GSTRI UNDER 'Start',
                INT_EFF-GLTRI UNDER '  Finish',
                YGAMNG        UNDER 'Production Ord',
                YMENGE        UNDER '   Receipt Qty',
                YPLN01        UNDER '   Plan Hr',
                INT_EFF-ISM01 UNDER ' Actual Hr',
                XSTDRATE      UNDER '      Std Rate',
                XACTRATE      UNDER '   Actual Rate',
                XLINEEFF      UNDER 'Efficiency (%)',
                XUTILISA      UNDER 'Utilisation Typ',
                INT_EFF-DAUAT UNDER 'PP Type'.
     ENDLOOP.
ENDFORM.

TOP-OF-PAGE.
FORMAT COLOR COL_TOTAL.
    WRITE: / SY-DATUM, SY-UZEIT, SY-REPID,
       110  'Assembly Line Efficiency Report - Closed (Period)',
       200  SY-UNAME, SY-PAGNO.

    SKIP.
    WRITE: /1 '      Material',
           20 ' Matl',
           25 'Production',
           36 'Start',
           47 '  Finish',
           58 'Production Ord',
           73 '   Receipt Qty',
           88 '   Plan Hr',
          103 ' Actual Hr',
          118 '      Std Rate',
          133 '   Actual Rate',
          148 'Efficiency (%)',
          163 'Utilisation Typ',
          179 'PP Type'.

INITIALIZATION.
   LDATE = SY-DATUM.
   LDATE+6(2) = '01'.
   LDATE  = LDATE - 1.
   FDATE = LDATE.
   FDATE+6(2) = '01'.
   MOVE:   FDATE         TO  XBUDAT-LOW,
           LDATE         TO  XBUDAT-HIGH.
   APPEND XBUDAT.
*---End of Program

Questions
Do you have a ABAP Question?

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.