Posted: Wed Sep 26, 2007 7:34 pm Post subject: Open Purchase order report
Open PO or Open sales order means that the complete cycle is not complete. That means the Sales order is not completely delievered or is not billed or is not paid for. Only once the cycle is completed the order status shows as complete untill then its Open.
You can use VA05 to find open sales orders.
Similarlry open PO's are those PO's whos inbound delivery is not complete or whos goods receipt is not complete and whos payment is not done to the vendor.
Look at VBFA Table -> enter delivery number (VBELV) and Sub sequent Item category VBTYP_N = Q then you will get transfer order
Transfer order nothing but material will come one location to other location(Target Location) so sap will create transfer order.
Look at Transaction : LT01,LT02,LT03
Tables are : LTAK,LTAP
Mentioned wrong table ekpa for document flow, it is partner function table
More tables related to Purchase documents.
EKAN Vendor Address: Purchasing Document
EKBE History per Purchasing Document
EKBEH Removed PO History Records
EKBO Index of Docs. for Price Determ./Updating,
EKBZ History per Purchasing Document: Delivery
EKBZH History per Purchasing Document: Delivery
EKCC Index Table for CCP Process
EKEH Scheduling Agreement Release Documentation
EKEK Header Data for Scheduling Agreement Relea
EKES Vendor Confirmations
EKET Scheduling Agreement Schedule Lines
EKETH Scheduling Agreement Schedules: History Ta
EKKI Purchasing Condition Index
EKKN Account Assignment in Purchasing Document
EKKO Purchasing Document Header
EKPA Partner Roles in Purchasing
EKPB "Material Provided" Item in Purchasing Doc
EKPO Purchasing Document Item
EKPV Shipping Data For Stock Transfer of Purcha
EKRS ERS Procedure: Goods (Merchandise) Movemen
EKUB Index for Stock Transport Orders for Mater
This is Open Purchase order report and see the logic:
Code:
REPORT zmm_open_po_report NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID zwave.
*======================================================================*
* *
* Program Name : ZMM_OPEN_PO_REPORT *
* *
* Description : This report displays all Open PO Items and output *
* would be PO Number,Material number and so on *
* *
* Author : Seshu
************************************************************************
************************************************************************
** D A T A D E C L A R A T I O N P A R T ***
************************************************************************
* type-pools
TYPE-POOLS : slis.
* Tables
TABLES : ekko, " Purchase order Header
ekpo, " Purchase order Item
marc. " Material with Plant data
* Internal table for output.
DATA : BEGIN OF i_output OCCURS 0,
ebeln LIKE ekko-ebeln,
matnr LIKE ekpo-matnr,
END OF i_output.
* ALV Data declaration.
DATA : v_repid LIKE sy-repid.
* ALV Function Module Variables
DATA: gs_layout TYPE slis_layout_alv,
g_exit_caused_by_caller,
gs_exit_caused_by_user TYPE slis_exit_by_user.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_print TYPE slis_print_alv,
gt_events TYPE slis_t_event,
gt_list_top_of_page TYPE slis_t_listheader,
g_status_set TYPE slis_formname VALUE 'PF_STATUS_SET',
g_user_command TYPE slis_formname VALUE 'USER_COMMAND',
g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
g_top_of_list TYPE slis_formname VALUE 'TOP_OF_LIST',
g_end_of_list TYPE slis_formname VALUE 'END_OF_LIST',
g_variant LIKE disvariant,
g_save(1) TYPE c,
g_tabname_header TYPE slis_tabname,
g_tabname_item TYPE slis_tabname,
g_exit(1) TYPE c,
gx_variant LIKE disvariant.
DATA : gr_layout_bck TYPE slis_layout_alv.
* Ranges
RANGES r_eindt FOR eket-eindt.
INITIALIZATION.
v_repid = sy-repid.
START-OF-SELECTION.
* Get the data from EKKO ,EKPO and MARC Table
PERFORM get_data_tables.
END-OF-SELECTION.
* display the data in the form of ALV
PERFORM display_data.
*&---------------------------------------------------------------------*
*& Form get_data_tables
*&---------------------------------------------------------------------*
* Get the data from EKKO,EKPO and MARC Table
*----------------------------------------------------------------------*
FORM get_data_tables.
CLEAR : i_output.
REFRESH : i_output.
* fill the dates in ranges
r_eindt-low = sy-datum - 7.
r_eindt-high = sy-datum + 14.
r_eindt-option = 'BT'.
r_eindt-sign = 'I'.
APPEND r_eindt.
* Get the data from EKKO,EKPO and EKET Tables
SELECT a~ebeln b~matnr INTO TABLE i_output
FROM ekko AS a INNER JOIN
ekpo AS b ON a~ebeln = b~ebeln
INNER JOIN marc AS c ON c~matnr = b~matnr
INNER JOIN mara AS d ON d~matnr = b~matnr
INNER JOIN eket AS e ON e~ebeln = a~ebeln
AND e~ebelp = b~ebelp
WHERE c~beskz = 'E'
AND c~werks = '1000'
AND d~mtart = 'FERT'
AND b~loekz = space
AND b~elikz = space
AND e~eindt IN r_eindt.
IF sy-subrc NE 0.
MESSAGE e000(zwave) WITH 'No open purchase order found'.
ENDIF.
ENDFORM. " get_data_tables
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_data.
* Fill the Fiedlcat
PERFORM fieldcat_init USING gt_fieldcat[].
ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GT_FIELDCAT[] text
*----------------------------------------------------------------------*
FORM fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.
This is closing the open purchase order and see the logic
Code:
REPORT zmmi_po_close NO STANDARD PAGE HEADING
LINE-COUNT 65
LINE-SIZE 128
MESSAGE-ID zcustrans.
************************************************************************
* DATA DECLARATION *
************************************************************************
* Table work area
TABLES: ekko,
ekpo,
eket.
* Internal tables
DATA: BEGIN OF t_po OCCURS 0,
ebeln LIKE ekko-ebeln,
ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
idnlf LIKE ekpo-idnlf,
menge LIKE ekpo-menge,
meins LIKE ekpo-meins,
netpr LIKE ekpo-netpr,
eindt LIKE eket-eindt,
lifnr LIKE ekko-lifnr,
END OF t_po.
DATA: BEGIN OF t_mess OCCURS 0,
ebeln LIKE ekko-ebeln,
message(100) TYPE c,
END OF t_mess.
DATA: t_po_dup LIKE t_po OCCURS 0 WITH HEADER LINE.
DATA: t_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: t_item LIKE bapimepoitem OCCURS 0 WITH HEADER LINE.
DATA: t_itemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE.
* Variables
DATA: w_col1 TYPE i,
w_col2 TYPE i,
w_len TYPE i,
w_str TYPE i,
w_color TYPE c.
DATA : v_day(2) TYPE c ,
v_days LIKE tvak-vlauf .
* Constants
CONSTANTS: c_usd LIKE tcurc-waers VALUE 'USD'.
************************************************************************
* TOP OF PAGE *
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN: SKIP 1.
PARAMETERS: p_werks LIKE ekpo-werks DEFAULT '1000' NO-DISPLAY,
p_lgort LIKE ekpo-lgort DEFAULT '1000' NO-DISPLAY,
p_bukrs LIKE ekko-bukrs DEFAULT '0011' NO-DISPLAY,
p_ekorg LIKE ekko-ekorg DEFAULT '1000'.
SELECT-OPTIONS: s_lifnr FOR ekko-lifnr,
s_ekgrp FOR ekko-ekgrp,
s_ebeln FOR ekko-ebeln,
s_matnr FOR ekpo-matnr.
SELECTION-SCREEN: SKIP 1.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-020.
SELECTION-SCREEN: SKIP 1.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(79) text-021.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(42) text-022.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN: SKIP 1.
SELECT-OPTIONS: s_eindt FOR eket-eindt NO INTERVALS NO-EXTENSION
OBLIGATORY.
* PARAMETERS: p_days LIKE tvak-vlauf OBLIGATORY.
PARAMETERS: p_days LIKE v_day OBLIGATORY.
SELECTION-SCREEN: SKIP 1.
SELECTION-SCREEN: END OF BLOCK b2.
************************************************************************
* AT SELECTION SCREEN *
************************************************************************
AT SELECTION-SCREEN.
* Ensure the delivery date is only in past
PERFORM check_date.
************************************************************************
* START OF SELECTION *
************************************************************************
START-OF-SELECTION.
* << Start delete >> Rajs-02/17/2005
* New rules have been created as variant. Do not need it any more
* Over-write delivery date if run in background
* IF NOT sy-batch IS INITIAL.
* PERFORM init_data.
* MESSAGE i000 WITH text-018 text-019.
* ENDIF.
* << End delete >>
v_days = p_days.
* Calculate date for selection: Rajs-04/08/2005
PERFORM get_delivery_date.
* Extract and process data
PERFORM get_data.
************************************************************************
* END OF SELECTION *
************************************************************************
END-OF-SELECTION.
* Screen output
PERFORM display_report.
************************************************************************
* AT LINE SELECTION *
************************************************************************
AT LINE-SELECTION.
* Display PO document
IF NOT t_po_dup-ebeln IS INITIAL.
SET PARAMETER ID 'BES' FIELD t_po_dup-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
CLEAR: t_po_dup-ebeln.
ENDIF.
************************************************************************
* SUB ROUTINES *
************************************************************************
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_data.
* Extract open PO items in past that have schedule delivery as given in
* selection
SELECT a~ebeln
b~ebelp b~matnr b~idnlf b~menge b~meins b~netpr
c~eindt a~lifnr
INTO TABLE t_po
FROM ( ( ekko AS a INNER JOIN ekpo
AS b ON a~ebeln = b~ebeln )
INNER JOIN eket
AS c ON b~ebeln = c~ebeln AND
b~ebelp = c~ebelp )
WHERE a~ebeln IN s_ebeln AND
a~bstyp = 'F' AND
a~bsart = 'NB' AND
a~loekz = space AND
a~lifnr IN s_lifnr AND
a~ekorg = p_ekorg AND
a~ekgrp IN s_ekgrp AND
b~loekz = space AND
b~matnr IN s_matnr AND
b~werks = p_werks AND
b~lgort = p_lgort AND
b~elikz = space AND
c~eindt IN s_eindt.
AT END OF ebeln.
CLEAR : t_return.
REFRESH: t_return.
* Set delivery complete indicator for items in a PO
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = t_po-ebeln
TABLES
return = t_return
poitem = t_item
poitemx = t_itemx.
LOOP AT t_return WHERE type = 'A' OR
type = 'E'.
MOVE: t_po-ebeln TO t_mess-ebeln,
t_return-message TO t_mess-message.
APPEND t_mess.
CLEAR t_mess.
ENDLOOP.
* Commit if there is no error
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
* This table contains only POs that are successfully processed
DELETE t_po_dup WHERE ebeln = t_po-ebeln.
ENDIF.
CLEAR : t_item, t_itemx.
REFRESH: t_item, t_itemx.
ENDAT.
CLEAR t_po.
ENDLOOP.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form get_header
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_header.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
PERFORM calc_col_and_write USING text-002
sy-linsz.
PERFORM calc_col_and_write USING sy-title
sy-linsz.
* User id
w_col1 = 2.
WRITE: AT /w_col1 'UserId : ', sy-uname.
w_len = sy-linsz - 1.
WRITE AT sy-colno(w_len) space.
* Run date
w_col2 = sy-linsz - 16.
WRITE: AT w_col2 'Date: ', sy-datum.
* Report name
WRITE: AT /w_col1 'Report Id : ', sy-repid.
WRITE AT sy-colno(w_len) space.
* Run time
w_col2 = sy-linsz - 16.
WRITE: AT w_col2 'Time: ', sy-uzeit.
** Delivery date
* WRITE: AT /w_col1 'Delivery date: ', p_vdatu.
* WRITE AT sy-colno(w_len) space.
* Page number
w_col2 = sy-linsz - 16.
WRITE: AT /w_col2 'Page: ', sy-pagno.
FORMAT RESET.
ULINE.
SKIP 1.
* Note
IF NOT t_po[] IS INITIAL.
FORMAT COLOR COL_NEGATIVE INVERSE ON.
WRITE: /2 text-012.
WRITE: /2 text-011.
FORMAT RESET.
ENDIF.
SKIP 1.
FORMAT COLOR COL_HEADING INVERSE OFF INTENSIFIED ON.
ULINE.
* Column heading
WRITE: /1 sy-vline, 2 text-003,
14 sy-vline, 15 text-004,
22 sy-vline, 23 text-005,
34 sy-vline, 35 text-010,
72 sy-vline, 73 text-006,
92 sy-vline, 93 text-007,
98 sy-vline, 99 text-008,
115 sy-vline, 116 text-009,
128 sy-vline.
ULINE.
FORMAT RESET.
ENDFORM. " get_header
*&---------------------------------------------------------------------*
*& Form display_report
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_report.
IF t_po[] IS INITIAL.
SKIP 2.
FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
WRITE: / text-015.
ELSE.
* List of PO items closed
LOOP AT t_po_dup.
IF w_color IS INITIAL.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
w_color = 'X'.
ELSE.
FORMAT COLOR COL_NORMAL INTENSIFIED ON.
CLEAR w_color.
ENDIF.
WRITE: /1 sy-vline, 2 t_po_dup-ebeln,
14 sy-vline, 15 t_po_dup-ebelp,
22 sy-vline, 23 t_po_dup-matnr NO-ZERO,
34 sy-vline, 35 t_po_dup-idnlf,
72 sy-vline, 73 t_po_dup-menge UNIT t_po_dup-meins,
92 sy-vline, 93 t_po_dup-meins,
98 sy-vline, 99 t_po_dup-netpr CURRENCY c_usd,
115 sy-vline, 116 t_po_dup-lifnr,
128 sy-vline.
HIDE : t_po_dup.
CLEAR: t_po_dup.
AT LAST.
ULINE.
ENDAT.
ENDLOOP.
IF sy-subrc <> 0.
SKIP 2.
FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
WRITE: / text-013.
ENDIF.
* Error messages - List of PO items not closed
LOOP AT t_mess.
AT FIRST.
SKIP 2.
ULINE.
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: /1 sy-vline, 2 text-003,
14 sy-vline, 15 text-014,
115 sy-vline.
ULINE.
ENDAT.
IF w_color IS INITIAL.
FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
w_color = 'X'.
ELSE.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
CLEAR w_color.
ENDIF.
WRITE: /1 sy-vline, 2 t_mess-ebeln,
14 sy-vline, 15 t_mess-message,
115 sy-vline.
HIDE : t_mess.
CLEAR: t_mess.
AT LAST.
ULINE.
ENDAT.
ENDLOOP.
IF sy-subrc <> 0.
SKIP 2.
FORMAT COLOR COL_POSITIVE INTENSIFIED ON.
WRITE: / text-016.
ENDIF.
ENDIF.
ENDFORM. " display_report
*&---------------------------------------------------------------------*
*& Form calc_col_and_write
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TEXT_002 text
* -->P_SY_LINSZ text
*----------------------------------------------------------------------*
FORM calc_col_and_write USING p_text
p_linsz.
WRITE: AT /w_col1 p_text.
WRITE AT sy-colno(w_len) space.
ENDFORM. " calc_col_and_write
*&---------------------------------------------------------------------*
*& Form check_date
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check_date.
LOOP AT s_eindt.
IF NOT s_eindt-high IS INITIAL AND
s_eindt-high > sy-datum.
MESSAGE e000 WITH text-017.
ELSEIF NOT s_eindt-low IS INITIAL AND
s_eindt-low > sy-datum.
MESSAGE e000 WITH text-017.
ENDIF.
ENDLOOP.
ENDFORM. " check_date
*&---------------------------------------------------------------------*
*& Form init_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_data.
CLEAR s_eindt.
REFRESH s_eindt.
* All POs that are open more than a specified number of days are to be
* closed automatically. Current day - 5 is defaulted
s_eindt-sign = 'I'.
s_eindt-option = 'LE'.
s_eindt-low = sy-datum.
APPEND s_eindt.
CLEAR s_eindt.
p_days = '5'.
ENDFORM. " init_data
*&---------------------------------------------------------------------*
*& Form get_delivery_date
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_delivery_date.
* Now, the no. of days to retain the PO is given as a parameter
* Any PO with delivery date prior to this date need to be closed
* Calculate the date based on selection and default the sign to "=<".
LOOP AT s_eindt.
s_eindt-sign = 'I'.
s_eindt-option = 'LE'.
s_eindt-low = s_eindt-low - v_days.
MODIFY s_eindt.
CLEAR s_eindt.
ENDLOOP.
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.