Physical Stock Take - With Posted Difference Value

* Function : To list stock take
* Download to dos:
* - use menu path List=>Save=>File...
* - select unconverted format
* - enter file name in dos format

REPORT ZPHYLIST LINE-SIZE 132 NO STANDARD PAGE HEADING
      LINE-COUNT 65(001).

TABLES: ISEG,
        IKPF,
        MBEW.

SELECT-OPTIONS: S_IBLNR FOR IKPF-IBLNR,
                S_WERKS FOR IKPF-WERKS,
                S_LGORT FOR IKPF-LGORT,
                S_MATNR FOR ISEG-MATNR,
                S_GIDAT FOR IKPF-GIDAT DEFAULT SY-DATUM.

SELECTION-SCREEN SKIP.
PARAMETERS:     C_XZAEL AS CHECKBOX DEFAULT 'X',
                C_XDIFF AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN SKIP.
PARAMETERS:     X_ZERO  AS CHECKBOX.
DATA: P_WERKS LIKE IKPF-WERKS,
      P_LGORT LIKE IKPF-LGORT,
      W_DIFF LIKE ISEG-MENGE,
      L_BTTL  LIKE ISEG-MENGE,
      L_PTTL LIKE ISEG-BUCHM,
      L_DTTL LIKE ISEG-MENGE,
      L_DVAL LIKE ISEG-DMBTR,
      P_BTTL  LIKE ISEG-MENGE,
      P_PTTL LIKE ISEG-BUCHM,
      P_DTTL LIKE ISEG-MENGE,
      P_DVAL LIKE ISEG-DMBTR,
      W_DMBTR LIKE ISEG-DMBTR,
      W_UCOST TYPE P DECIMALS 4,
      W_SPRICE TYPE P DECIMALS 4,
      W_LEN TYPE I.

FORMAT INTENSIFIED OFF.
SELECT * FROM IKPF WHERE IBLNR IN S_IBLNR AND
     WERKS IN S_WERKS AND
     LGORT IN S_LGORT AND
     GIDAT IN S_GIDAT AND
     SOBKZ NE 'O'
     ORDER BY WERKS LGORT IBLNR.
  IF P_WERKS IS INITIAL.
    P_WERKS = IKPF-WERKS.
    P_LGORT = IKPF-LGORT.
  ENDIF.
  IF P_WERKS NE IKPF-WERKS.
    SKIP.
    FORMAT INTENSIFIED ON.
    WRITE:/ ' ** ', P_LGORT, 'Location Total',
              056(14) L_PTTL,
              072(14) L_BTTL,
              088(14) L_DTTL,
              118(14) L_DVAL.
    SKIP.
    FORMAT COLOR COL_TOTAL.
    WRITE:/ '  **** ', P_WERKS, 'Plant Total',
              056(14) P_PTTL,
              072(14) P_BTTL,
              088(14) P_DTTL,
              118(14) P_DVAL.
    FORMAT INTENSIFIED OFF.
    FORMAT COLOR OFF.
    P_WERKS = IKPF-WERKS.
    P_LGORT = IKPF-LGORT.
    CLEAR: L_BTTL, P_BTTL, L_PTTL, P_PTTL, L_DTTL, P_DTTL,
             L_DVAL, P_DVAL.
    NEW-PAGE.
  ENDIF.
  IF P_LGORT NE IKPF-LGORT.
    FORMAT INTENSIFIED ON.
    ULINE AT /46(86).
    WRITE:/ ' ** ', P_LGORT, 'Location Total',
              056(14) L_PTTL,
              072(14) L_BTTL,
              088(14) L_DTTL,
              118(14) L_DVAL.
    FORMAT INTENSIFIED OFF.
    SKIP.
    SKIP.
    P_LGORT = IKPF-LGORT.
    CLEAR: L_BTTL, L_PTTL, L_DTTL, L_DVAL.
  ENDIF.
  SELECT * FROM ISEG WHERE IBLNR = IKPF-IBLNR AND
       XZAEL = C_XZAEL AND
       XDIFF = C_XDIFF
       ORDER BY ZEILI.
    IF ISEG-XNZAE = 'X'.
      CONTINUE.
    ENDIF.

    W_LEN = STRLEN( ISEG-MATNR ).
    IF W_LEN = 1.
      CONTINUE.
    ENDIF.

    CHECK S_MATNR.

    W_DIFF = ISEG-MENGE - ISEG-BUCHM.
    IF X_ZERO NE 'X'.
      CHECK W_DIFF NE 0.
    ENDIF.
    CLEAR: MBEW-VPRSV, W_UCOST.
    IF ISEG-XDIFF NE 'X'.
      CLEAR MBEW-VPRSV.
      SELECT SINGLE * FROM MBEW WHERE MATNR = ISEG-MATNR AND
              BWKEY = ISEG-WERKS.
      IF MBEW-VPRSV = 'S'.
        W_UCOST = MBEW-STPRS / MBEW-PEINH.
      ELSE.
        W_UCOST = MBEW-VERPR / MBEW-PEINH.
      ENDIF.
      W_DMBTR = W_DIFF * W_UCOST.
    ELSE.
      IF W_DIFF < 0.
        W_DMBTR = ISEG-DMBTR * -1.
      ELSE.
        W_DMBTR = ISEG-DMBTR.
      ENDIF.
      W_UCOST = W_DMBTR / W_DIFF.
    ENDIF.
    WRITE: /001 ISEG-WERKS,
       008 ISEG-IBLNR,
       020 ISEG-ZEILI,
       026 ISEG-MATNR,
       046 ISEG-LGORT,
       056(14) ISEG-MENGE,
       072(14) ISEG-BUCHM,
       088(14) W_DIFF NO-ZERO,
       104(12) W_UCOST NO-ZERO,
       118(14) W_DMBTR NO-ZERO.
*    if iseg-xloek = 'X'.
*      write: 118 '** deleted item'.
*    else.
    L_BTTL = L_BTTL + ISEG-BUCHM.
    P_BTTL = P_BTTL + ISEG-BUCHM.
    L_PTTL = L_PTTL + ISEG-MENGE.
    P_PTTL = P_PTTL + ISEG-MENGE.
    L_DVAL = L_DVAL + W_DMBTR.
    P_DVAL = P_DVAL + W_DMBTR.
    L_DTTL = L_DTTL + W_DIFF.
    P_DTTL = P_DTTL + W_DIFF.
    CLEAR: W_SPRICE, W_UCOST.
  ENDSELECT.
ENDSELECT.
FORMAT INTENSIFIED ON.
ULINE AT /46(86).
WRITE:/ ' ** ', P_LGORT, 'Location Total',
         056(14) L_PTTL,
         072(14) L_BTTL,
         088(14) L_DTTL,
         118(14) L_DVAL.
SKIP.
FORMAT COLOR COL_TOTAL.
WRITE:/ '  **** ', P_WERKS, 'Plant Total',
         056(14) P_PTTL,
         072(14) P_BTTL,
         088(14) P_DTTL,
         118(14) P_DVAL.
FORMAT INTENSIFIED OFF.
FORMAT COLOR OFF.

TOP-OF-PAGE.
  WRITE: / SY-DATUM, SY-UZEIT,
         50 'Physical Inventory Documents', 110 SY-UNAME,
         120 'Page', SY-PAGNO.
  SKIP.
  ULINE.
  WRITE:/001 'Plant',
         008 'Doc No',
         020 'Line',
         026 'Material',
         046 'Location',
         056 '      Phy Inv',
         072 '     Book Bal',
         088 '    Difference',
         104 '  Unit Cost',
         118 '     Diff (S$)'.
  ULINE.
  SKIP.

More Function Module
Functions / SAP Script / ALV

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.