ITPub博客

首页 > 数字化转型 > ERP > SAP物料主檔新舊物料碼對照

SAP物料主檔新舊物料碼對照

原创 ERP 作者:tolyhuang 时间:2007-12-07 11:23:56 0 删除 编辑
程式代碼:[@more@] report ZRP_NEW_OLD_MATNR.

tables: mara, makt, marc.

type-pools: slis.
data: fieldcat type slis_t_fieldcat_alv,
fieldcat_ln like line of fieldcat,
event_exit type slis_t_event_exit,
event_exit_ln like line of event_exit,
sortcat type slis_t_sortinfo_alv,
sortcat_ln like line of sortcat,
eventcat type slis_t_event,
eventcat_ln like line of eventcat.

data: gt_list_top_of_page type slis_t_listheader.
data: gc_formname_top_of_page type slis_formname value 'ALV_TOP_OF_PAGE'.
data : ps_layout type slis_layout_alv.

data: begin of wa_mara,
matnr like mara-matnr, "物料編碼
bismt like mara-bismt, "舊物料碼
werks like marc-werks, "工廠
matkl like mara-matkl, "物料群組
cmaktx like makt-maktx, "短文(中)
emaktx like makt-maktx, "短文(英)
chidesc type string, "長文(中)
engdesc type string, "長文(英)
spart like mara-spart, "部門
lvorm like mara-lvorm,
ersda like mara-ersda, "建立日期
ernam like mara-ernam, "建立人
laeda like mara-laeda, "修改日期
aenam like mara-aenam, "修改人
end of wa_mara.

data: it_mara like wa_mara occurs 0 with header line.

data: ittline like tline occurs 0 with header line.
data: tdname like thead-tdname.


selection-screen begin of block a001 with frame title t1.

select-options: v_matnr for mara-matnr,
v_werks for marc-werks,
v_mtart for mara-mtart obligatory,
v_matkl for mara-matkl,
v_bismt for mara-bismt,
v_spart for mara-spart,
v_ersda for mara-ersda,
v_ernam for mara-ernam,
v_laeda for mara-laeda,
v_aenam for mara-aenam.
selection-screen end of block a001.

selection-screen begin of block a002 with frame title t2.
parameter: p_lvorm as checkbox default 'X'.
selection-screen end of block a002.


initialization.
t1 = '基本搜索條件'.
t2 = '顯示選項'.

start-of-selection.
perform get_data.
refresh gt_list_top_of_page[].
perform e04_comment_build .
clear fieldcat.
refresh fieldcat.
perform build_fieldcat.
perform build_eventcat.
perform alv_display.


*&---------------------------------------------------------------------*
*& FORM GET_DATA
*&---------------------------------------------------------------------*
* 根據輸入的條件提取數據資料
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
form get_data .

if v_werks = ''.
select * into corresponding fields of table it_mara
from mara
where matnr in v_matnr
and mtart in v_mtart
and matkl in v_matkl
and bismt in v_bismt
and spart in v_spart
and ersda in v_ersda
and ernam in v_ernam
and laeda in v_laeda
and aenam in v_aenam
and matnr <> ''.

else.
select a~matnr a~bismt a~matkl a~spart a~lvorm a~ersda a~ernam a~laeda a~aenam b~werks into corresponding fields of table it_mara
from mara as a
inner join marc as b on a~matnr = b~matnr
where a~matnr in v_matnr
and werks in v_werks
and mtart in v_mtart
and matkl in v_matkl
and bismt in v_bismt
and spart in v_spart
and ersda in v_ersda
and ernam in v_ernam
and laeda in v_laeda
and aenam in v_aenam.
endif.

if p_lvorm = 'X'.
delete it_mara where lvorm = 'X'.
endif.

loop at it_mara into wa_mara.

select single maktx into wa_mara-cmaktx from makt where spras = 'M' and matnr = wa_mara-matnr.

select single maktx into wa_mara-emaktx from makt where spras = 'E' and matnr = wa_mara-matnr.



"長英文描述
clear: ittline, ittline[].
clear tdname.
tdname = wa_mara-matnr.
call function 'READ_TEXT'
exporting
client = sy-mandt
id = 'GRUN'
language = 'E'
name = tdname
object = 'MATERIAL'
tables
lines = ittline
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
others = 8.

loop at ittline.
wa_mara-engdesc = ittline-tdline.
endloop.

"長中文描述
clear: ittline, ittline[].
call function 'READ_TEXT'
exporting
client = sy-mandt
id = 'GRUN'
language = 'M'
name = tdname
object = 'MATERIAL'
tables
lines = ittline
exceptions
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
others = 8.

loop at ittline.
wa_mara-chidesc = ittline-tdline.
endloop.

modify it_mara from wa_mara transporting engdesc chidesc cmaktx emaktx where matnr = wa_mara-matnr.
clear wa_mara.
endloop.

endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_fieldcat .
data : col_pos type i value 0.

ps_layout-get_selinfos = 'X'.
ps_layout-colwidth_optimize = 'X'.
ps_layout-detail_popup = 'X'.
ps_layout-no_keyfix = ''.
ps_layout-colwidth_optimize = 'X'.


add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-ref_fieldname = 'MATNR'.
fieldcat_ln-fieldname = 'MATNR'.
fieldcat_ln-key = 'X'.
fieldcat_ln-seltext_s = '新物料編碼'.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '新物料編碼'.
fieldcat_ln-seltext_l = '新物料編碼'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'BISMT'.
fieldcat_ln-seltext_s = '舊物料編碼'.
" fieldcat_ln-no_zero = 'X'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '舊物料編碼'.
fieldcat_ln-seltext_l = '舊物料編碼'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'MATKL'.
fieldcat_ln-seltext_s = '物料群組'.
" fieldcat_ln-no_zero = 'X'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '物料群組'.
fieldcat_ln-seltext_l = '物料群組'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'CMAKTX'.
fieldcat_ln-seltext_s = '短中文描述'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '短中文描述'.
fieldcat_ln-seltext_l = '短中文描述'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'EMAKTX'.
fieldcat_ln-seltext_s = '短英文描述'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '短英文描述'.
fieldcat_ln-seltext_l = '短英文描述'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'CHIDESC'.
fieldcat_ln-seltext_s = '長中文描述'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '長中文描述'.
fieldcat_ln-seltext_l = '長中文描述'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'ENGDESC'.
fieldcat_ln-seltext_s = '長英文描述'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '長英文描述'.
fieldcat_ln-seltext_l = '長英文描述'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'SPART'.
fieldcat_ln-seltext_s = '部門'.
" fieldcat_ln-no_zero = 'X'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '部門'.
fieldcat_ln-seltext_l = '部門'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'LVORM'.
fieldcat_ln-seltext_s = '刪除標記'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '刪除標記'.
fieldcat_ln-seltext_l = '刪除標記'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'ERSDA'.
fieldcat_ln-seltext_s = '建立日期'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '建立日期'.
fieldcat_ln-seltext_l = '建立日期'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'ERNAM'.
fieldcat_ln-seltext_s = '建立人'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '建立人'.
fieldcat_ln-seltext_l = '建立人'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'LAEDA'.
fieldcat_ln-seltext_s = '最後修改日期'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '最後修改日期'.
fieldcat_ln-seltext_l = '最後修改日期'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'IT_MARA'.
fieldcat_ln-fieldname = 'AENAM'.
fieldcat_ln-seltext_s = '最後修改人'.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = '最後修改人'.
fieldcat_ln-seltext_l = '最後修改人'.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.

endform. " BUILD_FIELDCAT

*&---------------------------------------------------------------------*
*& Form BUILD_EVENTCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_eventcat .
data : ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = eventcat.

read table eventcat
with key name = slis_ev_top_of_page
into ls_event.
if sy-subrc = 0.
move gc_formname_top_of_page to ls_event-form.
append ls_event to eventcat.
endif.
endform. " BUILD_EVENTCAT
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form alv_display .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
is_layout = ps_layout
it_fieldcat = fieldcat
i_save = 'A'
it_events = eventcat
tables
t_outtab = it_mara
exceptions
program_error = 1
others = 2.
endform. " ALV_DISPLAY


*&--------------------------------------------------------------------*
*& FORM USER_COMMAND
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
* -->UCOMM TEXT
* -->SELFIELD TEXT
*---------------------------------------------------------------------*
form user_command using ucomm like sy-ucomm
selfield type slis_selfield.
read table it_mara index selfield-tabindex.
check sy-subrc = 0.
case ucomm.
when '&IC1'.
case selfield-sel_tab_field.
when 'IT_MARA-MATNR'.
set parameter id 'MAT' field it_mara-matnr.
call transaction 'MM03' and skip first screen.
endcase.
when 'PRI' .
endcase.
endform. "USER_COMMAND

*&---------------------------------------------------------------------*
*& Form alv_top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form alv_top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = gt_list_top_of_page.
endform. "ALV_TOP_OF_PAGE

*&---------------------------------------------------------------------*
*& Form e04_comment_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form e04_comment_build .
data : list_line like line of gt_list_top_of_page.
data: i_count type i, c_count(5) type c.
list_line-typ = 'H'.
list_line-key = ''.

describe table it_mara lines i_count.
c_count = i_count.

concatenate '符合條件的記錄數:' c_count into list_line-info.

append list_line to gt_list_top_of_page.
endform. " e04_comment_build

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9437124/viewspace-989486/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-22

  • 博文量
    268
  • 访问量
    1413841