Go on link..

link us with ...

Thursday, December 30, 2010

program the all the materials in a STO with their GR , PGI , Delivery Details in MM Module

*&---------------------------------------------------------------------*
*& Report ZVVF_MM_OPEN_ITEMS *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZVVF_MM_OPEN_ITEMS line-size 255 message-id zmess
no standard page heading.

**********************<>**********************************
*Transaction code : zmm_open
*Description : This program the all the materials in a STO with
* their GR , PGI , Delivery Details. It also
* calculates the difference between Delivery Qty and
* GR qty.
*Functional
*Brief Logic : The relevant data from various tables are selected
* into various internal tables . The data from these
* internal tables are then consolidated into one main
* internal table t_display . The number of open items
* is calculated by subtracting GR qty from the
* Delivery quantity. The report is then
* displayed by looping at this internal table
* t_display.
* If the belnr field of the internal table t_ekbe
* starts with 50 then that number is considered as
* the GR number and the corresponding BUDAT and MENGE
* fields are the GR date and the GR quantity . These
* 3 values are stored in the fields gr_belnr ,
* gr_budat and gr_menge of the table t_display.
* Similarly BELNR which start with 89 are taken as
* PGI number while BELNR starting with 49 are
* delivery numbers.PGI date is stored in PGI_BUDAT,
* PGI quantity is stored in PGI_MENGE.
* Delivery number is DEL_BELNR , delivery qty is
* DEL_MENGE and delivery date is DEL_BUDAT. All this
* data is stored in the internal table t_display.
* All possible GR numbers , with their correspnding
* qtys and posting date is stored in a table t_gr.
* Similarly for PGI details and Delivery details and
* table used in these cases are t_pgi and t_del
* First all the delivery details are appended into the
* table t_display. Then the table is modified to enter
* the PGI and GR details.
* But due to the modification operation the following
* problem arises .
* If for a material , there is one delivery and say
* two PGIs , because of modification command used
* the second PGI overwrites the first PGI since modify
* only modifies existing records, doesn't insert a new
* record. So for overwritten PGI numbers the followin
* logic is used.
* The internal table t_pgi has all possible PGI number
* for a material. So whichever PGI details for a
* a material is overwritten , is appended back into
* t_display , by looping at t_pgi . In this loop
* the table t_display is read and whichever PGI
* numbers are present in t_pgi,but not in t_display is
* appended into t_display. Similarly for the GR
* details.
************************<<<<<<<>>>>>>>>*********************************

*********************************TABLES USED***************************

tables : ekko,"Purchasing Document Header
mara, "Material master,
t001w, "Plant
ekbe,"History per Purchasing Document
marm,"Units of Measure for Material
ekpo."Purchasing Document Item
data d_tabix(10).
data d_diff(13).
data d_qty(13).


*************************SELECTION SCREEN*******************************
selection-screen begin of block b1 with frame title text-000.
select-options:
s_matnr for ekpo-ematn modif id SC1, "Material Number
s_ebeln for ekko-ebeln modif id SC2, "Purchasing document
s_reswk for ekko-reswk modif id SC1, "Supplying plant
s_werks for ekpo-werks modif id SC2, "Receiving plant
s_BUDAT FOR EKBE-BUDAT modif id SC1. "Purchase Order date
parameters:
p_diff as checkbox.

selection-screen end of block b1.

************************INTERNAL TABLES USED****************************
data: begin of t_ekko occurs 100,
ebeln like ekko-ebeln,
bedat like ekko-bedat,
reswk like ekko-reswk,
end of t_ekko.

data: begin of t_ekpo occurs 100,
ebeln LIKE EKPO-EBELN,
ebelp like ekpo-ebelp,
ematn like ekpo-ematn,
werks like ekpo-werks,
meins like ekpo-meins,
txz01 like ekpo-txz01,
end of t_ekpo.

data: begin of t_ekbe occurs 100,
ebeln like ekbe-ebeln,
bwart like ekbe-bwart,
ebelp like ekbe-ebelp,
vgabe like ekbe-vgabe,
bewtp like ekbe-bewtp,
gjahr like ekbe-gjahr,
belnr like ekbe-belnr,
matnr like ekbe-matnr,
buzei like ekbe-buzei,
budat like ekbe-budat,
menge like ekbe-menge,
shkzg like ekbe-shkzg,
end of t_ekbe.
* change
data: begin of t_del occurs 100,
ebeln like ekbe-ebeln,
bwart like ekbe-bwart,
ebelp like ekbe-ebelp,
vgabe like ekbe-vgabe,
bewtp like ekbe-bewtp,
gjahr like ekbe-gjahr,
belnr like mkpf-xblnr,
matnr like ekbe-matnr,
buzei like ekbe-buzei,
budat like ekbe-budat,
menge like ekbe-menge,
shkzg like ekbe-shkzg,
vbelv like vbfa-vbelv,
end of t_del.

* end change

data: begin of t_marm occurs 100,
matnr like marm-matnr,
meinh like marm-meinh,
UMREZ like marm-umrez,
UMREN like marm-umren,
end of t_marm.

data: begin of t_gr occurs 100,
ebeln like ekbe-ebeln,
ebelp like ekbe-ebelp,
matnr like ekbe-matnr,
buzei like ekbe-buzei,
gr_no like ekbe-belnr,
gr_date like ekbe-budat,
gr_qty like ekbe-menge,
gr_bwart like ekbe-bwart,
end of t_gr.

data: begin of t_pgi occurs 100,
ebeln like ekbe-ebeln,
ebelp like ekbe-ebelp,
matnr like ekbe-matnr,
buzei like ekbe-buzei,
pgi_no like ekbe-belnr,
pgi_qty like ekbe-menge,
pgi_date like ekbe-budat,
pgi_bwart like ekbe-bwart,
end of t_pgi.

data: begin of t_display occurs 100,
ebeln like ekko-ebeln, "Purchasing document number
ebelp like ekbe-ebelp, "Item number of purchasing document
vgabe like ekbe-vgabe,
bewtp like ekbe-bewtp,
gjahr like ekbe-gjahr,

bedat like ekko-bedat, "Purchasing document date
reswk like ekko-reswk, "Supplying (issuing) plant for STO
werks like ekpo-werks, "Receiving plant
ematn like ekpo-ematn, "Material
* buzei like ekbe-buzei, "Item in material document
txz01 like ekpo-txz01, "Desciption
del_belnr like ekbe-belnr, "Number of material document
del_buzei like ekbe-buzei,
del_menge like ekbe-menge, "Quantity
del_budat like ekbe-budat, "Posting date in the document
pgi_belnr like ekbe-belnr, "Number of material document
pgi_buzei like ekbe-buzei,
pgi_menge like ekbe-menge, "Quantity
pgi_budat like ekbe-budat, "Posting date in the document
gr_belnr like ekbe-belnr, "Number of material document
gr_buzei like ekbe-buzei,
gr_budat like ekbe-budat, "Posting date in the document
gr_menge like ekbe-menge,
base_open_qty(13) type c, "Base open item qty
case_open_qty(4) type P decimals 2, "Open items in cases
klmt_open_qty(4) type P decimals 2, "Open items in KL/MT
* buzei like ekbe-buzei,
end of t_display.

data: t_display1 like t_display occurs 100 with header line.

data: t_pgi1 like t_pgi occurs 100 with header line.

data: t_gr1 like t_gr occurs 100 with header line.
data: begin of t_mseg occurs 100,
ebeln like mseg-ebeln,
xblnr like mkpf-xblnr,
mblnr like mseg-mblnr,
matnr like mseg-matnr,
zeile like mseg-zeile,
bwart like mseg-bwart,
meins like mseg-meins,
end of t_mseg.

data: begin of wa_display.
include structure t_display.
data: end of wa_display.

data: begin of t_vbfa occurs 0,
vbelv like vbfa-vbelv,
vbeln like vbfa-vbeln.
data: end of t_vbfa.



***************************DATA VARIABLES USED**************************
data: d_series(2),
d_matn like t_display-ematn,
d_ebeln like t_display-ebeln,
d_date like t_display-del_budat,
d_tot_gr_menge(13) type p decimals 3,
d_tot_del_menge(13) type p decimals 3 ,
d_tot_pgi_menge(13) type p decimals 3,
d_gr_menge(13).

data: begin of t_display_struc.
include structure t_display.
data: end of t_display_struc.


data: begin of struc_gr.
include structure t_mseg.
data: end of struc_gr.

data: begin of struc_pgi.
include structure t_mseg.
data: end of struc_pgi.

data: d_grand_gr_menge like t_display-gr_menge,
d_grand_del_menge like t_display-del_menge,
d_grand_pgi_menge like t_display-pgi_menge.

top-of-page.

perform print_report_header.

at selection-screen.
*--check the sto numbers from EKKO for condition entered by user
select single ebeln bedat reswk from ekko into t_ekko WHERE
reswk in s_reswk and
ebeln in s_ebeln and
reswk ne space.

if ( sy-subrc <> 0 ).
message E001." no record matches your selection critetia
set screen 0.
leave screen.
exit.
endif.
*--check the material numbers
select single matnr from mara into (mara-matnr) where matnr in s_matnr.
if ( sy-subrc <> 0 ).
message e003.
set screen 0.
leave screen.
endif.
*--check for plant
select single werks from t001w into (t001w-werks) where
werks in s_werks .
if ( sy-subrc <> 0 ).
message e004.
set screen 0.
leave screen.
endif.

*--intialise variables used in the program
perform initialization.

start-of-selection.
*--extract the data needed for the report display
perform extract_data.

IF ( p_diff = ' ' ).
*--display the report
perform display_report.
else.
*--display only those details for which there is a difference in del qty
*--and GR qty
perform display_difference_only.
endif.
*&---------------------------------------------------------------------*
*& Form PRINT_REPORT_HEADER
*&---------------------------------------------------------------------*
* This form prints the header for the report which is displayed on
* every page
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM print_report_header. format color 7 inverse on. write: 100 'V V F Limited'. format color 7 inverse off. *******Begin of modification for Upgrade by Sanjeev(SR10082004)********* *uline at 0(242) . "- uline at (242) . "+ ********End of modification for Upgrade by Sanjeev(SR10082004)********** format color 4 intensified on. write:/ sy-vline, 'STO', 11 sy-vline, 12 'STO', 24 sy-vline, 25 'Supl' , 31 sy-vline, 32 'Recg', 37 sy-vline, 38 'Item', 45 sy-vline, 46 'Description', 75 sy-vline, 76 'Delv', 87 sy-vline, 88 'Delv', 102 sy-vline, 103 'Delv', 115 sy-vline, 116 'PGI', 127 sy-vline, 128 'PGI', 142 sy-vline, 143 'PGI', 155 sy-vline, 156 'GR', 168 sy-vline, 169 'GR', 181 sy-vline, 182 'GR', 196 sy-vline, 197 'Open', 211 sy-vline, 212 'Open', 226 sy-vline, 227 'Open', 242 sy-vline. write:/ sy-vline, 'No', 11 sy-vline, 12 'Date', 24 sy-vline, 25 'Plnt', 31 sy-vline, 32 'Plnt', 37 sy-vline, 38 'Code', 45 sy-vline, 75 sy-vline, 76 'No', 102 sy-vline, 87 sy-vline, 88 'Qty', 102 sy-vline, 103 'Date', 115 sy-vline, 116 'No', 127 sy-vline, 128 'Qty', 142 sy-vline, 143 'Date', 155 sy-vline, 156 'No', 168 sy-vline, 169 'Date', 181 sy-vline, 182 'Qty', 196 sy-vline, 197 'Qty(BU)', 211 sy-vline, 212 'Qty(CS)', 226 sy-vline, 227 'Qty(KL/MT)', 242 sy-vline. format color off. *******Begin of modification for Upgrade by Sanjeev(SR10082004)********* *uline at 0(242). "- uline at (242). "+ ********End of modification for Upgrade by Sanjeev(SR10082004)********** ENDFORM. " PRINT_REPORT_HEADER *&---------------------------------------------------------------------* *& Form INITIALIZATION *&---------------------------------------------------------------------* * This form initializes all the program variables and internal tables. *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text *----------------------------------------------------------------------* form initialization. clear: t_ekko, d_series, d_gr_menge, d_matn, t_ekpo, t_ekbe, d_ebeln, struc_gr, struc_pgi, t_mseg, t_marm, t_gr, t_pgi, d_tot_gr_menge, d_tot_del_menge, t_display. refresh: t_ekko, t_ekpo, t_ekbe, t_pgi, t_gr, t_mseg, t_marm, t_display. endform. " INITIALIZATION *&---------------------------------------------------------------------* *& Form EXTRACT_DATA *&---------------------------------------------------------------------* * This form extracts the required data into various internal tables * and combines them in one internal table t_display. *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text *----------------------------------------------------------------------* form extract_data. *--select the STO numbers from ekko corresponding to user entry on *--screen select ebeln bedat reswk from ekko into table t_ekko WHERE reswk in s_reswk and ebeln in s_ebeln and reswk ne space. *--to get the PO line item details for all POs selected above select EBELN ebelp EMATN WERKS meins TXZ01 FROM EKPO INTO TABLE T_EKPO for all entries in t_ekko where ebeln = t_ekko-ebeln and werks in S_WERKS AND MATNR IN S_MATNR. *--get the conversion factors for materials select matnr MEINH umrez umren from marm into table t_marm for all entries in t_ekpo where matnr = t_ekpo-ematn. *--to get the GR PGI Del details for all POs selected above select EBELN bwart ebelp vgabe bewtp gjahr belnr matnr buzei budat menge shkzg from ekbe into table t_ekbe for all entries in t_ekpo where ebeln = t_ekpo-ebeln and ( matnr = t_ekpo-ematn Or matnr eq space ) and EBELP = T_EKPO-EBELP AND BUDAT in s_BUDAT. * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>add
*t_del[] = t_ekbe[].

MOVE-CORRESPONDING t_ekbe TO T_DEL.

loop at t_del.
move t_del-belnr to d_Series.
if ( d_series <> '89' ).
delete t_del.
endif.
endloop.

sort t_del by belnr.
delete adjacent duplicates from t_del comparing belnr.


*select ebeln mblnr matnr zeile bwart meins from mseg into table t_mseg
*for all entries in t_ekbe where
* ebeln = t_ekbe-ebeln and
* matnr = t_ekbe-matnr and
* bwart = t_ekbe-bwart and
* mblnr = t_ekbe-belnr and
* xauto ne 'X'.
* Code below to allow select on vbfa
* In the absence of this code, R/3 will not allow query since fields
* are of different nature .
* codes - Courtesy :- Samir Saab of ABAP.
loop at t_del.
t_del-vbelv = t_del-belnr.
modify t_del.
endloop.

select vbelv vbeln
from vbfa
into corresponding fields of table t_vbfa
for all entries in t_del
where vbelv = t_del-vbelv
and vbelv like '89%'
and ( vbeln like '50%' or vbeln like '49%').

sort t_vbfa by vbelv vbeln.
delete adjacent duplicates from t_vbfa comparing vbelv vbeln.

loop at t_vbfa.
t_mseg-xblnr = t_vbfa-vbelv.
t_mseg-mblnr = t_vbfa-vbeln.
append t_mseg.
endloop.

* codes - Courtesy :- Samir Saab of ABAP.

*select xblnr mblnr from mkpf into corresponding fields of
*table t_mseg
*for all entries in t_del
*where
* xblnr = t_del-belnr.
*
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>end add


loop at t_ekbe.
*<<>>
*--all ebeln numbers starting with 49 are PGI numbers
clear d_Series.
move t_ekbe-belnr to d_Series.
if ( d_series = '49' ).
t_pgi-ebeln = t_ekbe-ebeln.
t_pgi-ebelp = t_ekbe-ebelp.
t_pgi-matnr = T_ekbe-matnr.
t_pgi-buzei = t_ekbe-buzei.
t_pgi-pgi_no = t_ekbe-belnr.
t_pgi-pgi_qty = t_ekbe-menge.
t_pgi-pgi_date = t_ekbe-budat.
t_pgi-pgi_bwart = t_ekbe-bwart.
append t_pgi.
endif.

*<<>>
*--all ebeln numbers starting with 50 are GR numbers
if ( d_series = '50' ).
t_gr-ebeln = t_ekbe-ebeln.
t_gr-ebelp = t_ekbe-ebelp.
t_gr-matnr = t_ekbe-matnr.
t_gr-matnr = t_ekbe-matnr.
t_gr-buzei = t_ekbe-buzei.
t_gr-gr_no = t_ekbe-belnr.
t_gr-gr_qty = t_ekbe-menge.
t_gr-gr_date = t_ekbe-budat.
append t_gr.
endif.

endloop.

t_pgi1[] = t_pgi[].
t_gr1[] = t_gr[].

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. add
loop at t_mseg.
move t_mseg-mblnr to d_Series.
if ( d_series = '49' ).
read table t_pgi with key pgi_no = t_mseg-mblnr.
if ( sy-subrc <> 0 ).
delete t_mseg.
endif.
endif.

if ( d_series = '50' ).
read table t_gr with key gr_no = t_mseg-mblnr.
if ( sy-subrc <> 0 ).
delete t_mseg.
endif.
endif.
endloop.

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end add



*<<<<>>
if ( d_series = '89' ) AND ( t_ekbe-menge <> 0 ).
t_display-del_belnr = t_ekbe-belnr."Delv No
t_display-del_budat = t_ekbe-budat. "Delv date
*--to check for document reversal
IF ( t_ekbe-bwart = '122' ) or ( t_ekbe-bwart = '102' ).
t_display-del_menge = ( t_ekbe-menge ) * ( -1 ). "Delv
else.
t_Display-del_menge = t_ekbe-menge.
endif.
append t_display.
endif.
endloop.
t_display1[] = t_display[].
*sort t_display by ebeln ebelp del_belnr.

*--this part of code is to sum up delivery qtys for delivery numbers
*--that repeat.

loop at t_display.
d_date = t_display-del_budat.
clear d_qty.

at new del_belnr.
loop at t_display1 where ebeln = t_display-ebeln and
ebelp = t_display-ebelp and
del_belnr = t_display-del_belnr.
d_qty = d_qty + t_display1-del_menge .
endloop.

t_display-del_menge = d_qty.
t_display-del_budat = d_date.
clear t_Display-pgi_belnr.
clear t_Display-gr_belnr.
modify t_display.
endat.
endloop.
delete adjacent duplicates from t_display comparing ebeln ebelp
del_belnr.
*<<>>


*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> add
loop at t_mseg.

loop at t_display where del_belnr = t_mseg-xblnr.

move t_mseg-mblnr to d_Series.
if ( d_series = '50' ).
t_display-gr_belnr = t_mseg-mblnr.
modify t_display.
endif.

if ( d_series = '49' ).
t_display-pgi_belnr = t_mseg-mblnr.
modify t_display.
endif.

endloop.

endloop.
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end add




*<<>>
*<<>>

*--this part of code is to sum up PGI qtys for PGI numbers
*--that repeat.

sort t_pgi by ebeln ebelp PGI_NO.

delete adjacent duplicates from t_pgi comparing ebeln ebelp pgi_no.

loop at t_pgi.
clear d_qty.

loop at t_pgi1 where ebeln = t_pgi-ebeln and
ebelp = t_pgi-ebelp and
pgi_no = t_pgi-pgi_no.
d_qty = d_qty + t_pgi1-pgi_qty.
endloop.

t_pgi-pgi_qty = d_qty.
modify t_pgi.
endloop.


sort t_display .

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> add

*loop at t_pgi.
*loop at t_display where pgi_belnr = ' ' and
* ebeln = t_pgi-ebeln and
* ebelp = t_pgi-ebelp and
* ematn = t_pgi-matnr .
* t_display-pgi_buzei = t_pgi-buzei.
* t_display-pgi_belnr = t_pgi-pgi_no.
* t_display-pgi_budat = t_pgi-pgi_date.
*if ( t_pgi-pgi_bwart = '642' )."or t_pgi-pgi_bwart = '102' ).
* t_display-pgi_menge = ( t_pgi-pgi_qty ) * ( -1 ).
*else.
* t_display-pgi_menge = t_pgi-pgi_qty.
*endif.
* modify t_display.
*exit.
*endloop.
*endloop.



loop at t_pgi.
loop at t_display where pgi_belnr = t_pgi-pgi_no and
ebeln = t_pgi-ebeln and
ebelp = t_pgi-ebelp and
ematn = t_pgi-matnr .
t_display-pgi_buzei = t_pgi-buzei.
t_display-pgi_belnr = t_pgi-pgi_no.
t_display-pgi_budat = t_pgi-pgi_date.
if ( t_pgi-pgi_bwart = '642' )."or t_pgi-pgi_bwart = '102' ).
t_display-pgi_menge = ( t_pgi-pgi_qty ) * ( -1 ).
else.
t_display-pgi_menge = t_pgi-pgi_qty.
endif.
modify t_display.
exit.
endloop.
endloop.



sort t_display.
*sort t_pgi by ebeln ebelp pgi_no.
*loop at t_pgi .
*read table t_display with key ebeln = t_pgi-ebeln
* ebelp = t_pgi-ebelp
* pgi_belnr = t_pgi-pgi_no.
**--if the record is already present then find out
**--its position in the table
*if ( sy-subrc = 0 ).
*clear d_tabix.
*d_tabix = sy-tabix.
*else.
**--insert the overwritten record at the next position
*d_tabix = d_tabix + 1.
**t_display-pgi_belnr = t_pgi-pgi_no.
**t_display-pgi_budat = t_pgi-pgi_date.
**t_display-pgi_menge = t_pgi-pgi_qty.
**modify t_display index d_tabix.
**if ( sy-subrc <> 0 ).
*clear wa_display-ebelp.
*wa_display-bedat = ' ' .
*clear wa_display-bedat.
*wa_display-ebeln = t_pgi-ebeln.
*wa_display-ebelp = t_pgi-ebelp.
*wa_display-pgi_belnr = t_pgi-pgi_no.
*wa_display-pgi_budat = t_pgi-pgi_date.
**--check for reveral of document
*if ( t_pgi-pgi_bwart = '642' ). " or ( t_pgi-pgi_bwart = '102' ).
* wa_display-pgi_menge = ( t_pgi-pgi_qty ) * ( -1 ).
*else.
*wa_display-pgi_menge = t_pgi-pgi_qty.
*endif.
**wa_display-pgi_menge = t_pgi-pgi_qty.
*insert wa_display into t_display index d_tabix.
*endif.
*clear wa_display.
*endloop.

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end add


**sort t_display by ebeln ebelp.
***<>
***<<>>
***sort t_ekbe by ebeln ebelp matnr buzei.

*--this part of code is to sum up GR qtys for GR numbers
*--that repeat.

sort t_gr by ebeln ebelp gr_no.
delete adjacent duplicates from t_gr comparing ebeln ebelp gr_no.

loop at t_gr.
clear d_qty.
loop at t_gr1 where ebeln = t_gr-ebeln and
ebelp = t_gr-ebelp and
gr_no = t_gr-gr_no.
d_qty = d_qty + t_gr1-gr_qty.

endloop.
t_gr-gr_qty = d_qty.
modify t_gr.
endloop.
*sort t_display by ebeln ebelp.

*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>add

*loop at t_gr.
*loop at t_display where gr_belnr = ' ' and
* ebeln = t_gr-ebeln and
* ebelp = t_gr-ebelp and
* ematn = t_gr-matnr .
* t_display-gr_buzei = t_gr-buzei.
* t_display-gr_belnr = t_gr-gr_no.
* t_display-gr_budat = t_gr-gr_date.
**--check for reversal of document
*if ( t_gr-gr_bwart = '102' ) ."or ( t_gr-gr_bwart = '102' ).
* t_display-gr_menge = ( t_gr-gr_qty ) * ( -1 ).
*else.
* t_display-gr_menge = t_gr-gr_qty.
*endif.
* modify t_display.
*exit.
*endloop.
*endloop.


loop at t_gr.
loop at t_display where gr_belnr = t_gr-gr_no and
ebeln = t_gr-ebeln and
ebelp = t_gr-ebelp and
ematn = t_gr-matnr .
t_display-gr_buzei = t_gr-buzei.
t_display-gr_belnr = t_gr-gr_no.
t_display-gr_budat = t_gr-gr_date.
*--check for reversal of document
if ( t_gr-gr_bwart = '102' ) ."or ( t_gr-gr_bwart = '102' ).
t_display-gr_menge = ( t_gr-gr_qty ) * ( -1 ).
else.
t_display-gr_menge = t_gr-gr_qty.
endif.
modify t_display.
exit.
endloop.
endloop.

*sort t_gr by ebeln ebelp gr_no.
*loop at t_gr.
*
*read table t_display with key gr_belnr = t_gr-gr_no
* ebeln = t_gr-ebeln
* ebelp = t_gr-ebelp
* gr_belnr = t_gr-gr_no.
**--if the record is already present then find out
**--its position in the table
*
*if ( sy-subrc = 0 ).
*clear d_tabix.
*d_tabix = sy-tabix .
*else.
*d_tabix = d_tabix + 1.
*t_display-gr_belnr = t_gr-gr_no.
*t_display-gr_budat = t_gr-gr_date.
*if ( t_gr-gr_bwart = '102' )." or ( t_gr-gr_bwart = '102' ).
* t_display-gr_menge = ( t_gr-gr_qty ) * ( -1 ).
*else.
* t_display-gr_menge = t_gr-gr_qty.
*endif.
*wa_display-ebeln = t_display-ebeln.
*wa_display-ebelp = t_display-ebelp.
*
*wa_display-gr_belnr = t_gr-gr_no.
*wa_display-gr_budat = t_gr-gr_date.
*wa_display-gr_menge = t_gr-gr_qty.
*insert wa_display into t_display index d_tabix.
*
**--insert the overwritten record at the next position
*modify t_display index d_tabix transporting gr_belnr gr_budat gr_menge.
*endif.
*clear wa_display.
*endloop.
*
* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> end add

*<<>>

************************************************************************
************************************************************************
**<<>>
loop at t_Display.
t_display-base_open_qty = T_display-del_menge -
t_display-gr_menge.
read table t_marm with key matnr = t_display-ematn
meinh = 'CS'.
if ( sy-subrc eq 0 ).

t_display-case_open_qty =
( t_display-base_open_qty ) * ( t_marm-umren / t_marm-umrez ) .

endif.
*<<>>
read table t_marm with key matnr = t_display-ematn
meinh = 'TO'.
if ( sy-subrc eq 0 ).
t_display-klmt_open_qty =
( t_display-base_open_qty ) * ( t_marm-umren / ( 1000000 *
t_marm-umrez ) ).
endif.

*<<>>
read table t_marm with key matnr = t_display-ematn
meinh = 'KL'.
if ( sy-subrc eq 0 ).
t_display-klmt_open_qty =
( t_display-base_open_qty ) * ( t_marm-umren / t_marm-umrez
)
.


endif.
modify t_display.
endloop.
endform. " EXTRACT_DATA

*&---------------------------------------------------------------------*
*& Form DISPLAY_REPORT
*&---------------------------------------------------------------------*
* This form displays the report in the desired format.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* form display_report. loop at t_display. if ( t_display-gr_budat = '********' ). clear t_display-gr_budat. modify t_display. endif. if ( t_display-pgi_budat = '********' ). clear t_display-pgi_budat. modify t_display. endif. endloop. loop at t_display . d_matn = t_Display-ematn. d_ebeln = t_display-ebeln. at new ebeln. format color 6 intensified on. write:/1 d_ebeln. format color 1 off. endat. write:/12 t_display-bedat no-zero, 25 t_display-reswk , 32 t_display-werks, 38 t_display-ematn, 46 t_display-txz01, 76 t_display-del_belnr, 87 t_display-del_menge no-zero right-justified, 104 t_display-del_budat no-zero, 116 t_display-pgi_belnr no-zero, 126 t_display-pgi_menge right-justified no-zero, 143 t_Display-pgi_budat no-zero, 156 t_Display-gr_belnr no-zero, 169 t_display-gr_budat no-zero, 179 t_display-gr_menge no-zero right-justified , 196 t_display-base_open_qty right-justified , 215 t_display-case_open_qty right-justified decimals 2, 230 t_display-klmt_open_qty right-justified decimals 2. *--to get the sum of all qtys item wise. d_tot_gr_menge = d_tot_gr_menge + t_display-gr_menge. d_tot_del_menge = d_tot_del_menge + t_display-del_menge. d_tot_pgi_menge = d_tot_pgi_menge + t_display-pgi_menge. *--to get the grand totals to print at end of report. d_grand_gr_menge = d_grand_gr_menge + t_display-gr_menge. d_grand_del_menge = d_grand_del_menge + t_display-del_menge. d_grand_pgi_menge = d_grand_pgi_menge + t_display-pgi_menge. *--to print the item wise totals *if ( sy-tabix <> 1 ).
at end of ebelp.
format color 7 intensified on.
d_diff = d_tot_del_menge - d_tot_gr_menge.
write:/'ITEM WISE TOTAL :',
77 d_tot_del_menge ,
116 d_tot_pgi_menge ,
169 d_tot_gr_menge ,
196 d_diff right-justified.
clear : d_tot_del_menge,
d_tot_pgi_menge,
d_tot_gr_menge.
format color 7 off.
uline.
endat.
*endif.
endloop.
*--prints the grand totals at the end of report.
*at last.
clear d_diff.
d_diff = d_grand_del_menge - d_grand_gr_menge.
format color 3 intensified on.
d_diff = d_tot_del_menge - d_tot_gr_menge.
write:/'GRAND TOTAL :',
87 d_grand_del_menge right-justified,
126 d_grand_pgi_menge right-justified,
179 d_grand_gr_menge right-justified ,
196 d_diff right-justified.

clear : d_tot_del_menge,
d_tot_gr_menge.
format color 5 off.
uline.
*endat.

endform. " DISPLAY_DATA


*&---------------------------------------------------------------------*
*& Form DISPLAY_DIFFERENCE_ONLY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* form display_difference_only. loop at t_display. if ( t_display-gr_budat = '********' ). clear t_display-gr_budat. modify t_display. endif. if ( t_display-pgi_budat = '********' ). clear t_display-pgi_budat. modify t_display. endif. endloop. loop at t_display. delete t_display where base_open_qty = 0. endloop. loop at t_display . d_matn = t_Display-ematn. d_ebeln = t_display-ebeln. at new ebeln. format color 6 intensified on. write:/1 d_ebeln. format color 1 off. endat. write:/12 t_display-bedat no-zero, 25 t_display-reswk , 32 t_display-werks, 38 t_display-ematn, 46 t_display-txz01, 76 t_display-del_belnr, 87 t_display-del_menge no-zero right-justified, 104 t_display-del_budat no-zero, 116 t_display-pgi_belnr no-zero, 126 t_display-pgi_menge right-justified no-zero, 143 t_Display-pgi_budat no-zero, 156 t_Display-gr_belnr no-zero, 169 t_display-gr_budat no-zero, 179 t_display-gr_menge no-zero right-justified , 196 t_display-base_open_qty right-justified , 215 t_display-case_open_qty right-justified decimals 2, 230 t_display-klmt_open_qty right-justified decimals 2. *--to get the sum of all qtys item wise. d_tot_gr_menge = d_tot_gr_menge + t_display-gr_menge. d_tot_del_menge = d_tot_del_menge + t_display-del_menge. d_tot_pgi_menge = d_tot_pgi_menge + t_display-pgi_menge. *--to get the grand totals to print at end of report. d_grand_gr_menge = d_grand_gr_menge + t_display-gr_menge. d_grand_del_menge = d_grand_del_menge + t_display-del_menge. d_grand_pgi_menge = d_grand_pgi_menge + t_display-pgi_menge. *--to print the item wise totals *if ( sy-tabix <> 1 ).
at end of ebelp.
format color 7 intensified on.
d_diff = d_tot_del_menge - d_tot_gr_menge.
write:/'ITEM WISE TOTAL :',
77 d_tot_del_menge ,
115 d_tot_pgi_menge ,
169 d_tot_gr_menge ,
196 d_diff right-justified.
clear : d_tot_del_menge,
d_tot_pgi_menge,
d_tot_gr_menge.
format color 7 off.
uline.
endat.
*endif.
endloop.
*--prints the grand totals at the end of report.
clear d_diff.
d_diff = d_grand_del_menge - d_grand_gr_menge.
format color 3 intensified on.
d_diff = d_tot_del_menge - d_tot_gr_menge.
write:/'GRAND TOTAL :',
87 d_grand_del_menge right-justified,
125 d_grand_pgi_menge right-justified,
179 d_grand_gr_menge right-justified ,
199 d_diff right-justified.

clear : d_tot_del_menge,
d_tot_gr_menge.
format color 5 off.
uline.
endform. " DISPLAY_DIFFERENCE_ONLY

No comments:

link us...

For Visitors

if you want to publish or Add something on ERP, SAP , SAP FUNCTIONAL, SAP ABAP then mail us along with your email-id. contain must be yours

email-id :- avinashkr_raj@yahoo.com(any email)

email-id :- avinaskr_raj.abap@blogger.com ( use only gmail)