TABLES : sscrfields .
TABLES : icon.
SELECTION-SCREEN: FUNCTION KEY 1.
INITIALIZATION.
functxt-icon_id = icon_export.
functxt-icon_text = '下载EXCEL模板' .
functxt-quickinfo = '下载EXCEL模板' .
sscrfields-functxt_01 = functxt.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'FC01'.
PERFORM fm_get_filepath.
CHECK gv_fullpath IS NOT INITIAL.
PERFORM fm_downm." 下载模板
ENDCASE.
举例子:(PO修改供应商回复交期,批量修改)
*&---------------------------------------------------------------------*
*& Report ZMM_PO_CHANGE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmm_po_change.
"INCLUDE zmm_po_change_top.
DATA: gv_fullpath TYPE string.
DATA: functxt TYPE smp_dyntxt.
DATA: co_objid TYPE wwwdatatab-objid .
TABLES :ekko,eban,eket,ekpo.
"TYPE-POOLS: icon.
TABLES : sscrfields .
TABLES : icon.
DATA : BEGIN OF lt_data occurs 0 ,
EBELN TYPE EKET-EBELN,"采购订单号
EBELP TYPE EKET-EBELP,"行项目号
"序列号
MATNR TYPE EKPO-MATNR,"物料编码
"物料描述
EINDT TYPE EKET-EINDT,"采购交期
SLFDT TYPE EKET-SLFDT,",供应商回复交期
MENGE TYPE EKET-MENGE, " 数量
MEINS type meins,"单位
TYPE TYPE C,
MESS TYPE STRING,
END OF lt_data.
****ALV参数定义:
"ALV
DATA: GT_FCAT TYPE LVC_T_FCAT,
GS_LAYO TYPE LVC_S_LAYO,
GV_TITLE TYPE LVC_TITLE,
GS_VARIANT TYPE DISVARIANT,
GT_EVENT TYPE SLIS_T_EVENT.
SELECTION-SCREEN: FUNCTION KEY 1.
SELECTION-SCREEN:BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001 .
SELECT-OPTIONS : s_banfn FOR eban-banfn MODIF ID ty1."
SELECT-OPTIONS : s_BSART FOR ekko-bsart MODIF ID ty1." 凭证类型
SELECT-OPTIONS : s_LIFNR FOR ekko-lifnr MODIF ID ty1." 供应商
SELECT-OPTIONS : s_EKORG FOR ekko-ekorg MODIF ID ty1 ."采购组织
SELECT-OPTIONS : s_EKGRP FOR ekko-ekgrp MODIF ID ty1." 采购组
SELECT-OPTIONS : s_WERKS FOR ekpo-werks MODIF ID ty1 ."工厂
SELECT-OPTIONS : s_EINDT FOR eket-eindt MODIF ID ty1 ."交货日期
SELECT-OPTIONS : s_MATNR FOR ekpo-matnr MODIF ID ty1 ."物料
SELECT-OPTIONS : s_MATKL FOR ekpo-matkl MODIF ID ty1."物料组
SELECT-OPTIONS : s_EBELN FOR ekko-ebeln MODIF ID ty1."凭证日期
SELECT-OPTIONS : s_SLFDT FOR eket-slfdt MODIF ID ty1."供应商回复交期
SELECTION-SCREEN:END OF BLOCK b1.
SELECTION-SCREEN:BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-001 .
PARAMETERS: pc_file1(128) TYPE c DEFAULT 'C:\*.xls' MODIF ID ty2.
* MODE LIKE apqi-putactive DEFAULT 'N' NO-DISPLAY.
PARAMETERS: p_line TYPE i DEFAULT '5' OBLIGATORY MODIF ID ty2.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN:END OF BLOCK b3.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
PARAMETERS: p1 TYPE c RADIOBUTTON GROUP g1 USER-COMMAND uc DEFAULT 'X', " 查询
p2 TYPE c RADIOBUTTON GROUP g1 . " 批导
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
functxt-icon_id = icon_export.
functxt-icon_text = '下载EXCEL模板' .
functxt-quickinfo = '下载EXCEL模板' .
sscrfields-functxt_01 = functxt.
INITIALIZATION.
PERFORM frm_set_application_toobar.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'TY1'.
IF p1 IS INITIAL.
screen-active = '0'.
ELSE.
screen-active = '1'.
ENDIF.
WHEN 'TY2'.
IF p2 IS INITIAL.
screen-active = '0'.
ELSE.
screen-active = '1'.
ENDIF.
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
***************屏幕事件
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pc_file1.
PERFORM frm_get_file USING pc_file1. " 获取模板地址
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'FC01'.
PERFORM fm_get_filepath.
CHECK gv_fullpath IS NOT INITIAL.
PERFORM fm_downm." 下载模板
ENDCASE.
END-OF-SELECTION.
START-OF-SELECTION.
**** 数据上传
PERFORM frm_upload_data.
PERFORM frm_upload_alv.
*&---------------------------------------------------------------------*
*& Form frm_get_file
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> PC_FILE1
*&---------------------------------------------------------------------*
FORM frm_get_file USING pr_file.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_path = 'C:\'
mask = '*.*'
title = 'OPEN FILE...'
IMPORTING
filename = pr_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
ENDFORM. "FRM_GET_FILE
*&---------------------------------------------------------------------*
*& Form fm_get_filepath
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM fm_get_filepath .
DATA: lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_title TYPE string.
.
co_objid = 'ZMM_PO_CHANGE'.
CONCATENATE co_objid '-' sy-datum sy-uzeit INTO lv_title .
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = '模板保存为EXCEL'
default_extension = 'XLS'
default_file_name = lv_title
* FILE_FILTER = '.XLS'
file_filter = 'EXCEL 文件 (*.XLS)'
initial_directory = 'D:/'
* DEFAULT_FILE_NAME = P_FILENAME
CHANGING
filename = lv_filename
path = lv_path
fullpath = gv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
STOP .
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form fm_downm
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM fm_downm .
DATA: ls_indcatortxt TYPE string,
p_filename TYPE sapb-sappfad.
DATA: lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
p_filename = gv_fullpath.
ls_indcatortxt = '程序正在下载模板' .
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 0
text = ls_indcatortxt.
CONCATENATE co_objid '.XLS' INTO ls_objnam.
CONDENSE ls_objnam NO-GAPS.
SELECT SINGLE relid objid FROM wwwdata
INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = co_objid .
IF sy-subrc NE 0 OR lo_objdata-objid EQ space .
CONCATENATE '模板文件:' ls_objnam '不存在,请用TCODE:SMW0进行加载' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E' .
ENDIF.
ls_destination = gv_fullpath.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE 0.
CONCATENATE '模板文件:' ls_objnam '下载失败' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E' .
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_upload_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_upload_data .
DATA :tab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA :v_symbol_1(50) TYPE c.
DATA: lv_meins TYPE mara-meins.
FIELD-SYMBOLS: <fs1>.
DATA : ld_index TYPE i.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = pc_file1
i_begin_col = 1
i_begin_row = p_line
i_end_col = 9
i_end_row = 40000
TABLES
intern = tab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
************把 表 TAB 的内容给到UPD_TAB1
LOOP AT tab.
AT NEW row.
CLEAR lt_data.
ENDAT.
MOVE tab-col TO ld_index.
ASSIGN COMPONENT ld_index OF STRUCTURE lt_data TO <fs1>.
MOVE tab-value TO <fs1>.
AT END OF row.
APPEND lt_data." TO GT_MAIN.
CLEAR lt_data.
ENDAT.
ENDLOOP.
LOOP AT lt_data." 字段检查
ENDLOOP.
DATA(num) = lines( lt_data ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_upload_alv
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_upload_alv .
*
"设置ALV参数
PERFORM frm_set_alv_parameter.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_PF_STATUS_SET'
i_callback_user_command = 'FRM_USER_COMMAND'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout_lvc = gs_layo
it_fieldcat_lvc = gt_fcat
TABLES
t_outtab = lt_data[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_alv_parameter
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_alv_parameter .
"设置ALV fieldcat
PERFORM frm_set_fieldcat.
"设置LAYOUT
gs_layo-cwidth_opt = 'X'. "Colwidth optimize
gs_layo-zebra = 'X'. "斑马线
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM
frm_set_fieldcat .
DATA: ls_fcat TYPE lvc_s_fcat. "字段目录结构
DEFINE app_fcat.
CLEAR: ls_fcat.
ls_fcat-fieldname = &1. "字段名
ls_fcat-coltext = &2. "标题
ls_fcat-scrtext_s = &2. "短标签
ls_fcat-scrtext_m = &2. "中标签
ls_fcat-scrtext_l = &2. "长标签
ls_fcat-seltext = &2. "选择文本
ls_fcat-ref_table = &3. "参考表
ls_fcat-ref_field = &4. "参考字段
ls_fcat-cfieldname = &5. "金额单位字段
ls_fcat-qfieldname = &6. "数量单位字段
ls_fcat-outputlen = &7. "输出长度
IF ls_fcat-fieldname = 'SEL'.
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
ENDIF.
APPEND ls_fcat TO gt_fcat.
END-OF-DEFINITION.
app_fcat 'EBELN' '采购订单号' '' '' '' '' '10'.
app_fcat 'EBELP' '行项目号' '' '' '' '' '10'.
app_fcat 'MATNR' '物料编码' '' '' '' '' '40'.
app_fcat 'EINDT' '采购交期' '' '' '' '' '4'.
app_fcat 'SLFDT' '供应商回复交期' '' '' '' '' '4'.
* app_fcat 'LX' '消息类型' '' '' '' '' '1'.
app_fcat 'MENGE' '数量' '' '' '' '' '1'.
app_fcat 'MEINS' '单位' '' '' '' '' '35'.
app_fcat 'TYPE' '消息类型' '' '' '' '' '10'.
app_fcat 'MESS' '消息' '' '' '' '' ''.
ENDFORM.
*&---------------------------------------------------------------------*
*& FRM_USER_COMMAND
*&---------------------------------------------------------------------*
FORM frm_user_command USING r_ucomm LIKE sy-ucomm
re_selfield TYPE slis_selfield.
* DATA: LRF_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: ls_data TYPE itab.
***------------更新内表数据-----------------
DATA: gw_grid TYPE REF TO cl_gui_alv_grid.
DATA :stbl TYPE lvc_s_stbl.
IF gw_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = gw_grid.
ENDIF.
IF gw_grid IS NOT INITIAL.
CALL METHOD gw_grid->check_changed_data.
ENDIF.
CASE r_ucomm.
WHEN 'CREATE'.
PERFORM frm_write_data .
re_selfield-col_stable = 'X'.
re_selfield-row_stable = 'X'.
re_selfield-refresh = 'X'.
ENDCASE.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = gw_grid.
CALL METHOD gw_grid->check_changed_data.
re_selfield-refresh = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& FRM_PF_STATUS_SET
*&---------------------------------------------------------------------*
FORM frm_pf_status_set USING pt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD' .
ENDFORM. "FRM_SET_ALV_PROC
*&---------------------------------------------------------------------*
*& Form frm_write_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_write_data .
DATA po_number TYPE bapimepoheader-po_number.
DATA return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA poschedule TYPE TABLE OF bapimeposchedule WITH HEADER LINE.
DATA poschedulex TYPE TABLE OF bapimeposchedulx WITH HEADER LINE.
LOOP AT lt_data.
po_number = lt_data-ebeln.
poschedule-po_item = lt_data-ebelp.
poschedule-quantity = lt_data-menge.
poschedule-stat_date = lt_data-slfdt.
APPEND poschedule.
CLEAR poschedule.
poschedulex-po_item = lt_data-ebelp.
poschedulex-quantity = 'X'.
poschedulex-stat_date = 'X'.
APPEND poschedulex.
CLEAR poschedulex.
AT END OF ebeln.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = po_number
* POHEADER =
* POHEADERX =
* POADDRVENDOR =
* TESTRUN =
* MEMORY_UNCOMPLETE =
* MEMORY_COMPLETE =
* POEXPIMPHEADER =
* POEXPIMPHEADERX =
* VERSIONS =
* NO_MESSAGING =
* NO_MESSAGE_REQ =
* NO_AUTHORITY =
* NO_PRICE_FROM_PO =
* PARK_UNCOMPLETE =
* PARK_COMPLETE =
* IMPORTING
* EXPHEADER =
* EXPPOEXPIMPHEADER =
TABLES
return = return
* POITEM =
* POITEMX =
* POADDRDELIVERY =
poschedule = poschedule
poschedulex = poschedulex
* POACCOUNT =
* POACCOUNTPROFITSEGMENT =
* POACCOUNTX =
* POCONDHEADER =
* POCONDHEADERX =
* POCOND =
* POCONDX =
* POLIMITS =
* POCONTRACTLIMITS =
* POSERVICES =
* POSRVACCESSVALUES =
* POSERVICESTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* POEXPIMPITEM =
* POEXPIMPITEMX =
* POTEXTHEADER =
* POTEXTITEM =
* ALLVERSIONS =
* POPARTNER =
* POCOMPONENTS =
* POCOMPONENTSX =
* POSHIPPING =
* POSHIPPINGX =
* POSHIPPINGEXP =
* POHISTORY =
* POHISTORY_TOTALS =
* POCONFIRMATION =
* SERIALNUMBER =
* SERIALNUMBERX =
* INVPLANHEADER =
* INVPLANHEADERX =
* INVPLANITEM =
* INVPLANITEMX =
* POHISTORY_MA =
* NFMETALLITMS =
.
ENDAT.
LOOP AT return WHERE type CA 'EA' .
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = return-TYPE
msgnr = return-NUMBER
MSGV1 = return-MESSAGE_V1
MSGV2 = return-MESSAGE_V2
MSGV3 = return-MESSAGE_V3
MSGV4 = return-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = lt_data-mess.
.
ENDLOOP.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
.
ELSE.
lt_data-type = 'E'.
ENDIF.
MODIFY lt_data.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_set_application_toobar
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_application_toobar .
functxt-icon_id = icon_export.
functxt-icon_text = '下载EXCEL模板' .
functxt-quickinfo = '下载EXCEL模板' .
sscrfields-functxt_01 = functxt.
ENDFORM.