成功的来了
重点来了 上代码
*&---------------------------------------------------------------------*
*& Report ZDIA_SO_C_FROM_XLSMODEL
*&
*&---------------------------------------------------------------------*
*& date : 20220121
*& author: gavin
*&---------------------------------------------------------------------*
REPORT ZDIA_SO_C_FROM_XLSMODEL.
TABLES SSCRFIELDS.
FIELD-SYMBOLS: <FS>.
INCLUDE OLE2INCL. " FOR OLE
DATA: EXCEL TYPE OLE2_OBJECT,
BOOKS TYPE OLE2_OBJECT,
SHEET TYPE OLE2_OBJECT,
CELL TYPE OLE2_OBJECT.
DATA:L_FILENAME TYPE STRING,L_MUBAN TYPE STRING.
DATA:GV_FULLPATH TYPE STRING,GV_PATH TYPE STRING,GV_NAME TYPE STRING.
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
WA_LAYOUT TYPE LVC_S_LAYO.
DATA: IT_OUTPUT TYPE REF TO DATA,
WA_OUTPUT TYPE REF TO DATA.
FIELD-SYMBOLS: <IT_OUTPUT> TYPE STANDARD TABLE,
<WA_OUTPUT>.
DATA:
STDATUM LIKE SY-DATUM,
STUZEIT LIKE SY-UZEIT,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
*head
DATA:BEGIN OF HEADWTAB,
AUART LIKE VBAK-AUART,"销售订单类型
WAERK LIKE VBAK-WAERK,"币种
VKORG LIKE VBAK-VKORG, "销售机构
VTWEG LIKE VBAK-VTWEG, "分销渠道
SPART LIKE VBAK-SPART, "部门
BSTKD LIKE VBKD-BSTKD, "采购订单合同号
BSTDK LIKE VBKD-BSTDK," 采购订单日期
REQDA LIKE VBKD-BSTDK," 请求交货
PRCDA LIKE VBKD-BSTDK," 定价日期
KUAGV LIKE VBAK-KUNNR," 售达方
KUWEV LIKE VBAK-KUNNR, "送达方
HTEXT(255) TYPE C, "抬头文本
ITEMS TYPE I,
ITEME TYPE I,
VBELN TYPE VBAK-VBELN,"销售订单号
STATUS TYPE C,"状态
MSGTXT(255) TYPE C, " 失败文本描述
END OF HEADWTAB.
DATA:BEGIN OF ITEMWTAB,
MATNR LIKE VBAP-MATNR,
MAKTX like makt-maktx,
MENEG LIKE VBAP-LFMNG,
WERKS LIKE VBAP-WERKS,
CODING(30) TYPE C,"配置编码
DEPICT(250) TYPE C,"配置编码描述
REQ_DATE like VBAK-ERDAT,"配置编码描述
ITEXT(255) TYPE C,
KSCHA LIKE ZM8KONV-KSCHA,
KBETR LIKE ZM8KONV-KBETR,
KOEIN LIKE ZM8KONV-KOEIN,
END OF ITEMWTAB.
DATA:SHEADITAB LIKE STANDARD TABLE OF HEADWTAB.
data:WHead like HEADWTAB.
DATA:SITEMITAB LIKE STANDARD TABLE OF ITEMWTAB.
DATA:SUBITEMTAB LIKE STANDARD TABLE OF ITEMWTAB.
DATA:WITEM LIKE ITEMWTAB.
*import
data:lSALESDOCUMENT like BAPIVBELN-VBELN.
data:lst TYPE i,lend TYPE i.
DATA: ll_lines(10),"行数
ll_tabix(10),"循环标号
ll_pecnt TYPE p LENGTH 6 DECIMALS 2,"百分比
ll_pecet(6),"百分数
ll_text(40)."消息
CLEAR: ll_lines,ll_tabix,ll_pecnt,ll_pecet,ll_text.
*&---------------------------------------------------------------------*
*& 选择界面
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TXT1 .
PARAMETER: P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT 'd:\Users\xiaof\Desktop\ZVA01.xlsx'.
PARAMETER: pflg as CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 5(20) but1 USER-COMMAND bt1.
*SELECTION-SCREEN PUSHBUTTON 30(20) but2 USER-COMMAND bt2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLK1.
SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME TITLE TXT2 .
PARAMETER: PHCOLST TYPE I DEFAULT 1,
PHCOLED TYPE I DEFAULT 14,
PHROWST TYPE I DEFAULT 3,
PHROWED TYPE I DEFAULT 500.
SELECTION-SCREEN END OF BLOCK BLK2.
SELECTION-SCREEN BEGIN OF BLOCK BLK3 WITH FRAME TITLE TXT3 .
PARAMETER: PICOLST TYPE I DEFAULT 1,
PICOLED TYPE I DEFAULT 11,
PIROWST TYPE I DEFAULT 3,
PIROWED TYPE I DEFAULT '9999'.
SELECTION-SCREEN END OF BLOCK BLK3.
INITIALIZATION.
TXT1 = '请输入条件'.
TXT2 = '请检查模板抬头行列开始结束'.
TXT3 = '请检查模板行项目行列开始结束'.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = ICON_BW_REF_STRUCTURE_SAP
TEXT = '模板下载'
INFO = '模板下载'
IMPORTING
result = but1
EXCEPTIONS
icon_not_found = 1
outputfield_too_short = 2
OTHERS = 3.
*&---------------------------------------------------------------------
AT SELECTION-SCREEN.
CASE SSCRFIELDS-UCOMM.
WHEN 'BT1'.
PERFORM DOWNLOAD_DATA.
ENDCASE.
* 选择文件
AT selection-SCREEN ON VALUE-request FOR P_FILE.
* 选择文件
PERFORM GET_FILENAME USING P_FILE.
start-of-selection.
*--取得销售订单抬头数据
PERFORM UPOLOAD_FILE TABLES SHEADITAB USING 'HEAD' PHCOLST PHROWST PHCOLED PHROWED .
PERFORM UPOLOAD_FILE TABLES SITEMITAB USING 'ITEM' PICOLST PIROWST PICOLED PIROWED.
PERFORM DISALV .
IF PFLG = 'X'.
CALL FUNCTION 'GUI_EXEC'
EXPORTING
COMMAND = 'CMD /C TASKKILL /IM EXCEL.EXE'.
ENDIF.
*&---------------------------------------------------------------------*
*& Form fillresult2file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->COL text
* -->LOW text
* -->VALUE text
*----------------------------------------------------------------------*
FORM FILLRESULT2FILE TABLES TABLEITEM TYPE STANDARD TABLE.
DATA: lv_string TYPE TZONREF-TSTAMPS.", TZONREF-TSTAMPL".
GET TIME STAMP FIELD lv_string.
data:lfilename TYPE STRING.
data:lext TYPE String.
SPLIT P_file at '.' into lfilename lext.
lfilename = lfilename && lv_string && '.txt'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = lfilename
FILETYPE = 'DAT' "'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = '4110'
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '