Project expense report
This tip is excerpted from Matt Wong's SAP Basis site.
This report displays information about internal orders. It has two parts: one for reporting data based on document information in BSIS and BSEG, and one for reporting data based on purchasing order information. The user selects which report to run with the appropriate radio button. For PO data, this report simply prepares and submits a set of parameters to the Outstanding Purchase Order report. For document information, this report prepares and lists the appropriate information from BSIS and BSEG.
Report By Document Data: The report looks up data in BSIS and BSEG that meets the user's selection criteria, and lists the data (one line per BSIS entry). Purchase order and cost object data resides in BSEG; the rest of the data resides in BSIS.
Report By PO Data: The report looks up purchase order information by referencing BSIS, and then referencing BSEG. It then keeps a list of purchase orders po_doc, which is passed on to the Outstanding Order report to limit its selection, and a list of (Purchase Order, Item Number) pairs (fields ebeln and ebelp in BSEG). In addition, it keeps a list of (Purchase Order, Internal Order) pairs (fields BSEG-ebeln and BSIS-aufnr), so that the Outstanding
Requires Free Membership to View
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
Hannah Smalltree, Editorial Director- the compare parameter is set to 'A' (an arbitrary value), which is a flag indicating that the report was called by this report, and to process as described here
- After looking up records for PO documents, limited by the PO numbers in the po_doc selection criteria passed to it, the report makes a further check on each line item, listing only those items found in the PO/Item pairs list po_itemp
- the report lists items with IR < GR, or GR = IR = 0 (rather than IR <> GR)
- the report's output list contains an additional field Internal Order, which is looked up in the PO/Internal Order pairs list po_order that is passed to it
For further details, see documentation in the Outstanding PO report.
Project Expense Report
*&---------------------------------------------------------------------*
*& Report ZPRJEXP2 *
*& Author: Matt Wong, SNI Taiwan, Aug 1998 *
*& *
*& Report for displaying expense data for internal orders/projects. *
*& PO_ITEMP contains PO/item pairs to be passed onto the Outstanding PO*
*& report, since we may only want to access certain items of a PO (not *
*& all items). *
*& Using a select-option to do this makes it easier to pass the info to*
*& the report *
*& *
*& PO_AUFNR is also for passing data between programs. It passes *
*& PO/Internal Order number pairs *
*&---------------------------------------------------------------------*
REPORT ZPRJEXP2 LINE-SIZE 250 LINE-COUNT 65 NO STANDARD PAGE HEADING.
TABLES: BSIS, BSEG.
PARAMETERS: COMPANY LIKE BSIS-BUKRS OBLIGATORY,
BYDOC RADIOBUTTON GROUP REPT,
BYPO RADIOBUTTON GROUP REPT.
SELECT-OPTIONS: ORDER FOR BSIS-AUFNR OBLIGATORY NO-EXTENSION,
POSTDATE FOR SY-DATUM NO-EXTENSION,
YEAR FOR BSIS-GJAHR NO-DISPLAY,
PO_DOC FOR BSEG-EBELN NO-DISPLAY,
PO_ITEMP FOR BSEG-EBELN NO-DISPLAY, "PO/item pair
PO_AUFNR FOR BSIS-AUFNR NO-DISPLAY.
DATA:
BSEG_FIELDS LIKE RSFS_STRUC OCCURS 10 WITH HEADER LINE,
BEGIN OF MYBSEG,
EBELN LIKE BSEG-EBELN,
EBELP LIKE BSEG-EBELP,
KSTRG LIKE BSEG-KSTRG,
END OF MYBSEG,
LASTAUFNR LIKE BSIS-AUFNR,
AUFNRSUBTOTAL LIKE BSIS-DMBTR,
TOTAL LIKE BSIS-DMBTR.
AT SELECTION-SCREEN ON POSTDATE.
CLEAR YEAR. REFRESH YEAR.
IF NOT POSTDATE-LOW IS INITIAL.
YEAR-SIGN = 'I'.
YEAR-OPTION = 'EQ'.
YEAR-LOW = POSTDATE-LOW(4).
IF NOT POSTDATE-HIGH IS INITIAL AND
( POSTDATE-LOW(4) <> POSTDATE-HIGH(4) ) .
MESSAGE E003(ZS).
ENDIF.
APPEND YEAR.
ENDIF.
INITIALIZATION.
BSEG_FIELDS = 'ebeln'. APPEND BSEG_FIELDS.
BSEG_FIELDS = 'ebelp'. APPEND BSEG_FIELDS.
BSEG_FIELDS = 'kstrg'. APPEND BSEG_FIELDS.
REFRESH PO_DOC.
PO_DOC-SIGN = 'I'.
PO_DOC-OPTION = 'EQ'.
REFRESH PO_ITEMP.
TOP-OF-PAGE.
WRITE: SY-DATUM.
WRITE: 85 'Project Expenditure Tracing Report (by Document),'.
WRITE: 'Posting date'.
IF POSTDATE-HIGH IS INITIAL.
WRITE: POSTDATE-LOW.
ELSE.
WRITE: 'Between', POSTDATE-LOW, 'and', POSTDATE-HIGH.
ENDIF.
WRITE: 240 'Page:', 248(2) SY-PAGNO, / SY-ULINE.
START-OF-SELECTION.
* should do authorization checking here **
SELECT * FROM BSIS WHERE
BUKRS = COMPANY AND
GJAHR IN YEAR AND
AUFNR IN ORDER AND
BUDAT IN POSTDATE
ORDER BY AUFNR BELNR.
IF BYPO = ' ' AND LASTAUFNR <> BSIS-AUFNR.
PERFORM WRITE_ORDER_HEADER.
ENDIF.
LASTAUFNR = BSIS-AUFNR.
* should do authorization checking here **
SELECT SINGLE (BSEG_FIELDS) FROM BSEG INTO MYBSEG WHERE
BUKRS = COMPANY AND
BELNR = BSIS-BELNR AND
GJAHR = BSIS-GJAHR AND
BUZEI = BSIS-BUZEI.
IF BYPO = 'X'. "output by PO doc: report zgmpo-05
LOOP AT PO_AUFNR WHERE HIGH = MYBSEG-EBELN AND LOW = BSIS-AUFNR.
ENDLOOP.
IF SY-SUBRC = 4. "no entry already exists
PO_AUFNR-HIGH = MYBSEG-EBELN.
PO_AUFNR-LOW = BSIS-AUFNR.
APPEND PO_AUFNR.
ENDIF.
IF MYBSEG-EBELN <> SPACE.
PERFORM ADD_PO_ITEM.
ENDIF.
ELSE. "output by document
IF BSIS-SHKZG = 'H'.
ELSE.
BSIS-DMBTR = - BSIS-DMBTR.
ENDIF.
PERFORM WRITE_OUTPUT.
TOTAL = TOTAL + BSIS-DMBTR.
AUFNRSUBTOTAL = AUFNRSUBTOTAL + BSIS-DMBTR.
ENDIF.
ENDSELECT.
IF BYPO = 'X'.
SUBMIT ZGMPO-05 WITH COMPARE = 'A'
WITH PO_ITEMP IN PO_ITEMP
WITH PO_DOC IN PO_DOC
WITH POSTDAT IN POSTDATE
WITH PO_AUFNR IN PO_AUFNR AND RETURN.
ELSE.
PERFORM WRITE_AUFNRSUBTOTAL.
PERFORM WRITE_TOTAL.
ENDIF.
*&---------------------------------------------------------------------*
*& Form WRITE_OUTPUT
*&---------------------------------------------------------------------*
FORM WRITE_OUTPUT.
WRITE: / BSIS-BELNR UNDER TEXT-001, "Document
BSIS-BUDAT UNDER TEXT-002, "Posting Date
BSIS-KOSTL UNDER TEXT-003, "Cost Center
BSIS-SGTXT UNDER TEXT-004, "Description
BSIS-DMBTR UNDER TEXT-005, "Amount
MYBSEG-KSTRG UNDER TEXT-006, "Cost Object
MYBSEG-EBELN UNDER TEXT-007. "PO Number
ENDFORM. " WRITE_OUTPUT
*&---------------------------------------------------------------------*
*& Form WRITE_COL_HEADERS
*&---------------------------------------------------------------------*
FORM WRITE_COL_HEADERS.
WRITE: / TEXT-001, "Document
16 TEXT-002, "Posting Date
28 TEXT-003, "Cost Center
36 TEXT-004, "Description
87 TEXT-005, "Amount
107 TEXT-006, "Cost Object
123 TEXT-007. "PO Number
ENDFORM.
*&---------------------------------------------------------------------*
*& Form WRITE_TOTAL
*&---------------------------------------------------------------------*
FORM WRITE_TOTAL.
WRITE: / SY-ULINE.
WRITE: / 'Total:' UNDER TEXT-004, TOTAL UNDER TEXT-005.
ENDFORM. " WRITE_TOTAL
*&---------------------------------------------------------------------*
*& Form ADD_PO_ITEM
*&---------------------------------------------------------------------*
FORM ADD_PO_ITEM.
LOOP AT PO_DOC WHERE LOW = MYBSEG-EBELN.
ENDLOOP.
IF SY-SUBRC = 4. "entry does not already exist
PO_DOC-LOW = MYBSEG-EBELN.
APPEND PO_DOC.
ENDIF.
* add po/item pair to list. PO goes into high, item into low
LOOP AT PO_ITEMP WHERE HIGH = MYBSEG-EBELN AND LOW = MYBSEG-EBELP.
ENDLOOP.
IF SY-SUBRC = 4. "entry does not already exist
PO_ITEMP-HIGH = MYBSEG-EBELN.
PO_ITEMP-LOW = MYBSEG-EBELP.
APPEND PO_ITEMP.
ENDIF.
ENDFORM. " ADD_PO_ITEM
*&---------------------------------------------------------------------*
*& Form WRITE_ORDER_HEADER
*&---------------------------------------------------------------------*
FORM WRITE_ORDER_HEADER.
IF NOT AUFNRSUBTOTAL IS INITIAL.
PERFORM WRITE_AUFNRSUBTOTAL.
ENDIF.
SKIP 1.
WRITE: / 'Project No:', BSIS-AUFNR.
WRITE: / SY-ULINE.
PERFORM WRITE_COL_HEADERS.
ENDFORM. " WRITE_ORDER_HEADER
*&---------------------------------------------------------------------*
*& Form WRITE_AUFNRSUBTOTAL
*&---------------------------------------------------------------------*
FORM WRITE_AUFNRSUBTOTAL.
WRITE: / SY-ULINE.
WRITE: / 'Project Total:' UNDER TEXT-004, AUFNRSUBTOTAL UNDER TEXT-005.
AUFNRSUBTOTAL = 0.
ENDFORM. " WRITE_AUFNRSUBTOTAL
Did you like this tip? If so (or if not) let us know. Send an email to sound off. Or go to our tips page and rate this, and other, tips, or send us one of your own.
Related Book
ABAP/4 : Programming the SAP R/3 System, Second Edition
Author : Bernd Matzke
Publisher : Addison Wesley
ISBN/CODE : 0201675153
Cover Type : Hard Cover
Pages : 864
Published : Nov 2000
Summary :
Many of the introductory SAP books currently on the market provide only a brief overview of ABAP. In ABAP/4: Programming the SAP R/3 System, Bernd Matzke builds on this information to look in depth at the programming language at the heart of the SAP R/3 system. This definitive guide to ABAP/4 aims to make the fundamentals of this evolving programming language accessible to anybody developing or maintaining an SAP R/3 system. Starting with the basic principles, it explains the essential characteristics of ABAP/4 and the SAP programming concept. With this book you will learn how to: master the ABAP/4 commands in order to analyze existing standard applications and write new programs; understand function modules to use program code from other applications; use the Workbench organizer and On-line Debugger to relay applications and document changes; and create your own programs and construct your own test environments with an expansive set of examples designed to build up knowledge and programming skills. The sample programs in the book were developed on a 3.0 system but can also run on other versions of the R/3 system. The accompanying CD-ROM contains sample programs used in this book for Version 3.0C together with a modified set of programs for systems running on Version 2.2E. --This text refers to the Paperback edition
This was first published in March 2001
Join the conversationComment
Share
Comments
Results
Contribute to the conversation