根据分类码查找特性清单
例子:
call function 'BAPI_CLASS_GET_CHARACTERISTICS'
exporting
classnum = ip_class "分类码
classtype = '001' "物料分类
* LANGU_ISO =
* LANGU_INT =
* KEY_DATE = SY-DATUM
* WITH_VALUES = 'X'
* IMPORTING
* RETURN =
tables
characteristics = t_characterlist "对应分类的特性清单
char_values = char_values "特性的值选项
根据分类码查找物料码清单
call function 'BAPI_CLASS_SELECT_OBJECTS'
exporting
classtype = '001' "001為物料分類
classnum = ip_class "分類碼
* LANGUISO =
* LANGUINT =
* KEYDATE = SY-DATUM
* MAXHITS = 100
* I_STATUS_LOCKED =
* I_STATUS_INCOMPLETE =
* IMPORTING
* RETURN =
tables
selectioncriterions = selectioncriterions "可能由特性值資料查找物料碼
selectedobjects = t_matnrlist "找到的物料清單
* OBJECTCLASSIFICATION =
.
根据物料码查找分类特性
例子:
call function 'CLAF_CLASSIFICATION_OF_OBJECTS'
exporting
* CLASS = ' '
* CLASSTEXT = 'X'
classtype = '001'
* CLINT = 0
* FEATURES = 'X'
* LANGUAGE = SY-LANGU
object = objek_matnr "物料碼
* OBJECTTABLE = ' '
* KEY_DATE = SY-DATUM
* INITIAL_CHARACT = 'X'
* NO_VALUE_DESCRIPT =
* CHANGE_SERVICE_CLF = 'X'
* INHERITED_CHAR = ' '
* CHANGE_NUMBER = ' '
tables
t_class = t_class "物料分类
t_objectdata = t_objectdata 分类特性值列表
* I_SEL_CHARACTERISTIC =
* T_NO_AUTH_CHARACT =
* EXCEPTIONS
* NO_CLASSIFICATION = 1
* NO_CLASSTYPES = 2
* INVALID_CLASS_TYPE = 3
* OTHERS = 4
根據選擇的物料顯示其特性值
report zrp_show_material_chara.
include <list>.
tables: mara, makt, marc, ausp, kssk, klah, ksml, cabn, cabnt.
data: gt_fieldcat type lvc_t_fcat.
data: gp_table type ref to data.
field-symbols: <gt_table> type table.
data: g_title type string.
data: begin of wa_fieldlist,
atinn like ausp-atinn, "特性碼
atbez like cabnt-atbez, "特性名稱
atfor like cabn-atfor, "資料類型
anzst like cabn-anzst, "字元數
anzdz like cabn-anzdz, "小數位數
end of wa_fieldlist.
data: it_fieldlist like wa_fieldlist occurs 0 with header line.
data: ok_code like sy-ucomm,
g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
grid1 type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container.
"ALV定義
type-pools: slis.
data: fieldcat type slis_t_fieldcat_alv,
gt_sort type slis_t_sortinfo_alv,
gs_sort type slis_sortinfo_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_itab,
matnr like mara-matnr, "物料編碼
maktx like makt-maktx, "物料短文說明
lvorm like mara-lvorm, "標識刪除物料
class like klah-class, "分類碼
atinn like ausp-atinn, "特性碼
atbez like cabnt-atbez, "特性說明
atfor like cabn-atfor, "類值型
atwrt like ausp-atwrt, "特性字串值
atflv like ausp-atflv, "物料數據值
zvalue like ausp-atwrt, "特性值
aterf like cabn-aterf, "必須輸入
msehi like cabn-msehi, "單位
end of wa_itab.
data: itab like wa_itab occurs 0 with header line.
selection-screen begin of block b2 with frame title t2.
parameter: p_opt1 radiobutton group grp1 default 'X',
p_opt2 radiobutton group grp1 .
selection-screen end of block b2.
selection-screen begin of block b1 with frame title t1.
select-options: v_matnr for mara-matnr,
v_werks for marc-werks,
v_mtart for mara-mtart,
v_matkl for mara-matkl,
v_bismt for mara-bismt,
v_atinn for ausp-atinn,
v_ersda for mara-ersda,
v_ernam for mara-ernam,
v_laeda for mara-laeda,
v_aenam for mara-aenam.
parameter: p_class like rmclm-class.
selection-screen end of block b1.
selection-screen begin of block b3 with frame title t3.
parameter: chk_a as checkbox default ''.
selection-screen end of block b3.
initialization.
t1 = '選擇物料條件'.
t2 = '選擇報表方式'.
t3 = '是否顯示刪除物料'.
authority-check object 'S_TCODE' id 'TCD' field 'ZMM12'.
if sy-subrc <> 0.
message s000(zmsg_wt_pub_01) with 'ZMM12'.
leave to screen 0.
endif.
start-of-selection.
if p_opt1 = 'X'.
if p_class = ''.
message'必須要輸入物料分類資料.' type 'S'.
else.
perform create_dynamic_itab.
call screen 100.
endif.
else.
perform get_data.
refresh gt_list_top_of_page[].
perform e04_comment_build .
clear fieldcat.
refresh fieldcat.
perform build_fieldcat.
perform build_sortcat.
perform build_eventcat.
perform alv_display.
sort itab by matnr.
endif.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
data: fnumfieldvalue(15) type p decimals 3.
if p_class <> ''.
if v_werks <> ''.
select * into corresponding fields of table itab from mara as a
inner join makt as h on a~matnr = h~matnr and h~spras = sy-langu
inner join marc as j on j~matnr = a~matnr
inner join kssk as e on a~matnr = e~objek and e~klart = '001'
inner join klah as f on e~clint = f~clint
inner join ksml as g on e~clint = g~clint
inner join ausp as b on g~imerk = b~atinn and b~objek = e~objek and b~klart = '001'
inner join cabn as c on c~atinn = g~imerk
inner join cabnt as d on d~atinn = g~imerk and d~spras = sy-langu
where a~matnr in v_matnr and matkl in v_matkl and bismt in v_bismt and mtart in v_mtart
and ersda in v_ersda and ernam in v_ernam and laeda in v_laeda and aenam in v_aenam
and g~imerk in v_atinn
and j~werks in v_werks
and f~class = p_class
order by a~matnr g~posnr g~imerk b~adzhl.
else.
select * into corresponding fields of table itab from mara as a
inner join makt as h on a~matnr = h~matnr and h~spras = sy-langu
inner join kssk as e on a~matnr = e~objek and e~klart = '001'
inner join klah as f on e~clint = f~clint
inner join ksml as g on e~clint = g~clint
inner join ausp as b on g~imerk = b~atinn and b~objek = e~objek and b~klart = '001'
inner join cabn as c on c~atinn = g~imerk
inner join cabnt as d on d~atinn = g~imerk and d~spras = sy-langu
where a~matnr in v_matnr and matkl in v_matkl and bismt in v_bismt and mtart in v_mtart
and ersda in v_ersda and ernam in v_ernam and laeda in v_laeda and aenam in v_aenam
and g~imerk in v_atinn
and f~class = p_class
order by a~matnr g~posnr g~imerk b~adzhl.
endif.
else.
if v_werks <> ''.
select * into corresponding fields of table itab from mara as a
inner join makt as h on a~matnr = h~matnr and h~spras = sy-langu
inner join marc as j on j~matnr = a~matnr
inner join kssk as e on a~matnr = e~objek and e~klart = '001'
inner join klah as f on e~clint = f~clint
inner join ksml as g on e~clint = g~clint
inner join ausp as b on g~imerk = b~atinn and b~objek = e~objek and b~klart = '001'
inner join cabn as c on c~atinn = g~imerk
inner join cabnt as d on d~atinn = g~imerk and d~spras = sy-langu
where a~matnr in v_matnr and matkl in v_matkl and bismt in v_bismt and mtart in v_mtart
and ersda in v_ersda and ernam in v_ernam and laeda in v_laeda and aenam in v_aenam
and g~imerk in v_atinn
and j~werks in v_werks
order by a~matnr g~posnr g~imerk b~adzhl.
else.
select * into corresponding fields of table itab from mara as a
inner join makt as h on a~matnr = h~matnr and h~spras = sy-langu
inner join kssk as e on a~matnr = e~objek and e~klart = '001'
inner join klah as f on e~clint = f~clint
inner join ksml as g on e~clint = g~clint
inner join ausp as b on g~imerk = b~atinn and b~objek = e~objek and b~klart = '001'
inner join cabn as c on c~atinn = g~imerk
inner join cabnt as d on d~atinn = g~imerk and d~spras = sy-langu
where a~matnr in v_matnr and matkl in v_matkl and bismt in v_bismt and mtart in v_mtart
and ersda in v_ersda and ernam in v_ernam and laeda in v_laeda and aenam in v_aenam
and g~imerk in v_atinn
order by a~matnr g~posnr g~imerk b~adzhl.
endif.
endif.
delete adjacent duplicates from itab.
loop at itab into wa_itab.
if wa_itab-lvorm = 'X' and chk_a = ''.
delete itab index sy-tabix.
continue.
endif.
case wa_itab-atfor.
when 'CHAR'.
wa_itab-zvalue = wa_itab-atwrt.
when 'NUM' or 'CURR'.
fnumfieldvalue = wa_itab-atflv.
wa_itab-zvalue = fnumfieldvalue.
when 'DATE'.
data: fv like cawn-atflv.
data: dv like cawn-atwrt.
fv = wa_itab-atflv.
call function 'CTCV_CONVERT_FLOAT_TO_DATE'
exporting
float = fv
importing
date = dv.
concatenate dv 0(4) dv 4(2) dv 6(2) into wa_itab-zvalue separated by '-'.
when others.
wa_itab-zvalue = wa_itab-atflv.
endcase.
condense wa_itab-zvalue.
modify itab from wa_itab transporting zvalue.
endloop.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* 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'.
ps_layout-cell_merge = 'X'.
perform build_field using 'MATNR' '物料編碼' col_pos 'X'.
perform build_field using 'MAKTX' '物料說明' col_pos ''.
perform build_field using 'LVORM' '刪除標識' col_pos ''.
perform build_field using 'CLASS' '分類碼' col_pos ''.
perform build_field using 'ATINN' '特性碼' col_pos ''.
perform build_field using 'ATBEZ' '特性說明' col_pos ''.
perform build_field using 'ZVALUE' '特性值' col_pos ''.
perform build_field using 'ATFOR' '值類型' col_pos ''.
perform build_field using 'ATERF' '必須輸入' col_pos ''.
perform build_field using 'MSEHI' '單位' col_pos ''.
endform. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form BUILD_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_CFIELDNAME text
* -->P_CFIELDDESC text
*----------------------------------------------------------------------*
form build_field using p_cfieldname
p_cfielddesc col_pos ckey.
add 1 to col_pos.
clear fieldcat_ln.
fieldcat_ln-tabname = 'ITAB'.
fieldcat_ln-ref_fieldname = p_cfieldname.
fieldcat_ln-fieldname = p_cfieldname.
fieldcat_ln-key = ckey.
fieldcat_ln-no_zero = 'X'.
fieldcat_ln-seltext_s = p_cfielddesc.
fieldcat_ln-seltext_l = p_cfielddesc.
fieldcat_ln-seltext_m = fieldcat_ln-reptext_ddic = p_cfielddesc.
fieldcat_ln-col_pos = col_pos.
append fieldcat_ln to fieldcat.
endform. " BUILD_FIELD
*&---------------------------------------------------------------------*
*& 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 = 'ZRP_MM_W_1201'
i_callback_user_command = 'USER_COMMAND'
is_layout = ps_layout
it_fieldcat = fieldcat
i_save = 'A'
it_sort = gt_sort
it_events = eventcat
tables
t_outtab = itab
exceptions
program_error = 1
others = 2.
endform. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& 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 itab 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
*&--------------------------------------------------------------------*
*& 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.
* I_LOGO = 'ZUCP' .
* I_END_OF_LIST_GRID = 'X'.
endform. "ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form BUILD_SORTCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_sortcat .
clear gs_sort.
gs_sort-fieldname = 'MATNR'.
gs_sort-spos = '1'.
gs_sort-up = 'X'.
append gs_sort to gt_sort.
clear gs_sort.
gs_sort-fieldname = 'MAKTX'.
gs_sort-spos = '2'.
gs_sort-up = 'X'.
append gs_sort to gt_sort.
clear gs_sort.
gs_sort-fieldname = 'LVORM'.
gs_sort-spos = '3'.
gs_sort-up = 'X'.
append gs_sort to gt_sort.
clear gs_sort.
gs_sort-fieldname = 'CLASS'.
gs_sort-spos = '4'.
gs_sort-up = ''.
gs_sort-down = ''.
append gs_sort to gt_sort.
endform. " BUILD_SORTCAT
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->UCOMM text
* -->SELFIELD text
*----------------------------------------------------------------------*
form user_command using ucomm like sy-ucomm
selfield type slis_selfield.
read table itab index selfield-tabindex.
check sy-subrc = 0.
case ucomm.
when '&IC1'.
case selfield-sel_tab_field.
when'ITAB-MATNR'.
set parameter id 'MAT' field itab-matnr.
call transaction'MM03' and skip first screen.
endcase.
when 'PRI' .
endcase.
endform. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form create_dynamic_itab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form create_dynamic_itab .
perform fieldcat_build.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = gt_fieldcat
importing
ep_table = gp_table.
assign gp_table->* to <gt_table>.
perform fill_table.
endform. " create_dynamic_itab
*&---------------------------------------------------------------------*
*& Form fieldcat_build
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fieldcat_build .
data: ls_fieldcat type lvc_s_fcat.
data: ctype(1) type c.
select d~atinn d~atbez c~atfor c~anzst c~anzdz b~posnr
into corresponding fields of table it_fieldlist from klah as a
inner join ksml as b on a~clint = b~clint
inner join cabn as c on b~imerk = c~atinn
inner join cabnt as d on d~atinn = c~atinn and d~spras = sy-langu
where class = p_class
order by b~posnr.
clear gt_fieldcat.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-key = 'X'.
ls_fieldcat-col_opt = 'X'.
* ls_fieldcat-no_zero = 'X'.
ls_fieldcat-convexit = 'MATN1'.
ls_fieldcat-inttype = 'C'.
ls_fieldcat-intlen = 18.
ls_fieldcat-coltext = '物料碼'.
ls_fieldcat-outputlen = 18.
append ls_fieldcat to gt_fieldcat.
ls_fieldcat-fieldname = 'MAKTX'.
ls_fieldcat-key = ''.
ls_fieldcat-col_opt = 'X'.
ls_fieldcat-inttype = 'C'.
ls_fieldcat-intlen = 40.
ls_fieldcat-coltext = '物料說明'.
ls_fieldcat-outputlen = 40.
append ls_fieldcat to gt_fieldcat.
ls_fieldcat-fieldname = 'LVORM'.
ls_fieldcat-key = ''.
ls_fieldcat-col_opt = 'X'.
ls_fieldcat-inttype = 'C'.
ls_fieldcat-intlen = 1.
ls_fieldcat-coltext = '刪除標識'.
ls_fieldcat-outputlen = 1.
append ls_fieldcat to gt_fieldcat.
loop at it_fieldlist into wa_fieldlist.
case wa_fieldlist-atfor.
when 'DATE'.
ctype = 'D'.
when others.
ctype = 'C'.
endcase.
ls_fieldcat-fieldname = wa_fieldlist-atinn.
ls_fieldcat-key = ''.
ls_fieldcat-col_opt = 'X'.
ls_fieldcat-inttype = ctype.
ls_fieldcat-intlen = wa_fieldlist-anzst.
ls_fieldcat-coltext = wa_fieldlist-atbez.
ls_fieldcat-decimals_o = wa_fieldlist-anzdz.
ls_fieldcat-outputlen = wa_fieldlist-anzst.
append ls_fieldcat to gt_fieldcat.
endloop.
endform. " fieldcat_build
*&---------------------------------------------------------------------*
*& Form fill_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fill_table .
data: oldma like mara-matnr.
data: l_row type sy-index, cfield(10) type c, cvalue(33) type c.
field-symbols: <ls_table>.
field-symbols: <l_field>.
perform get_data.
assign local copy of initial line of <gt_table> to <ls_table>.
clear <ls_table>.
loop at itab into wa_itab.
if oldma <> wa_itab-matnr.
if oldma <> ''.
append <ls_table> to <gt_table>.
clear <ls_table>.
endif.
oldma = wa_itab-matnr.
assign component 'MATNR' of structure <ls_table> to <l_field>.
<l_field> = wa_itab-matnr.
assign component 'MAKTX' of structure <ls_table> to <l_field>.
<l_field> = wa_itab-maktx.
assign component 'LVORM' of structure <ls_table> to <l_field>.
<l_field> = wa_itab-lvorm.
endif.
cfield = wa_itab-atinn.
assign component cfield of structure <ls_table> to <l_field>.
clear cvalue.
if <l_field> = ''.
concatenate wa_itab-zvalue ' ' wa_itab-msehi into cvalue.
else.
concatenate <l_field> ';' wa_itab-zvalue ' ' wa_itab-msehi into cvalue.
endif.
condense cvalue.
<l_field> = cvalue.
endloop.
if sy-subrc = 0.
append <ls_table> to <gt_table>.
endif.
endform. " fill_table
*----------------------------------------------------------------------*
* MODULE pbo OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
module pbo output.
data: irecordcount type i, crecordcount(5) type c.
set pf-status 'MAIN100'.
set titlebar 'TITLE0100'.
irecordcount = lines( <gt_table> ).
crecordcount = irecordcount.
condense crecordcount.
clear g_title.
concatenate '符合分類: ' p_class ' 的物料記錄總數: ' crecordcount into g_title.
data: t_is_variant type disvariant.
t_is_variant-report = 'ZRP_MM_W_1201'.
if g_custom_container is initial.
create object g_custom_container
exporting container_name = g_container.
create object grid1
exporting i_parent = g_custom_container.
call method grid1->set_table_for_first_display
exporting
i_save = 'X'
is_variant = t_is_variant
changing
it_fieldcatalog = gt_fieldcat
it_outtab = <gt_table>.
endif.
endmodule. "pbo OUTPUT
*---------------------------------------------------------------------*
* MODULE PAI INPUT *
*---------------------------------------------------------------------*
module pai input.
case ok_code.
when 'EXIT' or 'BACK' or 'CANCEL'.
perform exit_program.
when others.
* do nothing
endcase.
clear ok_code.
endmodule. "pai INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form exit_program.
call method g_custom_container->free.
call method cl_gui_cfw=>flush.
leave to screen 0.
endform. "exit_program