Posted: Sun Oct 14, 2007 9:22 pm Post subject: Purchase Orders blocked for Billing Report
Requirement:
A report is required to list the purchase orders which are blocked for billing, in the invoicing plan. This report gets Blocked Purchase Orders against slection criteria that includes, Vendor, Purchasing organisation, Plant,Purchasing group,Invoice date, PO Created on, PO Created By, Purchase order number.
The purchase orders relevant to this report will have a invoicing plan assigned to them in EKPO-FPLNR.
Processing:
Get Blocked PO data from a join of Purchase Order tables (EKKO,EKPO) and Invoice Plan Table FPLT using the selection criteria. Further, The report should only show the Purchase Orders of Purchasing Group to which the user belongs. This will be done by checking the authority object [ AUTHORITY-CHECK OBJECT 'M_BEST_EKG'] for Purchasing Group.
Further, selected and filtered data will be displayed using ALV FM 'REUSE_ALV_GRID_DISPLAY'.
Code:
*-----------------------------------------------------------------------
* Purchase Orders Blocked for Billing
*-----------------------------------------------------------------------
* Program : Z_PO_BLOCKED_FOR_BILLING
* Presented By : www.rmtiwari.com
*-----------------------------------------------------------------------
* This report provides the details of purchasing documents which are *
* blocked for Billing. *
*----------------------------------------------------------------------*
REPORT Z_PO_BLOCKED_FOR_BILLING .
* Database Tables used for data selection
TABLES : EKKO, "Purchase Doc. Header
EKPO, "Purchase Doc. Item
FPLT, "Invoice Plan
LFA1, "Vendor
TVFST. "Block Description
* Internal table for Blocked PO data selection
DATA: BEGIN OF GT_PO_BLOCK_REPORT occurs 0,
EBELN TYPE EKKO-EBELN ,
EKORG TYPE EKKO-EKORG ,
LIFNR TYPE EKKO-LIFNR ,
NAME1 TYPE LFA1-NAME1 ,
EKGRP TYPE EKKO-EKGRP ,
AEDAT TYPE EKKO-AEDAT ,
ERNAM TYPE EKKO-ERNAM ,
FPLNR TYPE EKPO-FPLNR ,
WERKS TYPE EKPO-WERKS ,
EBELP TYPE EKPO-EBELP ,
FAKWR TYPE FPLT-FAKWR ,
WAERS TYPE FPLT-WAERS ,
FKSAF TYPE FPLT-FKSAF ,
FAKSP TYPE FPLT-FAKSP ,
VTEXT TYPE TVFST-VTEXT ,
AFDAT TYPE FPLT-AFDAT ,
END OF GT_PO_BLOCK_REPORT.
* ALV stuff
type-pools: slis.
data: GT_FIELDCAT type SLIS_T_FIELDCAT_ALV,
GS_LAYOUT type SLIS_LAYOUT_ALV,
GT_SORT type SLIS_T_SORTINFO_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GT_EVENTS TYPE SLIS_T_EVENT.
SELECTION-SCREEN BEGIN OF BLOCK SPE WITH FRAME TITLE TEXT-S04.
SELECT-OPTIONS: FAKSP FOR FPLT-FAKSP, "Billing Block
AFDAT FOR FPLT-AFDAT OBLIGATORY
DEFAULT SY-datum."Invoice Date
SELECTION-SCREEN END OF BLOCK SPE.
SELECTION-SCREEN BEGIN OF BLOCK ORGA WITH FRAME TITLE TEXT-S01.
PARAMETER : EKORG LIKE EKKO-EKORG
OBLIGATORY. "Purchasing Organisation
SELECT-OPTIONS: WERKS FOR EKPO-WERKS, "Plant
EKGRP FOR EKKO-EKGRP. "Purchasing Group
SELECTION-SCREEN END OF BLOCK ORGA.
SELECTION-SCREEN BEGIN OF BLOCK USER WITH FRAME TITLE TEXT-S02.
SELECT-OPTIONS: AEDAT FOR EKKO-AEDAT, "Created On
ERNAM FOR EKKO-ERNAM
DEFAULT SY-UNAME. "Created By
SELECTION-SCREEN END OF BLOCK USER.
SELECTION-SCREEN BEGIN OF BLOCK DOCUMENT WITH FRAME TITLE TEXT-S03.
SELECT-OPTIONS: EBELN FOR EKKO-EBELN. "Purchasing Document
SELECTION-SCREEN END OF BLOCK DOCUMENT.
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
* Check if user is authorised to run this report.
PERFORM AUTHORIZATION_CHECK.
* Get Blocked Purchase Orders
PERFORM GET_BLOCKED_PO.
* Get Bliock description and Vendor Name
PERFORM GET_DESCRIPTION.
END-OF-SELECTION.
* Show report in ALV
PERFORM DISPLAY_REPORT.
*&---------------------------------------------------------------------*
*& Form get_blocked_po
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
form get_blocked_po.
*Get Blocked PO data from a join of Purchase Order and Invoice Plan
*tables.
select EKKO~EBELN
EKKO~EKORG
EKKO~LIFNR
EKKO~EKGRP
EKKO~AEDAT
EKKO~ERNAM
EKPO~FPLNR
EKPO~WERKS
EKPO~EBELP
FPLT~FAKWR
FPLT~WAERS
FPLT~FKSAF
FPLT~FAKSP
FPLT~AFDAT
into corresponding fields of table GT_PO_BLOCK_REPORT
from ( EKKO
inner join EKPO
on EKPO~EBELN = EKKO~EBELN
inner join FPLT
on FPLT~FPLNR = EKPO~FPLNR )
where EKKO~LIFNR in LIFNR
and EKKO~EKORG eq EKORG
and EKKO~EKGRP in EKGRP
and EKKO~EBELN in EBELN
and EKKO~AEDAT in AEDAT
and EKKO~ERNAM in ERNAM
and EKPO~WERKS in WERKS
and FPLT~FAKSP in FAKSP
and FPLT~AFDAT in AFDAT
and FPLT~FAKSP < > ' '
and FPLT~FKSAF < > 'C' .
endform. "get_blocked_po
*&---------------------------------------------------------------------*
*& Form get_description
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
form get_description.
data : LT_BLOCK_DESC type sorted table of TVFST with header line
with unique key SPRAS FAKSP.
data : begin of LT_PGRP occurs 0,
EKGRP type EKKO-EKGRP,
end of LT_PGRP.
data : LV_NO_AUTH_PGRP(100) type c.
* Get all the invoice block description in sorted internal table.
SELECT *
into table LT_BLOCK_DESC
from TVFST
where SPRAS eq SY-langu.
* Perform authority check for purchasing group
AUTHORITY-CHECK OBJECT 'M_BEST_EKG'
ID 'EKGRP' FIELD GT_PO_BLOCK_REPORT-EKGRP
ID 'ACTVT' FIELD '03'.
if SY-subrc ne 0.
LT_PGRP-ekgrp = GT_PO_BLOCK_REPORT-ekgrp.
append LT_PGRP.
delete GT_PO_BLOCK_REPORT.
continue.
endif.
* Get Vendor Name
SELECT SINGLE NAME1
into GT_PO_BLOCK_REPORT-NAME1
FROM LFA1
WHERE LIFNR = GT_PO_BLOCK_REPORT-LIFNR.
* Get Invoice Block Description
READ TABLE LT_BLOCK_DESC with key SPRAS = SY-langu
FAKSP = GT_PO_BLOCK_REPORT-FAKSP.
if SY-subrc eq 0.
GT_PO_BLOCK_REPORT-vtext = LT_BLOCK_DESC-vtext.
endif.
* Now transfer Vendor Name and Block description.
MODIFY GT_PO_BLOCK_REPORT transporting NAME1 VTEXT.
ENDLOOP.
* Message to user in case no authorization for the purchasing groups.
sort LT_PGRP by EKGRP.
delete adjacent duplicates from LT_PGRP.
loop at LT_PGRP.
concatenate LV_NO_AUTH_PGRP LT_PGRP-ekgrp into lv_no_auth_pgrp.
endloop.
if not LT_PGRP[] is initial.
message i004(Z001) with LV_NO_AUTH_PGRP.
endif.
endform. "get_description
*&---------------------------------------------------------------------*
*& Form display_report
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
form display_report.
perform GRID_DISPLAY.
endform. "display_report
*&---------------------------------------------------------------------*
*& Form layout_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
endform. " layout_init
*&---------------------------------------------------------------------*
*& Form COMMENT_BUILD
*&---------------------------------------------------------------------*
* Processing of listheader
*----------------------------------------------------------------------*
FORM COMMENT_BUILD USING P_FK_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
REFRESH P_FK_LIST_TOP_OF_PAGE.
* List Heading : Typ H
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
LS_LINE-INFO = 'Purchase Orders Blocked for Billing'.
APPEND LS_LINE TO P_FK_LIST_TOP_OF_PAGE.
* List : Typ S
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'Invoice Date Range'.
LS_LINE-INFO = AFDAT-LOW.
IF NOT AFDAT-HIGH IS INITIAL.
WRITE ' To ' TO LS_LINE-INFO+30.
LS_LINE-INFO+36 = AFDAT-HIGH.
ENDIF.
APPEND LS_LINE TO P_FK_LIST_TOP_OF_PAGE.
ENDFORM. " COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
form fieldcat_init.
data: LS_FIELDCAT type SLIS_FIELDCAT_ALV.
clear LS_FIELDCAT.
LS_FIELDCAT-fieldname = 'EBELN'.
LS_FIELDCAT-key = 'X'.
LS_FIELDCAT-reptext_ddic = 'PO Number'.
LS_FIELDCAT-outputlen = 10.
* Fix for ALV print bug, which puts 'N/A' over last digit
* Set inttype to 'N' to stop corruption of printed ALV cell.
LS_FIELDCAT-inttype = 'N'.
append LS_FIELDCAT to GT_FIELDCAT.
*&---------------------------------------------------------------------*
*& Form sort_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
form sort_init.
data: LS_SORT type SLIS_SORTINFO_ALV.
* Default sorting by PO item and Invoice block code.
clear LS_SORT.
LS_SORT-fieldname = 'EBELN'.
LS_SORT-spos = 1.
LS_SORT-up = 'X'.
append LS_SORT to GT_SORT.
FORM EVENTTAB_BUILD USING P_FK_EVENTS TYPE SLIS_T_EVENT.
DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = P_FK_EVENTS.
READ TABLE P_FK_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.
APPEND LS_EVENT TO P_FK_EVENTS.
ENDIF.
READ TABLE P_FK_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE 'USER_COMMAND' TO LS_EVENT-FORM.
APPEND LS_EVENT TO P_FK_EVENTS.
ENDIF.
ENDFORM. " EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*& Form grid_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
form grid_display.
* Show Invoice Block Report in ALV.
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = SY-REPID
i_callback_user_command = 'USER_COMMAND'
is_layout = GS_LAYOUT
it_fieldcat = GT_FIELDCAT
it_sort = GT_SORT
i_default = ' '
i_save = 'X'
IT_EVENTS = gt_EVENTS[]
TABLES
t_outtab = GT_PO_BLOCK_REPORT
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
if SY-subrc < > 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. "grid_display
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* User commands for ALV Function
*----------------------------------------------------------------------*
FORM user_command USING R_UCOMM TYPE syucomm
RS_SELFIELD TYPE SLIS_SELFIELD.
IF R_UCOMM EQ '&IC1'.
* Drilldown by user.
READ TABLE GT_PO_BLOCK_REPORT INDEX RS_SELFIELD-tabindex.
CASE RS_SELFIELD-fieldname.
* For Purchase Order
WHEN 'EBELN'.
* Call transaction ME23N to display the PO
SET PARAMETER ID 'BES' FIELD GT_PO_BLOCK_REPORT-EBELN.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDCASE.
ENDIF.
ENDFORM. "user_command
*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* Ereigniss TOP_OF_PAGE *
* event TOP_OF_PAGE
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
PERFORM COMMENT_BUILD USING gt_LIST_TOP_OF_PAGE[].
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
ENDFORM. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form authorization_check
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* < -- p2 text
*----------------------------------------------------------------------*
FORM authorization_check.
*
*
* CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
* EXPORTING
* TCODE = 'ZPOBL'
* EXCEPTIONS
* OK = 1
* NOT_OK = 2
* OTHERS = 3
* .
* IF SY-SUBRC < > 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
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.