一个简单的库龄计算报表,根据移动类型来判断最后移动日期,包含批次和非批次库存。
*&---------------------------------------------------------------------*
*& Report ZMMR_016
*&---------------------------------------------------------------------*
*& Created by :
*& Created on : 2024.07.19
*& Requested by :
*& Description :
*& Description : 根据物料的最后一次移动记录计算库存的时间。排除311,312位置移动的规则
*&
*& Authority Object :
*& Transport Request :
*&---------------------------------------------------------------------*
REPORT zmmr_016.
TABLES:vggt2.
INCLUDE zmmr_016_top.
INCLUDE zmmr_016_s01.
INCLUDE zmmr_016_form.
INITIALIZATION.
START-OF-SELECTION.
PERFORM get_data.
IF so_charg IS INITIAL.
PERFORM get_data2.
ENDIF.
PERFORM build_data.
*--------- END-OF-SELECTION ----------
END-OF-SELECTION.
IF gt_data IS INITIAL.
MESSAGE '没有找到相关的数据!' TYPE 'S' DISPLAY LIKE 'E'. " 没有找到相关的数据!
ELSE.
* 显示alv界面
PERFORM frm_display_alv.
ENDIF.
*&---------------------------------------------------------------------*
*& Include ZMMR_016_TOP
*&---------------------------------------------------------------------*
TYPE-POOLS slis.
INCLUDE <icon>.
INCLUDE <symbol>.
TABLES: mara,marc,mard,mch1,mchb,t001l,ekpo,vbrk.
TYPES :BEGIN OF gy_data,
werks TYPE mchb-werks,
matnr TYPE mchb-matnr,
maktx TYPE makt-maktx,
mfrnr TYPE mara-mfrnr, "生产商
mftxt TYPE text80, "生产商名称
bu_sort1 TYPE bu_sort1, "业务伙伴的搜索词 1
mfrpn TYPE mara-mfrpn, "生产商货号
groes TYPE mara-groes, "大小/量纲
charg TYPE mchb-charg,
licha TYPE mch1-licha, "供应商批次
lgort TYPE mchb-lgort,
lgobe TYPE t001l-lgobe,
zzfi01 TYPE ekpo-zzfi01,
zzfi02 TYPE ekpo-zzfi02,
zzfi03 TYPE ekpo-zzfi03,
zzfi04 TYPE ekpo-zzfi04,
vfdat TYPE mcha-vfdat,
meins TYPE mara-meins,
cuobj_bm TYPE mcha-cuobj_bm, "内部对象号
cspem TYPE mchb-cspem,
clabs TYPE mchb-clabs,
cinsm TYPE mchb-cinsm,
ceinm TYPE mchb-ceinm,
msbookpartno TYPE mara-msbookpartno,
bu_sort2 TYPE but000-bu_sort1,
ktext TYPE aufk-ktext,
ktext2 TYPE cskt-ktext,
text TYPE char255,
ZEINR TYPE mara-zeinr, " 成品出库短描述 20210512 addby XXX
hsdat TYPE mch1-hsdat, " 生产日期 addby XXX 20240318
budat TYPE mkpf-budat, " 最后移动的日期
zzkts TYPE i, " 在库天数
END OF gy_data.
DATA :gt_data TYPE TABLE OF gy_data,
gs_data TYPE gy_data.
DATA :gt_data2 TYPE TABLE OF gy_data,
gs_data2 TYPE gy_data.
DATA :gt_but000 TYPE TABLE OF but000,
gs_but000 TYPE but000.
TYPES :BEGIN OF gy_objek ,
objek TYPE cuobn,
END OF gy_objek.
DATA:gt_objek TYPE TABLE OF gy_objek,
gs_objek TYPE gy_objek.
DATA:gt_ausp_1 TYPE TABLE OF ausp,
gs_ausp_1 TYPE ausp.
DATA:gt_ausp_2 TYPE TABLE OF ausp,
gs_ausp_2 TYPE ausp.
DATA:gt_ausp_3 TYPE TABLE OF ausp,
gs_ausp_3 TYPE ausp.
DATA:gt_ausp_4 TYPE TABLE OF ausp,
gs_ausp_4 TYPE ausp.
DATA:gt_t001l TYPE TABLE OF t001l,
gs_t001l TYPE t001l.
TYPES:BEGIN OF gy_mara,
matnr TYPE mara-matnr,
mfrnr TYPE mara-mfrnr,
mfrpn TYPE mara-mfrpn,
meins TYPE mara-meins,
msbookpartno TYPE dimp_drm_msbookpart,
groes TYPE mara-groes,
ZEINR TYPE mara-zeinr, " 成品出库短描述 20210512 addby XXX
END OF gy_mara.
DATA:gt_mara TYPE TABLE OF gy_mara,
gs_mara TYPE gy_mara.
DATA:gt_makt TYPE TABLE OF makt,
gs_makt TYPE makt.
DATA:gt_mch1 TYPE TABLE OF mch1, " 增加生产日期 by XXX 20240218
gs_mch1 TYPE mch1.
TYPES:BEGIN OF gy_mkpf, " XXX 20240717
matnr TYPE mara-matnr,
charg TYPE mseg-charg,
mblnr TYPE mkpf-mblnr,
mjahr type mkpf-mjahr,
budat type mkpf-budat,
END OF gy_mkpf.
DATA:gt_mkpf TYPE TABLE OF gy_mkpf,
gs_mkpf TYPE gy_mkpf.
DATA gv_pur_glag(1).
****Defination for FM geting classification
DATA gv_objkey TYPE bapi1003_key-object.
DATA:gt_num_v TYPE TABLE OF bapi1003_alloc_values_num,
gs_num_v TYPE bapi1003_alloc_values_num,
gt_char_v TYPE TABLE OF bapi1003_alloc_values_char,
gs_char_v TYPE bapi1003_alloc_values_char,
gt_curr_v TYPE TABLE OF bapi1003_alloc_values_curr,
gs_curr_v TYPE bapi1003_alloc_values_curr,
gt_return TYPE TABLE OF bapiret2.
DATA:gt_characteristic TYPE TABLE OF bapi1003_object_keys,
gs_characteristic TYPE bapi1003_object_keys,
gt_message TYPE TABLE OF bapiret2.
DATA: gs_layout TYPE slis_layout_alv,
gs_layout_lvc TYPE lvc_s_layo.
DATA: gs_grid TYPE lvc_s_glay.
DATA: gs_fieldcat TYPE slis_fieldcat_alv,
gt_fieldcat TYPE TABLE OF slis_fieldcat_alv,
gt_fieldca1 TYPE TABLE OF slis_fieldcat_alv,
gt_fieldca2 TYPE TABLE OF slis_fieldcat_alv,
gt_fieldcat_item TYPE TABLE OF slis_fieldcat_alv,
gt_fieldcat_msg TYPE TABLE OF slis_fieldcat_alv.
DATA: gs_fieldcat_lvc TYPE lvc_s_fcat,
gt_fieldcat_lvc TYPE lvc_t_fcat.
DATA: gs_sortinfo_alv TYPE slis_sortinfo_alv,
gt_sortinfo_alv TYPE slis_t_sortinfo_alv.
DATA: gs_sortinfo_lvc TYPE lvc_s_sort,
gt_sortinfo_lvc TYPE lvc_t_sort.
DATA: gt_list_top_of_page TYPE slis_t_listheader.
DATA: gs_print_alv TYPE slis_print_alv.
DATA: gs_event TYPE slis_alv_event,
gt_event TYPE slis_t_event.
DATA: col_pos TYPE i,
g_fieldcat_value TYPE text10.
DATA: galv_grid TYPE REF TO cl_gui_alv_grid.
DATA:
cal_intime TYPE i.
DATA res_intime TYPE p DECIMALS 2.
* ------ macro defination
CLEAR: gt_fieldcat.
REFRESH: gt_fieldcat.
DEFINE fieldcat_macro.
CLEAR gs_fieldcat.
col_pos = col_pos + 1.
gs_fieldcat-tabname = 'GT_DATA'.
gs_fieldcat-fieldname = '&1'.
gs_fieldcat-seltext_l = &2.
gs_fieldcat-key = &3.
gs_fieldcat-decimals_out = &4.
* gs_fieldcat-emphasize = &5.
* gs_fieldcat-edit = &5.
gs_fieldcat-no_out = &5.
* gs_fieldcat-hotspot = &6.
gs_fieldcat-checkbox = &6.
gs_fieldcat-outputlen = &7.
gs_fieldcat-no_zero = &8.
gs_fieldcat-just = &9.
gs_fieldcat-col_pos = col_pos.
APPEND gs_fieldcat TO gt_fieldcat.
END-OF-DEFINITION.
*&---------------------------------------------------------------------*
*& Include ZMMR_016_S01
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK 0 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: so_matnr FOR mch1-matnr .
SELECT-OPTIONS: so_werks FOR mchb-werks OBLIGATORY DEFAULT '1000'.
SELECT-OPTIONS: so_lgort FOR mchb-lgort.
SELECT-OPTIONS: so_charg FOR mchb-charg.
SELECTION-SCREEN END OF BLOCK 0.
*&---------------------------------------------------------------------*
*& Include ZMMR_016_FORM
*&---------------------------------------------------------------------*
*逻辑:通过客制化字段(项目、部门、申请人、任务)查询物料库存物资。
*&---------------------------------------------------------------------*
*& Form GET_DATA
* 获取数据
*----------------------------------------------------------------------*
FORM get_data .
***** 抓取符合前4个条件的批次
FREE gt_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM mchb INNER JOIN mch1
ON mch1~matnr = mchb~matnr AND mch1~charg = mchb~charg
WHERE mchb~matnr IN so_matnr
AND mchb~werks IN so_werks
AND mchb~lgort IN so_lgort
AND mchb~charg IN so_charg
AND ( clabs NE '' OR cinsm NE '' OR ceinm NE '' OR cspem NE '' ). "无库存不显示在报表中
**** 以下转换仅用来适应 FOR ALL ENTRIES IN 关键字
FREE gt_objek .
LOOP AT gt_data INTO gs_data.
CLEAR gs_objek.
gs_objek-objek = gs_data-cuobj_bm.
APPEND gs_objek TO gt_objek.
ENDLOOP.
IF gt_data IS NOT INITIAL.
FREE gt_mara.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_mara
FROM mara
FOR ALL ENTRIES IN gt_data
WHERE matnr = gt_data-matnr.
FREE gt_makt.
SELECT * FROM makt INTO TABLE gt_makt
FOR ALL ENTRIES IN gt_data
WHERE matnr = gt_data-matnr
AND spras = sy-langu.
FREE gt_mch1. " addby XXX 20240318
SELECT * FROM mch1 INTO TABLE gt_mch1
FOR ALL ENTRIES IN gt_data
WHERE matnr = gt_data-matnr
AND charg = gt_data-charg.
IF gt_mara IS NOT INITIAL.
FREE gt_but000.
SELECT * FROM but000 INTO TABLE gt_but000
FOR ALL ENTRIES IN gt_mara
WHERE partner = gt_mara-mfrnr.
ENDIF.
FREE gt_t001l.
SELECT * FROM t001l INTO TABLE gt_t001l
FOR ALL ENTRIES IN gt_data
WHERE werks = gt_data-werks
AND lgort = gt_data-lgort.
FREE gt_mkpf. " XXX 20240717
SELECT mkpf~budat mseg~charg mkpf~mblnr mkpf~mjahr
from mkpf INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr and mkpf~mjahr = mseg~mjahr
INTO CORRESPONDING FIELDS OF TABLE gt_mkpf
FOR ALL ENTRIES IN gt_data
WHERE mseg~charg = gt_data-charg
AND BWART NOT IN ('311','312','321','322').
SORT gt_mkpf DESCENDING by charg budat.
DELETE ADJACENT DUPLICATES FROM gt_mkpf COMPARING charg..
ENDIF.
LOOP AT gt_data INTO gs_data.
**** 生产商 生产商货号 单位 规格型号 成品出库短描述
CLEAR gs_mara .
READ TABLE gt_mara INTO gs_mara WITH KEY matnr = gs_data-matnr.
IF sy-subrc = 0.
gs_data-mfrnr = gs_mara-mfrnr.
gs_data-mfrpn = gs_mara-mfrpn.
gs_data-meins = gs_mara-meins.
gs_data-msbookpartno = gs_mara-msbookpartno.
gs_data-groes = gs_mara-groes.
gs_data-zeinr = gs_mara-zeinr.
CLEAR gs_but000.
READ TABLE gt_but000 INTO gs_but000 WITH KEY partner = gs_mara-mfrnr.
IF sy-subrc = 0.
* gs_data-bu_sort1 = gs_but000-bu_sort1 .
CONCATENATE gs_but000-name_org1 gs_but000-name_org2
gs_but000-name_org3 gs_but000-name_org4 INTO gs_data-mftxt.
ENDIF.
ENDIF.
**** 物料描述
CLEAR gs_makt.
READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_data-matnr.
IF sy-subrc = 0.
gs_data-maktx = gs_makt-maktx.
ENDIF.
**** 生产日期 addby XXX 20240318
CLEAR gs_mch1.
READ TABLE gt_mch1 INTO gs_mch1 WITH KEY matnr = gs_data-matnr charg = gs_data-charg.
IF sy-subrc = 0.
gs_data-hsdat = gs_mch1-hsdat.
ENDIF.
CLEAR gs_mkpf. " XXX 20240717
READ TABLE gt_mkpf INTO gs_mkpf WITH KEY charg = gs_data-charg.
IF sy-subrc = 0.
gs_data-budat = gs_mkpf-budat.
ENDIF.
gs_data-zzkts = sy-datum - gs_data-budat.
**** 仓库描述
CLEAR gs_t001l .
READ TABLE gt_t001l INTO gs_t001l WITH KEY werks = gs_data-werks lgort = gs_data-lgort.
IF sy-subrc = 0.
gs_data-lgobe = gs_t001l-lgobe.
ENDIF.
* CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
* EXPORTING
* input = gs_data-meins
* IMPORTING
* long_text = gs_data-meins.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_data-zzfi03
IMPORTING
output = gs_data-zzfi03.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_data-zzfi04
IMPORTING
output = gs_data-zzfi04.
PERFORM frm_get_text USING gs_data-matnr gs_data-charg CHANGING gs_data-text."批次长文本,包装批次
MODIFY gt_data FROM gs_data.
ENDLOOP.
ENDFORM. " GET_DATA
FORM get_data2.
SELECT mard~matnr mard~werks mard~lgort meins mfrnr mfrpn msbookpartno
labst AS clabs insme AS cinsm einme AS ceinm speme AS cspem
FROM mard INNER JOIN mara ON mard~matnr = mara~matnr
INTO CORRESPONDING FIELDS OF TABLE gt_data2
WHERE mard~matnr IN so_matnr
AND mard~werks IN so_werks
AND mard~lgort IN so_lgort
AND mara~xchpf NE 'X'
AND ( labst NE '' OR insme NE '' OR einme NE '' OR speme NE '' ). "无库存不显示在报表中
FREE:gt_t001l, gt_makt ,gt_but000.
IF gt_data2 IS NOT INITIAL.
SELECT * FROM makt INTO CORRESPONDING FIELDS OF TABLE gt_makt
FOR ALL ENTRIES IN gt_data2
WHERE matnr = gt_data2-matnr
AND spras = sy-langu.
SELECT * FROM t001l INTO CORRESPONDING FIELDS OF TABLE gt_t001l
FOR ALL ENTRIES IN gt_data2
WHERE werks = gt_data2-werks
AND lgort = gt_data2-lgort.
SELECT * FROM but000 INTO TABLE gt_but000
FOR ALL ENTRIES IN gt_data2
WHERE partner = gt_data2-mfrnr.
FREE gt_mkpf. " XXX 20240717
SELECT mkpf~budat mseg~matnr mkpf~mblnr mkpf~mjahr
from mkpf INNER JOIN mseg ON mkpf~mblnr = mseg~mblnr and mkpf~mjahr = mseg~mjahr
INTO CORRESPONDING FIELDS OF TABLE gt_mkpf
FOR ALL ENTRIES IN gt_data2
WHERE mseg~matnr = gt_data2-matnr
AND BWART NOT IN ('311','312','321','322').
SORT gt_mkpf DESCENDING by matnr budat.
DELETE ADJACENT DUPLICATES FROM gt_mkpf COMPARING matnr.
ENDIF.
LOOP AT gt_data2 INTO gs_data2.
**** 物料描述
CLEAR gs_makt.
READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_data2-matnr.
IF sy-subrc = 0.
gs_data2-maktx = gs_makt-maktx.
ENDIF.
CLEAR gs_but000.
READ TABLE gt_but000 INTO gs_but000 WITH KEY partner = gs_data2-mfrnr.
IF sy-subrc = 0.
gs_data2-bu_sort1 = gs_but000-bu_sort1 .
ENDIF.
**** 仓库描述
CLEAR gs_t001l .
READ TABLE gt_t001l INTO gs_t001l WITH KEY werks = gs_data2-werks lgort = gs_data2-lgort.
IF sy-subrc = 0.
gs_data2-lgobe = gs_t001l-lgobe.
ENDIF.
CLEAR gs_mkpf. " XXX 20240717
READ TABLE gt_mkpf INTO gs_mkpf WITH KEY matnr = gs_data2-matnr.
IF sy-subrc = 0.
gs_data2-budat = gs_mkpf-budat.
ENDIF.
gs_data2-zzkts = sy-datum - gs_data2-budat.
* CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
* EXPORTING
* input = gs_data2-meins
* IMPORTING
* long_text = gs_data2-meins.
PERFORM frm_get_text USING gs_data2-matnr gs_data2-charg CHANGING gs_data2-text.
MODIFY gt_data2 FROM gs_data2.
ENDLOOP.
APPEND LINES OF gt_data2 TO gt_data.
SORT gt_data BY matnr.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_DATA
*&---------------------------------------------------------------------*
* 整理数据
*----------------------------------------------------------------------*
FORM build_data .
TYPES:BEGIN OF gy_setheadert,
setclass TYPE setclass,
subclass TYPE setsubcls,
setname TYPE setnamenew,
langu TYPE spras,
descript TYPE settext,
kostl TYPE kostl,
END OF gy_setheadert.
DATA :gt_but000 TYPE TABLE OF but000,
gs_but000 TYPE but000,
gt_but000_2 TYPE TABLE OF but000,
gs_but000_2 TYPE but000,
gt_ztask TYPE TABLE OF ztask,
gs_ztask TYPE ztask,
gt_aufk TYPE TABLE OF aufk,
gs_aufk TYPE aufk,
gt_cskt TYPE TABLE OF cskt,
gs_cskt TYPE cskt,
gt_setheadert TYPE TABLE OF gy_setheadert,
gs_setheadert TYPE gy_setheadert.
ENDFORM. " BUILD_DATA
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
* 显示alv界面
*----------------------------------------------------------------------*
FORM frm_display_alv .
* 设定报表输出样式
PERFORM set_layout.
* 设定报表列标题格式
PERFORM set_fieldcat.
* 输出ALV报表
PERFORM alv_grid_display.
ENDFORM. " FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* 设定报表输出样式。
*----------------------------------------------------------------------*
FORM set_layout .
* 设置Grid的字段列宽度自动适应
gs_layout-colwidth_optimize = 'X'.
* 设置Grid的行颜色变换显示
gs_layout-zebra = 'X'.
* 置弹出窗口的标题栏
gs_layout-detail_titlebar = TEXT-t16.
* 设置Grid的多行选择列,其中BOX必须为内表的一列,为一个字符长度
* gs_layout-box_fieldname = 'SEL'.
* 设置Grid是否显示行分割线
* gs_layout-no_vline = 'X'.
* 设置Grid是否显示列分隔线
* gs_layout-no_hline = 'X'.
* 设置Grid的没有标题
* gs_layout-no_colhead = ' '.
* 设置Grid不显示弹出明细显示窗口
* gs_layout-detail_popup = 'X'.
* 行颜色字段设置
* gs_layout-info_fieldname = 'ROWCOLOR'.
ENDFORM. " SET_LAYOUT
*&---------------------------------------------------------------------*
*& Form SET_FIELDCAT
*&---------------------------------------------------------------------*
* 设定报表列标题格式
*----------------------------------------------------------------------*
FORM set_fieldcat .
* 列标题设定
col_pos = 0.
fieldcat_macro matnr '物料号' '' '' '' '' '10' 'X' 'L'.
fieldcat_macro maktx '物料描述' '' '' '' '' '6' 'X' 'L'.
* fieldcat_macro mfrnr '生产商' '' '' '' '' '12' 'X' 'L'.
* fieldcat_macro bu_sort1 '生产商名称' '' '' '' '' '12' 'X' 'L'.
fieldcat_macro mftxt '生产商名称' '' '' '' '' '12' 'X' 'L'.
fieldcat_macro mfrpn '生产商货号' '' '' '' '' '10' '' 'L'.
fieldcat_macro groes '规格' '' '' '' '' '12' 'X' 'L'.
* fieldcat_macro zeinr '成品出库短描述' '' '' '' '' '12' 'X' 'L'.
* fieldcat_macro msbookpartno '包装规格' '' '' '' '' '12' 'X' 'L'.
fieldcat_macro charg '批次号' '' '' '' '' '15' '' 'L'.
fieldcat_macro licha '供应商批次' '' '' '' '' '20' '' 'L'.
fieldcat_macro lgort '库存地点' '' '' '' '' '15' '' 'L'.
fieldcat_macro lgobe '库存地点描述' '' '' '' '' '15' '' 'L'.
fieldcat_macro hsdat '生产日期' '' '' '' '' '10' '' 'L'.
fieldcat_macro vfdat '有效至' '' '' '' '' '10' '' 'L'.
fieldcat_macro meins '单位' '' '' '' '' '10' '' 'L'.
fieldcat_macro cspem '冻结库存' '' '' '' '' '10' '' 'L'.
fieldcat_macro clabs '非限制库存' '' '' '' '' '10' '' 'L'.
fieldcat_macro cinsm '质检库存' '' '' '' '' '10' '' 'L'.
fieldcat_macro ceinm '限制库存' '' '' '' '' '10' '' 'L'.
fieldcat_macro budat '最后移动日期' '' '' '' '' '10' '' 'L'.
fieldcat_macro zzkts '天数' '' '' '' '' '10' '' 'L'.
ENDFORM. " SET_FIELDCAT
*&---------------------------------------------------------------------*
*& Form ALV_GRID_DISPLAY
*&---------------------------------------------------------------------* ,
* 输出ALV报表
*----------------------------------------------------------------------*
FORM alv_grid_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
* add by CUDK905767
* i_callback_html_end_of_list = 'HTML_END_OF_LIST'
* i_background_id = 'ALV_BACKGROUND'
* end by CUDK905767
is_layout = gs_layout "设定报表输出样式
it_fieldcat = gt_fieldcat[]
i_default = 'X'
i_save = 'A' "设定是否可以保存报表布局
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
*& Form SET_PF_STATUS
*&---------------------------------------------------------------------*
* 定义用户自定义的屏幕菜单。
*----------------------------------------------------------------------*
FORM set_pf_status USING im_extab TYPE slis_t_extab.
DATA: l_count TYPE char5.
DATA: l_fcode TYPE TABLE OF sy-ucomm.
DESCRIBE TABLE gt_data LINES l_count.
* SET TITLEBAR 'TITLE' WITH l_count.
SET PF-STATUS 'SET_PF_STATUS'.
ENDFORM. "SET_PF_STATUS
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* 响应菜单项及相应事件。
*----------------------------------------------------------------------*
FORM user_command USING im_ucomm TYPE sy-ucomm
im_filecat TYPE slis_selfield.
PERFORM alv_check_value.
CASE im_ucomm .
WHEN '&F03' OR 'EXIT'.
LEAVE TO SCREEN 0.
WHEN 'CANCEL'.
WHEN OTHERS.
ENDCASE.
ENDFORM. "user_command
FORM html_end_of_list USING document TYPE REF TO cl_dd_document.
DATA: text TYPE sdydo_text_element.
CLEAR res_intime.
CALL METHOD document->add_gap
EXPORTING
width = 0. " 空格.
CLEAR text.
text = '机器完成总数: '.
CALL METHOD document->add_text
EXPORTING
text = text
sap_emphasis = 'Strong'
. " Style: HEADING;KEY;
CALL METHOD document->new_line. "换行
ENDFORM. "html_end_of_list
*&---------------------------------------------------------------------*
*& Form ALV_CHECK_VALUE
*&---------------------------------------------------------------------*
* 获取改变后的值
*----------------------------------------------------------------------*
FORM alv_check_value.
IF galv_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = galv_grid.
ENDIF.
IF NOT galv_grid IS INITIAL.
CALL METHOD galv_grid->check_changed_data.
ENDIF.
ENDFORM. " ALV_CHECK_VALUE
*&---------------------------------------------------------------------*
*& Form ALV_REJUST_LAYOUT_WIDTH
*&---------------------------------------------------------------------*
* 重新调整列宽
*----------------------------------------------------------------------*
FORM alv_rejust_layout_width.
DATA: lv_layout TYPE lvc_s_layo.
IF galv_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = galv_grid.
ENDIF.
IF NOT galv_grid IS INITIAL.
CALL METHOD galv_grid->get_frontend_layout
IMPORTING
es_layout = lv_layout.
lv_layout-cwidth_opt = 'X'. " 设置Grid的字段列宽度自动适应
CALL METHOD galv_grid->set_frontend_layout
EXPORTING
is_layout = lv_layout.
ENDIF.
ENDFORM. " ALV_REJUST_LAYOUT_WIDTH
*&---------------------------------------------------------------------*
*& Form frm_get_text
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GS_DATA_MATNR
*& --> GS_DATA_CHARG
*& <-- GS_DATA_TEXT
*&---------------------------------------------------------------------*
FORM frm_get_text USING p_matnr
p_charg
CHANGING p_text.
DATA: lv_name TYPE thead-tdname,
lt_line TYPE TABLE OF tline WITH HEADER LINE.
FREE :lt_line[] .
CLEAR lv_name.
lv_name+0(18) = p_matnr.
lv_name+044(10) = p_charg.
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'VERM'
language = sy-langu
name = lv_name
object = 'CHARGE'
TABLES
lines = lt_line[]
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
LOOP AT lt_line.
p_text = | { p_text } { lt_line-tdline } |.
ENDLOOP.
SHIFT p_text LEFT DELETING LEADING ' '.
ENDFORM.