Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9236

Re: Goods recieved or not for a particular PO

$
0
0

Hi Sanjeev,

 

In my reruirement, they already developed a report for goods status i.e. whether goods recieved , intransit or cancelled etc...

 

But what actually happening is, for a particular PO having the status GR, but in the output we are getting the status as cancelled. because in the select query for VBFA, they had used vbtyp_n in ('i','R'). in where condition....Below is the program.. Please suggest me how to proceed.

 


tables: ekko,   "Purchasing Document Header
ekpo
,   "Purchasing Document Item
ekbe
,   "History per Purchasing Document
eket
,   "Scheduling Agreement Schedule Lines
likp
,   "SD Document: Delivery Header Data
vbfa
.   "Sales Document Flow.

selection-screen begin of block a1 with frame
title text-001.
parameter: p_po like ekko-ebeln.
select-options: s_erdat2 for ekko-bedat.
parameter: p_werks like ekpo-werks.
selection-screen end of block a1.

data: begin of i_ekko_combo occurs 0,
ebeln
like ekko-ebeln,
bsart
like ekko-bsart,
bedat
like ekko-bedat,
reswk
like ekko-reswk,
ebelp
like ekpo-ebelp,
loekz
like ekpo-loekz,
matnr
like ekpo-matnr,
werks
like ekpo-werks,
menge
like ekpo-menge,
elikz
like ekpo-elikz,
zbsgru
TYPE bsgru,                                 "MRDK902666
end of i_ekko_combo.

data: begin of i_eket occurs 0,
ebeln
like eket-ebeln,
ebelp
like eket-ebelp,
wemng
like eket-wemng,
end of i_eket.

data: begin of i_ekbe occurs 0,
ebeln
like ekbe-ebeln,
ebelp
like ekbe-ebelp,
belnr
like ekbe-belnr,
end of i_ekbe.

data: begin of i_likp occurs 0,
vbeln
like likp-vbeln,
wadat_ist
like likp-wadat_ist,
end of i_likp.

data: begin of i_vbfa occurs 0,
vbelv
like vbfa-vbelv,
vbeln
like vbfa-vbeln,
vbtyp_n
like vbfa-vbtyp_n,
rfmng
like vbfa-rfmng,
end of i_vbfa.

data: begin of i_art occurs 0,
matnr
like mara-matnr,
upc
like mean-ean11,
maktx
like makt-maktx,
idnlf
like eina-idnlf,
category
(3),
class(5),
lifnr
like eina-lifnr,
name1
like lfa1-name1,
mtart
like mara-mtart,
mstae
like mara-mstae,
mmsta
like marc-mmsta,
zzfc03
like mara-zzfc03,
kbetr
like konp-kbetr,            " Current Price
gmargin
(9),                       " Gross Margin
fretail
like konp-kbetr,          " Future Retail
fdate
like sy-datum,
pretail
like konp-kbetr,          " Prior Retail
pdate
like sy-datum,
labst
like mard-labst,
zzmenge
like mard-zzmenge,
pmax_alloc
like mard-zzopenstoqty,
in_transit
like marc-trame,
committed
like mard-zzopenrtvqty,
end of i_art.

data: begin of i_ekpo_art occurs 0,
matnr
like mara-matnr,
upc
like mean-ean11,
maktx
like makt-maktx,
idnlf
like eina-idnlf,
end of i_ekpo_art.

databegin of itab_report occurs 0,
upc
(14),
matnr         
like ekpo-matnr,
idnlf
(25),
maktx         
like makt-maktx,
menge         
like ekpo-menge,
rfmng         
like vbfa-rfmng,
po_delivery   
like ekbe-belnr,
status
(10)      type c,
end of itab_report.

dataline_cntr      type i,
total_days
(6type n,
order_type
(11) type c,
vendor_po
(11type c value 'Vendor P.O.',
delivery
(8)    type c value 'Delivery',
order_date 
like sy-datum,
order_date2
like sy-datum,
edit_werks 
like wosa-kunnr,
po_delivery
like ekbe-belnr,
quantity
(6)   type n,
qty_shipped
(6) type n value 0,
qty_shipped_out
(6) type n value 0,
status
(10)     type c,
received_qty
like ekpo-menge,
received_flag
type c value 'N',
set_matnr
like ekpo-matnr.
data: ws_cnt type i.

top-of-page.
include: zsrd_header.
include: zsrs_header.
uline.
skip.

if not s_erdat2[] is initial.
move s_erdat2-low to order_date.
move s_erdat2-high to order_date2.
write/01 'Order Date Range:',
19 order_date,
30 'to',
33 order_date2.
endif.

skip.
uline.
format color 1 intensified on.
write: /01 'UPC',
16 'Article',
26 'Style',
53 'Description',
86 'Quantity',
96 'Quantity',
107 'P.O/Delivery#',
121 'Status'.
write: /86 'Ordered',
96 'Shipped' ,
126 ' '.
uline.
format color off.

at selection-screen.
if p_po is initial.
if s_erdat2 is initial.
message e043 with 'Please enter a PO number or Date range'.
endif.
if s_erdat2-low = '00000000'.
message e005.
endif.
total_days
= 0.
total_days
= s_erdat2-high - s_erdat2-low.
if total_days > 60.
message e043 with
'Search limit is 60 Days, please reduce date range'.
endif.
endif.

start-of-selection.
perform po_type_select.
perform po_type.
perform get_article_data.
perform po_or_delivery_number.
perform write_report.

end-of-selection.

move 65 to sy-linno.

*&--------------------------------------------------------------------*
*&      Form  po_type_select
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
form po_type_select.
* ZCTN is a CDC PO

if not p_po is initial.
select a~ebeln a~bsart a~bedat a~reswk b~ebelp b~loekz b~matnr
b
~werks b~menge b~elikz
from ( ekko as a inner join ekpo as b
on a~ebeln = b~ebeln )
into table i_ekko_combo
where a~ebeln = p_po
and b~werks = p_werks.
if sy-subrc <> 0.
message e043 with 'Invalid PO Number'.
endif.
endif.

if not s_erdat2[] is initial.
select a~ebeln a~bsart a~bedat a~reswk b~ebelp b~loekz b~matnr
b
~werks b~menge b~elikz
a
~zbsgru                                          "MRDK902666
from ( ekko as a inner join ekpo as b
on a~ebeln = b~ebeln )
into table i_ekko_combo
*          where a~bsart = 'ZCTN'                           "MRDK902666
where a~bsart IN ('ZCTN', 'ZUBI')                 "MRDK902666
and a~bedat in s_erdat2
and b~werks = p_werks.
DELETE i_ekko_combo WHERE bsart = 'ZUBI' AND  zbsgru <> 'RSS'. "MRDK902666
*    if sy-subrc <> 0.                                      "MRDK902666
if i_ekko_combo[] IS INITIAL.                           "MRDK902666
message e043 with 'No Data Found for Date range'.
endif.
endif.
endform.                    "po_type_select

*----------------------------------------------------------------------*
* FORM get_article_data.
*----------------------------------------------------------------------*
form get_article_data.
sort i_ekko_combo by matnr.
loop at i_ekko_combo.
if set_matnr <> i_ekko_combo-matnr.
set_matnr
= i_ekko_combo-matnr.
else.
continue.
endif.
refresh i_art.
call function 'Z_ORS_ARTICLE_DATA_BUILD'
EXPORTING
SITE                
= i_ekko_combo-werks
ARTICLE             
= i_ekko_combo-matnr
TABLES
ARTICLE_DATA        
= i_art
EXCEPTIONS
ARTICLE_UPC_INVALID 
= 1
ARTICLE_INVALID     
= 2
UPC_INVALID         
= 3
ARTICLE_SITE_INVALID
= 4.
if sy-subrc = 0.
i_ekpo_art
-matnr = i_ekko_combo-matnr.
i_ekpo_art
-upc = i_art-upc.
i_ekpo_art
-maktx = i_art-maktx.
i_ekpo_art
-idnlf = i_art-idnlf.
append i_ekpo_art.
endif.
endloop.
sort i_ekpo_art by matnr.
endform.                                "get_article_data.
*----------------------------------------------------------------------*
* FORM po_type.
*----------------------------------------------------------------------*
form po_type.

check not i_ekko_combo[] is initial.

sort i_ekko_combo by ebeln ebelp matnr.

select ebeln ebelp wemng
from eket
into table i_eket
for all entries in i_ekko_combo
where ebeln = i_ekko_combo-ebeln
and ebelp = i_ekko_combo-ebelp.

select ebeln ebelp belnr
from ekbe
into table i_ekbe
for all entries in i_ekko_combo
where ebeln = i_ekko_combo-ebeln
and ebelp = i_ekko_combo-ebelp.

describe table i_ekbe lines line_cntr.
if line_cntr > 0.
sort i_ekbe by ebeln ebelp belnr.

select vbeln wadat_ist
from likp
into table i_likp
for all entries in i_ekbe
where vbeln = i_ekbe-belnr.

select vbelv vbeln vbtyp_n rfmng
from vbfa
into table i_vbfa
for all entries in i_ekbe
where vbelv = i_ekbe-belnr
and vbtyp_n in ('i','R').

sort i_likp by vbeln wadat_ist.
sort i_vbfa by vbelv vbeln vbtyp_n.
endif.
endform.                                "po_type.
*----------------------------------------------------------------------*
* FORM po_or_delivery_number.
*----------------------------------------------------------------------*
form po_or_delivery_number.
order_type
= ' '.
status
= ' '.
received_qty
= 0.
sort i_ekko_combo by ebeln ebelp matnr.
loop at i_ekko_combo.
received_flag
= 'N'.
qty_shipped
= 0.

read table i_ekbe with key ebeln = i_ekko_combo-ebeln
ebelp
= i_ekko_combo-ebelp
binary search.
if sy-subrc <> 0.
status
= 'IN PROCESS'.
po_delivery
= i_ekko_combo-ebeln.
order_type
= space.
if i_ekko_combo-loekz = 'L'.
status
= 'DELETED'.
endif.
else.
po_delivery
= i_ekbe-belnr.
order_type
= delivery.
read table i_likp with key vbeln = i_ekbe-belnr
binary search.
if sy-subrc = 0.
if not i_likp-wadat_ist = '00000000'.
read table i_vbfa with key vbelv = i_ekbe-belnr
vbtyp_n
= 'R'
binary search.
if sy-subrc = 0.
status
= 'INTRANSIT'.
qty_shipped
= i_vbfa-rfmng.
endif.
status
= 'INTRANSIT'.
read table i_vbfa with key vbelv = i_ekbe-belnr
vbtyp_n
= 'i'
binary search.
if sy-subrc = 0.
status
= 'RECEIVED'.
received_flag
= 'Y'.
qty_shipped
= i_vbfa-rfmng.
endif.
else.
status
= 'OPEN'.
endif.
endif.
endif.
if received_flag = 'N'.
if order_type = delivery.
if i_ekko_combo-elikz = 'X'.
status
= 'CANCELLED'.
endif.
else.
if i_ekko_combo-elikz = 'X'.
read table i_vbfa with key vbelv = i_ekko_combo-ebeln
binary search.
if sy-subrc = 0.
if i_vbfa-vbtyp_n = 'i'.
status
= 'CANCELLED'.
endif.
endif.
endif.
endif.
endif.
perform create_report.
endloop.
endform.                                "po_or_delivery_number.
*----------------------------------------------------------------------*
* FORM create_report.
*----------------------------------------------------------------------*
form create_report.
itab_report
-po_delivery = po_delivery.
itab_report
-matnr       = i_ekko_combo-matnr.
itab_report
-menge       = i_ekko_combo-menge.
itab_report
-status      = status.
itab_report
-rfmng       = qty_shipped.

*---> Article Data
read table i_ekpo_art with key matnr = i_ekko_combo-matnr
binary search.
if sy-subrc = 0.
shift i_ekpo_art-upc left deleting leading '0' IN CHARACTER MODE ."smart: 2010-04-07 #115
itab_report
-upc         = i_ekpo_art-upc.
shift itab_report-upc right deleting trailing space IN CHARACTER  "smart: 2010-04-07 #115
MODE .                                                          "smart: 2010-04-07 #115
overlay  itab_report-upc with '00000000000000'.
itab_report
-idnlf = i_ekpo_art-idnlf(25).
itab_report
-maktx = i_ekpo_art-maktx.
endif.
append itab_report.

endform.                                "create_report.
*----------------------------------------------------------------------*
* FORM write_report.
*----------------------------------------------------------------------*
form write_report.
sort itab_report by po_delivery matnr.
loop at itab_report.
move itab_report-menge to quantity.
move itab_report-rfmng to qty_shipped_out.
write: /01 itab_report-upc.

clear ws_cnt.
select count(*) into ws_cnt from mean
where matnr = itab_report-matnr.
if ws_cnt > 1.
write 15(1) '*'.
endif.

write16 itab_report-matnr,
26 itab_report-idnlf,
53 itab_report-maktx(32),
85 quantity no-zero,
95 qty_shipped_out no-zero,
107 itab_report-po_delivery,
121 itab_report-status.

endloop.
endform.                                "write_report.

end-of-page.
write:
'* = Multiple UPCs exist for this article, primary UPC is displayed.'.


Viewing all articles
Browse latest Browse all 9236

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>