ABAP/4 Program: Outstanding PO Report
--------------------------------------------------------------------------------
This report displays information for outstanding purchase orders. The report has two parts:
one is the standard report, and the other is called from the Project Expense report. Note that both reports
output GL Account, cost center, and cost object information (from table EKKN) as a single value on the output
line. Actually, each line may have several cost centers and cost object to which the invoices were allocated;
however, the user only wanted one (any one) to be listed.
Standard Report: The standard report lists info (limited by selection criteria) for purchase order items whose
GR and IR are not equal. The report first accesses the header table EKKO, limited by purchasing group and
purchase order. It then accesses EKPO, limited by PO item and material selection criteria. An internal table
sums keeps subtotals of the related GR/IR quantities and values, read from EKBE, for the given PO and item.
In the fill_sums routine, the subtotals are grouped by Credit/Debit indicator (EKBE-SHKZG), account assignment
(EKBE-ZEKKN), and PO Doc Category (EKBE-BEWTP). These subtotals are then processed by the fill_outtab routine,
which makes the GR/IR totals and compares them. If they are unequal, data is looked up further from EKKN, and
the item is output.
Report Called from Project Expense Report: The report called from the Project Expense Report is the same as the
standard report except that:
the compare variable is set to value 'A'.
records are outputted if GR < IR, or if both GR and IR are zero
selection criteria is based on the data in the po_itemp select-options list. This list is filled when the report is
called project number is output (project number is looked up in the po_aufnr select-options list which is filled
when the report is called) subtotals are not outputted
*&---------------------------------------------------------------------*
*& Outstanding POs *
*& *
*& ekbe has GR/IR records. If there is account assignment (ekpo-knttp *
*& is not blank), then ekkn will also have records related to the ekbe *
*& records. First check ekbe to see if GR/IR are unequal. If they are, *
*& list them and show related info. *
*& *
*& The ekkn table may contain several records with different G/L Accts *
*& Cost Centers, and/or Cost Objects. This report selects one record *
*& at random and uses it to get this data. Thus the *
*& report's output is somewhat misleading, as the G/L, Cctr, and CObj *
*& are listed as a single value rather than several values. A better *
*& implementation would list this info in sub-records (e.g. drill-down)*
*&---------------------------------------------------------------------*
REPORT ZGRIROPO LINE-SIZE 250 LINE-COUNT 65 NO STANDARD PAGE HEADING.
TABLES: EKBE, EKPO, EKKO, EKKN, BSIS.
PARAMETERS: COMPARE TYPE C NO-DISPLAY.
SELECT-OPTIONS:
PO_DOC FOR EKPO-EBELN, "Purchase order
PO_ITEM FOR EKPO-EBELP,"Purchase order item
PUR_GRP FOR EKKO-EKGRP,"Purchasing Group
MAT_NR FOR EKPO-MATNR, "material #
SEL_ACCT FOR EKPO-KNTTP, "account assignment category
POSTDAT FOR SY-DATUM NO-DISPLAY, "posting date
"transfer of params from project expense report
PO_ITEMP FOR EKPO-EBELN NO-DISPLAY, "PO/item pair
PO_AUFNR FOR BSIS-AUFNR NO-DISPLAY. "PO/order pair
DATA:
LN TYPE I, "subtotal for cost objects
TOTAL LIKE EKBE-DMBTR,
OLDSAKTO LIKE EKKN-SAKTO,
OLDKOSTL LIKE EKKN-KOSTL,
OLDKSTRG LIKE EKKN-KSTRG,
DO_SUBTOTAL TYPE C,
WROTE_SUBT TYPE C,
BEGIN OF COBJ_SUBTOTAL,
MENGE LIKE EKBE-MENGE,
GR LIKE EKBE-MENGE,
IR LIKE EKBE-MENGE,
ESTGRVAL LIKE EKBE-DMBTR,
IRVAL LIKE EKBE-DMBTR,
OUT LIKE EKBE-MENGE,
ESTOUTVAL LIKE EKBE-DMBTR,
END OF COBJ_SUBTOTAL,
BEGIN OF TOTALS.
INCLUDE STRUCTURE COBJ_SUBTOTAL.
DATA:END OF TOTALS,
EKKOEBELN LIKE EKKO-EBELN, "for ekko data
BEGIN OF MYEKPO, "for ekpo data
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MENGE LIKE EKPO-MENGE,
NETPR LIKE EKPO-NETPR,
KNTTP LIKE EKPO-KNTTP,
TXZ01 LIKE EKPO-TXZ01,
END OF MYEKPO,
BEGIN OF MYEKKN,
* zekkn like ekkn-zekkn,
MENGE LIKE EKKN-MENGE,
VPROZ LIKE EKKN-VPROZ,
SAKTO LIKE EKKN-SAKTO,
KOSTL LIKE EKKN-KOSTL,
KSTRG LIKE EKKN-KSTRG,
END OF MYEKKN,
BEGIN OF SUMS OCCURS 20, "totals for gr and ir
ZEKKN LIKE EKBE-ZEKKN, "Acct assignment serial
BEWTP LIKE EKBE-BEWTP, "PO Doc category
MENGE LIKE EKBE-MENGE, "GR/IR Quantity
DMBTR LIKE EKBE-DMBTR, "GR Value
SHKZG LIKE EKBE-SHKZG, "Debt/Credit indicator
END OF SUMS,
BEGIN OF OUTTAB OCCURS 1000, "output list
EBELN LIKE EKPO-EBELN, "PO Doc
EBELP LIKE EKPO-EBELP, "PO item
ZEKKN LIKE EKKN-ZEKKN, "account serial #
SAKTO LIKE EKKN-SAKTO, "G/L acct
KOSTL LIKE EKKN-KOSTL, "cost center
KSTRG LIKE EKKN-KSTRG, "cost object
MENGE LIKE EKPO-MENGE, "Quantity (total)
TXZ01 LIKE EKPO-TXZ01, "short text
GR LIKE EKPO-MENGE, "GR Quantity
ESTGRVAL LIKE EKBE-DMBTR,
GRVAL LIKE EKBE-DMBTR, "GR Value
IR LIKE EKPO-MENGE, "IR Quantity
IRVAL LIKE EKBE-DMBTR, "IR Value
OUT LIKE EKPO-MENGE, "Outstanding IR quantity
OUTVAL LIKE EKPO-BRTWR, "Outstanding IR value
ESTOUTVAL LIKE EKPO-BRTWR, "Estimated Outstanding IR Value
END OF OUTTAB.
AT SELECTION-SCREEN.
IF PUR_GRP IS INITIAL AND PO_DOC IS INITIAL.
MESSAGE E007(ZS).
ENDIF.
START-OF-SELECTION.
* should do authorization checking here **
SELECT EBELN FROM EKKO "select POs from pur grp and po doc
INTO EKKOEBELN
WHERE LOEKZ = ' ' AND "not to be deleted
EKGRP IN PUR_GRP AND "criteria
EBELN IN PO_DOC
ORDER BY EBELN.
* should do authorization checking here **
SELECT EBELN EBELP MENGE NETPR KNTTP TXZ01
FROM EKPO "select POs from material criteria
INTO MYEKPO
WHERE LOEKZ = ' ' AND "not to be deleted
KNTTP IN SEL_ACCT AND
EBELN = EKKOEBELN AND
EBELP IN PO_ITEM AND
MATNR IN MAT_NR
ORDER BY EBELN EBELP.
IF COMPARE = 'A'. "only use PO/item pairs passed from proj exp
LOOP AT PO_ITEMP
WHERE HIGH = MYEKPO-EBELN AND LOW = MYEKPO-EBELP.
ENDLOOP.
CHECK SY-SUBRC = 0. "PO/item pair was listed
ENDIF.
* should do authorization checking here **
PERFORM FILL_SUMS.
PERFORM FILL_OUTTAB. "fill info for output
CLEAR OUTTAB.
ENDSELECT.
ENDSELECT.
PERFORM WRITE_OUTTAB.
*---------------------------------------------------------------------*
* FORM FILL_SUMS *
*---------------------------------------------------------------------*
FORM FILL_SUMS. "fill sums table with GR/IR data from ekbe
CLEAR SUMS. CLEAR SUMS[].
SELECT ZEKKN BEWTP MENGE DMBTR SHKZG FROM EKBE INTO SUMS
WHERE EBELN = MYEKPO-EBELN AND EBELP = MYEKPO-EBELP.
CHECK SUMS-SHKZG <> ' '.
IF SUMS-SHKZG = 'H'. "negative value
SUMS-MENGE = - SUMS-MENGE.
SUMS-DMBTR = - SUMS-DMBTR.
ENDIF.
SUMS-SHKZG = ' '.
COLLECT SUMS.
ENDSELECT.
ENDFORM.
*---------------------------------------------------------------------*
* FORM FILL_OUTTAB *
*---------------------------------------------------------------------*
FORM FILL_OUTTAB.
* preconditions: myekpo is set at current PO and item
* sums has gr/ir totals, by zekkn sub-index
CLEAR OUTTAB.
LOOP AT SUMS.
IF SUMS-BEWTP = 'E'. "goods receipt
OUTTAB-GR = OUTTAB-GR + SUMS-MENGE.
OUTTAB-GRVAL = OUTTAB-GRVAL + SUMS-DMBTR.
ELSEIF SUMS-BEWTP = 'R'. "invoice receipt
OUTTAB-IR = OUTTAB-IR + SUMS-MENGE.
OUTTAB-IRVAL = OUTTAB-IRVAL + SUMS-DMBTR.
ELSE.
* perform write_bewtp_unhandled.
ENDIF.
ENDLOOP.
IF COMPARE = SPACE.
CHECK OUTTAB-GR <> OUTTAB-IR. "if gr/ir is equal, stop processing
ELSE. "COMPARE = 'A'.
CHECK ( OUTTAB-IR < OUTTAB-GR OR
( OUTTAB-GR = 0 AND OUTTAB-IR = 0 ) ).
ENDIF.
OUTTAB-EBELN = MYEKPO-EBELN.
OUTTAB-EBELP = MYEKPO-EBELP.
OUTTAB-MENGE = MYEKPO-MENGE.
OUTTAB-TXZ01 = MYEKPO-TXZ01.
OUTTAB-OUT = OUTTAB-GR - OUTTAB-IR.
OUTTAB-OUTVAL = OUTTAB-GRVAL - OUTTAB-IRVAL.
OUTTAB-ESTGRVAL = OUTTAB-GR * MYEKPO-NETPR.
OUTTAB-ESTOUTVAL = OUTTAB-ESTGRVAL - OUTTAB-IRVAL.
IF MYEKPO-KNTTP <> ' '. "account assignment: need to use ekkn
IF EKPO-VRTKZ = '2'. "multiple account distributed by percentage
WRITE: / 'This program does not handle accounts distributed',
'by percentage. Pls check manually (PO number',
EKPO-EBELN, ')'.
EXIT.
ENDIF.
* Fill in random info from ekkn.
SELECT SINGLE MENGE VPROZ SAKTO KOSTL KSTRG FROM EKKN
INTO MYEKKN WHERE
EBELN = MYEKPO-EBELN AND EBELP = MYEKPO-EBELP.
OUTTAB-SAKTO = MYEKKN-SAKTO.
OUTTAB-KOSTL = MYEKKN-KOSTL.
OUTTAB-KSTRG = MYEKKN-KSTRG.
APPEND OUTTAB. CLEAR OUTTAB.
ENDIF. "account assignment
ENDFORM.
*---------------------------------------------------------------------*
* FORM WRITE_OUTTAB *
*---------------------------------------------------------------------*
FORM WRITE_OUTTAB.
DESCRIBE TABLE OUTTAB LINES LN.
IF LN = 0.
WRITE: / 'No records found.'.
EXIT.
ENDIF.
SORT OUTTAB BY SAKTO KOSTL KSTRG.
LOOP AT OUTTAB.
IF ( NOT OLDSAKTO IS INITIAL ) AND OUTTAB-SAKTO <> OLDSAKTO AND
WROTE_SUBT = SPACE.
DO_SUBTOTAL = 'X'.
ENDIF.
OLDSAKTO = OUTTAB-SAKTO.
IF ( NOT OLDKOSTL IS INITIAL ) AND OUTTAB-KOSTL <> OLDKOSTL AND
WROTE_SUBT = SPACE.
DO_SUBTOTAL = 'X'.
ENDIF.
IF ( NOT OLDKSTRG IS INITIAL ) AND OLDKSTRG <> OUTTAB-KSTRG.
DO_SUBTOTAL = 'X'.
ENDIF.
OLDKSTRG = OUTTAB-KSTRG.
WROTE_SUBT = SPACE.
IF DO_SUBTOTAL = 'X'.
PERFORM WRITE_COBJ_SUBTOTAL.
CLEAR COBJ_SUBTOTAL.
DO_SUBTOTAL = SPACE.
ENDIF.
ADD-CORRESPONDING OUTTAB TO COBJ_SUBTOTAL.
ADD-CORRESPONDING OUTTAB TO TOTALS.
IF OUTTAB-OUT < 0.
FORMAT COLOR COL_NEGATIVE.
ENDIF.
WRITE: /
OUTTAB-EBELN UNDER TEXT-004, "PO doc
OUTTAB-EBELP UNDER TEXT-005, "PO item
OUTTAB-SAKTO UNDER TEXT-006, "G/L Acct
OUTTAB-KOSTL UNDER TEXT-007, "Cost Center
OUTTAB-KSTRG UNDER TEXT-008, "Cost Object
(13) OUTTAB-MENGE UNDER TEXT-009, "Quantity
(13) OUTTAB-GR UNDER TEXT-010, "GR quantity
(13) OUTTAB-IR UNDER TEXT-011, "IR quantity
(13) OUTTAB-ESTGRVAL UNDER TEXT-017, "Estimated GR Value
* (13) outtab-grval under text-012, "GR Val
(13) OUTTAB-IRVAL UNDER TEXT-013, "IR Value
(13) OUTTAB-OUT UNDER TEXT-014, "Outstandng IR qty
(13) OUTTAB-ESTOUTVAL UNDER TEXT-018, "Estimated Out IR Value
* (13) outtab-outval under text-015. "Outstandng IRval
OUTTAB-TXZ01 UNDER TEXT-019.
IF COMPARE = 'A'.
LOOP AT PO_AUFNR WHERE HIGH = OUTTAB-EBELN.
WRITE: PO_AUFNR-LOW UNDER TEXT-020.
ENDLOOP.
ENDIF.
FORMAT COLOR OFF.
ENDLOOP.
PERFORM WRITE_COBJ_SUBTOTAL.
PERFORM WRITE_TOTALS.
ENDFORM.
*---------------------------------------------------------------------*
* FORM WRITE_HEADERS *
*---------------------------------------------------------------------*
FORM WRITE_HEADERS.
FORMAT COLOR COL_HEADING.
WRITE: / TEXT-004, "PO
12 TEXT-005, "Item
18 TEXT-006, "G/L
29 TEXT-007, "Cost Center
40 TEXT-008, "Cost Object
49 TEXT-009, "Tot Qty
57 TEXT-010, "GR Qty
71 TEXT-011, "IR Qty
85 TEXT-017, "Est GR Value
* 85 text-012, "GR Val
99 TEXT-013, "IR Val
113 TEXT-014, "Outstanding IR Qty
* 127 text-015. "Outstanding IR Val
127 TEXT-018, "Est Out IR Val
141 TEXT-019. "short text
IF COMPARE = 'A'.
WRITE: 183 TEXT-020. "project
ENDIF.
WRITE: / SY-ULINE.
FORMAT COLOR OFF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form WRITE_COBJ_SUBTOTAL
*&---------------------------------------------------------------------*
FORM WRITE_COBJ_SUBTOTAL.
IF COMPARE = ' '.
WRITE: / SY-ULINE.
WRITE: / 'Subtotal' UNDER TEXT-008,
(13) COBJ_SUBTOTAL-MENGE UNDER TEXT-009, "Quantity
(13) COBJ_SUBTOTAL-GR UNDER TEXT-010, "GR quantity
(13) COBJ_SUBTOTAL-IR UNDER TEXT-011, "IR quantity
(13) COBJ_SUBTOTAL-ESTGRVAL UNDER TEXT-017, "Estimated GR Value
(13) COBJ_SUBTOTAL-IRVAL UNDER TEXT-013, "IR Value
(13) COBJ_SUBTOTAL-OUT UNDER TEXT-014, "Outstandng IR qty
(13) COBJ_SUBTOTAL-ESTOUTVAL UNDER TEXT-018. "Estimated Out IRva
SKIP 1.
WROTE_SUBT = 'X'.
ENDIF.
ENDFORM. " WRITE_COBJ_SUBTOTAL
*&---------------------------------------------------------------------*
*& Form WRITE_TOTALS
*&---------------------------------------------------------------------*
FORM WRITE_TOTALS.
WRITE: / SY-ULINE.
WRITE: / 'Total:' UNDER TEXT-008,
(13) TOTALS-MENGE UNDER TEXT-009, "Quantity
(13) TOTALS-GR UNDER TEXT-010, "GR quantity
(13) TOTALS-IR UNDER TEXT-011, "IR quantity
(13) TOTALS-ESTGRVAL UNDER TEXT-017, "Estimated GR Value
(13) TOTALS-IRVAL UNDER TEXT-013, "IR Value
(13) TOTALS-OUT UNDER TEXT-014, "Outstandng IR qty
(13) TOTALS-ESTOUTVAL UNDER TEXT-018. "Estimated Out IRva
ENDFORM. " WRITE_TOTALS
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.