SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Plant / Stock / Material report



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Fri Oct 05, 2007 11:41 pm    Post subject: Plant / Stock / Material report Reply with quote

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.


endif.
endif.
endif.

end-of-selection.

end of selection.


*assigning current program name.

gd_repid = sy-repid.



*declaration of fields using fieldcatalog.

d_fieldcat_wa-fieldname = 'MATNR'.
d_fieldcat_wa-seltext_l = 'material number'.
d_fieldcat_wa-col_pos = 1.
* d_fieldcat_wa-symbol = .
d_fieldcat_wa-emphasize = 'X'.

append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'MAKTX'.
d_fieldcat_wa-seltext_l = 'Description'.
d_fieldcat_wa-col_pos = 2.

append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'WERKS'.
d_fieldcat_wa-seltext_l = 'plant number'.
d_fieldcat_wa-col_pos = 3.

append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'QUANTITY'.
d_fieldcat_wa-seltext_l = 'quantity'.
d_fieldcat_wa-do_sum = 'X'.
d_fieldcat_wa-col_pos = 4.

append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'LGORT'.
d_fieldcat_wa-seltext_l = 'STORAGE LOCATION'.
d_fieldcat_wa-do_sum = 'X'.
d_fieldcat_wa-col_pos = 5.

append d_fieldcat_wa to d_fieldcat.
clear d_fieldcat_wa.


*call function module for display.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = gd_repid
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
* I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = gd_layout
IT_FIELDCAT = d_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'X'
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = itab_final
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


*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.

wa_header-typ = 'H'.
wa_header-info = 'ALV Report'.
append wa_header to t_header.
clear wa_header.

wa_header-typ = 'S'.
wa_header-key = 'Date :'.
concatenate Sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) into wa_header-info.
append wa_header to t_header.
clear wa_header.

wa_header-typ = 'S'.
wa_header-key = 'Time :'.
concatenate Sy-uzeit(2) ':'
sy-uzeit+2(2) ':'
sy-uzeit+4(2) into wa_header-info.
append wa_header to t_header.
clear wa_header.


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.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = t_header
I_LOGO = 'ZPICTURES'
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.

endform. "top_of_page

form gd_layout.

gd_layout-edit = 'X'.
gd_layout-zebra = 'X'.
*gd_layout-no_hotspot = 'X'.
*gd_layout-f2code = 'DISP'.
*gd_layout-colwidth_optimize = 'X'.

endform. "gd_layout


The Second Sample.
Code:
REPORT YSG_MATSTK_REP LINE-SIZE 220
LINE-COUNT 50(5).


*&---------------------------------------------------------------------*
*& 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 *
*&-------------------------------------------------------------------*

INITIALIZATION.

S_MATNR-SIGN = 'I'.
S_MATNR-OPTION = 'EQ'.
S_MATNR-LOW = 'M-14'.
S_MATNR-HIGH = 'M-18'.

P_WERKS = '3000'.

S_LGORT-SIGN = 'I'.
S_LGORT-OPTION = 'EQ'.
S_LGORT-LOW = '0001'.
S_LGORT-HIGH = '0004'.

S_DISPO-SIGN = 'I'.
S_DISPO-OPTION = 'EQ'.
S_DISPO-LOW = '001'.
S_DISPO-HIGH = '002'.


APPEND S_DISPO.
APPEND S_LGORT.
APPEND S_MATNR.

CLEAR S_DISPO.
CLEAR S_LGORT.
CLEAR S_MATNR.

*&---------------------------------------------------------------------*
*& 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.

APPEND I_OUT.
ENDLOOP.


CLEAR I_OUT.

ENDLOOP.


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\matstk.TXT'
FILETYPE = 'ASC'
TABLES
DATA_TAB = I_OUT.


*&---------------------------------------------------------------------*
*& 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 *
*&---------------------------------------------------------------------*

END-OF-PAGE.

WRITE: / SY-ULINE,
/100 'PAGNO: ',SY-PAGNO,
SY-ULINE.


*&---------------------------------------------------------------------*
*& 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.

WRITE:/ SY-VLINE,
I_OUT-MATNR,SY-VLINE,
I_OUT-MEINS,SY-VLINE,
I_OUT-WERKS,SY-VLINE,
I_OUT-LVORM,SY-VLINE,
I_OUT-PSTAT,SY-VLINE,
I_OUT-DISPO,SY-VLINE,
I_OUT-MBRSH,SY-VLINE,
I_OUT-MAKTX,SY-VLINE,
I_OUT-VKORG,SY-VLINE,
I_OUT-VTWEG,SY-VLINE,
I_OUT-LGORT,SY-VLINE,
I_OUT-LABST,SY-VLINE.


TOT = TOT + I_OUT-LABST.

AT NEW MATNR.
WRITE : 'NEW RECORD',
SY-VLINE.
ENDAT.

AT END OF LABST.
WRITE : 'STOCK = ',
TOT,
SY-VLINE,
SY-ULINE.
ENDAT.

AT LAST.
FORMAT COLOR 7 INTENSIFIED OFF.
WRITE : /159 'TOTAL STOCK = ',
TOT.
ENDAT.

ENDLOOP.
WRITE : /159 'TOTAL STOCK = ', TOT.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.