*&——————————————————————–*
*& Form fields_build
*&——————————————————————–*
* Set information of row display attributes
*———————————————————————*
FORM fields_build .
REFRESH i_fieldcat_alv.
CLEAR i_fieldcat.
DATA colnum TYPE i VALUE 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘WERKS’.
i_fieldcat-seltext_s = ‘工厂’.
i_fieldcat-lzero = ‘X’.
i_fieldcat-key = ‘X’.
i_fieldcat-hotspot = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
IF p_po = ‘X’. “根据判断标识决定是否显示相应字段
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘LGORT’.
i_fieldcat-seltext_s = ‘库存地点’.
i_fieldcat-no_zero = ‘X’. “前导零不显示
i_fieldcat-lzero = ‘X’.
i_fieldcat-key = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘LGOBE’.
i_fieldcat-seltext_s = ‘库存地点描述’.
i_fieldcat-lzero = ‘X’.
i_fieldcat-key = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘SOBKZ’.
i_fieldcat-seltext_s = ‘特殊’.
i_fieldcat-seltext_m = ‘特殊标识’.
i_fieldcat-seltext_l = ‘特殊库存标识’.
i_fieldcat-key = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
ENDIF.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘MATNR’.
i_fieldcat-seltext_s = ‘物料编号’.
i_fieldcat-no_zero = ‘X’. “前导零不显示
i_fieldcat-key = ‘X’.
i_fieldcat-lzero = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-outputlen =’30’.
i_fieldcat-fieldname = ‘MAKTX’.
i_fieldcat-seltext_s = ‘物料描述’.
i_fieldcat-key = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-outputlen =’30’.
i_fieldcat-fieldname = ‘MATKL’.
i_fieldcat-seltext_s = ‘物料组’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-outputlen =’30’.
i_fieldcat-fieldname = ‘SPART’.
i_fieldcat-seltext_s = ‘产品组’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-outputlen =’30’.
i_fieldcat-fieldname = ‘VTEXT’.
i_fieldcat-seltext_s = ‘产品组描述’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
IF p_po = ‘X’. “根据判断标识决定是否显示相应字段
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘CHARG’.
i_fieldcat-seltext_s = ‘批次号’.
i_fieldcat-no_zero = ‘X’. “前导零不显示
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
ENDIF.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘CLABS’.
i_fieldcat-seltext_s = ‘当前库存’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
IF p_mr = ‘X’.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘MNG01’.
i_fieldcat-seltext_s = ‘可用库存’.
i_fieldcat-emphasize = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
ENDIF.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘MEINS’.
i_fieldcat-seltext_s = ‘单位’.
i_fieldcat-seltext_m = ‘计量单位’.
i_fieldcat-seltext_l = ‘基本计量单位’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘ZKCSL’.
IF p_po = ‘X’. “根据判断标识决定字段的显示名称为可用还是当前库存
i_fieldcat-seltext_s = ‘当前库存(KG)’.
i_fieldcat-seltext_l = ‘以公斤计当前库存’.
ELSE.
i_fieldcat-seltext_s = ‘可用库存(KG)’.
i_fieldcat-seltext_l = ‘以公斤计可用库存’.
i_fieldcat-emphasize = ‘X’.
ENDIF.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘ZKCJS’.
i_fieldcat-seltext_s = ‘当前件数’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
IF p_mr = ‘X’. “根据判断标识决定是否显示相应字段
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘MNG01JS’.
i_fieldcat-seltext_s = ‘可用件数’.
i_fieldcat-emphasize = ‘X’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
ENDIF.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘ZMEINH’.
i_fieldcat-seltext_s = ‘单位’.
i_fieldcat-seltext_l = ‘条目单位’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
IF p_po = ‘X’. “根据判断标识决定是否显示相应字段
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘KUNNR’.
i_fieldcat-seltext_s = ‘客户号’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘NAME1’.
i_fieldcat-seltext_s = ‘客户名称’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘LIFNR’.
i_fieldcat-seltext_s = ‘供应商号’.
i_fieldcat-no_zero = ‘X’. “前导零不显示
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘NAME2’.
i_fieldcat-seltext_s = ‘供应商名称’.
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘VBELN’.
i_fieldcat-seltext_s = ‘销售订单号’.
i_fieldcat-no_zero = ‘X’. “前导零不显示
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = ‘POSNR’.
i_fieldcat-seltext_s = ‘订单项目号’.
i_fieldcat-no_zero = ‘X’. “前导零不显示
APPEND i_fieldcat TO i_fieldcat_alv.
CLEAR i_fieldcat.
ENDIF.
ENDFORM. ” fields_build
*&——————————————————————–*
*& Form display_data
*&——————————————————————–*
* display content of report
*———————————————————————*
FORM display_data .
SORT hd_itab BY sobkz werks lgort matnr charg.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = w_repid
i_callback_user_command = ‘USER_COMMAND_ALV’
is_layout = i_layout
it_fieldcat = i_fieldcat_alv[]
it_events = i_events[]
i_save = ‘A’ “允许用户定义自己的布局并保存
i_grid_title = i_title
* i_callback_user_command = ‘USER_COMMAND’
TABLES
t_outtab = hd_itab.
ENDFORM. ” display_data
*&——————————————————————–*
*& Form whole_toolbar
*&——————————————————————–*
* text
*———————————————————————*
* –>EXTAB text
*———————————————————————*
FORM whole_toolbar USING extab TYPE slis_t_extab. “#EC CALLED
SET PF-STATUS ‘WHOLE_TOOLBAR’ EXCLUDING extab.
ENDFORM. “whole_toolbar
*&——————————————————————–*
*& Form events_build
*&——————————————————————–*
* Define ALV event
*———————————————————————*
FORM events_build .
CALL FUNCTION ‘REUSE_ALV_EVENTS_GET’
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_events.
READ TABLE i_events WITH KEY name = ‘TOP_OF_PAGE’
INTO w_events.
ENDFORM. ” events_build
*&———————————————————————*
*& Form schedule
*&———————————————————————*
* text
*———————————————————————-*
* –>C_MESSAGE text
* –>I_PERCENT text
*———————————————————————-*
FORM schedule USING
c_message TYPE c
i_percent TYPE i.
DATA: c_sche(204).
IF i_percent <= 0 OR i_percent > 100 .
c_sche = ‘百分比错误!!!’.
ELSE.
DATA: c_percent(4),
c_block(6) TYPE c VALUE ‘.’,
i_blocklen TYPE i,
i_count TYPE i,
i_col TYPE i,
i_len TYPE i,
i_temp TYPE i VALUE 0,
i_mod TYPE i.
i_blocklen = strlen( c_block ).
c_percent = i_percent.
CONDENSE c_percent.
c_percent+3(1) = ‘%’.
c_sche = c_percent.
i_count = i_percent / 4.
DO i_count TIMES.
i_col = ( i_temp * i_blocklen ) + 4.
c_sche+i_col(i_blocklen) = c_block.
i_temp = i_temp + 1.
ENDDO.
i_len = strlen( c_message ).
i_mod = i_len MOD 2.
IF i_mod = 1.
i_len = i_len + 1.
ENDIF.
IF i_len > 0.
c_sche+4(i_len) = c_message.
ENDIF.
i_len = strlen( c_sche ).
ENDIF.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR’
EXPORTING
percentage = 0
text = c_sche
EXCEPTIONS
OTHERS = 1.
ENDFORM. ” SCHEDULE
*&———————————————————————*
*& Form sub_get_stock_requirements
*&———————————————————————*
* 取可用库存
*———————————————————————-*
FORM sub_get_stock_requirements.
DATA: it_mdps TYPE STANDARD TABLE OF mdps WITH HEADER LINE,
it_mdez TYPE STANDARD TABLE OF mdez WITH HEADER LINE,
it_mdsu TYPE STANDARD TABLE OF mdsu WITH HEADER LINE,
l_mng01 LIKE mdez-mng01.
SORT hd_itab BY werks matnr.
LOOP AT hd_itab.
MOVE-CORRESPONDING hd_itab TO pop_data.
APPEND pop_data.
hd_itab-lgort = ”.
hd_itab-lgobe = ”.
hd_itab-xchpf = ”.
hd_itab-sobkz = ”.
hd_itab-charg = ”.
hd_itab-kunnr = ”.
hd_itab-name1 = ”.
hd_itab-lifnr = ”.
hd_itab-name2 = ”.
hd_itab-vbeln = ”.
hd_itab-posnr = ”.
COLLECT hd_itab INTO ltd_data. “按关键列统计值
ENDLOOP.
REFRESH hd_itab.
LOOP AT ltd_data.
MOVE-CORRESPONDING ltd_data TO hd_itab.
APPEND hd_itab.
ENDLOOP.
LOOP AT hd_itab.
CLEAR: it_mdps[], it_mdps, it_mdez[], it_mdez,
it_mdsu[], it_mdsu.
CALL FUNCTION ‘MD_STOCK_REQUIREMENTS_LIST_API’
EXPORTING
matnr = hd_itab-matnr
werks = hd_itab-werks
TABLES
mdpsx = it_mdps
mdezx = it_mdez
mdsux = it_mdsu
EXCEPTIONS
material_plant_not_found = 1
plant_not_found = 2
OTHERS = 3.
IF sy-subrc = 0.
CLEAR: l_mng01.
LOOP AT it_mdez.
IF it_mdez-plaab = ’02’ AND it_mdez-sort0 <= s_sort0-low. ” 计算可用库存
l_mng01 = l_mng01 + it_mdez-mng01.
ENDIF.
ENDLOOP.
IF l_mng01 < 0. “如果可用数量小于零,则显示可用数量为零
l_mng01 = 0.
ENDIF.
hd_itab-mng01 = l_mng01.
MODIFY hd_itab.
ENDIF.
CLEAR: hd_itab.
ENDLOOP.
ENDFORM. “sub_get_stock_requirements
*&———————————————————————*
*& Form user_command_alv
*&———————————————————————*
* ALV 用户事件,双击弹出库存(当前及可用)明细窗口
*&———————————————————————*
FORM user_command_alv USING p_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
DATA: v_row TYPE i, “alv 单元格光标定位行变量
v_col TYPE i. “alv 单元格光标定位列变量
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
CALL METHOD lr_grid->get_current_cell “获取ALV中当前单元格的行坐标 和 列坐标
IMPORTING
e_row = v_row
e_col = v_col.
* rs_selfield-refresh = ‘X’. “自动刷新
* CALL METHOD LR_GRID->REFRESH_TABLE_DISPLAY.
* PERFORM SET_CURSOR USING V_COL V_ROW. “根据行坐标 和 列坐标 对刷新后的ALV进行光标定位
CASE p_ucomm.
WHEN ‘&IC1’ . “这个功能码对应的双击/单击事件
IF rs_selfield-tabindex > 0.
PERFORM sub_pop_main USING rs_selfield.
ENDIF.
ENDCASE.
ENDFORM. “USER_COMMAND_ALV
*&———————————————————————*
*&———————————————————————*
*& Form SUB_POP_MAIN
*&———————————————————————*
* ALV display
*ALV除了可以显示列表在当前窗口,也可以用弹出窗口的形式显示列表。设
*置弹出窗口显示列表需要设置REUSE_ALV_GRID_DISPLAY四个参数:
*i_screen_start_column 弹出窗口的左边距
*i_screen_start_line 弹出窗口的上边距
*i_screen_end_column 到弹出窗口显示结束的左边距
*i_screen_end_line 到弹出窗口显示结束的上边距
*通过这四个参数可以设置弹出窗口的显示大小和位置。
*———————————————————————-*
FORM sub_pop_main USING rs_selfield TYPE slis_selfield.
DATA:
td_spfli TYPE TABLE OF spfli,
td_fieldcat TYPE slis_t_fieldcat_alv,
pop_layout TYPE slis_layout_alv. “alv format.
FIELD-SYMBOLS LIKE LINE OF hd_itab.
READ TABLE hd_itab INDEX rs_selfield-tabindex ASSIGNING .
PERFORM get_data USING -matnr -werks -meins -xmeinh -zmeinh rs_selfield-fieldname.
PERFORM set_catalog USING rs_selfield-fieldname CHANGING td_fieldcat .
pop_layout-colwidth_optimize = ‘X’.
IF rs_selfield-fieldname = ‘MNG01’ OR rs_selfield-fieldname = ‘MNG01JS’.
CONCATENATE ‘ 物料 ” ‘ -matnr ”’ 可用库存明细状况’ INTO pop_layout-window_titlebar.
ELSE.
CONCATENATE ‘ 物料 ” ‘ -matnr ”’ 当前库存明细状况’ INTO pop_layout-window_titlebar.
ENDIF.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
it_fieldcat = td_fieldcat
i_screen_start_column = 10
i_screen_start_line = 1
i_screen_end_column = 100
i_screen_end_line = 25
is_layout = pop_layout
* I_GRID_TITLE = L_TITLE
TABLES
t_outtab = pop_itab
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. ” SUB_POP_MAIN
*&———————————————————————*
*& Form GET_DATA
*&———————————————————————*
* Get the data for output
*———————————————————————-*
* –>PTD_SPFLI data internal table
*———————————————————————-*
FORM get_data USING rs_matnr TYPE mchb-matnr
rs_werks TYPE mchb-werks
rs_meins TYPE mara-meins
rs_xmeinh TYPE marm-meinh
rs_zmeinh TYPE marm-meinh
rs_fieldname TYPE slis_selfield-fieldname.
CLEAR: pop_itab,pop_itab[].
IF rs_fieldname = ‘MNG01’ OR rs_fieldname = ‘MNG01JS’.
DATA: it_mdps TYPE STANDARD TABLE OF mdps WITH HEADER LINE,
it_mdez TYPE STANDARD TABLE OF mdez WITH HEADER LINE,
it_mdsu TYPE STANDARD TABLE OF mdsu WITH HEADER LINE.
CLEAR: it_mdps[], it_mdps, it_mdez[], it_mdez,
it_mdsu[], it_mdsu.
CALL FUNCTION ‘MD_STOCK_REQUIREMENTS_LIST_API’
EXPORTING
matnr = rs_matnr
werks = rs_werks
TABLES
mdezx = it_mdez
EXCEPTIONS
material_plant_not_found = 1
plant_not_found = 2
OTHERS = 3.
IF sy-subrc = 0.
LOOP AT it_mdez WHERE plaab = ’02’.
MOVE-CORRESPONDING it_mdez TO pop_itab.
CONCATENATE pop_itab-md4kd pop_itab-md4li INTO pop_itab-kunli.
pop_itab-matnr = rs_matnr.
pop_itab-meins = rs_meins.
pop_itab-xmeinh = rs_xmeinh.
pop_itab-zmeinh = rs_zmeinh.
**调用函数,进行可用库存件数换算 “可用库存件数
CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT’
EXPORTING
i_matnr = rs_matnr
i_in_me = rs_meins
i_out_me = rs_xmeinh
i_menge = pop_itab-mng02
IMPORTING
e_menge = pop_itab-mngjs
EXCEPTIONS
error_in_application = 1
error = 2
OTHERS = 3.
APPEND pop_itab.
CLEAR pop_itab.
ENDLOOP.
ENDIF.
ELSE.
IF p_po = ‘X’. “当前库存查询
LOOP AT hd_itab WHERE matnr = rs_matnr.
MOVE-CORRESPONDING hd_itab TO pop_itab.
APPEND pop_itab.
CLEAR pop_itab.
ENDLOOP.
ELSEIF p_mr = ‘X’. “可用库存查询
LOOP AT pop_data WHERE matnr = rs_matnr.
**调用函数,根据登录时候的语言显示条目单位采用何种语言显示“如中文 套、件 而英文 EA ST ”
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_OUTPUT’ ”
EXPORTING
input = pop_data-xmeinh
language = sy-langu
IMPORTING
output = pop_data-zmeinh
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
MOVE-CORRESPONDING pop_data TO pop_itab.
APPEND pop_itab.
CLEAR pop_itab.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. ” GET_DATA
*&———————————————————————*
*& Form SET_CATALOG
*&———————————————————————*
* set fieldcatalog for alv output
*———————————————————————-*
FORM set_catalog USING rs_fieldname TYPE slis_selfield-fieldname CHANGING ptd_fieldcat TYPE slis_t_fieldcat_alv.
DATA:
lth_fieldcat TYPE slis_fieldcat_alv.
“MACRO
DEFINE add_field.
clear: lth_fieldcat.
lth_fieldcat-col_pos = &1.
lth_fieldcat-fieldname = &2.
lth_fieldcat-seltext_l = &3.
lth_fieldcat-do_sum = &4.
lth_fieldcat-no_zero = &5.
append lth_fieldcat to ptd_fieldcat.
END-OF-DEFINITION.
IF rs_fieldname = ‘MNG01’ OR rs_fieldname = ‘MNG01JS’ .
“add field catalog
add_field 1 ‘SORT0’ ‘日期’ ” ”.
add_field 2 ‘DELB0’ ‘MRP元素’ ” ”.
add_field 3 ‘EXTRA’ ‘MRP元素数据’ ” ”.
add_field 4 ‘MNG01’ ‘收货/需求’ ” ”.
add_field 5 ‘MNG02’ ‘可用数量’ ” ”.
add_field 6 ‘MEINS’ ‘单位’ ” ”.
add_field 7 ‘MNGJS’ ‘件数’ ” ”.
add_field 8 ‘ZMEINH’ ‘单位’ ” ”.
add_field 9 ‘KUNLI’ ‘客户&供应商’ ” ”.
ELSE.
“add field catalog
add_field 1 ‘WERKS’ ‘工厂’ ” ”.
add_field 2 ‘LGORT’ ‘库存地点’ ” ”.
add_field 3 ‘LGOBE’ ‘地点描述’ ” ”.
add_field 4 ‘MATNR’ ‘物料’ ” ‘X’.
add_field 5 ‘CHARG’ ‘批号’ ” ”.
add_field 6 ‘CLABS’ ‘当前库存’ ‘X’ ”.
add_field 7 ‘MEINS’ ‘单位’ ” ”.
add_field 8 ‘ZKCJS’ ‘件数’ ‘X’ ”.
add_field 9 ‘ZMEINH’ ‘单位’ ” ”.
ENDIF.
ENDFORM. ” SET_CATALOG