Go on link..

link us with ...

Thursday, December 30, 2010

Report RG3 COPY FO RG4

*&---------------------------------------------------------------------*
*& Report ZVVF_MR038_RG4_COPY *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT ZVVF_MR038_RG4_COPY no standard page heading line-size 155
MESSAGE-ID ZMM .

*---------------------------------------------------------------------*
* MODULE MM. *
*---------------------------------------------------------------------*
* Objective : Report RG3
*
*
*
* Technical Spec No .
* Date Created
* Author
* Location
* LDB Nil
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*

*---------------------------------------------------------------------*
* Amendment History *
*---------------------------------------------------------------------*
* Who Change ID Reason *
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ *
*---------------------------------------------------------------------*

*---------------------------------------------------------------------*
* Tables *
*---------------------------------------------------------------------*



tables : mseg, "Document Segment: Material
makt, "Material Descriptions
mkpf,
ekpo,
afko,
stpo,
mara,
MARM.

*---------------------------------------------------------------------*
* Types Begin with TY_ *
*---------------------------------------------------------------------*

Types : begin of ty_display,
matnr like mseg-matnr,
WERKS LIKE mseg-WERKS,
date type dats,

charg_h like mseg-charg,
menge_h like mseg-menge,
meins_h like mseg-meins,
alcont_h like mseg-menge,

charg_e like mseg-charg,
mengeb_e like mseg-menge,
mengea_e like mseg-menge,

mengeb_w like mseg-menge,
mengea_w like mseg-menge,

mengeb_c like mseg-menge,
mengea_c like mseg-menge,

end of ty_display.

types : begin of ty_mseg,
WERKS LIKE Mseg-WERKS,
budat like mkpf-budat,
mblnr like mseg-mblnr,
matnr like mseg-matnr,
charg like mseg-charg,
BWART like mseg-BWART,
SHKZG like mseg-SHKZG,

lifnr like mseg-lifnr,
ebeln like mseg-ebeln,
ebelp like mseg-ebelp,
bednr like ekpo-bednr,
menge like mseg-menge,
meins like mseg-meins,
sgtxt like mseg-sgtxt,
aufnr like mseg-aufnr,
end of ty_mseg.

types : begin of ty_recve,
matnr like mseg-matnr,
WERKS LIKE MCHBH-WERKS,
budat like mkpf-budat,
charg like mseg-charg,
menge like mseg-menge,
meins like mseg-meins,
strngt like mseg-menge,
actve like mseg-menge,
end of ty_recve.

types : begin of ty_recve1,
matnr like mseg-matnr,
WERKS LIKE MCHBH-WERKS,
budat like mkpf-budat,
mblnr like mseg-mblnr,
end of ty_recve1.

types : begin of ty_expend,
matnr like mseg-matnr,
WERKS LIKE MCHBH-WERKS,
budat like mkpf-budat,
charg like mseg-charg,
menge like mseg-menge,
meins like mseg-meins,
mblnr like mseg-mblnr,
end of ty_expend.

types : begin of ty_manf,
matnr like mseg-matnr,
WERKS LIKE MSEG-WERKS,
budat like mkpf-budat,
charg like mseg-charg,
menge like mseg-menge,
meins like mseg-meins,
mblnr like mseg-mblnr,
end of ty_manf.

types : begin of ty_MchbH,
matnr like mchbh-matnr,
charg like mchbh-charg,
* WERKS LIKE MARDH-WERKS,
CLABS like mchbh-CLABS,
CINSM like mchbh-CINSM,
CEINM like mchbh-CEINM,
CSPEM like mchbh-CSPEM,
end of ty_MchbH.

types : begin of ty_MAKT,
matnr like mseg-matnr,
MAKTX LIKE MAKT-MAKTX,
end of ty_MAKT.

types : begin of ty_MATNR,
matnr like MARM-matnr,
end of ty_MATNR.

Types : begin of ty_MBEWH,
matnr like mbewh-matnr,
bwkey like mbewh-bwkey,
lbkum like mbewh-lbkum,
vprsv like mbewh-vprsv,
verpr like mbewh-verpr,
stprs like mbewh-stprs,
end of ty_MBEWH.
**---------------------------------------------------------------------*
* Constants Begin with C_
**---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Internal tables Begin with IT_ *
*---------------------------------------------------------------------*

data : it_mseg type standard table of ty_mseg with header line,
it_mseg1 type standard table of ty_mseg with header line,
it_mseg2 type standard table of ty_mseg with header line,
it_recve type standard table of ty_recve with header line,
it_recve1 type standard table of ty_recve1 with header line,
it_expend type standard table of ty_expend with header line,
it_manf type standard table of ty_maNF with header line,
it_maKT type standard table of ty_maKT with header line,
it_display type standard table of ty_display with header line,
it_mATNR type standard table of ty_mATNR with header line,
it_display1 type standard table of ty_display with header line,
it_Mchbh1 type standard table of ty_MchbH with header line,
it_Mbewh type standard table of ty_Mbewh with header line,
it_MchbH type standard table of ty_MchbH with header line.
*---------------------------------------------------------------------*
* Work Area Begin with WA_ *
*---------------------------------------------------------------------*
data : wa_mseg like line of it_mseg,
wa_mseg1 like line of it_mseg,
wa_recve like line of it_recve,
wa_recve1 like line of it_recve1,
wa_exPend like line of it_exPend,
wa_manf like line of it_manf,
wa_maKT like line of it_maKT,
wa_MchbH1 like line of it_MchbH1,
wa_MchbH like line of it_MchbH,
wa_MbewH like line of it_MbewH,
wa_display1 like line of it_display,
wa_display like line of it_display.

*---------------------------------------------------------------------*
* Data Begin with W_ *
*---------------------------------------------------------------------*
DATA : W_KEY LIKE INOB-OBJEK,
W_STRENGTH LIKE AUSP-ATFLV,
w_stlnr like afko-stlnr,
w_gamng like afko-gamng,
w_menge like stpo-menge,
w_qty like stpo-menge,
w_aqty like stpo-menge,
W_SBMNG LIKE afko-SBMNG,
W_BUPER LIKE T009B-POPER,
W_lfmon LIKE mchb-lfmon,
W_YEAR LIKE T009B-BDATJ,
W_DATE LIKE MKPF-BUDAT,
W_MON(2) TYPE N,
W_INDEX TYPE SY-INDEX,
W_DATE1 LIKE MKPF-BUDAT.
*---------------------------------------------------------------------*
* Select Options Begin with SO_ *
*---------------------------------------------------------------------*


selection-screen : begin of block b1 with frame title text-000.
PARAMETERS : PR_plant LIKE mseg-werks ."default 'P001' .
PARAMETERS : PR_MONTH TYPE mchb-lfmon .
PARAMETERS : PR_YEAR TYPE T009B-BDATJ.
select-options : so_matnr for mseg-matnr obligatory. "Material code
*select-options : so_date for sy-datum obligatory no-extension.


selection-screen : end of block b1.

************************************************************************


*---------------------------------------------------------------------*
* Ranges Begin with R_ *
*---------------------------------------------------------------------*


ranges : r_movtype for mseg-bwart, "Movement type
r_MARM for MARM-MATNR.

*---------------------------------------------------------------------*
* Initialisation *
*---------------------------------------------------------------------*



initialization.

*---------------------------------------------------------------------*
* At selection-screen *
*---------------------------------------------------------------------*

at selection-screen output.



***********************************************************************
* S T A R T O F S E L E C T I O N *
***********************************************************************


start-of-selection.
****Dates should be from the similar month of the similar year
* if ( so_date-high+4(2) ne so_date-low+4(2) )
* or ( so_date-high+0(4) ne so_date-low+0(4) ).
* message e119(zmm) .
* endif.
perform Get_movetype.
perform get_mchb.
perform get_mseg.
perform get_MAKT.

end-of-selection.
PERFORM DATA_SUM.
perform list_display.


*&---------------------------------------------------------------------*
*& Form get_mchb
*&---------------------------------------------------------------------*
form Get_movetype.

r_movtype-sign = 'I'.
r_movtype-option = 'EQ'.
r_movtype-low = '311'.
r_movtype-high = ' '.
append r_movtype.

r_movtype-sign = 'I'.
r_movtype-option = 'EQ'.
r_movtype-low = '312'.
r_movtype-high = ' '.
append r_movtype.


r_movtype-sign = 'I'.
r_movtype-option = 'EQ'.
r_movtype-low = '261'.
r_movtype-high = ' '.
append r_movtype.

r_movtype-sign = 'I'.
r_movtype-option = 'EQ'.
r_movtype-low = '262'.
r_movtype-high = ' '.
append r_movtype.

r_movtype-sign = 'I'.
r_movtype-option = 'EQ'.
r_movtype-low = '101'.
r_movtype-high = ' '.
append r_movtype.

r_movtype-sign = 'I'.
r_movtype-option = 'EQ'.
r_movtype-low = '102'.
r_movtype-high = ' '.
append r_movtype.

endform. "Get_movetype

*&---------------------------------------------------------------------*
*& Form get_mchb
*&---------------------------------------------------------------------*
form get_mchb.

CONCATENATE PR_YEAR PR_MONTH '01' INTO W_DATE.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
EXPORTING
IV_DATE = W_DATE
IMPORTING
EV_MONTH_BEGIN_DATE = W_DATE
EV_MONTH_END_DATE = W_DATE1.




PERFORM FISCAL_PERIOD USING W_DATE
CHANGING W_BUPER
W_YEAR.
w_lfmon = w_buper+1(2).

SELECT matnr charg clabs cinsm cEINM cspem
FROM MchbH INTO CORRESPONDING
FIELDS OF TABLE It_MchbH1
WHERE WERKS = pr_plant
AND MATNR in so_matnr
AND LFGJA = w_year
AND LFMON = w_lfmon.
if sy-subrc = 0.
LOOP AT IT_MchbH1 INTO WA_MchbH1.
MOVE-CORRESPONDING WA_MchbH1 TO WA_MchbH.
COLLECT WA_MchbH INTO IT_MchbH.
ENDLOOP.
endif.

ENDFORM.


*&---------------------------------------------------------------------*
*& Form get_mseg
*&---------------------------------------------------------------------*
form get_mseg.


select mseg~WERKS
mkpf~budat
mseg~mblnr
mseg~matnr
mseg~charg
mseg~bwart
mseg~SHKZG
mseg~lifnr
mseg~ebeln
mseg~ebelp
mseg~menge
mseg~meins
mseg~sgtxt
mseg~aufnr
into corresponding
fields of
table it_mseg
from mseg inner join mkpf
on mkpf~mblnr = mseg~mblnr and
mkpf~mjahr = mseg~mjahr
where
mseg~werks = PR_plant and
* mseg~matnr in so_matnr and
mseg~bwart in r_movtype and
mkpf~budat BETWEEN W_DATE AND W_DATE1 and
mkpf~mjahr = PR_YEAR.

IF SY-SUBRC = 0.




it_mseg2[] = it_mseg[].
delete it_mseg where not matnr in so_matnr.


READ TABLE it_mseg into wa_mseg WITH KEY bwart = '101' .

IF SY-SUBRC = 0.

loop at it_mseg2 into wa_mseg where ( bwart = '261' or
bwart = '262' ) AND
AUFNR = wa_mseg-AUFNR.

SELECT SINGLE MEINH INTO MARM-MEINH FROM MARM WHERE
MATNR = wa_mseg-MATNR AND
MEINH = 'LAI' .

IF SY-SUBRC = 0.
r_mARM-sign = 'I'.
r_mARM-option = 'EQ'.
r_mARM-low = wa_mseg-MATNR.
r_mARM-high = ' '.
append r_mARM.
ENDIF.

ENDLOOP.
ENDIF.

CLEAR IT_MSEG.
REFRESH IT_MSEG.

it_mseg[] = it_mseg2[].
delete it_mseg where not matnr in R_maRM.


loop at it_mseg into wa_mseg where bwart = '261' or
bwart = '262' .

* if wa_mseg-bwart = '261'.
*
* move-corresponding wa_mseg to wa_recve1.
* collect wa_recve1 into it_recve1.
* endif.

* if wa_mseg-SHKZG = 'H'.
* wa_mseg-menge = wa_mseg-menge * ( -1 ).
* endif.
move-corresponding wa_mseg to wa_expend.
collect wa_expend into it_expend.

endloop.

* loop at it_mseg into wa_mseg where bwart = '101' or
* bwart = '102' .
* if wa_mseg-SHKZG = 'H'.
* wa_mseg-menge = wa_mseg-menge * ( -1 ).
* endif.
* move-corresponding wa_mseg to wa_recve1.
* collect wa_recve1 into it_recve1.
* endloop.



loop at it_expend into wa_expend.

loop at it_mseg2 into wa_mseg where WERKS = wa_expend-WERKS and
budat = wa_expend-budat and
mblnr = wa_expend-mblnr and
bwart = '101' or
bwart = '102'.


* if wa_mseg-SHKZG = 'H'.
* wa_mseg-menge = wa_mseg-menge * ( -1 ).
* endif.
move-corresponding wa_mseg to wa_manf.
collect wa_manf into it_manf.

endloop.

endloop.


it_mseg1[] = it_mseg2[].

sort it_mseg1 stable by budat matnr charg.
delete adjacent duplicates from it_mseg1
comparing budat matnr charg.
delete it_mseg1 where not matnr in so_matnr.
ELSE.

MESSAGE E006.

ENDIF.
endform. "get_mseg

*&---------------------------------------------------------------------*
*& Form FISCAL_PERIOD
*&---------------------------------------------------------------------*
FORM FISCAL_PERIOD USING W_DATE
CHANGING W_BUPER
W_YEAR.
***find the fiscal year and month of previous year&month
call function 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = W_DATE
i_periv = 'V3'
IMPORTING
e_buper = w_buper
e_gjahr = w_year.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form DATA_SUM
*&---------------------------------------------------------------------*
FORM DATA_SUM.

sort it_mseg1 stable by matnr budat.
loop at it_manf into wa_manf.

wa_display-charg_h = wa_manf-charg.
wa_display-menge_h = wa_manf-menge.
wa_display-meins_h = wa_manf-meins.

wa_display-matnr = wa_manf-matnr.


read table it_mchbh into wa_mchbh with key matnr = wa_manf-matnr
charg = wa_manf-charg.
if sy-subrc = 0.
wa_display-charg_h = wa_display-charg_h + wa_mchbh-clabs +
wa_mchbh-cinsm + wa_mchbh-cEINM + wa_mchbh-cspem.
endif.

read table it_expend into wa_expend with key
WERKS = wa_manf-WERKS
budat = wa_manf-budat
mblnr = wa_manf-mblnr.
if sy-subrc = 0.

PERFORM GET_CONTENT USING wa_expend-MATNR
wa_expend-meins
wa_expend-menge
wa_expend-charg
CHANGING WA_DISPLAY-alcont_h.

endif.

w_qty = wa_display-menge_h.
w_aqty = WA_DISPLAY-alcont_h.

read table it_mseg2 into wa_mseg1 with key matnr = wa_manf-matnr
werks = wa_manf-WERKS
bwart = '261'.

if sy-subrc = 0.

loop at it_mseg2 into wa_mseg1 where matnr = wa_manf-matnr and
werks = wa_manf-WERKS and
bwart = '261'.
wa_display-date = wa_mseg1-budat.

wa_display-menge_h = w_qty.
WA_DISPLAY-alcont_h = w_aqty.

read table it_mseg2 into wa_mseg with key mblnr = wa_mseg1-mblnr
bwart = '101'.

if sy-subrc = 0.

select single stlnr gamng SBMNG into (w_stlnr,w_gamng,W_SBMNG) from afko
where aufnr = wa_mseg-aufnr.
if sy-subrc = 0.

select single menge into w_menge from stpo where
stlnr = w_stlnr and
idnrk = wa_manf-matnr.

if sy-subrc = 0.
wa_display-charg_e = wa_mseg-charg.
wa_display-mengeb_e = wa_mseg1-menge.

wa_display-mengea_e = ( WA_DISPLAY-alcont_h / w_qty ) *
wa_display-mengeb_e.



wa_display-mengeb_w =
( ( wa_mseg1-menge * w_gamng ) /
( ( w_menge * w_gamng ) / W_SBMNG ) - wa_mseg-MENGE ).


wa_display-mengea_w = ( WA_DISPLAY-alcont_h / w_qty ) *
wa_display-mengeb_W.


wa_display-mengeb_c = wa_display-menge_h - wa_display-mengeb_e -
wa_display-mengeb_w.
wa_display-mengea_c = WA_DISPLAY-alcont_h - wa_display-mengea_e -
wa_display-mengea_w.




endif.


endif.


endif.

append wa_display to it_display.
w_qty = wa_display-mengeb_c.
w_aqty = wa_display-mengea_c.


endloop.
else.
message e006.
endif.

clear wa_display.
endloop.


DELETE it_display1 WHERE menge_h = 0 AND
mengeb_E = 0 AND
mengeb_w = 0.
ENDFORM. "DATA_SUM


*&---------------------------------------------------------------------*
*& Form GET_MAKT
*&---------------------------------------------------------------------*
FORM GET_MAKT.

* SELECT MATNR MAKTX INTO CORRESPONDING FIELDS OF TABLE IT_MAKT FROM
*MAKT
* for all entries in it_manf WHERE MATNR = it_manf-matnr AND
* SPRAS = SY-LANGU.
* IF SY-SUBRC NE 0.
* MESSAGE W120.
* ENDIF.

ENDFORM. "GET_MAKT

*&--------------------------------------------------------------------*
*& Form GET_CONTENT
*&--------------------------------------------------------------------*
*---------------------------------------------------------------------*
FORM GET_CONTENT USING WA_MCHB-MATNR
WA_DISPLAY-meins_h
WA_DISPLAY-menge_h
WA_DISPLAY-charg_h
CHANGING WA_DISPLAY-actve_h.
.
CALL FUNCTION 'MB_UNIT_CONVERSION'
EXPORTING
ERFME = 'LAI'
MATNR = WA_MCHB-MATNR
MEINS = WA_DISPLAY-meins_h
MENGE = WA_DISPLAY-menge_h
CHARG = WA_DISPLAY-charg_h
WERKS = pr_plant
IMPORTING
O_ERFMG = WA_DISPLAY-actve_h.
ENDFORM. "GET_CONTENT

*&--------------------------------------------------------------------*
*& Form list_display
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form list_display.

WRITE : /80 'FORM R.G.4',
/77 '(Rule 31 and 35)',
/61 'Register of Preparation in the Bonded Manufactory'.
skip 3.

skip 1.
write : sy-uline(150) .
write : / '|' ,12 '|' ,31 'Qty in Hand',61 '|' ,
74 'Qty Expended',
98 '|' ,
99 'Qty Expended(Wastage)' ,124 '|' ,
128 'Closing Balance',150 '|'.
write : sy-uline(150) .
write : / '|' ,4 'Date', 12 '|' ,'Batch' , 23 '|','Material',
33 '|' ,'Quantity' , 43 '|' ,'UOM' ,48
'|' ,'Alc.Content',


61 '|' ,'Batch(FG)' , 72
'|' ,'Qty of Bulk' ,
84 '|' ,'Qty of Alc.' , 98 '|' ,'Qty of Bulk' ,111
'|' ,'Qty of Alc.' ,
124 '|' ,'Qty of Bulk' ,137 '|' ,'Qty of Alc.' ,
150 '|'.
write : sy-uline(150) .

loop at it_display into wa_display.

perform Get_positive.

write : / '|' ,2 wa_display-date , 12 '|',
wa_display-charg_h,
23 '|',wa_display-matnr,
33 '|' ,wa_display-menge_h left-justified,
43 '|' ,wa_display-meins_h ,
48 '|' ,wa_display-alcont_h left-justified,


61 '|',wa_display-charg_e ,
72 '|',wa_display-mengeb_e left-justified,
85 '|',wa_display-mengea_e left-justified,

98 '|',wa_display-mengeb_w left-justified,
111 '|',wa_display-mengea_w left-justified,
124 '|',wa_display-mengeb_c left-justified,
137 '|',wa_display-mengea_c left-justified,
150 '|'.
write : sy-uline(150) .
endloop.


endform. "list_display

*&--------------------------------------------------------------------*
*& Form STRENGTH_CALC
*&--------------------------------------------------------------------*
FORM STRENGTH_CALC USING W_KEY
CHANGING W_STRENGTH.
DATA : W_CUOBJ LIKE INOB-CUOBJ,
W_KLART LIKE INOB-KLART.

SELECT SINGLE CUOBJ KLART INTO (W_CUOBJ,W_KLART) FROM INOB WHERE
OBTAB = 'MCHA' AND
OBJEK = W_KEY.
IF SY-SUBRC = 0.
SELECT SINGLE ATFLV INTO W_STRENGTH FROM AUSP WHERE
OBJEK = W_CUOBJ AND
KLART = W_KLART.
ENDIF.
CLEAR : W_CUOBJ,W_KLART.
ENDFORM. "STRENGTH_CALC

*&--------------------------------------------------------------------*
*& Form Get_positive
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form Get_positive.

if wa_display-menge_h lt 0.
wa_display-menge_h = wa_display-menge_h * ( -1 ).
endif.
if wa_display-alcont_h lt 0.
wa_display-alcont_h = wa_display-alcont_h * ( -1 ).
endif.
* if wa_display-mengeb_e lt 1.
* wa_display-mengeb_e = wa_display-mengeb_e * ( -1 ).
* endif.
* if wa_display-mengea_e lt 1.
* wa_display-mengea_e = wa_display-mengea_e * ( -1 ).
* endif.
* if wa_display-strngt_e lt 1.
* wa_display-strngt_e = wa_display-strngt_e * ( -1 ).
* endif.
* if wa_display-actve_e lt 1.
* wa_display-actve_e = wa_display-actve_e * ( -1 ).
* endif.

endform. "Get_positive

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)