Open Order + VBUK + VBAP
hi
all
Plz look at this code
i m trying to loop at VBFA table and Read VBUk table
actually i have to found the open delivery .so i m looping on table T_VBPA_TAB (bcoz for 1 order there may be multiple Delivery) and check VBTYP_N eq 'J'in T_VBFA
.now read T_VBUK to find WBSTK and get open quantity .
But it gives wrong result..my logic is correct but what i
have to put for corresponding cases.
Plz check it.
Loop at T_VBPA_tab
Loop at T_VBFA where vbelv eq T_VBPA_tab-vbeln
and posnv eq T_VBPA_tab-posnr
and vbtyp_n eq 'J' .
Read T_VBUK with key vbeln eq T_VBFA-vbeln
if sy-subrc eq 0.
case t_vbuk-wbstk.
when c_a .
w_open_qty = t_vbfa-rfmng + w_open_qty.
when c_b .
w_open_qty =T_VBAP-kwmeng - t_vbfa-rfmng+w_open_qty
when c_c.
w_open_qty = '0.000' + w_open_qty .
endcase.
endloop.
if sy-subrc ne 0.
w_open_qty = hldmatl-kwmeng.
write : W_OPEN_QTY.
endloop.
Thanks
Saurabh
Hi Tiwari ,
check ur values with VA05 and table entries of KUNNR In S066/67.
Regards
Prabhu
Similar Messages
-
How to find open orders with amount and open deliveries?
Hi All,
I want to find out the open orders with open amount and open deliveries for a particular customer.
We need this for credit check purpose.
Kindly guide us for this.
Regards,
Satish.Hi,
To find out open order:
data: c_bef_pgi(1) TYPE c VALUE 'A',
RANGES: rg_wbstk FOR vbuk-wbstk."range for wbstk
rg_wbstk-sign = 'I'.
rg_wbstk-option = 'EQ'.
rg_wbstk-low = 'C'.
APPEND rg_wbstk.
rg_wbstk-low = 'A'.
APPEND rg_wbstk.
1.first put query on vbak table
2.Put query on vbuk table as
SELECT vbeln bestk lfstk gbstk FROM vbuk
INTO TABLE it_vbuk_open
FOR ALL ENTRIES IN it_vbak
WHERE vbeln = it_vbak-vbeln AND
bestk IN rg_wbstk AND
lfstk = c_bef_pgi.
so this wil give u open orders.
3. Then according to vbuk, get the details from vbap.
To find open delivery
1. First put query on vbak table
2. Put query on vbfa as
SELECT vbelv posnv vbeln posnn vbtyp_n vbtyp_v FROM vbfa
INTO TABLE it_vbfa
FOR ALL ENTRIES IN it_vbak
WHERE vbelv = it_vbak-vbeln AND
vbtyp_n = 'J' AND
vbtyp_v = 'C'.
3.Then from VBfa,get the details from LIkp
4.Then put entry on vbuk as
*entries from vbuk
SELECT vbeln wbstk fkstk gbstk FROM vbuk
INTO TABLE it_vbuk_del
FOR ALL ENTRIES IN it_likp
WHERE vbeln = it_likp-vbeln AND
wbstk IN rg_wbstk AND
fkstk = c_bef_pgi.
Thanks & Regards,
Anagha Deshmukh -
Hi All,
A report is needed for open return orders that do not have a credit memo issued or a goods receipt processed against the delivery
The Validation requires
Credit not issued (may be default because of billing block) orders.
can anyone help in the following
1)what are open return orders
2)open return orders that do not have a credit memo
3)goods receipts processed against the delivery
what are the transaction codes and fields related to ithi for open orders ,
Transaction Code: VA05
Select Open Orders.
first get the sd flow ...
SD FLOW
SD Flow Cycle:
INQUIRY ( VA11)
QUOTATION (VA21)
PURCHASE ORDER (ME21)
ORDER CONFIRMATION (VA01)
PICKING LIST (VL36)
PACKING LIST - (VL02, VL01)
SHIPPING (VT01)
INVOICE (VF21, VF01)
AR
Enquiry - Customer enquires about the Products services that were sold by a company - VA11
Quotation - Company Gives a Quotation for the products and Services to a Customer
Sales Order - Customer gives a Purchase order to the company agaionst which a Sales order will be raised to Customer in SAP.
VBAK: Sales Document(Header Data) (VBELN)
VBAP: Sales Document(Item Data) (VBELN,POSNR,MATNR,ARKTX,CHARG)
Enquiry, Quotation, Sales Order are differentiated based on Doc.
Type(VBTYP field) in VBAK,VBAP Tables( for Enquiry VBTYP = A,
for Quotation 'B' & for Order it is 'C'.)
Delivery(Picking, Packing, Post Goods Issue and Shipment)->
Company sends the material after picking it from Godown and Packing it in a Handling Unit(box) and Issues the goods
LIKP: Delivery Table (Header Data)(VBELN,LFART,KUNNR,WADAT,INCO1)
LIPS: Delivery Table (Item Data)(VBELN,POSNR,WERKS,LGORT,MATNR,VGBEL)
(LIPS-VGBEL = VBAK-VBELN, LIPS-VGPOS = VBAP-POSNR)
Billing - Also company bills to the customer for those deliveries
And in FI against this billing Accounting doc is created.
VBRK: Billing Table(Header Data)(VBELN,FKART,BELNR)
VBRP: Billing Table(Item Data)(VBELN,POSNR,FKIMG,NETWR,VGBEL,VGPOS)
(VBRP-AUBEL = VBAK-VBELN, VBRP-VGBEL = LIKP-VBELN)
Apart from these tables there are lot of other tables which starts with
V, but we use the following tables frequently.
VBUK: All Sales Documents status & Admn. Data(Header)(VBELN,VBTYP)
VBTYP= C(Sales Order) VBTYP=J(Delivery) VBTYP=M(Invoice)
VBUP: Sales Documents status & Admn. Data(Item)(VBELN,POSNR)
VBEP: Sales Doc. Schedule Lines Data(VBELN,POSNR,EDATU,WMENG)
VBKD: To get sales related Business data like Payment terms etc.(VBELN,ZTERM)
VBFA: sales document flow data(VBELV,VBELN,POSNV,VBTYP)
VBPA: Partner functions Data(VBELN,PARVW,KUNNR,LIFNR)
VEDA: Contract Data(VBELN,VPOSN)
VEDAPO: Contract Data(VBELN,VPOSN)
KONA: Rebate Agreements (KNUMA,VKORG,VTWEG,SPART)
http://www.sapgenie.com/abap/tables_sd.htm
Please check this SD online documents.
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CAARCSD/CAARCSD.pdf
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/MYSAP/SR_SD.pdf
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCBMTWFMSD/BCBMTWFMSD.pdf
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/LOLISPLN/LOLISPLN.pdf
Also please check this SD links as well.
http://help.sap.com/saphelp_47x200/helpdata/en/92/df293581dc1f79e10000009b38f889/frameset.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/dd/55f33e545a11d1a7020000e829fd11/frameset.htm
http://www.sap-basis-abap.com/sapsd.htm
http://www.sap-img.com/sap-sd.htm
http://www.sapgenie.com/abap/tables_sd.htm
http://searchsap.techtarget.com/featuredTopic/0,290042,sid21_gci961718,00.html
http://www.sapbrain.com/TUTORIALS/FUNCTIONAL/SD_tutorial.html
All help ebooks are in PDF format here
http://www.easymarketplace.de/online-pdfs.php
regards,
venkat. -
Hi experts,
Open Order Shipment,Stock on Hand report, Delivery Order History, Credit/Debit Notes
for this report what are the tables and fields are used.
thanks in advance.Hi Deepak,
Check these tables:
Delivery Tables:
LIKP - Delivery Header Data
LIPS - Delivery: Item data
Sales Tables:
VBAK - Sales Document: Header Data
VBAP - Sales Document: Item Data
VBBE - Sales Requirements: Individual Records
VBEH - Schedule line history
VBEP - Sales Document: Schedule Line Data
VBFA - Sales Document Flow
VBLB - Sales document: Release order data
VBLK - SD Document: Delivery Note Header
VBPA - Sales Document: Partner
VBRK - Billing: Header Data
VBRP - Billing: Item Data
VBUK - Sales Document: Header Status and Administrative
Data
VBUP Sales Document: Item Status
VEKP Handling Unit - Header Table
VEPO Packing: Handling Unit Item (Contents)
VEPVG Delivery Due Index
Stock Tables:
MARD - Material stock
MBEW - Material stock with valuation
MSKA - Stock balance with associated sales order
data
EKUB - Index for Stock Transport Orders for
MDUB - Material Reading View of Stock Transport Ord. for
Release Ord.
Hope this helps you.
Regards,
Chandra Sekhar -
Hello,
Can anyone give me the code for the open orders report??Using the tables VBAP,VBAK and VBUK.
Thanking you in anticipation.
Regards,
Sirisha.hi sirisha ,
check this code for open sales order(basic list) + open items (secondary list).
check the status as A--not yet processed..
B--partially processed
C--completely processed
hope this helps u out in getting the functionality.
u can take the header data from vbakuk ( vbak + vbuk )
and items from vbap as shown ..
fetching the data from vbakuk minimizes joins on vbak and vbuk.
execute the below code.
REPORT ZEX2 MESSAGE-ID arc NO STANDARD PAGE HEADING.
Tables :kna1,vbak.
SELECT-OPTIONS : so_vkorg FOR vbak-vkorg OBLIGATORY,
so_vtweg FOR vbak-vtweg OBLIGATORY,
so_spart FOR vbak-spart,
so_kunnr FOR kna1-kunnr.
DATA : BEGIN OF sales_open OCCURS 0 ,
vbeln LIKE vbak-vbeln,
auart LIKE vbak-auart,
kunnr LIKE kna1-kunnr,
bstnk LIKE vbak-bstnk,
lfstk LIKE vbuk-lfstk,
fkstk LIKE vbuk-fkstk,
gbstk LIKE vbuk-gbstk,
END OF sales_open.
DATA : BEGIN OF itm_sales OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
lfsta LIKE vbup-lfsta,
lfgsa LIKE vbup-lfgsa,
fksta LIKE vbup-fksta,
fksaa LIKE vbup-fksaa,
gbsta LIKE vbup-gbsta,
END OF itm_sales.
DATA : l_kunnr LIKE kna1-kunnr,
l_vkorg LIKE vbak-vkorg,
l_vtweg LIKE vbak-vtweg,
l_spart LIKE vbak-spart.
DATA: v_statusl(20) TYPE c,
v_statusb(20) TYPE c,
v_statusf(20) TYPE c,
v_statusg(20) TYPE c,
v_status(20) TYPE c,
v_field(1) TYPE c.
**Selection Screen Validations.
AT SELECTION-SCREEN.
PERFORM validations.
*& Form Validations
text
--> p1 text
<-- p2 text
FORM validations.
**Customer
IF NOT so_kunnr[] IS INITIAL.
SELECT SINGLE kunnr INTO l_kunnr
FROM kna1
WHERE kunnr IN so_kunnr.
IF sy-subrc NE 0.
MESSAGE e002 WITH text-005.
ENDIF.
ENDIF.
**Sales Organization
IF NOT so_vkorg[] IS INITIAL.
SELECT SINGLE vkorg INTO l_vkorg
FROM tvko
WHERE vkorg IN so_vkorg.
IF sy-subrc NE 0.
MESSAGE e003 WITH text-006.
ENDIF.
ENDIF.
**Distribution Channel
IF NOT so_vtweg[] IS INITIAL.
SELECT SINGLE vtweg INTO l_vtweg
FROM tvkov
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg.
IF sy-subrc NE 0.
MESSAGE e004 WITH text-007.
ENDIF.
ENDIF.
**Division
IF NOT so_spart[] IS INITIAL.
SELECT SINGLE spart INTO l_spart
FROM tvta
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg
AND spart IN so_spart.
IF sy-subrc NE 0.
MESSAGE e005 WITH text-008.
ENDIF.
ENDIF.
ENDFORM. " Validations
Top-of-page.
PERFORM sales_top_of_page.
Start-of-selection.
PERFORM sales_sel.
*& Form sales_sel
text
--> p1 text
<-- p2 text
FORM sales_sel.
SELECT vbeln auart kunnr bstnk
lfstk fkstk gbstk
INTO TABLE sales_open
FROM vbakuk
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg
AND spart IN so_spart
AND kunnr IN so_kunnr
AND gbstk NE 'C'.
LOOP AT sales_open.
WRITE:/4 sy-vline,
5 sales_open-vbeln HOTSPOT ON COLOR 2 INTENSIFIED OFF,
16 sy-vline,
17 sales_open-auart COLOR 2 INTENSIFIED OFF,
27 sy-vline,
28 sales_open-kunnr COLOR 2 INTENSIFIED OFF,
40 sy-vline,
41 sales_open-bstnk COLOR 2 INTENSIFIED OFF,
55 sy-vline,
56 sales_open-lfstk,
76 sy-vline,
77 sales_open-fkstk,
96 sy-vline,
97 sales_open-gbstk ,
117 sy-vline.
HIDE sales_open-vbeln .
ENDLOOP.
ENDFORM. " sales_sel
*& Form sales_top_of_page
text
--> p1 text
<-- p2 text
FORM sales_top_of_page.
WRITE:/4 sy-uline(114),
50 'OPEN SALES ORDERS' COLOR 7 INTENSIFIED ON .
WRITE: /4 sy-vline,
5 'SalesOrder' COLOR 1 ,
16 sy-vline,
17 'OrderType' COLOR 1,
27 sy-vline,
28 'Customer' COLOR 1,
40 sy-vline,
41 'PoNumber' COLOR 1,
55 sy-vline,
56 'Delivery Status' COLOR 1,
76 sy-vline,
77 'Billing Status' COLOR 1,
96 sy-vline,
97 'Processing Status' COLOR 1,
117 sy-vline .
WRITE:/4 sy-uline(114).
ENDFORM. " sales_top_of_page
AT LINE-SELECTION.
SELECT a~vbeln
a~posnr
a~matnr
a~kwmeng
b~lfsta
b~lfgsa
b~fksta
b~fksaa
b~gbsta
INTO TABLE itm_sales
FROM vbap AS a JOIN vbup AS b
ON avbeln EQ bvbeln
AND aposnr EQ bposnr
AND b~gbsta NE 'C'
WHERE a~vbeln EQ sales_open-vbeln.
IF NOT sales_open IS INITIAL.
LOOP AT itm_sales.
WRITE:/5 itm_sales-vbeln,
itm_sales-posnr,
itm_sales-matnr,
itm_sales-lfsta,
itm_sales-lfgsa,
itm_sales-fksta,
itm_sales-fksaa,
itm_sales-gbsta.
ENDLOOP.
ENDIF.
Regards,
Vijay
check the entries with t-code va05 for the same criteria.
Message was edited by: Vijay -
Open Order Quantity in Contracts
Dear Gurus
I am trying to create a report which will show the Open Order quantity of SD Contracts.
This being the figure of the target quantity less the called off quantity.
Please advise on the best method of getting this information, I can see the cumulative order total in the contracts but this is held in a structure (RV45a- KWMENG) and I am struggling to get this information into a report
Many thanks
TonyHi Tony,
To the best of my knowledge you will not be able to read value into your report from RV45A- KWMENG. To get this value you need to first fetch the list of subsequent SD documents from VBFA table. Later you need check status of those documents both at header and item/s level using VBUK and VBUP. If you find the open items for documents you need to sum up all those quantities to arrive at a open quantity for the contract using tables VBAK and VBAP
Please keep in mind performance issues which may arrive in this process as it deals with linking of 5 tables. You may need additional database index for the table VBAK (Thanks to check on this point).
Below information may be useful to activate the index:
To activate the index, proceed as follows:
1. Call transaction SE11 and enter the database table VBAK. Choose "Display" and then select "Goto -> Indexes" (Ctrl+F5) in the menu.
2. Double-click the entry I01.
3. Change the option to "Index on all database systems".
4. Activate the index (Ctrl+F3).
5. You must collect the database statistics for the index so that the optimizer can recognize the index (transaction DB20).
Hope this helps you.
Regards,
Praveen -
Hello Abapers,
where should I find a table that gives me "remaining open order" information? and its respective field name?
Thanks in advance.
Ol Pom.hi POm ,
check this code for open sales order(basic list) + open items (secondary list).
check the status as A--not yet processed..
B--partially processed
C--completely processed
hope this helps u out in getting the functionality.
u can take the header data from vbakuk ( vbak + vbuk )
and items from vbap as shown ..
fetching the data from vbakuk minimizes joins on vbak and vbuk.
execute the below code.
REPORT ZEX2 MESSAGE-ID arc NO STANDARD PAGE HEADING.
Tables :kna1,vbak.
SELECT-OPTIONS : so_vkorg FOR vbak-vkorg OBLIGATORY,
so_vtweg FOR vbak-vtweg OBLIGATORY,
so_spart FOR vbak-spart,
so_kunnr FOR kna1-kunnr.
DATA : BEGIN OF sales_open OCCURS 0 ,
vbeln LIKE vbak-vbeln,
auart LIKE vbak-auart,
kunnr LIKE kna1-kunnr,
bstnk LIKE vbak-bstnk,
lfstk LIKE vbuk-lfstk,
fkstk LIKE vbuk-fkstk,
gbstk LIKE vbuk-gbstk,
END OF sales_open.
DATA : BEGIN OF itm_sales OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
lfsta LIKE vbup-lfsta,
lfgsa LIKE vbup-lfgsa,
fksta LIKE vbup-fksta,
fksaa LIKE vbup-fksaa,
gbsta LIKE vbup-gbsta,
END OF itm_sales.
DATA : l_kunnr LIKE kna1-kunnr,
l_vkorg LIKE vbak-vkorg,
l_vtweg LIKE vbak-vtweg,
l_spart LIKE vbak-spart.
DATA: v_statusl(20) TYPE c,
v_statusb(20) TYPE c,
v_statusf(20) TYPE c,
v_statusg(20) TYPE c,
v_status(20) TYPE c,
v_field(1) TYPE c.
**Selection Screen Validations.
AT SELECTION-SCREEN.
PERFORM validations.
*& Form Validations
text
--> p1 text
<-- p2 text
FORM validations.
**Customer
IF NOT so_kunnr[] IS INITIAL.
SELECT SINGLE kunnr INTO l_kunnr
FROM kna1
WHERE kunnr IN so_kunnr.
IF sy-subrc NE 0.
MESSAGE e002 WITH text-005.
ENDIF.
ENDIF.
**Sales Organization
IF NOT so_vkorg[] IS INITIAL.
SELECT SINGLE vkorg INTO l_vkorg
FROM tvko
WHERE vkorg IN so_vkorg.
IF sy-subrc NE 0.
MESSAGE e003 WITH text-006.
ENDIF.
ENDIF.
**Distribution Channel
IF NOT so_vtweg[] IS INITIAL.
SELECT SINGLE vtweg INTO l_vtweg
FROM tvkov
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg.
IF sy-subrc NE 0.
MESSAGE e004 WITH text-007.
ENDIF.
ENDIF.
**Division
IF NOT so_spart[] IS INITIAL.
SELECT SINGLE spart INTO l_spart
FROM tvta
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg
AND spart IN so_spart.
IF sy-subrc NE 0.
MESSAGE e005 WITH text-008.
ENDIF.
ENDIF.
ENDFORM. " Validations
Top-of-page.
PERFORM sales_top_of_page.
Start-of-selection.
PERFORM sales_sel.
*& Form sales_sel
text
--> p1 text
<-- p2 text
FORM sales_sel.
SELECT vbeln auart kunnr bstnk
lfstk fkstk gbstk
INTO TABLE sales_open
FROM vbakuk
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg
AND spart IN so_spart
AND kunnr IN so_kunnr
AND gbstk NE 'C'.
LOOP AT sales_open.
WRITE:/4 sy-vline,
5 sales_open-vbeln HOTSPOT ON COLOR 2 INTENSIFIED OFF,
16 sy-vline,
17 sales_open-auart COLOR 2 INTENSIFIED OFF,
27 sy-vline,
28 sales_open-kunnr COLOR 2 INTENSIFIED OFF,
40 sy-vline,
41 sales_open-bstnk COLOR 2 INTENSIFIED OFF,
55 sy-vline,
56 sales_open-lfstk,
76 sy-vline,
77 sales_open-fkstk,
96 sy-vline,
97 sales_open-gbstk ,
117 sy-vline.
also check in transaction va05 for the same entries ..
regards
vijay. -
Retrive open order and open delivery value x custome
Hi,
how can i obtain a list of open order value and open delivery value per customer?
10x
byeCheck the following code which give details of pending orders & values and it can be modified as per ur requirement.
REPORT ZPEND_ORDER no standard page heading line-size 255.
*& Purpose : Details of Sale order having pending deliveries *
*& ( For Rake order handling ) *
tables : vbak, vbap, likp, lips, kna1, vbuk, vbpa, vepvg, vbfa, vbup.
data : pend_qty like vbap-kwmeng,
dlv_qty like vbap-kwmeng,
ord_qty like vbap-kwmeng.
data: begin of itab_vbak occurs 0,
vbeln like vbak-vbeln, "sales order no
audat like vbak-audat, " created date
auart like vbak-auart, " Sales Document Type
vkorg like vbak-vkorg, "Sales Organization
vtweg like vbak-vtweg, " distribution channel
spart like vbak-spart, " Division
vkgrp like vbak-vkgrp, " Sales group
vkbur like vbak-vkbur, " Sales office
kunnr like vbak-kunnr, " sold to party
kunag like vbak-kunnr, " ship to party
cust like vbak-kunnr, " sold to party
ship like kna1-name1, " ship to party
city like kna1-ort01, " ship to party location
deliv like likp-vbeln, " delivery
matnr like vbap-matnr,
arktx like vbap-arktx, " mat description
kwmeng like vbap-kwmeng,
kbmeng like vbap-kbmeng,
fkrel like vbap-matnr,
vstel like vbap-vstel,
route like vbap-route,
chln_no like likp-xabln,
grn_no like likp-bolnr,
truck_no like likp-traid,
dlv_dt like vbfa-erdat, "dlvy date
ord_qty like vbap-kwmeng,
dlvd_qty like vbap-kwmeng,
pend_qty like vbap-kwmeng,
kzwi5 like vbap-kzwi5,
posnr like vbap-posnr,
end of itab_vbak.
data posnr like vbap-posnr.
*FOR ALV DISPLAY
type-pools: slis.
constants: formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.
*Data Decelararion for alv display
data: i_fieldtab type slis_t_fieldcat_alv,
i_heading type slis_t_listheader,
i_layout type slis_layout_alv,
i_sort type slis_t_sortinfo_alv,
i_print type slis_print_alv,
i_events type slis_t_event,
i_repname like sy-repid,
f2code like sy-ucomm value '&ETA',
i_save(1) type c,
i_exit(1) type c,
i_variant like disvariant,
h_text(50).
start-of-selection.
selection-screen skip 1.
selection-screen begin of block v1 with frame title text-001.
selection-screen skip 1.
select-options:
ord_no for vepvg-vbeln,
audat for vbak-audat obligatory,
matnr for vbap-matnr,
spart for vbap-spart obligatory,
vstel for vepvg-vstel obligatory,
sale_org for vbak-vkorg obligatory,
sale_off for vbak-vkbur.
selection-screen skip 1.
check box for ALV display
parameters p_alv as checkbox.
selection-screen end of block v1.
selection-screen skip 1.
data: ftab(72) occurs 5 with header line.
refresh ftab.
ftab = 'VBELN'. append ftab.
refresh itab_vbak.
initialization.
i_repname = sy-repid.
start-of-selection.
select vbeln audat vkorg vtweg spart vkbur kunnr from vbak
into
(itab_vbak-vbeln, itab_vbak-audat,
vbak-vkorg, vbak-vtweg, vbak-spart,
itab_vbak-vkbur, itab_vbak-kunnr)
where vbeln in ord_no
and audat in audat
and vbtyp = 'C'
and vkorg in sale_org
and spart in spart
and vkbur in sale_off.
if sy-subrc = 0.
select posnr kwmeng kbmeng matnr arktx "added for mat description
fkrel vstel route kzwi5 spart
from vbap into corresponding fields of itab_vbak
where vbeln = itab_vbak-vbeln .
check ( itab_vbak-fkrel = 'A' or "Delivery-related billing document
itab_vbak-fkrel = 'D' ) "Relevant for pro forma
and itab_vbak-vstel in vstel
and itab_vbak-matnr in matnr
and itab_vbak-spart in spart.
select single * from vbup where vbeln = itab_vbak-vbeln
and posnr = itab_vbak-posnr.
check vbup-gbsta ne 'C'.
dlv_qty = 0.
select single kunnr from vbpa into itab_vbak-kunnr
where vbeln = itab_vbak-vbeln
and parvw = 'WE'.
select single name1 ort01 from kna1 into
(itab_vbak-cust, itab_vbak-city)
where kunnr = itab_vbak-kunnr.
in case of partially processed sale order get delivery details
clear : dlv_qty, itab_vbak-dlv_dt, itab_vbak-dlvd_qty, itab_vbak-chln_no,
itab_vbak-grn_no, itab_vbak-truck_no.
if vbup-gbsta eq 'B'. "partially processed
dlv_qty = 0.
get details from delivery
select vbfavbeln vbfarfmng vbfavbtyp_n vbfaerdat
into (vbfa-vbeln, vbfa-rfmng, vbfa-vbtyp_n, vbfa-erdat)
from vbfa
where vbelv = itab_vbak-vbeln
and posnv = itab_vbak-posnr.
check vbfa-vbtyp_n = 'J'.
clear : dlv_qty, itab_vbak-dlv_dt, itab_vbak-dlvd_qty, itab_vbak-chln_no,
itab_vbak-grn_no, itab_vbak-truck_no.
select single erdat xabln bolnr traid kunag
into (itab_vbak-dlv_dt, itab_vbak-chln_no, itab_vbak-grn_no,
itab_vbak-truck_no, itab_vbak-kunag)
from likp
where vbeln = vbfa-vbeln.
if sy-subrc = 0.
dlv_qty = dlv_qty + vbfa-rfmng.
itab_vbak-dlv_dt = vbfa-erdat.
itab_vbak-dlvd_qty = dlv_qty.
itab_vbak-deliv = vbfa-vbeln.
endif.
append itab_vbak.
endselect.
elseif vbup-gbsta eq 'A'.
for unprocessed sale order
ship to party details
itab_vbak-kunag = itab_vbak-kunnr.
itab_vbak-ship = itab_vbak-cust.
append itab_vbak.
endif.
endselect.
endif.
clear itab_vbak.
endselect.
loop at itab_vbak.
clear with change in document / item no
on change of itab_vbak-vbeln or itab_vbak-posnr.
clear: dlv_qty,ord_qty,pend_qty.
endon.
at new posnr.
In case full qty not delivered
if itab_vbak-kwmeng > itab_vbak-dlvd_qty.
select single vbpa~kunnr into vbpa-kunnr
from vbpa
where vbeln = itab_vbak-vbeln
and posnr = itab_vbak-posnr
and parvw = 'WE'.
if sy-subrc eq 0.
itab_vbak-kunag = vbpa-kunnr.
select single name1 ort01 from kna1 into
(itab_vbak-ship, itab_vbak-city)
where kunnr = itab_vbak-kunag.
if sy-subrc ne 0.
select single vbpa~kunnr into vbpa-kunnr
from vbpa
where vbeln = itab_vbak-vbeln
and parvw = 'WE'.
itab_vbak-kunag = vbpa-kunnr.
if sy-subrc ne 0 and p_alv ne 'X'.
write :/ 'vbpadetls' , itab_vbak-vbeln, itab_vbak-posnr, itab_vbak-vbeln.
endif.
endif.
endif.
endif.
itab_vbak-ord_qty = itab_vbak-kwmeng.
Delivered Qty & Pending qty
dlv_qty = dlv_qty + itab_vbak-dlvd_qty.
itab_vbak-pend_qty = itab_vbak-kwmeng - dlv_qty.
modify itab_vbak transporting kunag ship city dlvd_qty ord_qty pend_qty .
endat.
endloop.
end-of-selection.
sort itab_vbak by vbeln posnr audat kunnr matnr.
if p_alv ne 'X'.
loop at itab_vbak.
select single kna1name1 kna1ort01
into
(kna1-name1, kna1-ort01)
from kna1
where kunnr = itab_vbak-kunnr.
pend_qty = itab_vbak-ord_qty - itab_vbak-dlvd_qty.
format color col_normal.
write : /01(10) itab_vbak-vbeln,
12(10) itab_vbak-audat,
24(8) itab_vbak-kunag no-zero,
34(6) itab_vbak-posnr no-zero,
42(10) itab_vbak-matnr no-zero,
54(15) itab_vbak-arktx,
72(25) itab_vbak-ship,
100(15) itab_vbak-city,
118(8) itab_vbak-ord_qty,
128(10) itab_vbak-route,
140(10) itab_vbak-dlv_dt,
152(10) itab_vbak-dlvd_qty,
164(10) itab_vbak-chln_no,
176(10) itab_vbak-grn_no,
188(10) itab_vbak-truck_no,
200(10) itab_vbak-pend_qty,
218(15) itab_vbak-kzwi5 left-justified.
format reset.
at end of audat.
sum.
pend_qty = itab_vbak-ord_qty - itab_vbak-dlvd_qty.
format color col_background.
write: /118(8) itab_vbak-ord_qty,
152(10) itab_vbak-dlvd_qty,
200(10) pend_qty,
218 itab_vbak-kzwi5 left-justified.
format reset.
endat.
at last.
sum.
pend_qty = itab_vbak-ord_qty - itab_vbak-dlvd_qty.
format color col_total.
write : /5 'Grand Total : '.
write: /118(8) itab_vbak-ord_qty,
152(10) itab_vbak-dlvd_qty,
200(10) pend_qty,
218 itab_vbak-kzwi5 left-justified.
format reset.
endat.
endloop.
else.
for ALV Display
i_repname = sy-repid.
perform fieldcat using i_fieldtab[].
perform eventtab using i_events[].
perform comment using i_heading[].
perform call_alv.
perform build_layout using i_layout.
endif.
top-of-page.
if p_alv ne 'X'.
format color col_heading.
write: /01 'Ord No',
12 'Ord Date',
24 'Sold to Party',
34 'Item No',
42 'Mat No',
54 'Mat Descp',
72 'Ship to Party',
100 'City',
118 'Qty',
128 'Route',
140 'Dlv Date',
152 'Dlv Qty',
164 'Challan No',
176 'GRN No',
188 'Truck No',
200 'Pend Qty',
218 'Total Value'.
format reset.
endif.
*& Form fieldcat
text
-->P_I_FIELDTAB[] text
form fieldcat using p_fieldtab type slis_t_fieldcat_alv.
data: l_fieldcat type slis_fieldcat_alv.
clear l_fieldcat.
l_fieldcat-tabname = 'ITAB_VBAK'.
l_fieldcat-fix_column = 'X'.
l_fieldcat-no_out = ' '.
l_fieldcat-fieldname = 'VKBUR'.
l_fieldcat-outputlen = 6.
l_fieldcat-seltext_l = 'Sales Office'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'VSTEL'.
l_fieldcat-outputlen = 5.
l_fieldcat-seltext_l = 'Shipping Point'.
l_fieldcat-no_zero = ' '.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'VBELN'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Order No.'.
l_fieldcat-no_zero = 'X'.
l_fieldcat-hotspot = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'AUDAT'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Doc Date'.
l_fieldcat-hotspot = ''.
l_fieldcat-no_zero = ' '.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'POSNR'.
l_fieldcat-outputlen = 5.
l_fieldcat-seltext_l = 'Item'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'MATNR'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Material No'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'ARKTX'.
l_fieldcat-outputlen = 15.
l_fieldcat-seltext_l = 'Mat. Description'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'KUNNR'.
l_fieldcat-outputlen = 8.
l_fieldcat-seltext_l = 'Sold to Party'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'CUST'.
l_fieldcat-outputlen = 15.
l_fieldcat-seltext_l = 'Sold to Party Descp.'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'KUNAG'.
l_fieldcat-outputlen = 8.
l_fieldcat-seltext_l = 'Ship to Party'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'SHIP'.
l_fieldcat-outputlen = 15.
l_fieldcat-seltext_l = 'Ship to Party Descp'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'CITY'.
l_fieldcat-outputlen = 13.
l_fieldcat-seltext_l = 'City'.
l_fieldcat-no_zero = ' '.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'DELIV'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Delivery No.'.
l_fieldcat-no_zero = 'X'.
l_fieldcat-hotspot = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'ORD_QTY'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Qty'.
l_fieldcat-no_zero = ' '.
l_fieldcat-hotspot = ' '.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'ROUTE'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Route'.
l_fieldcat-no_zero = 'X'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'DLV_DT'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Delivered date'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'DLVD_QTY'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Delivered Qty'.
l_fieldcat-no_zero = ' '.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'CHLN_NO'.
l_fieldcat-outputlen = 15.
l_fieldcat-seltext_l = 'Challan No'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'GRN_NO'.
l_fieldcat-outputlen = 15.
l_fieldcat-seltext_l = 'GR Number'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'TRUCK_NO'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Truck No'.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'PEND_QTY'.
l_fieldcat-outputlen = 10.
l_fieldcat-seltext_l = 'Pending Qty'.
l_fieldcat-no_zero = ' '.
append l_fieldcat to p_fieldtab.
l_fieldcat-fieldname = 'KZWI5'.
l_fieldcat-outputlen = 13.
l_fieldcat-seltext_l = 'Value'.
append l_fieldcat to p_fieldtab.
clear l_fieldcat.
endform. " FIELDCAT
*& Form EVENTTAB
text
-->P_I_EVENTS[] text
form eventtab using p_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_events.
read table p_events with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move formname_top_of_page to ls_event-form.
append ls_event to p_events.
endif.
endform. " EVENTTAB
*& Form BUILD_LAYOUT
text
-->P_LAYOUT text
form build_layout using p_layout type slis_layout_alv.
p_layout-f2code = f2code.
p_layout-zebra = 'X'.
p_layout-detail_popup = 'X'.
endform. " BUILD_LAYOUT
*& Form COMMENT
text
-->P_I_HEADING[] text
form comment using p_i_heading type slis_t_listheader.
data: hline type slis_listheader,
text(60) type c,
sep(20) type c.
clear: hline, text.
hline-typ = 'H'.
write : 'Pending Sale Order Details' to hline-info.
append hline to i_heading.
endform. " COMMENT
*& Form TOP_OF_PAGE
text
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_heading
i_logo = 'ALV_REPORT'.
endform. " TOP_OF_PAGE
*& Form call_alv
text
--> p1 text
<-- p2 text
form call_alv .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_interface_check = ' '
i_buffer_active = ' '
i_callback_program = i_repname
i_callback_pf_status_set = ' '
i_callback_user_command = 'FRM_ALV_USER_COMMAND'
i_structure_name = 'ITAB_VBAK'
i_background_id = ' '
is_layout = i_layout
it_fieldcat = i_fieldtab
it_sort = i_sort[]
i_default = 'X'
i_save = 'A'
is_variant = i_variant
it_events = i_events[]
is_print = i_print
tables
t_outtab = itab_vbak.
if sy-subrc <> 0.
write: 'SY-SUBRC: ', sy-subrc, 'REUSE_ALV_LIST_DISPLAY'.
endif.
endform. " call_alv
*& Form frm_alv_user_command
text
-->UCOMM text
-->SELFIELD text
form frm_alv_user_command using ucomm like sy-ucomm
selfield type slis_selfield.
case ucomm.
when '&IC1'.
if selfield-tabname = 'ITAB_VBAK'.
if selfield-fieldname = 'VBELN'.
read table itab_vbak index selfield-tabindex.
if sy-subrc = 0.
set parameter id 'AUN' field itab_vbak-vbeln.
call transaction 'VA03' and skip first screen.
endif.
elseif selfield-fieldname = 'DELIV'.
read table itab_vbak index selfield-tabindex.
if sy-subrc = 0.
set parameter id 'VL' field itab_vbak-deliv.
call transaction 'VL03N' and skip first screen.
endif.
endif.
endif.
endcase.
endform. "frm_alv_user_command -
Open orders and Shipped not billed orders
Hi All,
What is the fastest way to calculate the open orders amount and shipped not billed amount for a given customer.
Thanks
Venugopal ReddyCan u try this option and see if this is increasin your performance.
For the billing documents ...
Goto table VBUK and check the fields LFSTK = 'C' " Delivery completed and
FKSTK NE 'C' . "billing open
At header level check that GBSTK ne C "over all processing status is open .
This will yield you the list of open Invoices ..
You need to bring in the select query with a join on VBRK and VBUK ..
once u get the list of open invoices then calculate the open qty from VBRP and VBUP where VBUP-GBSTA ne 'C'.
here pick the qty from vbrp and sum it up to check the open qty.
just like this ..
SELECT vbeln
fkart
kunag
gbstk
INTO TABLE it_billing_h
FROM vbrkuk "VBRKUK is a DB view " VBAK+VBUK
WHERE vkorg IN so_vkorg
AND vtweg IN so_vtweg
AND spart IN so_spart
AND kunag IN so_kunnr
AND gbstk NE 'C'.
IF NOT it_billing_h[] IS INITIAL.
SELECT c~vbeln
c~posnr
c~matnr
c~fkimg "---->open qty
d~fksta
d~fksaa
d~uvfak
d~fkivp
d~fssta
d~gbsta
INTO TABLE it_billing_items
FROM vbrp AS c JOIN vbup AS d
ON dvbeln EQ cvbeln
AND dposnr EQ cposnr
FOR ALL ENTRIES IN it_billing_h
WHERE d~vbeln EQ it_billing_h-vbeln
AND d~gbsta NE 'C'.
use control break and sum the qty ..
hope this helps ,
Regards,
Vijay -
How to get the open order quantity for a material
Hi All,
We need to get the open order quantity for materials. At present we are using the following logic...
SELECT VBAKVBELN VBAPPOSNR VBAP~KWMENG
INTO TABLE IT_VBAP
FROM VBAP
INNER JOIN VBAK ON VBAKVBELN = VBAPVBELN
INNER JOIN VAPMA ON VAPMAVBELN = VBAPVBELN
AND VAPMAPOSNR = VBAPPOSNR
INNER JOIN VBUP ON VBUPVBELN = VBAPVBELN
AND VBUPPOSNR = VBAPPOSNR
WHERE VAPMA~MATNR = IT_OUTPUT-MATNR
AND VAPMA~WERKS = IT_OUTPUT-WERKS
AND VBAK~AUART IN S_AUART
AND VBUP~GBSTA NE 'C'.
But the Query takes quite a long time as it does a full range scan on all the tables. Is there any way the query can be improved, may be by creating an index etc? Or is there anyother way by which i can get the required data?
Any input is appreciated.
Regards
Brain.This could help.
*& Report: zsdvr055 date written: 03/24/00 *
*& Author: Brian Huntley last update: 03/24/00 *
*& Program Title: Open Order Report *
*& Description: This report will create a list of sales documents *
*& that are open (contain at least one item that is not shipped). *
*& The report will sort by ship-to customer name and by sales *
*& document number. *
*& Tables: *
*& Files: *
*& Transactions: *
*& Changes: *
REPORT ZSDVR055 LINE-SIZE 255.
TABLES: VBPA,
VBAP,
VBUP,
VBAK,
VBKD,
KNA1,
VBEP,
VBFA,
LIKP,
LIPS,
EKET,
T171T.
define hashed table for selected ship-to and sold-to SO's
TYPES: BEGIN OF TVBPA_TYPE,
VBELN LIKE VBPA-VBELN, "sales document
POSNR LIKE VBPA-POSNR, "item number
PARVW LIKE VBPA-PARVW, "partner function
KUNNR LIKE VBPA-KUNNR, "customer number
END OF TVBPA_TYPE.
DATA: TVBPA TYPE HASHED TABLE OF TVBPA_TYPE
WITH UNIQUE KEY VBELN POSNR PARVW WITH HEADER LINE.
define internal table for all selected SO's
DATA: BEGIN OF ITAB0 OCCURS 0,
VBELN LIKE VBPA-VBELN, "sales document
END OF ITAB0.
define internal table for all selected SO items
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAP-VBELN, "document number
POSNR LIKE VBAP-POSNR, "item number
MATNR LIKE VBAP-MATNR, "material
ARKTX LIKE VBAP-ARKTX, "description
PSTYV LIKE VBAP-PSTYV, "item category
KDMAT LIKE VBAP-KDMAT, "customer material
NETWR LIKE VBAP-NETWR, "net value
WAERK LIKE VBAP-WAERK, "currency
KWMENG LIKE VBAP-KWMENG, "quantity
ERDAT LIKE VBAP-ERDAT, "entry date
NETPR LIKE VBAP-NETPR, "net price
KPEIN LIKE VBAP-KPEIN, "pricing unit
PRCTR LIKE VBAP-PRCTR, "profit center
ERNAM LIKE VBAK-ERNAM, "entered by
AUART LIKE VBAK-AUART, "order type
VKORG LIKE VBAK-VKORG, "sales organization
VTWEG LIKE VBAK-VTWEG, "distribution channel
VDATU LIKE VBAK-VDATU, "requested date (header)
BNAME LIKE VBAK-BNAME, "name of orderer
KUNNR LIKE VBAK-KUNNR, "sold-to customer
BZIRK LIKE VBKD-BZIRK, "sales district
KURSK LIKE VBKD-KURSK, "conversion rate
BSTKD LIKE VBKD-BSTKD, "customer PO
LFGSA LIKE VBUP-LFGSA, "overall delivery status
FKSAA LIKE VBUP-FKSAA, "overall billing status
KUNWE LIKE VBPA-KUNNR, "ship-to customer
NAME1 LIKE KNA1-NAME1, "ship-to customer name
ORT01 LIKE KNA1-ORT01, "ship-to address
REGIO LIKE KNA1-REGIO, "ship-to region (state)
LAND1 LIKE KNA1-LAND1, "ship-to country
END OF ITAB.
create internal table for open orders
DATA: BEGIN OF ITAB1 OCCURS 0,
KUNNR LIKE VBAK-KUNNR, "sold-to customer
KUNWE LIKE VBPA-KUNNR, "ship-to customer
VBELN LIKE VBAP-VBELN, "document number
POSNR LIKE VBAP-POSNR, "item number
ZDATE1 LIKE VBEP-EDATU, "requested date
ZDATE2 LIKE VBEP-EDATU, "scheduled date (confirm)
ZDATE3 LIKE VBEP-EDATU, "committed date
ZQTY1 LIKE VBAP-KWMENG, "qty ordered
ZQTY2 LIKE VBEP-BMENG, "backlog qty
ZEXTD LIKE VBAP-NETWR, "backlog net value
ZDESC(30) TYPE C, "backlog description
END OF ITAB1.
define internal table for SO schedule lines
DATA: BEGIN OF ITAB2A OCCURS 0,
WADAT LIKE VBEP-WADAT, "planned goods issue date
VBELN LIKE VBAP-VBELN, "document number
POSNR LIKE VBAP-POSNR, "item number
WMENG LIKE VBEP-WMENG, "qty ordered
BMENG LIKE VBEP-BMENG, "qty confirmed
END OF ITAB2A.
define internal table for SO item request dates
DATA: BEGIN OF ITAB2B OCCURS 0,
EDATU LIKE VBEP-EDATU, "delivery date
VBELN LIKE VBAP-VBELN, "document number
POSNR LIKE VBAP-POSNR, "item number
WMENG LIKE VBEP-WMENG, "qty ordered
END OF ITAB2B.
define internal table for SO item commit dates
DATA: BEGIN OF ITAB2C OCCURS 0,
EDATU LIKE VBEP-EDATU, "delivery date
VBELN LIKE VBAP-VBELN, "document number
POSNR LIKE VBAP-POSNR, "item number
ROMS1 LIKE VBEP-WMENG, "committed qty
END OF ITAB2C.
define internal table for SO item deliveries
DATA: BEGIN OF ITAB3 OCCURS 0,
VGBEL LIKE LIPS-VGBEL, "sales document
VGPOS LIKE LIPS-VGPOS, "sales document item
VBELN LIKE LIKP-VBELN, "delivery number
POSNR LIKE LIPS-POSNR, "delivery item number
WADAT LIKE LIKP-WADAT, "planned GI date
WADAT_IST LIKE LIKP-WADAT_IST, "actual GI date
LFIMG LIKE LIPS-LFIMG, "actual qty delivered
ERDAT LIKE LIKP-ERDAT, "date created
ERZET LIKE LIKP-ERZET, "time created
END OF ITAB3.
define internal table for SO item / delivery cross reference
DATA: BEGIN OF ITAB4 OCCURS 0,
VBELV LIKE VBFA-VBELV, "sales document
POSNV LIKE VBFA-POSNV, "sales document item
VBELN LIKE VBFA-VBELN, "delivery number
POSNN LIKE VBFA-POSNN, "delivery item
VBTYP_N LIKE VBFA-VBTYP_N, "document category
RFMNG LIKE VBFA-RFMNG, "qty delivered
PLMIN LIKE VBFA-PLMIN, "plus/minus flag
END OF ITAB4.
define local variables
DATA: ORDR_QTY LIKE VBEP-WMENG, "order qty
CONF_QTY LIKE VBEP-BMENG, "confirmed qty
NOCONF_QTY LIKE VBEP-BMENG, "qty not confirmed
DELV_QTY LIKE VBEP-WMENG, "qty delivered
NODELV_QTY LIKE VBEP-WMENG, "qty not delivered
REMAIN_QTY LIKE VBEP-WMENG, "qty remain to get conf date
REQ_DATE LIKE VBEP-EDATU, "request date
COM_DATE LIKE VBEP-EDATU, "committed date
DELV_QTY1 LIKE VBEP-WMENG, "preceding delivery qty
REMAIN_QTY1 LIKE VBEP-WMENG, "qty remain to get reqest date
REMAIN_QTY2 LIKE VBEP-WMENG, "qty remain to get commit date
THIRD_QTY LIKE VBEP-WMENG, "3rd party no PO qty
SO_STOCK LIKE MSKA-KALAB, "sales order stock
ZPRICE LIKE VBAP-NETPR, "unit price USD
ADRS1(40) TYPE C, "concatenated city and region
ADRS2(45) TYPE C, "city, region and country
ADRS3(80) TYPE C, "name, city, rgn, ctry
ZCNTR TYPE I. "counter
define select options
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_VKORG FOR VBAK-VKORG DEFAULT '1000',
S_VTWEG FOR VBAK-VTWEG DEFAULT '10' NO-DISPLAY,
S_SPART FOR VBAK-SPART DEFAULT '00' NO-DISPLAY,
S_KUNNR FOR VBPA-KUNNR MATCHCODE OBJECT DEBI,
S_KUNWE FOR VBPA-KUNNR MATCHCODE OBJECT DEBI.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS:
S_BZIRK FOR VBKD-BZIRK,
S_PRCTR FOR VBAP-PRCTR,
S_MATNR FOR VBAP-MATNR MATCHCODE OBJECT MAT1,
S_ERNAM FOR VBAK-ERNAM,
S_ERDAT FOR VBAP-ERDAT.
SELECTION-SCREEN END OF BLOCK BLK1.
AT SELECTION-SCREEN.
IF S_KUNNR IS INITIAL AND S_KUNWE IS INITIAL.
MESSAGE E005(ZM) WITH TEXT-100.
ENDIF.
MAIN PROGRAM
INITIALIZATION.
INCLUDE ZSYHEADR.
START-OF-SELECTION.
PERFORM 100_GET_SO_ITEMS.
PERFORM 200_GET_NO_DELIVERY.
PERFORM 300_GET_NO_GOODS_ISSUE.
PERFORM 400_GET_PARTIAL_DELIVERY.
PERFORM 500_GET_THIRD_PARTY.
PERFORM 900_CREATE_LIST.
FORM 100_GET_SO_ITEMS
FORM 100_GET_SO_ITEMS.
get SO's for selected ship-to and sold-to customers
REFRESH TVBPA.
IF NOT S_KUNNR IS INITIAL.
SELECT VBELN POSNR PARVW KUNNR
FROM VBPA INTO TABLE TVBPA
WHERE KUNNR IN S_KUNNR AND PARVW = 'AG' AND VBELN < '0080000000'.
ENDIF.
IF NOT S_KUNWE IS INITIAL.
SELECT VBELN POSNR PARVW KUNNR
FROM VBPA APPENDING TABLE TVBPA
WHERE KUNNR IN S_KUNWE AND PARVW = 'WE' AND VBELN < '0080000000'.
ENDIF.
DESCRIBE TABLE TVBPA LINES ZCNTR.
IF ZCNTR = 0.
WRITE: /1 'No data found for selection'.
STOP.
ENDIF.
eliminate duplicate SO's
LOOP AT TVBPA.
CLEAR ITAB0.
MOVE TVBPA-VBELN TO ITAB0-VBELN.
APPEND ITAB0.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM ITAB0.
get SO detail
SELECT VBAP~VBELN VBAP~POSNR VBAP~MATNR VBAP~ARKTX VBAP~PSTYV
VBAP~KDMAT VBAP~NETWR VBAP~WAERK VBAP~KWMENG VBAP~ERDAT
VBAP~NETPR VBAP~KPEIN VBAP~PRCTR VBAK~ERNAM VBAK~AUART
VBAK~VKORG VBAK~VTWEG VBAK~VDATU VBAK~BNAME VBAK~KUNNR
VBKD~BZIRK VBKD~KURSK VBKD~BSTKD VBUP~LFGSA VBUP~FKSAA
FROM VBAP INNER JOIN VBUP ON VBUP~VBELN = VBAP~VBELN AND
VBUP~POSNR = VBAP~POSNR
INNER JOIN VBKD ON VBKD~VBELN = VBAP~VBELN AND
VBKD~POSNR = VBAP~POSNR
INNER JOIN VBAK ON VBAK~VBELN = VBAP~VBELN
INTO TABLE ITAB FOR ALL ENTRIES IN ITAB0
WHERE VBAP~VBELN = ITAB0-VBELN AND VBAP~MATNR IN S_MATNR AND
VBAP~ERDAT IN S_ERDAT AND VBAP~PRCTR IN S_PRCTR AND
VBAP~ABGRU = SPACE AND VBKD~BZIRK IN S_BZIRK AND
VBAK~VKORG IN S_VKORG AND VBAK~VTWEG IN S_VTWEG AND
VBAK~SPART IN S_SPART AND VBAK~KUNNR IN S_KUNNR AND
VBAK~ERNAM IN S_ERNAM.
IF SY-SUBRC <> 0.
WRITE: /1 'No data found for selection'.
STOP.
ENDIF.
loop thru SO items
LOOP AT ITAB.
get ship-to customer
IF NOT S_KUNWE IS INITIAL.
CLEAR TVBPA.
READ TABLE TVBPA WITH TABLE KEY VBELN = ITAB-VBELN
POSNR = ITAB-POSNR PARVW = 'WE'.
IF SY-SUBRC <> 0.
READ TABLE TVBPA WITH TABLE KEY VBELN = ITAB-VBELN
POSNR = '000000' PARVW = 'WE'.
ENDIF.
MOVE TVBPA-KUNNR TO ITAB-KUNWE.
ELSE.
CLEAR ITAB-KUNWE.
SELECT SINGLE KUNNR FROM VBPA INTO ITAB-KUNWE
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
PARVW = 'WE'.
IF SY-SUBRC <> 0.
SELECT SINGLE KUNNR FROM VBPA INTO ITAB-KUNWE
WHERE VBELN = ITAB-VBELN AND POSNR = '000000' AND
PARVW = 'WE'.
ENDIF.
ENDIF.
IF NOT ITAB-KUNWE IN S_KUNWE.
DELETE ITAB.
CONTINUE.
ENDIF.
get ship-to customer address info
SELECT SINGLE NAME1 ORT01 REGIO LAND1 FROM KNA1
INTO (ITAB-NAME1, ITAB-ORT01, ITAB-REGIO, ITAB-LAND1)
WHERE KUNNR = ITAB-KUNWE.
MODIFY ITAB.
ENDLOOP.
SORT ITAB BY VBELN POSNR.
ENDFORM.
FORM 200_GET_NO_DELIVERY
get detail for SO items w/ no deliveries for order document types
(ZZOR, ZZC1, ZZCO, ZZRP, ZZRW, KE, KR, ZCHP, ZPSO, ZZNC)
FORM 200_GET_NO_DELIVERY.
LOOP AT ITAB WHERE AUART = 'ZZOR' OR AUART = 'ZZC1' OR
AUART = 'ZZCO' OR AUART = 'ZZRP' OR AUART = 'ZZRW' OR
AUART = 'KE' OR AUART = 'KR' OR AUART = 'ZCHP' OR
AUART = 'ZPSO' OR AUART = 'ZZNC'.
select if delivery status = A (not delivered)
IF ITAB-LFGSA = 'A'.
assign values to detail fields
CLEAR ITAB1.
ITAB1-KUNNR = ITAB-KUNNR.
ITAB1-KUNWE = ITAB-KUNWE.
ITAB1-VBELN = ITAB-VBELN.
ITAB1-POSNR = ITAB-POSNR.
IF ITAB-KURSK = 0.
ITAB-KURSK = 1.
ENDIF.
IF ITAB-KPEIN = 0.
ITAB-KPEIN = 1.
ENDIF.
select schedule lines for SO item and write to internal table itab2a
SELECT WADAT VBELN POSNR WMENG BMENG
FROM VBEP INTO TABLE ITAB2A
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR.
select sched lines w/request date and write to internal table itab2b
SELECT EDATU VBELN POSNR WMENG
FROM VBEP INTO TABLE ITAB2B
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
WMENG <> 0.
select sched lines w/commit date and write to internal table itab2c
SELECT EDATU VBELN POSNR ROMS1
FROM VBEP INTO TABLE ITAB2C
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
ROMS1 <> 0.
SORT ITAB2A BY WADAT.
SORT ITAB2B BY EDATU.
SORT ITAB2C BY EDATU.
ORDR_QTY = 0.
CONF_QTY = 0.
NOCONF_QTY = 0.
calculate the unconfirmed qty for a SO item
LOOP AT ITAB2A.
CONF_QTY = CONF_QTY + ITAB2A-BMENG.
ORDR_QTY = ORDR_QTY + ITAB2A-WMENG.
ENDLOOP.
NOCONF_QTY = ORDR_QTY - CONF_QTY.
LOOP AT ITAB2A WHERE BMENG <> 0.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING ITAB2A-BMENG REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING ITAB2A-BMENG COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = ITAB2A-WADAT.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = ITAB2A-BMENG.
ITAB1-ZDESC = 'no delivery, confirmed'.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
if order type is consignment return (KR), reverse sign
IF ITAB-AUART = 'KR'.
ITAB1-ZQTY1 = ITAB1-ZQTY1 * -1.
ITAB1-ZQTY2 = ITAB1-ZQTY2 * -1.
ITAB1-ZEXTD = ITAB1-ZEXTD * -1.
ENDIF.
APPEND ITAB1.
ENDLOOP.
get request date for SO item
IF NOCONF_QTY <> 0.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING NOCONF_QTY REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING NOCONF_QTY COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = '99991231'.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = NOCONF_QTY.
ITAB1-ZDESC = 'no delivery, not confirmed'.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
if order type is consignment return (KR), reverse sign
IF ITAB-AUART = 'KR'.
ITAB1-ZQTY1 = ITAB1-ZQTY1 * -1.
ITAB1-ZQTY2 = ITAB1-ZQTY2 * -1.
ITAB1-ZEXTD = ITAB1-ZEXTD * -1.
ENDIF.
APPEND ITAB1.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
FORM 300_GET_NO_GOODS_ISSUE
get detail for SO items w/deliveries and no goods issue for
doc types (ZZOR, ZZC1, ZZCO, ZZRP, ZZRW, KE, KR, ZCHP, ZPSO, ZZNC)
FORM 300_GET_NO_GOODS_ISSUE.
get detail for deliveries w/no goods issue
SELECT VBELN WADAT WADAT_IST ERDAT ERZET
FROM LIKP INTO (LIKP-VBELN, LIKP-WADAT, LIKP-WADAT_IST,
LIKP-ERDAT, LIKP-ERZET)
WHERE WADAT_IST = 0.
select if actual qty delivered <> 0
CLEAR LIPS.
SELECT POSNR VGBEL VGPOS LFIMG
FROM LIPS INTO (LIPS-POSNR, LIPS-VGBEL, LIPS-VGPOS, LIPS-LFIMG)
WHERE VBELN = LIKP-VBELN AND LFIMG <> 0.
select if goods movement status on delivery = A (no goods issue)
CLEAR VBUP.
SELECT SINGLE WBSTA FROM VBUP INTO VBUP-WBSTA
WHERE VBELN = LIKP-VBELN AND POSNR = LIPS-POSNR.
IF VBUP-WBSTA = 'A'.
CLEAR ITAB3.
ITAB3-VGBEL = LIPS-VGBEL.
ITAB3-VGPOS = LIPS-VGPOS.
ITAB3-VBELN = LIKP-VBELN.
ITAB3-POSNR = LIPS-POSNR.
ITAB3-WADAT = LIKP-WADAT.
ITAB3-WADAT_IST = LIKP-WADAT_IST.
ITAB3-LFIMG = LIPS-LFIMG.
ITAB3-ERDAT = LIKP-ERDAT.
ITAB3-ERZET = LIKP-ERZET.
APPEND ITAB3.
ENDIF.
ENDSELECT.
ENDSELECT.
SORT ITAB3 BY VGBEL VGPOS VBELN POSNR.
loop thru deliveries w/no goods issue and get SO item detail
LOOP AT ITAB3.
CLEAR ITAB.
READ TABLE ITAB WITH KEY VBELN = ITAB3-VGBEL POSNR = ITAB3-VGPOS.
IF SY-SUBRC <> 0.
IF ITAB-AUART = 'ZZOR' OR ITAB-AUART = 'ZZC1' OR
ITAB-AUART = 'ZZCO' OR ITAB-AUART = 'ZZRP' OR
ITAB-AUART = 'ZZRW' OR ITAB-AUART = 'KE' OR
ITAB-AUART = 'KR' OR ITAB-AUART = 'ZCHP' OR
ITAB-AUART = 'ZPSO' OR ITAB-AUART = 'ZZNC'.
assign values to detail fields
CLEAR ITAB1.
ITAB1-KUNNR = ITAB-KUNNR.
ITAB1-KUNWE = ITAB-KUNWE.
ITAB1-VBELN = ITAB-VBELN.
ITAB1-POSNR = ITAB-POSNR.
IF ITAB-KURSK = 0.
ITAB-KURSK = 1.
ENDIF.
IF ITAB-KPEIN = 0.
ITAB-KPEIN = 1.
ENDIF.
select delivery qty for SO item and write to internal table
SELECT VBELV POSNV VBELN POSNN VBTYP_N RFMNG PLMIN
FROM VBFA INTO TABLE ITAB4
WHERE VBELV = ITAB-VBELN AND POSNV = ITAB-POSNR AND
( VBTYP_N = 'J' OR VBTYP_N = 'T' ).
calculate total delivery qty for SO item
DELV_QTY = 0.
DELV_QTY1 = 0.
LOOP AT ITAB4.
IF ITAB4-VBTYP_N = 'J' OR ( ITAB4-VBTYP_N = 'T' AND
ITAB-AUART = 'KR').
IF ITAB4-PLMIN = '-'.
ITAB4-RFMNG = ITAB4-RFMNG * -1.
ENDIF.
determine if delivery for SO item precedes delivery w/no goods
issue (to determine request date and qty)
CLEAR LIKP.
SELECT SINGLE ERDAT ERZET
FROM LIKP INTO (LIKP-ERDAT, LIKP-ERZET)
WHERE VBELN = ITAB4-VBELN.
IF LIKP-ERDAT < ITAB3-ERDAT OR ( LIKP-ERDAT = ITAB3-ERDAT
AND LIKP-ERZET < ITAB3-ERZET ).
DELV_QTY1 = DELV_QTY1 + ITAB4-RFMNG.
ENDIF.
DELV_QTY = DELV_QTY + ITAB4-RFMNG.
ENDIF.
ENDLOOP.
get request dates for SO item
REFRESH ITAB2B.
SELECT EDATU VBELN POSNR WMENG
FROM VBEP INTO TABLE ITAB2B
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
WMENG <> 0.
select sched lines w/commit date and write to itab2c
REFRESH ITAB2C.
SELECT EDATU VBELN POSNR ROMS1
FROM VBEP INTO TABLE ITAB2C
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
ROMS1 <> 0.
SORT ITAB2B BY EDATU.
SORT ITAB2C BY EDATU.
loop thru request dates and delete request date entries for
quantity(s) for preceding deliveries
REMAIN_QTY1 = DELV_QTY1.
LOOP AT ITAB2B.
IF ITAB2B-WMENG > REMAIN_QTY1.
ITAB2B-WMENG = ITAB2B-WMENG - REMAIN_QTY1.
MODIFY ITAB2B.
EXIT.
ELSEIF ITAB2B-WMENG = REMAIN_QTY1.
DELETE ITAB2B.
EXIT.
ELSE.
REMAIN_QTY1 = REMAIN_QTY1 - ITAB2B-WMENG.
DELETE ITAB2B.
ENDIF.
ENDLOOP.
loop thru commit dates and delete commit date entries for
quantity(s) for preceding deliveries
REMAIN_QTY2 = DELV_QTY1.
LOOP AT ITAB2C.
IF ITAB2C-ROMS1 > REMAIN_QTY2.
ITAB2C-ROMS1 = ITAB2C-ROMS1 - REMAIN_QTY2.
MODIFY ITAB2C.
EXIT.
ELSEIF ITAB2C-ROMS1 = REMAIN_QTY2.
DELETE ITAB2C.
EXIT.
ELSE.
REMAIN_QTY2 = REMAIN_QTY2 - ITAB2C-ROMS1.
DELETE ITAB2C.
ENDIF.
ENDLOOP.
if planned goods issue date is 0, put qty in non-confirmed
get request date for SO item
IF ITAB3-WADAT <> 0.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING ITAB3-LFIMG REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING ITAB3-LFIMG COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = ITAB3-WADAT.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = ITAB3-LFIMG.
ITAB1-ZDESC = 'delivery, no goods issue'.
ELSE.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING ITAB3-LFIMG REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING ITAB3-LFIMG COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = '99991231'.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = ITAB3-LFIMG.
ITAB1-ZDESC = 'delivery, no goods issue date'.
ENDIF.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
if order type is consignment return (KR), reverse sign
IF ITAB-AUART = 'KR'.
ITAB1-ZQTY1 = ITAB1-ZQTY1 * -1.
ITAB1-ZQTY2 = ITAB1-ZQTY2 * -1.
ITAB1-ZEXTD = ITAB1-ZEXTD * -1.
ENDIF.
APPEND ITAB1.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
FORM 400_GET_PARTIAL_DELIVERY
get detail for SO items w/partial deliveries for document types
(ZZOR, ZZC1, ZZCO, ZZRP, ZZRW, KE, KR, ZCHP, ZPSO, ZZNC)
FORM 400_GET_PARTIAL_DELIVERY.
process SO items for selected order types
LOOP AT ITAB WHERE AUART = 'ZZOR' OR AUART = 'ZZC1' OR
AUART = 'ZZCO' OR AUART = 'ZZRP' OR AUART = 'ZZRW' OR
AUART = 'KE' OR AUART = 'KR' OR AUART = 'ZCHP' OR
AUART = 'ZPSO' OR AUART = 'ZZNC'.
select if delivery status = B (partially delivered)
IF ITAB-LFGSA = 'B'.
assign values to detail fields
CLEAR ITAB1.
ITAB1-KUNNR = ITAB-KUNNR.
ITAB1-KUNWE = ITAB-KUNWE.
ITAB1-VBELN = ITAB-VBELN.
ITAB1-POSNR = ITAB-POSNR.
IF ITAB-KURSK = 0.
ITAB-KURSK = 1.
ENDIF.
IF ITAB-KPEIN = 0.
ITAB-KPEIN = 1.
ENDIF.
select delivery qty for SO item and write to internal table
SELECT VBELV POSNV VBELN POSNN VBTYP_N RFMNG PLMIN
FROM VBFA INTO TABLE ITAB4
WHERE VBELV = ITAB-VBELN AND POSNV = ITAB-POSNR AND
( VBTYP_N = 'J' OR VBTYP_N = 'T' ).
calculate total delivery qty for SO item
DELV_QTY = 0.
LOOP AT ITAB4.
IF ITAB4-VBTYP_N = 'J' OR ( ITAB4-VBTYP_N = 'T' AND
ITAB-AUART = 'KR').
IF ITAB4-PLMIN = '-'.
ITAB4-RFMNG = ITAB4-RFMNG * -1.
ENDIF.
DELV_QTY = DELV_QTY + ITAB4-RFMNG.
ENDIF.
ENDLOOP.
select schedule lines for SO item and write to internal table
REFRESH ITAB2A.
SELECT WADAT VBELN POSNR WMENG BMENG
FROM VBEP INTO TABLE ITAB2A
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR.
get request dates from schedule line table
REFRESH ITAB2B.
SELECT EDATU VBELN POSNR WMENG
FROM VBEP INTO TABLE ITAB2B
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
WMENG <> 0.
get commit dates from schedule line table
REFRESH ITAB2C.
SELECT EDATU VBELN POSNR ROMS1
FROM VBEP INTO TABLE ITAB2C
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
ROMS1 <> 0.
SORT ITAB2B BY EDATU.
SORT ITAB2C BY EDATU.
SORT ITAB2A BY WADAT.
loop thru request dates and delete request date entries for
quantity(s) already delivered
REMAIN_QTY1 = DELV_QTY.
LOOP AT ITAB2B.
IF ITAB2B-WMENG > REMAIN_QTY1.
ITAB2B-WMENG = ITAB2B-WMENG - REMAIN_QTY1.
MODIFY ITAB2B.
EXIT.
ELSEIF ITAB2B-WMENG = REMAIN_QTY1.
DELETE ITAB2B.
EXIT.
ELSE.
REMAIN_QTY1 = REMAIN_QTY1 - ITAB2B-WMENG.
DELETE ITAB2B.
ENDIF.
ENDLOOP.
loop thru commit dates and delete request date entries for
quantity(s) already delivered
REMAIN_QTY2 = DELV_QTY.
LOOP AT ITAB2C.
IF ITAB2C-ROMS1 > REMAIN_QTY2.
ITAB2C-ROMS1 = ITAB2C-ROMS1 - REMAIN_QTY2.
MODIFY ITAB2C.
EXIT.
ELSEIF ITAB2C-ROMS1 = REMAIN_QTY2.
DELETE ITAB2C.
EXIT.
ELSE.
REMAIN_QTY2 = REMAIN_QTY2 - ITAB2C-ROMS1.
DELETE ITAB2C.
ENDIF.
ENDLOOP.
ORDR_QTY = 0.
CONF_QTY = 0.
NOCONF_QTY = 0.
calculate the unconfirmed qty for SO item
LOOP AT ITAB2A.
ORDR_QTY = ORDR_QTY + ITAB2A-WMENG.
CONF_QTY = CONF_QTY + ITAB2A-BMENG.
ENDLOOP.
NOCONF_QTY = ORDR_QTY - CONF_QTY.
NODELV_QTY = ORDR_QTY - DELV_QTY.
loop thru schedule lines and process entries with no related
delivery(s)
REMAIN_QTY = DELV_QTY.
LOOP AT ITAB2A.
IF ITAB2A-BMENG <> 0.
IF ITAB2A-BMENG <= REMAIN_QTY.
REMAIN_QTY = REMAIN_QTY - ITAB2A-BMENG.
ELSE.
ITAB2A-BMENG = ITAB2A-BMENG - REMAIN_QTY.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING ITAB2A-BMENG REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING ITAB2A-BMENG COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = ITAB2A-WADAT.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = ITAB2A-BMENG.
ITAB1-ZDESC = 'partial delivery'.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
if order type is consignment return (KR), reverse sign
IF ITAB-AUART = 'KR'.
ITAB1-ZQTY1 = ITAB1-ZQTY1 * -1.
ITAB1-ZQTY2 = ITAB1-ZQTY2 * -1.
ITAB1-ZEXTD = ITAB1-ZEXTD * -1.
ENDIF.
APPEND ITAB1.
REMAIN_QTY = 0.
ENDIF.
ENDIF.
ENDLOOP.
if total unconfirmed >= total not delivered, qty is unconfirmed
IF NOCONF_QTY >= NODELV_QTY.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING NODELV_QTY REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING NODELV_QTY COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = '99991231'.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = NODELV_QTY.
ITAB1-ZDESC = 'partial delv, not confirmed'.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
if order type is consignment return (KR), reverse sign
IF ITAB-AUART = 'KR'.
ITAB1-ZQTY1 = ITAB1-ZQTY1 * -1.
ITAB1-ZQTY2 = ITAB1-ZQTY2 * -1.
ITAB1-ZEXTD = ITAB1-ZEXTD * -1.
ENDIF.
APPEND ITAB1.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
FORM 500_GET_THIRD_PARTY
get detail for third party SO items
FORM 500_GET_THIRD_PARTY.
process SO items for selected order types
LOOP AT ITAB WHERE PSTYV = 'TAS' AND ( AUART = 'ZZOR' OR
AUART = 'ZZC1' OR AUART = 'ZZCO' OR AUART = 'ZZRP' OR
AUART = 'ZZRW' OR AUART = 'KE' OR AUART = 'KR' OR
AUART = 'ZCHP' OR AUART = 'ZPSO' OR AUART = 'ZZNC' ).
select if billing status <> C (billed)
IF ITAB-FKSAA <> 'C'.
assign values to detail fields
CLEAR ITAB1.
ITAB1-KUNNR = ITAB-KUNNR.
ITAB1-KUNWE = ITAB-KUNWE.
ITAB1-VBELN = ITAB-VBELN.
ITAB1-POSNR = ITAB-POSNR.
IF ITAB-KURSK = 0.
ITAB-KURSK = 1.
ENDIF.
IF ITAB-KPEIN = 0.
ITAB-KPEIN = 1.
ENDIF.
get request dates from schedule line table
REFRESH ITAB2B.
SELECT EDATU VBELN POSNR WMENG
FROM VBEP INTO TABLE ITAB2B
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
WMENG <> 0.
get commit dates from schedule line table
REFRESH ITAB2C.
SELECT EDATU VBELN POSNR ROMS1
FROM VBEP INTO TABLE ITAB2C
WHERE VBELN = ITAB-VBELN AND POSNR = ITAB-POSNR AND
ROMS1 <> 0.
SORT ITAB2B BY EDATU.
SORT ITAB2C BY EDATU.
get PO number(s) for SO item and write to internal table
REFRESH ITAB4.
SELECT VBELV POSNV VBELN POSNN VBTYP_N RFMNG PLMIN
FROM VBFA INTO TABLE ITAB4
WHERE VBELV = ITAB-VBELN AND POSNV = ITAB-POSNR AND
VBTYP_N = 'V' AND RFMNG <> 0.
calculate total delivery qty for PO item
DELV_QTY = 0.
LOOP AT ITAB4.
IF ITAB4-PLMIN = '-'.
ITAB4-RFMNG = ITAB4-RFMNG * -1.
ENDIF.
DELV_QTY = DELV_QTY + ITAB4-RFMNG.
ENDLOOP.
loop thru PO's for SO item
LOOP AT ITAB4.
select delivery lines for PO item
SELECT EINDT EBELN EBELP MENGE FROM EKET
INTO (EKET-EINDT, EKET-EBELN, EKET-EBELP, EKET-MENGE)
WHERE EBELN = ITAB4-VBELN AND EBELP = ITAB4-POSNN.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING EKET-MENGE REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING EKET-MENGE COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = EKET-EINDT.
ITAB1-ZDATE3 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = EKET-MENGE.
ITAB1-ZDESC = '3rd party item'.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
APPEND ITAB1.
ENDSELECT.
ENDLOOP.
if total delivery qty < order qty, put remaining in non-confirmed
IF DELV_QTY < ITAB-KWMENG.
THIRD_QTY = ITAB-KWMENG - DELV_QTY.
PERFORM GET_REQUEST_DATE TABLES ITAB2B
USING THIRD_QTY REQ_DATE.
PERFORM GET_COMMIT_DATE TABLES ITAB2C
USING THIRD_QTY COM_DATE.
ITAB1-ZDATE1 = REQ_DATE.
ITAB1-ZDATE2 = '99991231'.
ITAB1-ZDATE2 = COM_DATE.
ITAB1-ZQTY1 = ITAB-KWMENG.
ITAB1-ZQTY2 = THIRD_QTY.
ITAB1-ZDESC = '3rd party item, no PO'.
calculate net value for backlog qty
ZPRICE = ( ITAB-NETPR / ITAB-KPEIN ) * ITAB-KURSK.
ITAB1-ZEXTD = ITAB1-ZQTY2 * ZPRICE.
APPEND ITAB1.
CONTINUE.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
FORM 900_CREATE_LIST
process open business detail and create list
FORM 900_CREATE_LIST.
if internal table is empty, write message and exit
DESCRIBE TABLE ITAB1 LINES ZCNTR.
IF ZCNTR = 0.
WRITE: / 'No Data Found for Selection'.
STOP.
ENDIF.
SORT ITAB1 BY KUNNR KUNWE VBELN POSNR.
loop thru sorted table and create list
LOOP AT ITAB1.
IF ITAB1-ZDATE1 = SPACE.
ITAB1-ZDATE1 = '99991231'.
ENDIF.
IF ITAB1-ZDATE3 = SPACE.
ITAB1-ZDATE3 = '99991231'.
ENDIF.
get SO item detail
CLEAR ITAB.
READ TABLE ITAB WITH KEY VBELN = ITAB1-VBELN
POSNR = ITAB1-POSNR BINARY SEARCH.
print sold-to and ship-to customer header info
AT NEW KUNWE.
CLEAR KNA1.
SELECT SINGLE NAME1 FROM KNA1 INTO KNA1-NAME1
WHERE KUNNR = ITAB1-KUNNR.
CONCATENATE ITAB-ORT01 ITAB-REGIO INTO ADRS1 SEPARATED BY ', '.
CONCATENATE ADRS1 ITAB-LAND1 INTO ADRS2 SEPARATED BY ' '.
CONCATENATE ITAB-NAME1 ADRS2 INTO ADRS3 SEPARATED BY ' '.
FORMAT COLOR 1 INTENSIFIED OFF.
WRITE: /1 'Sold-to:', 10 ITAB1-KUNNR, 18 KNA1-NAME1,
56 'Ship-to:', 65 ITAB1-KUNWE, 73 ADRS3.
FORMAT RESET.
SKIP.
ENDAT.
print out backlog detail
CLEAR T171T.
SELECT SINGLE BZTXT FROM T171T INTO T171T-BZTXT
WHERE SPRAS = SY-LANGU AND BZIRK = ITAB-BZIRK.
WRITE: /1 ITAB1-VBELN,
13(6) ITAB1-POSNR NO-ZERO,
21 ITAB-MATNR,
41 ITAB-ARKTX,
83 ITAB1-ZDATE1,
95 ITAB1-ZDATE3,
107 ITAB1-ZDATE2,
119 ITAB-ERNAM,
129 ITAB-BZIRK, 135 T171T-BZTXT,
157(20) ITAB-BSTKD,
179(12) ITAB1-ZQTY1 DECIMALS 0,
193(12) ITAB1-ZQTY2 DECIMALS 0,
207(16) ITAB1-ZEXTD DECIMALS 2,
225 ITAB1-ZDESC.
AT END OF VBELN.
SKIP.
ENDAT.
print footing at ship-to customer
AT END OF KUNWE.
SUM.
ULINE: /193(12), 207(16).
FORMAT COLOR 1 INTENSIFIED OFF.
WRITE: /1 'Total: Sold-to:', 18 ITAB1-KUNNR,
25 '/', 27 'Ship-to:', 36 ITAB1-KUNWE,
193(12) ITAB1-ZQTY2 DECIMALS 0,
207(16) ITAB1-ZEXTD DECIMALS 2.
FORMAT RESET.
SKIP 2.
ENDAT.
AT LAST.
SUM.
ULINE: /193(12), 207(16).
FORMAT COLOR 1 INTENSIFIED ON.
WRITE: /1 'Report Total:',
193(12) ITAB1-ZQTY2 DECIMALS 0,
207(16) ITAB1-ZEXTD DECIMALS 2.
FORMAT RESET.
ENDAT.
ENDLOOP.
ENDFORM.
FORM GET_REQUEST_DATE
subroutine to get request date for SO item
FORM GET_REQUEST_DATE TABLES FTAB STRUCTURE ITAB2B
USING CONF_QTY REQ_DATE.
DATA: REMAIN LIKE VBEP-WMENG, "qty remaining
CNTR TYPE I, "loop counter
TAB_INDEX TYPE I. "table index
initialize
REMAIN = 0.
REQ_DATE = SPACE.
get first request date from table
TAB_INDEX = 1.
READ TABLE FTAB INDEX TAB_INDEX.
if request date not found, set request date to blank
IF SY-SUBRC <> 0.
REQ_DATE = SPACE.
EXIT.
ELSE.
REQ_DATE = FTAB-EDATU.
ENDIF.
calculate quantity remaining for request date
REMAIN = FTAB-WMENG - CONF_QTY.
if qty remaining > 0, update request date with qty remaining
IF REMAIN > 0.
FTAB-WMENG = REMAIN.
MODIFY FTAB INDEX TAB_INDEX.
if qty remaining = 0, delete request date (so next request
date will be used for next confirmed qty)
ELSEIF REMAIN = 0.
DELETE FTAB INDEX TAB_INDEX.
if qty remaining < 0, find next request date and update
ELSE.
CNTR = 0.
WHILE REMAIN < 0 OR CNTR < 10.
DELETE FTAB INDEX TAB_INDEX.
TAB_INDEX = TAB_INDEX + 1.
READ TABLE FTAB INDEX TAB_INDEX.
REMAIN = REMAIN + FTAB-WMENG.
CNTR = CNTR + 1.
ENDWHILE.
IF REMAIN = 0.
DELETE FTAB INDEX TAB_INDEX.
ELSEIF REMAIN > 0.
FTAB-WMENG = REMAIN.
MODIFY FTAB INDEX TAB_INDEX.
ENDIF.
ENDIF.
ENDFORM.
FORM GET_COMMIT_DATE
subroutine to get commit date for SO item
FORM GET_COMMIT_DATE TABLES CTAB STRUCTURE ITAB2C
USING CONF_QTY COM_DATE.
DATA: REMAIN LIKE VBEP-WMENG, "qty remaining
CNTR TYPE I, "loop counter
TAB_INDEX TYPE I. "table index
initialize
REMAIN = 0.
COM_DATE = SPACE.
get first commit date from table
TAB_INDEX = 1.
READ TABLE CTAB INDEX TAB_INDEX.
if request date not found, set request date to blank
IF SY-SUBRC <> 0.
COM_DATE = SPACE.
EXIT.
ELSE.
COM_DATE = CTAB-EDATU.
ENDIF.
calculate quantity remaining for request date
REMAIN = CTAB-ROMS1 - CONF_QTY.
if qty remaining > 0, update request date with qty remaining
IF REMAIN > 0.
CTAB-ROMS1 = REMAIN.
MODIFY CTAB INDEX TAB_INDEX.
if qty remaining = 0, delete request date (so next request
date will be used for next confirmed qty)
ELSEIF REMAIN = 0.
DELETE CTAB INDEX TAB_INDEX.
if qty remaining < 0, find next request date and update
ELSE.
CNTR = 0.
WHILE REMAIN < 0 OR CNTR < 10.
DELETE CTAB INDEX TAB_INDEX.
TAB_INDEX = TAB_INDEX + 1.
READ TABLE CTAB INDEX TAB_INDEX.
REMAIN = REMAIN + CTAB-ROMS1.
CNTR = CNTR + 1.
ENDWHILE.
IF REMAIN = 0.
DELETE CTAB INDEX TAB_INDEX.
ELSEIF REMAIN > 0.
CTAB-ROMS1 = REMAIN.
MODIFY CTAB INDEX TAB_INDEX.
ENDIF.
ENDIF.
ENDFORM.
END-OF-REPORT. -
Open Order Quantity based on the processing Material (loop)
Hi,
How do you get the open order quantity from VBAP/VBAK, based on the material?
As far as I know, the order is an open order if the Item Qty (VBAP-KWMENG) and Delivery Qty (LIPS-LFIMG) do not match.
How you I get the full quantity for all Open Orders based on the Material?
Points will be rewarded!
Thanks,
JohnTwo ways i can think of..
1. Standard vbap/lips check
( Use table VAPMA to start, since material is indexed on this table)
2. From your MRP-MD06/MD04(There will be a table for MRP log.please check this)
Thanks
Siva
Siva K -
Calculation of open orders and shipped not billed orders amount
Hi All,
I have a requirement to arrive at the values of Open Order and Shipped not billed .
This is an interface program and the output will be sent to a target server.
Input : Company code, Customer Code , Document date.
Output Fields are:
Customer Code
Sum of all open orders value
Sum of all shipped not billed orders value
To give an example
A Customer has 50 orders and the number of line items are 200 .
Overall order amount for 200 line items is 10,000.
70 line items have been delivered (amounting to 5,000) and
30 line items among the 70 delivered have been invoiced. (amounting to 3,000).
I need to know the best way to get to:
(1) Total "Open order" amount for the customer which is 5,000 in this example.
(2) Total "Shipped not billed" amount for the customer which is 2,000 in this example.
(3) Total "Invoiced" amount for the customer which is 3,000 in this example.
We are looking for the tables to access and the sequence of access
Since the interface is to be executed more than once in a day ,
the execution time should be optimum
Please suggest
Thanks
Venucheck table VBUK
GBSTK ne 'C' "over all processing status
and FKSTK ne 'C' "open billing orders
at header level
and
for item level check
Vbup tbale
make a join on Vbrk and VBuk in the where condition in addition to the selection criteria add the above two conditions and check the same.
once you have all the open orders enable the items and do the subtotalling and grand total on the item loop.
regards,
vijay -
Hi Gurus,
I want all Open Orders & P.O's > 15 days to be assigned a Reason of Rejection and dumped.
Can anyone suggest?
Thanks & Regards,
VinodHi
Either you have to do it manually or prepare a report to list all the open orders and then filter them at item level and finally list all the open line item and then a a reason for rejection should be assigned with help of BDC. THe system check the table VBUK and VBUP for the status.
Thanks,
Ravi -
Open Orders - Extractor 2LIS_11_VASTI
We are trying to develop an Open Orders report that would include items that are delivered (delivery related) and those that are dropped ship from a 3rd party (order related). We need to show open quantity and value.
The standard BI Content that we are currently using only shows open items that are delivered through SAP. We need the other 3rd party items as well. We believe that a solution would most likely require the order header and order line item status data (data from tables VBUK and VBUP in SAP).
Has anyone else had to develop a solution like this? Did you use the standard extractors? Is there a standard SAP solution for this in BW or did you have to create something custom?
Thank you for your help.Hi Ann,
I have a solution for you, which you can try...
create a table level generic data source on the table/view of VBBE which would
contains all your required data Hopefully..
Hope it helps..
assign points if useful..
Cheers,
Pattan. -
How to find open orders and open quantity
Hi abap gurus,
i want to find the open orders with the quantity means those orders for which we don't have goods issues(and partial deliverys is also possible). i get this scenario but i don't know how to start.
i think i should go to VBUP table and get all the orders
which have overall status GBSTA = 'A' OR 'B'.
So from this i will get all the open orders but i need to find open quantity also .
please tell me how can i find out and which table do i need to use.You need to check between delivery line item table as well sales order line item table.
Sales order Line item table : VBAP
Delivery line item table : LIPS
if order qty and delivery qty are same then there is no open qty if not then there is open qty.
Thanks
Seshu
Maybe you are looking for
-
BAPI or FM for Sales Scheduling Agreement
Hi ABAPers, I need to transfer the Sales Scheduling Agreement (T-code: VA31) data into SAP. I am sure that it is not possible by LSMW and BDC methods as I have to upload Header and Item texts for the scheduling agreement. So, I am trying to find any
-
Hard Drive Failure - Music Files backed up to external hard drive ...
i reinstalled itunes and successfully copied over the music folders. i can play all of my music in itunes except the purchased music. an error comes up that says the original file is missing. if i plug in the external drive i can search and play the
-
Sequence Settings for "Apple Lossless" codec !?!?
Help, I am editing a project and the material was delivered to me in the "Apple Lossless, stereo, 44100 khz DV, 720x480 (640x480), millions Is there a Sequence settings I can use to edit this without having to render it in the timeline ?!? Many thank
-
Compiler error. Ivrt patch out of range: ofst=0xC547
Compiler error occured during full ATE run.
-
Upload through FTP, wheres my files?
ive made a website on ilife 08 and went to fetch to upload it to my hosting service, I can not find where iweb saved my files! anyone know what I can do? thanks