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

Show Material Master Views



 
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: Mon Oct 08, 2007 4:51 pm    Post subject: Show Material Master Views Reply with quote

Code:
REPORT WHATEVER.

* tables
TABLES: MARA, " Material Master: General Data
MSTA, " Material Master Status
T130M, " Transaction control parameters
T134. " Material Types

* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK DIRECT1 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN: SKIP.
PARAMETER: P_MATNR LIKE MSTA-MATNR MEMORY ID MAT OBLIGATORY.
PARAMETER: P_TCODE LIKE T130M-TCODE OBLIGATORY DEFAULT 'MM03'.
SELECTION-SCREEN: END OF BLOCK DIRECT1.
SELECTION-SCREEN: BEGIN OF BLOCK DIRECT2 WITH FRAME TITLE TEXT-014.
SELECTION-SCREEN: SKIP.
PARAMETER: P_DISPL AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN: END OF BLOCK DIRECT2.

* data
DATA: T_VIEWS LIKE MSTA OCCURS 0 WITH HEADER LINE.
DATA: T_MSTA LIKE MSTA OCCURS 0 WITH HEADER LINE.
DATA: W_LINES TYPE I.
DATA: W_LENGTH TYPE I.
DATA: W_TKSTATUS LIKE T130M-PSTAT VALUE 'ABCDEFGKLPQSVXZ'.
DATA: W_BILDSEQUENZ LIKE T133A-BILDS VALUE '21'.
DATA: TKSTATUS LIKE T130M-PSTAT.
DATA: W_ANZGSTATUS LIKE T130M-PSTAT.
DATA: W_STRING(15) TYPE C.
DATA: W_OFFSET LIKE SY-TABIX.

DATA: BEGIN OF BILDTAB OCCURS 0.
INCLUDE STRUCTURE MBILDTAB.
DATA: END OF BILDTAB.

DATA: BEGIN OF ITAB1 OCCURS 0,
STATM LIKE MSTA-STATM,
DYTXT LIKE BILDTAB-DYTXT,
GUIFU LIKE BILDTAB-GUIFU,
END OF ITAB1.

*Constants
CONSTANTS: C_WORK_SCHEDULING LIKE T132-STATM VALUE 'A',
C_ACCOUNTING LIKE T132-STATM VALUE 'B',
C_CLASSIFICATION LIKE T132-STATM VALUE 'C',
C_MRP LIKE T132-STATM VALUE 'D',
C_PURCHASING LIKE T132-STATM VALUE 'E',
C_PRODUCTION_RES LIKE T132-STATM VALUE 'F',
C_COSTING LIKE T132-STATM VALUE 'G',
C_BASIC_DATA LIKE T132-STATM VALUE 'K',
C_STORAGE LIKE T132-STATM VALUE 'L',
C_FORECASTING LIKE T132-STATM VALUE 'P',
C_QUALITY_MAN LIKE T132-STATM VALUE 'Q',
C_WAREHOUSE_MAN LIKE T132-STATM VALUE 'S',
C_SALES LIKE T132-STATM VALUE 'V',
C_PLANT_STOCKS LIKE T132-STATM VALUE 'X',
C_STORAGE_LOC LIKE T132-STATM VALUE 'Z'.

* Initialization.
GET PARAMETER ID 'MAT' FIELD P_MATNR.

START-OF-SELECTION.

* Select current maintenance status and material type
SELECT SINGLE VPSTA
MTART
FROM MARA
INTO (MARA-VPSTA,
MARA-MTART)
WHERE MATNR EQ P_MATNR.
IF SY-SUBRC <> 0.
SKIP.
WRITE: /001 P_MATNR, TEXT-009.
EXIT.
ENDIF.

* Select maintenance status for the material type
SELECT SINGLE PSTAT
FROM T134
INTO T134-PSTAT
WHERE MTART EQ MARA-MTART.
IF SY-SUBRC <> 0.
SKIP.
WRITE: /001 TEXT-010, MARA-MTART.
EXIT.
ENDIF.

* Select fields, according to tcode selected, for use in later fm
SELECT SINGLE TRREF
AKTYP
FROM T130M
INTO (T130M-TRREF,
T130M-AKTYP)
WHERE TCODE EQ P_TCODE.
IF SY-SUBRC <> 0.
SKIP.
WRITE: /001 TEXT-006, P_TCODE.
EXIT.
ENDIF.

* Get screen sequence number, used in later fm
CLEAR W_BILDSEQUENZ.
CALL FUNCTION 'BILDSEQUENZ_IDENTIFY'
EXPORTING
KZRFB = 'X'
TCODE_REF = T130M-TRREF
IMPORTING
BILDSEQUENZ = W_BILDSEQUENZ.
IF SY-SUBRC <> 0.
SKIP.
WRITE: /001 TEXT-011, SY-SUBRC.
EXIT.
ENDIF.

* Select maintenance views that have been created/extended
SELECT *
INTO TABLE T_VIEWS
FROM MSTA
WHERE MATNR = P_MATNR
ORDER BY STATM ZHLER.

* Strip out old views
DESCRIBE TABLE T_VIEWS LINES W_LINES.
WHILE W_LINES > 0.
READ TABLE T_VIEWS INDEX 1.
CLEAR T_MSTA.
MOVE T_VIEWS TO T_MSTA.
LOOP AT T_VIEWS WHERE STATM = T_MSTA-STATM.
IF T_VIEWS-ZHLER < T_MSTA-ZHLER.
CLEAR T_MSTA.
MOVE T_VIEWS TO T_MSTA.
ENDIF.
ENDLOOP.
APPEND T_MSTA.
DELETE T_VIEWS WHERE STATM = T_MSTA-STATM.
DESCRIBE TABLE T_VIEWS LINES W_LINES.
ENDWHILE.

SORT T_MSTA BY STATM.

* Display user and material's views
SKIP.
WRITE: /001 TEXT-015, SY-UNAME.
SKIP.
WRITE: /001 TEXT-002, P_MATNR.
SKIP.
LOOP AT T_MSTA.
WRITE: /001 T_MSTA-STATM.
PERFORM DISPLAY_VIEW.
ENDLOOP.
SKIP.
WRITE: /001 TEXT-008, MARA-VPSTA.

* Display user's views
CLEAR TKSTATUS.
CALL FUNCTION 'MATERIAL_INIT'
EXPORTING
TCODE = P_TCODE
KZ_BERPRF = 'X'
IMPORTING
TKSTATUS = TKSTATUS
EXCEPTIONS
NO_AUTHORITY = 01.
IF SY-SUBRC <> 0.
SKIP.
WRITE: /001 TEXT-012, SY-SUBRC.
EXIT.
ENDIF.

CLEAR W_ANZGSTATUS.
CALL FUNCTION 'ANZGSTATUS_SETZEN'
EXPORTING
AKTYP = T130M-AKTYP
MARASTATUS = MARA-VPSTA
T134STATUS = T134-PSTAT
TKSTATUS = TKSTATUS
IMPORTING
ANZGSTATUS = W_ANZGSTATUS
EXCEPTIONS
ANZGSTATUS_EMPTY = 1
WRONG_CALL = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
SKIP.
WRITE: /001 TEXT-013, SY-SUBRC.
EXIT.
ENDIF.

* Delete missing statii
LOOP AT T_MSTA.
IF W_ANZGSTATUS NS T_MSTA-STATM.
DELETE T_MSTA.
ENDIF.
ENDLOOP.

* Add statii
MOVE W_ANZGSTATUS TO W_STRING.
LOOP AT T_MSTA.
IF W_STRING CS T_MSTA-STATM.
REPLACE T_MSTA-STATM WITH ' ' INTO W_STRING.
ENDIF.
ENDLOOP.

CONDENSE W_STRING NO-GAPS.
W_LENGTH = STRLEN( W_STRING ).
CLEAR W_OFFSET.
WHILE W_OFFSET < W_LENGTH.
MOVE W_STRING+W_OFFSET(1) TO T_MSTA-STATM.
APPEND T_MSTA.
W_OFFSET = W_OFFSET + 1.
ENDWHILE.

SKIP.
WRITE: /001 TEXT-007, SY-UNAME.
SKIP.
LOOP AT T_MSTA.
WRITE /001 T_MSTA-STATM.
PERFORM DISPLAY_VIEW.
ENDLOOP.

* Reaminder of processing
PERFORM BILDTAB.
PERFORM DISPLAY_SCREEN.
PERFORM END_OF_REPORT.

*---------------------------------------------------------------------*
* FORM DISPLAY_VIEW *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM DISPLAY_VIEW.

CASE T_MSTA-STATM.
WHEN C_WORK_SCHEDULING. WRITE 'Work scheduling'.
WHEN C_ACCOUNTING. WRITE 'Accounting'.
WHEN C_CLASSIFICATION. WRITE 'Classification'.
WHEN C_MRP. WRITE 'MRP'.
WHEN C_PURCHASING. WRITE 'Purchasing'.
WHEN C_PRODUCTION_RES. WRITE 'Production resources/tools'.
WHEN C_COSTING. WRITE 'Costing'.
WHEN C_BASIC_DATA. WRITE 'Basic data'.
WHEN C_STORAGE. WRITE 'Storage'.
WHEN C_FORECASTING. WRITE 'Forecasting'.
WHEN C_QUALITY_MAN. WRITE 'Quality management'.
WHEN C_WAREHOUSE_MAN. WRITE 'Warehouse management'.
WHEN C_SALES. WRITE 'Sales'.
WHEN C_PLANT_STOCKS. WRITE 'Plant stocks'.
WHEN C_STORAGE_LOC. WRITE 'Storage location stocks'.
ENDCASE.

ENDFORM.

*---------------------------------------------------------------------*
* FORM BILDTAB *
*---------------------------------------------------------------------*
* Display shortcuts *
*---------------------------------------------------------------------*
FORM BILDTAB.

IF NOT P_DISPL IS INITIAL.
SKIP.
WRITE /001 TEXT-003.
SKIP.
ENDIF.

CALL FUNCTION 'SELECTION_VIEWS_FIND'
EXPORTING
BILDSEQUENZ = W_BILDSEQUENZ
PFLEGESTATUS = W_TKSTATUS
TABLES
BILDTAB = BILDTAB
EXCEPTIONS
CALL_WRONG = 1
EMPTY_SELECTION = 2
OTHERS = 3.
IF SY-SUBRC = 0.
LOOP AT BILDTAB.
IF NOT P_DISPL IS INITIAL.
WRITE: /001 BILDTAB-AUSWG,
BILDTAB-PSTAT,
BILDTAB-GUIFU,
BILDTAB-DYTXT,
BILDTAB-KZPRO.
ENDIF.
ENDLOOP.
ENDIF.

ENDFORM.

*---------------------------------------------------------------------*
* FORM DISPLAY_SCREEN *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM DISPLAY_SCREEN.

SKIP.

LOOP AT T_MSTA.
LOOP AT BILDTAB.
IF T_MSTA-STATM EQ BILDTAB-PSTAT.
MOVE T_MSTA-STATM TO ITAB1-STATM.
MOVE BILDTAB-DYTXT TO ITAB1-DYTXT.
MOVE BILDTAB-GUIFU TO ITAB1-GUIFU.
APPEND ITAB1.
ENDIF.
ENDLOOP.
ENDLOOP.

W_LENGTH = STRLEN( P_TCODE ) + 2.
WRITE /001 P_TCODE.
WRITE AT W_LENGTH TEXT-004.
SKIP.

SORT ITAB1 BY GUIFU.
LOOP AT ITAB1.
WRITE: /001 ITAB1-DYTXT, '(', ITAB1-GUIFU, ITAB1-STATM, ')'.
ENDLOOP.

ENDFORM.

*---------------------------------------------------------------------*
* FORM END_OF_REPORT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM END_OF_REPORT.

SKIP.
WRITE: /001 TEXT-005.

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