Posted: Fri Oct 05, 2007 11:41 pm Post subject: Plant / Stock / Material report
Report which give the existing stock for a material with a subtotal for stock for each storage location and grand total of the stock at the end of the plant. Plant data start a newpage.
Code:
REPORT Z_MATNR_STOCK_PLANT message-id (zmessage).
*table declaration
tables : mara,marc,makt.
* type-pool declaration
type-pools : slis,icon.
*table type specification
types : begin of ty_mara,
matnr type matnr,
end of ty_mara.
types : begin of ty_marc,
matnr type matnr,
werks type werks_d,
end of ty_marc.
types : begin of ty_makt,
matnr type matnr,
maktx type maktx,
end of ty_makt.
types : begin of ty_mard,
matnr type matnr,
lgort type lgort,
end of ty_mard.
types : begin of ty_final,
matnr type matnr,
werks type werks_d,
maktx type maktx,
lgort ty[e lgort,
end of ty_final.
*table type specification.
types : tt_mara type standard table of ty_mara,
tt_marc type standard table of ty_marc,
tt_makt type standard table of ty_makt,
tt_mard type standard table of ty_mard,
tt_final type standard table of ty_final.
*work area declaration.
data : wa_mara type ty_mara,
wa_marc type ty_marc,
wa_makt type ty_makt,
wa_mard type ty_mard,
wa_final type ty_final.
*internal table creation.
data : itab_mara type tt_mara,
itab_marc type tt_marc,
itab_makt type tt_makt,
itab_mard type tt_mard,
itab_final type tt_final.
*selection-screen
selection-screen : begin of block blk1 with frame title text-005.
parameters : p_matnr like mara-matnr .
select-options : s_werks for marc-werks .
data : gd_repid like sy-repid.
data : d_fieldcat type slis_t_fieldcat_alv,
d_fieldcat_wa type slis_fieldcat_alv.
data : t_header type slis_t_listheader,
wa_header type slis_listheader,
linecount(10) type c,
line(10) type c.
data : gd_layout type slis_layout_alv.
selection-screen : end of block blk1.
at selection-screen on s_werks.
select single * from marc where matnr = p_matnr and werks in s_werks.
if sy-subrc <> 0.
message e000(zmessage).
endif.
*begin of selection.
start-of-selection.
select matnr from mara into table itab_mara where matnr = p_matnr.
if not itab_mara is initial.
select matnr werks from marc into table itab_marc where werks in s_werks
and matnr = p_matnr.
if not itab_marc is initial.
select matnr maktx from makt into table itab_makt where matnr = p_matnr.
if not itab_mard is initial.
select matnr lgort from mard into table itab_mard where matnr = p_matnr.
*LAYOUT SPECIFICATION
*&---------------------------------------------------------------------*
*& Form set_pf_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RT_EXTAB text
*----------------------------------------------------------------------*
form set_pf_status using rt_extab type slis_t_extab.
set pf-status 'NEW'.
endform. "set_pf_status
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form top_of_page.
describe table itab_final lines line.
wa_header-typ ='A'.
linecount = line.
concatenate 'THe total no of records are:' linecount into wa_header-info separated by space.
append wa_header to t_header.
clear wa_header.
*&---------------------------------------------------------------------*
*& DATA DECLARATION *
*&---------------------------------------------------------------------*
TABLES: MARA, "GENERAL MASTER DATA
MARC, "PLANT DATA FOR MATERIAL
MARD, "STORAGE LOCATION DATA FOR MATERIAL
MBEW, "MATERIAL VALUATION
MVKE, "SALES DATA FOR MATERIAL
MAKT. "MATERIAL DESCRIPTION
DATA: BEGIN OF I_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,"MATERIAL NUMBER
MBRSH LIKE MARA-MBRSH,"INDUSTRY SECTOR
MEINS LIKE MARA-MEINS,"BASE UNIT OF MEASURE
END OF I_MARA.
DATA: BEGIN OF I_MARC OCCURS 0,
MATNR LIKE MARC-MATNR,"MATERIAL NUMBER
WERKS LIKE MARC-WERKS,"PLANT
LVORM LIKE MARC-LVORM,"FLAG MATERIAL FOR DELETION AT PLANT
"LEVEL
PSTAT LIKE MARC-PSTAT,"MAINTENANCE STATUS
DISPO LIKE MARC-DISPO,"MRP CONTROLLER
END OF I_MARC.
DATA: BEGIN OF I_MAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,"MATERIAL NUMBER
MAKTX LIKE MAKT-MAKTX,"MATERIAL DESCRIPTION
END OF I_MAKT.
DATA: BEGIN OF I_MVKE OCCURS 0,
MATNR LIKE MVKE-MATNR,"MATERIAL NUMBER
VKORG LIKE MVKE-VKORG,"SALES ORGANIZATION
VTWEG LIKE MVKE-VTWEG,"DISTRIBUTION CHANNEL
END OF I_MVKE.
DATA: BEGIN OF I_MARD OCCURS 0,
MATNR LIKE MARD-MATNR,"MATERIAL NUMBER
LGORT LIKE MARD-LGORT,"STORAGE LOCATION
LABST LIKE MARD-LABST,"VALUATED STOCK WITH UNRESTRICTED USE
END OF I_MARD.
DATA: BEGIN OF I_OUT OCCURS 0,
MATNR LIKE MARC-MATNR,
WERKS LIKE MARC-WERKS,
LVORM LIKE MARC-LVORM,
PSTAT LIKE MARC-PSTAT,
DISPO LIKE MARC-DISPO,
MBRSH LIKE MARA-MBRSH,
MEINS LIKE MARA-MEINS,
MAKTX LIKE MAKT-MAKTX,
VKORG LIKE MVKE-VKORG,
VTWEG LIKE MVKE-VTWEG,
LGORT LIKE MARD-LGORT,
LABST LIKE MARD-LABST,
END OF I_OUT.
DATA : TOT TYPE I. " TOT - TOTAL TO PRINT STOCK
*&---------------------------------------------------------------------*
*& S E L E C T I O N - S C R E E N *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-100.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR OBLIGATORY.
PARAMETERS: P_WERKS LIKE MARC-WERKS OBLIGATORY.
SELECT-OPTIONS: S_LGORT FOR MARD-LGORT,
S_DISPO FOR MARC-DISPO.
SELECTION-SCREEN END OF BLOCK B1.
*&-------------------------------------------------------------------*
*& I N I T I A L I Z A T I O N *
*&-------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& S T A R T - O F - S E L E C T I O N *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT MATNR WERKS LVORM DISPO FROM MARC
INTO CORRESPONDING FIELDS OF TABLE I_MARC
WHERE WERKS EQ P_WERKS
AND MATNR IN S_MATNR
AND DISPO IN S_DISPO
AND WERKS = P_WERKS.
IF I_MARC[] IS INITIAL.
WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MARC'.
EXIT.
ENDIF.
SELECT MATNR LGORT LABST FROM MARD INTO TABLE I_MARD
FOR ALL ENTRIES IN I_MARC
WHERE MATNR = I_MARC-MATNR
AND WERKS EQ P_WERKS
AND LGORT IN S_LGORT.
IF I_MARD[] IS INITIAL.
WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MARD'.
EXIT.
ENDIF.
SELECT MATNR VKORG VTWEG FROM MVKE INTO TABLE I_MVKE
FOR ALL ENTRIES IN I_MARC
WHERE MATNR = I_MARC-MATNR.
IF I_MVKE[] IS INITIAL.
WRITE:/ 'NO MATCHING DATA AVAILABLE FROM MVKE'.
EXIT.
ENDIF.
LOOP AT I_MARC.
MOVE-CORRESPONDING I_MARC TO I_OUT.
CLEAR MARC.
SELECT SINGLE MATNR MBRSH MEINS FROM MARA
INTO CORRESPONDING FIELDS OF MARA
WHERE MATNR = I_OUT-MATNR.
IF SY-SUBRC = 0.
MOVE: MARA-MBRSH TO I_OUT-MBRSH,
MARA-MEINS TO I_OUT-MEINS.
ELSE.
CONTINUE.
ENDIF.
SELECT SINGLE MATNR MAKTX FROM MAKT
INTO CORRESPONDING FIELDS OF MAKT
WHERE MATNR = I_OUT-MATNR.
IF SY-SUBRC = 0.
MOVE: MAKT-MAKTX TO I_OUT-MAKTX.
ELSE.
CONTINUE.
ENDIF.
LOOP AT I_MARD WHERE MATNR = I_MARC-MATNR.
MOVE: I_MARD-LABST TO I_OUT-LABST,
I_MARD-LGORT TO I_OUT-LGORT.
APPEND I_OUT.
ENDLOOP.
LOOP AT I_MVKE WHERE MATNR = I_MARC-MATNR.
MOVE: I_MVKE-VKORG TO I_OUT-VKORG,
I_MVKE-VTWEG TO I_OUT-VTWEG.
*&---------------------------------------------------------------------*
*& T O P - O F - P A G E *
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
WRITE:/ 'DATE:' ,SY-DATUM.
*&---------------------------------------------------------------------*
*& E N D - O F - P A G E *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& E N D -- O F -- S E L E C T I O N *
*&---------------------------------------------------------------------*
END-OF-SELECTION.
LOOP AT I_OUT.
AT FIRST.
WRITE :/ 'MATERIAL EXTRACTION REPORT',
SY-ULINE.
ENDAT.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.