SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S33 {
color: #4DA619;
}
.L0S52 {
color: #0000FF;
}
TABLES:vbak,vbap.
DATA:BEGIN OF wa_itab ,
vbeln LIKE vbak-vbeln,
vkorg LIKE vbak-vkorg,
erdat LIKE vbak-erdat,
kunnr LIKE vbak-kunnr,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
kwmeng LIKE vbap-kwmeng,
ttext(100) type c,
END OF wa_itab.
DATA:itab LIKE wa_itab OCCURS 0 WITH HEADER LINE.
DATA:g_file LIKE rlgrap-filename.
DATA:s_file LIKE rlgrap-filename.
DATA:menge(20).
DATA:line(1000) TYPE c.
data tab VALUE cl_abap_char_utilities=>horizontal_tab.
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE t1.
SELECT-OPTIONS:s_erdat FOR vbak-erdat,
s_vbeln FOR vbak-vbeln,
s_kunnr FOR vbak-kunnr,
s_vkorg FOR vbak-vkorg.
PARAMETERS:p_client AS CHECKBOX,
p_dnfile LIKE rlgrap-filename DEFAULT 'D:\',
p_server AS CHECKBOX,
p_sefile LIKE rlgrap-filename DEFAULT '/down/'." '/usr/sap/tmp'.
SELECTION-SCREEN END OF BLOCK bl1 .
INITIALIZATION.
t1 = '选择条件'.
START-OF-SELECTION.
PERFORM sub_read_data.
END-OF-SELECTION.
PERFORM sub_write_data.
*&---------------------------------------------------------------------*
*& Form SUB_READ_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_read_data .
SELECT vbak~vbeln vkorg vbak~erdat kunnr posnr matnr kwmeng
INTO TABLE itab
FROM vbak
JOIN vbap ON vbap~vbeln = vbak~vbeln
WHERE vbak~vbeln IN s_vbeln
AND vbak~erdat IN s_erdat
AND vkorg IN s_vkorg
AND kunnr IN s_kunnr.
ENDFORM. " SUB_READ_DATA
*&---------------------------------------------------------------------*
*& Form SUB_WRITE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_write_data .
IF p_client = 'X'.
CONCATENATE p_dnfile 'SD' sy-datum sy-uzeit '.xls' INTO g_file. "文本格式
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = g_file
filetype = 'DAT'
TABLES
data_tab = itab. "被下载的内表
ENDIF.
IF p_server = 'X'.
CONCATENATE p_sefile 'SD' sy-datum SY-UZEIT '.xls' INTO s_file. "服务器保存的目录和文件名
OPEN DATASET s_file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE."UTF-8."DEFAULT . "打开文件
if sy-subrc = 0.
CONCATENATE '销售组织' tab
'客户' tab
'订单' tab
'日期' tab
'行号' tab
'无聊' tab
'weben' tab
menge
INTO line SEPARATED BY ''.
TRANSFER line TO s_file .
LOOP AT itab INTO wa_itab.
menge = wa_itab-kwmeng.
wa_itab-ttext = '中文测试'.
CONCATENATE wa_itab-vkorg tab
wa_itab-kunnr tab
wa_itab-vbeln tab
wa_itab-erdat tab
wa_itab-posnr tab
wa_itab-matnr tab
wa_itab-ttext tab
menge
INTO line SEPARATED BY ''.
TRANSFER line TO s_file .
IF sy-subrc NE 0 .
MESSAGE 'ERROR!!' type 'E'.
ENDIF.
CLEAR line .
ENDLOOP.
CLOSE DATASET s_file.
else.
MESSAGE 'OPEN ERROR!!' type 'E'.
endif.
ENDIF.
ENDFORM. " SUB_WRITE_DATA
阅读(1451) | 评论(0) | 转发(0) |