Posted: Mon Oct 08, 2007 4:51 pm Post subject: Show Material Master Views
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.
* 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.
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.