SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Purchase Orders blocked for Billing Report



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sun Oct 14, 2007 9:22 pm    Post subject: Purchase Orders blocked for Billing Report Reply with quote

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.


*------------------PARAMETER------------------------------------------*
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS: LIFNR FOR EKKO-LIFNR.      "Vendor
SELECTION-SCREEN SKIP 1.

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.

INITIALIZATION.
    perform FIELDCAT_INIT.
    perform LAYOUT_INIT.
    perform SORT_INIT.
    PERFORM EVENTTAB_BUILD USING gt_EVENTS[].

START-OF-SELECTION.

* 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.

  LOOP AT GT_PO_BLOCK_REPORT.

    clear : GT_PO_BLOCK_REPORT-vtext,
            GT_PO_BLOCK_REPORT-NAME1.

*   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
*----------------------------------------------------------------------*
 
form layout_init.
  GS_LAYOUT-zebra             = 'X'.
  GS_LAYOUT-cell_merge        = 'X'.
  GS_LAYOUT-colwidth_optimize = 'X'.
  GS_LAYOUT-no_vline          = ' '.
  GS_LAYOUT-totals_before_items = ' '.
  GS_LAYOUT-KEY_HOTSPOT         = 'X'.

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.


  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'EBELP'.
  LS_FIELDCAT-reptext_ddic = 'Item'.
  LS_FIELDCAT-outputlen    = 5.
  LS_FIELDCAT-inttype = 'N'.
  append LS_FIELDCAT to GT_FIELDCAT.

*  clear ls_fieldcat.
*  ls_fieldcat-fieldname    = 'EKORG'.
*  ls_fieldcat-reptext_ddic = 'Pur Org'.
*  ls_fieldcat-outputlen    = 6.
*  append ls_fieldcat to gt_fieldcat.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'LIFNR'.
  LS_FIELDCAT-reptext_ddic = 'Vendor'.
  LS_FIELDCAT-outputlen    = 12.
  LS_FIELDCAT-inttype = 'N'.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'NAME1'.
  LS_FIELDCAT-reptext_ddic = 'Vendor Name'.
  LS_FIELDCAT-outputlen    = 35.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'FPLNR'.
  LS_FIELDCAT-reptext_ddic = 'Inv. Plan No'.
  LS_FIELDCAT-outputlen    = 10.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'AFDAT'.
  LS_FIELDCAT-reptext_ddic = 'Invoice Date'.
  LS_FIELDCAT-outputlen    = 10.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'FAKWR'.
  LS_FIELDCAT-reptext_ddic = 'Invoice Amount'.
  LS_FIELDCAT-outputlen    = 15.
*  ls_fieldcat-cfieldname   = 'WARES'.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'WAERS'.
  LS_FIELDCAT-reptext_ddic = 'Curr'.
  LS_FIELDCAT-outputlen    = 5.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'FAKSP'.
  LS_FIELDCAT-reptext_ddic = 'Block'.
  LS_FIELDCAT-outputlen    = 2.
  append LS_FIELDCAT to GT_FIELDCAT.

  clear LS_FIELDCAT.
  LS_FIELDCAT-fieldname    = 'VTEXT'.
  LS_FIELDCAT-reptext_ddic = 'Block Description'.
  LS_FIELDCAT-outputlen    = 20.
  append LS_FIELDCAT to GT_FIELDCAT.

endform.                    "fieldcat_init

*&---------------------------------------------------------------------*
*&      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.

  clear LS_SORT.
  LS_SORT-fieldname = 'EBELP'.
  LS_SORT-spos      = 2.
  LS_SORT-up        = 'X'.
  append LS_SORT to GT_SORT.

  clear LS_SORT.
  LS_SORT-fieldname = 'FAKSP'.
  LS_SORT-spos      = 3.
  LS_SORT-up        = 'X'.
  append LS_SORT to GT_SORT.

endform.                    "sort_init

*&---------------------------------------------------------------------*
*&      Form  EVENTTAB_BUILD
*&---------------------------------------------------------------------*
*      Ereignistabelle Bilden
*      EVENTS TABLE BUILD
*----------------------------------------------------------------------*
 
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.

ENDFORM.                    " authorization_check
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.