*----------------------------------------------------------------------*
* TYPES DEFINITION *
*----------------------------------------------------------------------*
TYPES: BEGIN OF typ_data,
banfn LIKE eban-banfn, "采购申请编号
bnfpo LIKE eban-bnfpo, "采购申请的项目编号
txz01 LIKE eban-txz01, "短文本
posid LIKE prps-posid, "WBS
matnr LIKE mara-matnr, "物料号
maktx LIKE makt-maktx, "物料描述(短文本)
menge LIKE eban-menge, "采购申请数量
meins LIKE eban-meins, "采购申请计量单位
lfdat LIKE eban-lfdat, "项目交货日期
preis LIKE eban-preis, "采购申请中的价格
afnam LIKE eban-afnam, "需求者/请求者姓名
bednr LIKE eban-bednr, "需求跟踪号
ekgrp LIKE eban-ekgrp, "采购组
txt50 LIKE anla-txt50, "资产名称
anlkl LIKE anla-anlkl, "资产分类
txk20 LIKE ankt-txk20, "资产分类描述
kostl LIKE anlz-kostl, "资产成本中心
ktext LIKE cskt-ktext, "资产成本中心描述
END OF typ_data.
*----------------------------------------------------------------------*
* INNER TABLE DEFINITION *
*----------------------------------------------------------------------*
DATA: it_data TYPE TABLE OF typ_data WITH HEADER LINE.
*----------------------------------------------------------------------*
* WROK AREA DEFINITION *
*----------------------------------------------------------------------*
*DATA: wa_data TYPE typ_data.
*----------------------------------------------------------------------*
* PARAMETERS/SELECT-OPTION DEFINITION *
*----------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK blk01 WITH FRAME TITLE text-010.
PARAMETERS: p_file LIKE rlgrap-filename.
SELECTION-SCREEN: END OF BLOCK blk01.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = p_file
.
IF sy-subrc NE 0.
CLEAR p_file.
* MESSAGE e001(zcjxz00).
ENDIF.
*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM frm_get_data.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form frm_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_get_data.
FIELD-SYMBOLS: <f1>.
DATA: l_i_xlstmp TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA: l_col TYPE i.
CLEAR l_i_xlstmp.
REFRESH l_i_xlstmp.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 2
i_begin_row = 5
i_end_col = 20
i_end_row = 30000
TABLES
intern = l_i_xlstmp
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0 .
MESSAGE '导入文件失败。' TYPE 'E'.
ENDIF.
*-转换内表
REFRESH: it_data.
CLEAR: it_data.
SORT l_i_xlstmp BY row col.
LOOP AT l_i_xlstmp.
l_col = l_i_xlstmp-col.
ASSIGN COMPONENT l_col OF STRUCTURE it_data TO <f1>.
<f1> = l_i_xlstmp-value.
AT END OF row.
APPEND it_data.
CLEAR it_data.
ENDAT.
ENDLOOP.
ENDFORM. "frm_get_data
***********************************************************************************************************************************************************************************
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = c_strx
i_line_header = c_strx
i_tab_raw_data = lt_tab_raw_data
i_filename = p_file
TABLES
i_tab_converted_data = gt_data
EXCEPTIONS
conversion_failed = 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.
IF gt_data[] IS INITIAL.
MESSAGE e208 WITH '选择的文件没有数据......'.
ENDIF.
**--数据合法性检查
LOOP AT gt_data.
TRANSLATE gt_data-werks TO UPPER CASE.
gt_out-werks = gt_data-werks.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = gt_data-matnr
IMPORTING
output = gt_out-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
CONCATENATE sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO gt_out-bz.
ENDIF.
"---物料编号是否在物料的仓储位置数据中存在
SELECT matnr
werks
lgort
lgort1
lgort2
INTO TABLE lt_mard
FROM mard
WHERE matnr EQ gt_out-matnr.
IF sy-subrc NE 0.
CONCATENATE '物料编号' gt_data-matnr '不存在' INTO gt_out-bz.
gt_out-flag = '1'. "导入数据存在错误
g_error_lines = g_error_lines + 1.
ELSE.
APPEND LINES OF lt_mard TO gt_mard.
SELECT SINGLE maktx
INTO gt_out-maktx
FROM makt
WHERE spras EQ sy-langu
AND matnr EQ gt_out-matnr.
"---工厂是否在物料的仓储位置数据中存在
LOOP AT lt_mard WHERE matnr = gt_out-matnr
AND werks = gt_data-werks.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
CONCATENATE '工厂' gt_data-werks '不存在' INTO gt_out-bz.
gt_out-flag = '1'. "导入数据存在错误
g_error_lines = g_error_lines + 1.
ELSE.
"---库位是否在物料的仓储位置数据中存在
LOOP AT lt_mard WHERE matnr = gt_out-matnr
AND werks = gt_data-werks
AND lgort = gt_data-lgort.
EXIT.
ENDLOOP.
IF sy-subrc NE 0.
CONCATENATE '库位' gt_data-lgort '不存在' INTO gt_out-bz.
gt_out-flag = '1'. "导入数据存在错误
g_error_lines = g_error_lines + 1.
ELSE.
AUTHORITY-CHECK OBJECT 'Z_HY_MM'
ID 'WERKS' FIELD gt_out-werks.
IF sy-subrc <> 0.
CONCATENATE '无工厂' gt_out-werks '使用权限' INTO gt_out-bz.
gt_out-flag = '1'.
g_error_lines = g_error_lines + 1.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
** gt_out-werks = gt_data-werks.
gt_out-lgort = gt_data-lgort.
gt_out-lgort1 = gt_data-lgort1.
gt_out-lgort2 = gt_data-lgort2.
APPEND gt_out.
g_lines = g_lines + 1.
CLEAR gt_out.
ENDLOOP.
1、SNRO维护编号范围;
2、NUMBER_RANGE_ENQUEUE→NUMBER_GET_NEXT→NUMBER_RANGE_DEQUEUE