REPORT Z_ALV_MARCO.
TYPE-POOLS SLIS.
TABLES: MARA,MAST,STKO,STPO,MAKT.
DATA: BEGIN OF I_MARA OCCURS 0,
MATNR LIKE MARA-MATNR,
END OF I_MARA.
DATA: BEGIN OF I_MAST OCCURS 0 ,
MATNR LIKE MAST-MATNR,
STLNR LIKE MAST-STLNR,
IDNRK LIKE STPO-IDNRK,
MENGE LIKE STPO-MENGE,
MAKTX LIKE MAKT-MAKTX,
MAKTG LIKE MAKT-MAKTX,
END OF I_MAST.
DATA: BEGIN OF I_STKO OCCURS 0,
IDNRK LIKE STPO-IDNRK,
MENGE LIKE STPO-MENGE,
STLNR LIKE STPO-STLNR,
END OF I_STKO.
FIELD-SYMBOLS: LIKE LINE OF I_MAST.
DATA: G_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: IT_SORT TYPE SLIS_T_SORTINFO_ALV.
DATA: WA_SORT TYPE SLIS_SORTINFO_ALV.
SELECT-OPTIONS: R_MATNR FOR MARA-MATNR.
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(28) V_1 FOR FIELD P_MAX.
PARAMETERS P_MAX(3) TYPE N DEFAULT '200' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
V_1 = 'Maximum of records to read'.
START-OF-SELECTION.
PERFORM F_GET_DATA.
PERFORM F_DISPLAY_DATA.
*&---------------------------------------------------------------------*
*& Form f_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_GET_DATA .
CLEAR I_MARA.
" 取整机物料
SELECT * INTO CORRESPONDING FIELDS OF TABLE I_MARA FROM MARA UP TO P_MAX ROWS WHERE MATNR IN R_MATNR AND MATKL = '1001' .
IF NOT I_MARA[] IS INITIAL.
CLEAR I_MAST.
REFRESH I_MAST.
SELECT * INTO CORRESPONDING FIELDS OF TABLE I_MAST FROM MAST JOIN STKO ON STKO~STLNR = MAST~STLNR FOR ALL ENTRIES IN I_MARA
WHERE MATNR = I_MARA-MATNR
AND STKO~LKENZ = ''
AND STKO~STLAL = '01'
AND MAST~WERKS = ''
AND MAST~STLAN = '1'
AND MAST~STLAL = '01'.
FREE I_MARA.
SORT I_MAST BY MATNR.
CLEAR I_STKO.
REFRESH I_STKO.
SELECT * INTO CORRESPONDING FIELDS OF TABLE I_STKO FROM STPO
FOR ALL ENTRIES IN I_MAST
WHERE STLNR = I_MAST-STLNR
AND STPO~STLTY = 'M'
AND STPO~LKENZ = ''.
SORT I_STKO BY STLNR.
LOOP AT I_MAST ASSIGNING .
READ TABLE I_STKO WITH KEY STLNR = -STLNR BINARY SEARCH .
IF SY-SUBRC = 0 .
-IDNRK = I_STKO-IDNRK.
-MENGE = I_STKO-MENGE.
MODIFY I_MAST FROM .
ENDIF.
ENDLOOP.
FREE I_STKO.
SORT I_MAST BY MATNR .
LOOP AT I_MAST ASSIGNING .
CLEAR: -MAKTX,-MAKTG .
SELECT SINGLE MAKTX INTO -MAKTX FROM MAKT WHERE MATNR = -MATNR AND SPRAS = SY-LANGU.
SELECT SINGLE MAKTX INTO -MAKTG FROM MAKT WHERE MATNR = -IDNRK AND SPRAS = SY-LANGU.
MODIFY I_MAST FROM .
ENDLOOP.
ELSE.
MESSAGE 'NO FOUND!' TYPE 'E'.
ENDIF.
ENDFORM. " f_get_data
*&---------------------------------------------------------------------*
*& Form f_display_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F_DISPLAY_DATA .
DEFINE ADD_FIELDCAT.
* WA_FIELDCAT-FIELDNAME = '&1'.
* WA_FIELDCAT-SELTEXT_M = '&2'.
** WA_FIELDCATCOL_POS = NN.
* WA_FIELDCAT-OUTPUTLEN = &3.
* WA_FIELDCAT-DATATYPE = &4.
* WA_FIELDCAT-NO_ZERO = 'X'.
* WA_FIELDCAT-DO_SUM = &5.
* WA_FIELDCAT-KEY = &6."锁定列
** WS_FIELD-just = &7."定义左L、中C、右R
* WA_FIELDCAT-EMPHASIZE = 'C2'.
* WA_FIELDCAT-EDIT = ''." 定义字段可更改
WA_FIELDCAT-FIELDNAME = &1.
WA_FIELDCAT-SELTEXT_L = &2.
WA_FIELDCAT-NO_ZERO = &3.
WA_FIELDCAT-DO_SUM = &4.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
END-OF-DEFINITION.
DEFINE ADD_SORT.
WA_SORT-FIELDNAME = &1.
WA_SORT-SPOS = &2.
WA_SORT-UP = &3.
APPEND WA_SORT TO IT_SORT.
CLEAR WA_SORT.
END-OF-DEFINITION.
G_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ADD_FIELDCAT 'MATNR' '物料号' 'X' ''.
ADD_FIELDCAT 'MAKTX' '物料描述' '' ''.
ADD_FIELDCAT 'IDNRK' 'BOM 组件' 'X' ''.
ADD_FIELDCAT 'MAKTG' '组件描述' 'X' ''.
ADD_FIELDCAT 'MENGE' '数量' 'X' ''.
ADD_SORT 'MATNR' 1 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FIELDCAT
IS_LAYOUT = G_LAYOUT
IT_SORT = IT_SORT
I_SAVE = 'A'
TABLES
T_OUTTAB = I_MAST.
ENDFORM. " f_display_data
阅读(649) | 评论(0) | 转发(1) |