REPORT ZBMMR_001.
TYPE-POOLS:slis.
TABLES:mara,marc,makt,t001w,ztmm002,ztmm021,zbtmm001.
TYPES:BEGIN OF ty_mater,
werks TYPE marc-werks, "工厂代码
name1 TYPE t001w-name1, "工厂
matnr type marc-matnr, "物料号
mtart TYPE mara-mtart, "物料类型
matkl TYPE mara-matkl, "物料组
bismt TYPE mara-bismt, "旧物料号
meins TYPE mara-meins, "单位
maktx TYPE makt-maktx, "物料描述
maktx1 TYPE ztmm021-maktx2, "附加物料描述
pstat TYPE marc-pstat, "维护状态
lvorm TYPE marc-lvorm, "删除状态
zmaker TYPE ztmm002-zmaker, "制造商
zdocu TYPE zbtmm001-zdocu, "承认书编号
zacti TYPE zbtmm001-zacti, "承认时间
END OF ty_mater.
data:t_marc TYPE STANDARD TABLE OF marc WITH HEADER LINE,
w_marc TYPE marc,
t_mara TYPE STANDARD TABLE OF MARA WITH HEADER LINE,
w_mara TYPE mara,
t_t001w TYPE STANDARD TABLE OF t001w WITH HEADER LINE,
w_t001w TYPE t001w,
t_makt TYPE STANDARD TABLE OF makt WITH HEADER LINE,
w_makt TYPE makt,
t_makt1 TYPE STANDARD TABLE OF makt WITH HEADER LINE,
w_makt1 TYPE makt,
t_ztmm021 TYPE STANDARD TABLE OF ztmm021 WITH HEADER LINE,
w_ztmm021 TYPE ztmm021,
t_zbtmm001 TYPE STANDARD TABLE OF zbtmm001,
w_zbtmm001 TYPE zbtmm001,
t_ztmm002 TYPE STANDARD TABLE OF ztmm002,
w_ztmm002 TYPE ztmm002,
t_mater TYPE STANDARD TABLE OF ty_mater,
w_mater TYPE ty_mater.
DATA:t_fieldcat TYPE slis_t_fieldcat_alv,
w_fieldcat TYPE slis_fieldcat_alv,
w_layout TYPE slis_layout_alv,
t_sort TYPE slis_t_sortinfo_alv,
w_sort TYPE slis_sortinfo_alv.
SELECT-OPTIONS:g_matnr FOR marc-matnr.
SELECT-OPTIONS:g_mtart FOR mara-mtart.
SELECT-OPTIONS:g_matkl FOR mara-matkl.
SELECT-OPTIONS:g_maktx FOR makt-maktx.
SELECT-OPTIONS:g_maktx2 FOR ztmm021-maktx2.
SELECT-OPTIONS:g_maker FOR ztmm002-zmaker.
SELECT-OPTIONS:g_zdocu FOR zbtmm001-zdocu.
SELECT-OPTIONS:g_zacti FOR zbtmm001-zacti.
SELECT-OPTIONS:g_plant FOR marc-werks.
AT SELECTION-SCREEN.
START-OF-SELECTION.
PERFORM prm_get_marc.
PERFORM prm_get_data.
PERFORM prm_fieldcat.
PERFORM prm_layout.
PERFORM prm_sort.
PERFORM prm_callalv.
case sy-ucomm.
when 'DATA_SAVE'.
PERFORM prm_modify_zbtmm001.
when 'BACK'.
call selection-screen 1000.
when 'EXIT'.
leave program.
when others.
endcase.
end-of-SELECTION.
*&---------------------------------------------------------------------*
*& Form PRM_GET_MATER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_GET_MARC .
FREE t_marc.
SELECT * INTO CORRESPONDING FIELDS OF TABLE t_marc
FROM marc
WHERE matnr in g_matnr
AND werks in g_plant.
* FREE t_mara.
* SELECT * INTO CORRESPONDING FIELDS OF TABLE t_mara
* FROM mara
* WHERE matnr in g_matnr
* AND mtart in g_mtart
* AND matkl in g_matkl.
ENDFORM. " PRM_GET_MATER
*&---------------------------------------------------------------------*
*& Form PRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_GET_DATA .
if t_marc[] IS NOT INITIAL.
FREE t_mara.
SELECT * FROM mara
INTO CORRESPONDING FIELDS OF TABLE t_mara
FOR ALL ENTRIES IN t_marc
WHERE matnr = t_marc-matnr
AND mtart IN g_mtart
AND matkl IN g_matkl.
if sy-subrc eq 0.
if g_mtart is not initial or g_matkl is not initial.
clear:w_marc,w_mara.
loop at t_marc into w_marc.
READ TABLE t_mara INTO w_mara WITH KEY matnr = w_marc-matnr.
if sy-subrc ne 0.
DELETE TABLE t_marc FROM w_marc.
endif.
clear:w_marc,w_mara.
ENDLOOP.
endif.
else.
if g_mtart is not initial or g_matkl is not initial.
FREE t_marc.
endif.
endif.
* if t_mara[] IS NOT INITIAL.
*
* FREE t_marc.
* SELECT * FROM marc
* INTO CORRESPONDING FIELDS OF TABLE t_marc
* FOR ALL ENTRIES IN t_mara
* WHERE matnr = t_mara-matnr
* AND werks IN g_plant.
* if sy-subrc eq 0.
* if g_plant is not initial.
* clear:w_marc,w_mara.
* loop at t_mara into w_mara.
* READ TABLE t_marc INTO w_marc WITH KEY matnr = w_mara-matnr.
* if sy-subrc ne 0.
* DELETE TABLE t_mara FROM w_mara.
* endif.
* clear:w_marc,w_mara.
* ENDLOOP.
* endif.
* else.
* if g_plant is not initial.
* FREE t_mara.
* endif.
* endif.
FREE t_t001w.
SELECT * FROM t001w
INTO CORRESPONDING FIELDS OF TABLE t_t001w
FOR ALL ENTRIES IN t_marc
WHERE werks = t_marc-werks.
FREE t_makt.
SELECT * FROM makt
INTO CORRESPONDING FIELDS OF TABLE t_makt
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr
AND maktx in g_maktx.
if sy-subrc eq 0.
if g_maktx is not initial.
clear:w_marc,w_makt.
loop at t_marc into w_marc.
READ TABLE t_makt INTO w_makt WITH KEY matnr = w_marc-matnr.
if sy-subrc ne 0.
DELETE TABLE t_marc FROM w_marc.
endif.
clear:w_marc,w_makt.
ENDLOOP.
endif.
else.
if g_maktx is not initial.
FREE t_marc.
endif.
endif.
FREE t_makt1.
SELECT * FROM makt
INTO CORRESPONDING FIELDS OF TABLE t_makt1
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr
AND maktx in g_maktx2
AND SPRAS = 'Z'.
if sy-subrc eq 0.
if g_maktx2 is not initial.
clear:w_marc,w_makt1.
loop at t_marc into w_marc.
READ TABLE t_makt1 INTO w_makt1 WITH KEY matnr = w_marc-matnr.
if sy-subrc ne 0.
DELETE TABLE t_marc FROM w_marc.
endif.
clear:w_marc,w_makt1.
ENDLOOP.
endif.
else.
if g_maktx2 is not initial.
FREE t_marc.
endif.
endif.
FREE t_ztmm002.
SELECT * FROM ztmm002
INTO CORRESPONDING FIELDS OF TABLE t_ztmm002
FOR ALL ENTRIES IN t_mara
WHERE matnr = t_mara-matnr
AND zmaker IN g_maker.
if sy-subrc eq 0.
if g_maker is not initial.
clear:w_marc,w_ztmm002.
loop at t_marc into w_marc.
READ TABLE t_ztmm002 INTO w_ztmm002 WITH KEY matnr = w_marc-matnr.
if sy-subrc ne 0.
DELETE TABLE t_marc FROM w_marc.
endif.
clear:w_marc,w_ztmm002.
ENDLOOP.
endif.
else.
if g_maker is not initial.
FREE t_marc.
endif.
endif.
FREE t_zbtmm001.
SELECT * FROM zbtmm001
INTO CORRESPONDING FIELDS OF TABLE t_zbtmm001
FOR ALL ENTRIES IN t_marc
WHERE matnr = t_marc-matnr
AND werks = t_marc-werks
AND zdocu in g_zdocu
AND zacti in g_zacti.
if sy-subrc eq 0.
if g_zdocu is not INITIAL or g_zacti is not INITIAL.
clear:w_marc,w_zbtmm001.
loop at t_marc INTO w_marc.
READ TABLE t_zbtmm001 INTO w_zbtmm001 WITH KEY matnr = w_marc-matnr
werks = w_marc-werks.
* if w_zbtmm001-zdocu eq ' ' and w_zbtmm001-zacti eq '00000000'.
if sy-subrc ne 0.
delete TABLE t_marc FROM w_marc.
ENDIF.
* else.
* PERFORM prm_set_zbtmm001.
* MODIFY t_marc FROM w_marc.
* ENDIF.
clear:w_marc,w_zbtmm001.
ENDLOOP.
ENDIF.
else.
if g_zdocu is not INITIAL or g_zacti is not INITIAL.
FREE t_marc.
ENDIF.
ENDIF.
endif.
LOOP at t_marc INTO w_marc.
CLEAR:w_mara,w_t001w,w_makt,w_makt1,w_ztmm002,w_zbtmm001.
READ TABLE t_mara INTO w_mara WITH KEY matnr = w_marc-matnr.
READ TABLE t_t001w INTO w_t001w WITH KEY werks = w_marc-werks.
READ TABLE t_makt INTO w_makt WITH KEY matnr = w_mara-matnr.
READ TABLE t_makt1 INTO w_makt1 WITH KEY matnr = w_mara-matnr spras = 'Z'.
READ TABLE t_ztmm002 INTO w_ztmm002 WITH KEY matnr = w_mara-matnr.
READ TABLE t_zbtmm001 INTO w_zbtmm001 WITH KEY matnr = w_marc-matnr
werks = w_marc-werks.
clear w_mater.
w_mater-werks = w_marc-werks.
w_mater-name1 = w_t001w-name1.
w_mater-matnr = w_mara-matnr.
w_mater-mtart = w_mara-mtart.
w_mater-matkl = w_mara-matkl.
w_mater-bismt = w_mara-bismt.
w_mater-meins = w_mara-meins.
w_mater-maktx = w_makt-maktx.
w_mater-maktx1 = w_makt1-maktx.
w_mater-pstat = w_mara-pstat.
w_mater-lvorm = w_mara-lvorm.
w_mater-zmaker = w_ztmm002-zmaker.
w_mater-zdocu = w_zbtmm001-zdocu.
w_mater-zacti = w_zbtmm001-zacti.
APPEND w_mater to t_mater.
ENDLOOP.
ENDFORM. "PRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form PRM_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_FIELDCAT .
DATA : num(2) TYPE n.
num = 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'WERKS'.
w_fieldcat-seltext_l = text-001.
w_fieldcat-seltext_m = text-001.
w_fieldcat-seltext_s = text-001.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'NAME1'.
w_fieldcat-seltext_l = text-002.
w_fieldcat-seltext_m = text-002.
w_fieldcat-seltext_s = text-002.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'MATNR'.
w_fieldcat-seltext_l = text-003.
w_fieldcat-seltext_m = text-003.
w_fieldcat-seltext_s = text-003.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'MTART'.
w_fieldcat-seltext_l = text-004.
w_fieldcat-seltext_m = text-004.
w_fieldcat-seltext_s = text-004.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'MATKL'.
w_fieldcat-seltext_l = text-005.
w_fieldcat-seltext_m = text-005.
w_fieldcat-seltext_s = text-005.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'MEINS'.
w_fieldcat-seltext_l = text-012.
w_fieldcat-seltext_m = text-012.
w_fieldcat-seltext_s = text-012.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'MAKTX'.
w_fieldcat-seltext_l = text-007.
w_fieldcat-seltext_m = text-007.
w_fieldcat-seltext_s = text-007.
w_fieldcat-no_zero = 'X'.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'MAKTX1'.
w_fieldcat-seltext_l = text-013.
w_fieldcat-seltext_m = text-013.
w_fieldcat-seltext_s = text-013.
w_fieldcat-no_zero = 'X'.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'PSTAT'.
w_fieldcat-seltext_l = text-008.
w_fieldcat-seltext_m = text-008.
w_fieldcat-seltext_s = text-008.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'LVORM'.
w_fieldcat-seltext_l = text-009.
w_fieldcat-seltext_m = text-009.
w_fieldcat-seltext_s = text-009.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'ZMAKER'.
w_fieldcat-seltext_l = text-014.
w_fieldcat-seltext_m = text-014.
w_fieldcat-seltext_s = text-014.
w_fieldcat-no_zero = 'X'.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'ZDOCU'.
w_fieldcat-ref_fieldname = 'ZDOCU'.
w_fieldcat-ref_tabname = 'ZBTMM001'.
w_fieldcat-ddic_outputlen = 20.
w_fieldcat-seltext_l = text-010.
w_fieldcat-seltext_m = text-010.
w_fieldcat-seltext_s = text-010.
w_fieldcat-edit = 'X'.
APPEND w_fieldcat TO t_fieldcat.
num = num + 1.
CLEAR w_fieldcat.
w_fieldcat-col_pos = num.
w_fieldcat-fieldname = 'ZACTI'.
w_fieldcat-ref_fieldname = 'ZACTI'.
w_fieldcat-ref_tabname = 'ZBTMM001'.
w_fieldcat-seltext_l = text-011.
w_fieldcat-seltext_m = text-011.
w_fieldcat-seltext_s = text-011.
w_fieldcat-edit = 'X'.
APPEND w_fieldcat TO t_fieldcat.
ENDFORM. " PRM_FIELDCAT
*&---------------------------------------------------------------------*
*& Form PRM_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_LAYOUT .
"w_layout-colwidth_optimize = 'X'.
w_layout-zebra = 'X'.
ENDFORM. " PRM_LAYOUT
*&---------------------------------------------------------------------*
*& Form PRM_SORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_SORT .
CLEAR w_sort.
w_sort-up = 'X'.
APPEND w_sort TO t_sort.
ENDFORM. " PRM_SORT
*&---------------------------------------------------------------------*
*& Form PRM_CALLALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_CALLALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
i_callback_pf_status_set = 'FORM_ALV_STATUS'
i_callback_user_command = 'FORM_ALV_COMMAND'
* I_CALLBACK_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 = w_layout
IT_FIELDCAT = t_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT = t_sort
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* 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 = t_mater
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.
ENDFORM. " PRM_CALLALV
*&---------------------------------------------------------------------*
*& Form PRM_MODIFY_ZBTMM001
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PRM_MODIFY_ZBTMM001 .
LOOP AT t_mater INTO w_mater." WHERE zdocu ne ' ' AND zacti ne ' '.
w_zbtmm001-matnr = w_mater-matnr.
w_zbtmm001-werks = w_mater-werks.
w_zbtmm001-zdocu = w_mater-zdocu.
w_zbtmm001-zacti = w_mater-zacti.
if w_mater-werks is NOt INITIAL.
MODIFY zbtmm001 FROM w_zbtmm001.
if sy-subrc eq 0.
message '物料承认书编号维护成功' TYPE 'S'.
endif.
else.
MESSAGE '物料未维护在工厂端,不能编辑物料编码' TYPE 'E'.
ENDIF.
ENDLOOP.
ENDFORM. " PRM_MODIFY_ZBTMM001
*&---------------------------------------------------------------------*
*& Form FORM_ALV_STATUS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form form_alv_status using pt_extab type slis_t_extab.
set pf-status 'STANDARD_FULLSCREEN' excluding pt_extab.
endform. " FORM_ALV_STATUS
*&---------------------------------------------------------------------*
*& Form form_alv_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PU_UCOMM text
* -->PU_SELFIELD text
*----------------------------------------------------------------------*
form form_alv_command using g_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case sy-ucomm.
when '&DATA_SAVE'.
PERFORM prm_modify_zbtmm001.
when 'BACK'.
call selection-screen 1000.
when 'EXIT'.
leave program.
when others.
endcase.
endform. "form_alv_command