往服务器里面抛数,首先要通过AL11在服务器directory上设置好文本的路径:
1、AL11的具体用法:
2、从文件服务器里面读取文件名的FM:(有时可能会用上)
3、那么具体我们的程序怎么写代码往服务器里面写数据和读数据呢:
PARAMETERS: p_path(200) DEFAULT '/interface/data1/TS_I_ZFIR146.txt' 选择屏幕里面输入路径和文件名,如果文件路径有问题,open dateset的时候就会dump
LOWER CASE,
p_logic LIKE path-pathintern VALUE 'ZINTG_DATA '. 目前来看是写定的,已配好路径和文件名
SELECT SINGLE p~pathextern INTO DSN 抓取文件路径及文件名,而文件名一般是<FILENAME>
FROM path AS p JOIN opsystem AS o
ON p~filesys = o~filesys
WHERE p~pathintern = p_logic
AND o~opsys = sy-opsys.
IF sy-subrc = 0.
REPLACE: '<FILENAME>' IN DSN WITH 'ts_i_036.txt' . 这句就是写上文档名字
ELSE.
MESSAGE i208(00) WITH 'Logic path is invalid!'.
STOP.
ENDIF.
open dataset dsn for output in text mode ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
loop at isale3.
transfer isale3 to dsn.
endloop.
close dataset dsn.
endform.
以上语句就可以完成往服务器里写数的功能。下面再逐一分析各个语句怎么使用:
1)open dataset的使用:
OPEN DATASET dset FOR access IN mode [position]
[os_additions]
[error_handling].
Dset 是指文件路径
Assess 文件的访问方式,有INPUT OUTPUT APPENDING UPDATE
分别是读、写、append、change
Mode 文件访问模式,有BINARY TEXT LEGACY BINARY BEGACY TEXT
BINARY :
TEXT :
LEGACY BINARY :
BEGACY TEXT :
Position 设置文件的起始读取位置
Os_conditions 设置系统设置
Error_handing 存放错误信息的,MESSAGE msg IGNORING CONVERSION ERRORS REPLACEMENT CHARACTER rc
2)Open dataset 之前进行权限检查:
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING
program = sy-cprog
activity = sabc_act_write
filename = l_file
EXCEPTIONS
no_authority = 1
activity_unknown = 2
OTHERS = 3.
3)读取数据: lv_pent 就是directory路径
OPEN DATASET lv_pent FOR INPUT IN binary MODE.
IF sy-subrc = 0.
clear wa_xml.
READ DATASET lv_pent INTO wa_xml.
IF sy-subrc <> 0 or wa_xml is initial.
CLOSE DATASET lv_pent.
EXIT.
ENDIF.
endif.
4)写数据: dsn 就是directory路径
open dataset dsn for output in text mode ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
loop at isale3.
transfer isale3 to dsn.
endloop.
close dataset dsn.
5)设置文件位置,然后写数据
DATA: file TYPE string VALUE 'test.dat',
pos TYPE i,
text TYPE string.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER '1234567890' TO file.
GET DATASET file POSITION pos.
TRANSFER 'ABCDEFGHIJ' TO file.
CLOSE DATASET file.
OPEN DATASET file FOR INPUT IN TEXT MODE
ENCODINGDEFAULT
WITHSMART LINEFEED
ATPOSITION pos.
READ DATASET file INTO text.
CLOSE DATASET file.
DATA: file TYPE string VALUE 'test1.dat',
pos TYPE i,
text TYPE string.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER: 'Line1' TO file,
'Line2'TO file,
'Line3'TO file.
SET DATASET file POSITION 0.
READ DATASET file INTO text.
SET DATASET file POSITION END OF FILE.
TRANSFER: 'Line4' TO file,
'Line5'TO file,
'Line6'TO file.
CLOSE DATASET file.
6)关闭文件路径,每次不管是读还是写,操作完之后都要关闭:
CLOSE DATASET file.
7)删除文件
Delete dataset