*&---------------------------------------------------------------------*
*& 包括 YR3TABLE2FTP_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form f_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_get_data .
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_table_new> TYPE STANDARD TABLE,
<dyn_wa>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data.
DATA: str TYPE string.
DATA: lv_selflds TYPE string.
IF p_ymd = ‘YYYYMMDD‘.
IF p_ymd2 IS NOT INITIAL.
CONCATENATE p_fil_px p_ymd2 INTO p_fil_px2.
ELSE.
CONCATENATE p_fil_px sy-datum INTO p_fil_px2.
ENDIF.
ELSEIF p_ymd = ‘YYYYMM‘.
IF p_ymd2 IS NOT INITIAL.
CONCATENATE p_fil_px p_ymd2+0(6) INTO p_fil_px2.
ELSE.
CONCATENATE p_fil_px sy-datum+0(6) INTO p_fil_px2.
ENDIF.
ELSEIF p_ymd = ‘YYYYMMDDHHMMSS‘.
IF p_ymd2 IS NOT INITIAL.
CONCATENATE p_fil_px p_ymd2 sy-uzeit INTO p_fil_px2.
ELSE.
CONCATENATE p_fil_px sy-datum sy-uzeit INTO p_fil_px2.
ENDIF.
ELSE.
p_fil_px2 = p_fil_px.
ENDIF.
CLEAR: gt_YTEST300,gt_YTEST300[].
SELECT * FROM YTEST300 INTO TABLE gt_YTEST300 WHERE username = p_varusr AND tabname = p_table ORDER BY sequence ASCENDING.
struct_type ?= cl_abap_typedescr=>describe_by_name( p_table ).
comp_tab[] = struct_type->get_components( ).
PERFORM frm_comp_tab TABLES comp_tab.
IF gt_YTEST300[] IS NOT INITIAL.
CLEAR:comp_tab2[].
LOOP AT gt_YTEST300.
READ TABLE comp_tab WITH KEY name = gt_YTEST300-fldname.
MOVE-CORRESPONDING comp_tab TO comp_tab2.
APPEND comp_tab2.
CONCATENATE lv_selflds ` ` gt_YTEST300-fldname INTO lv_selflds.
ENDLOOP.
comp_tab[] = comp_tab2[].
IF timestmp = ‘X‘.
comp_tab-name = ‘ZTIMESTAMPL‘.
comp_tab-type = cl_abap_elemdescr=>get_c( 22 ).
APPEND comp_tab.
ENDIF.
struct_type = cl_abap_structdescr=>create( comp_tab[] ).
ELSE.
LOOP AT comp_tab.
CONCATENATE lv_selflds ` ` comp_tab-name INTO lv_selflds.
ENDLOOP.
IF timestmp = ‘X‘.
comp_tab-name = ‘ZTIMESTAMPL‘.
comp_tab-type = cl_abap_elemdescr=>get_c( 22 ).
APPEND comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab[] ).
ENDIF.
ENDIF.
table_type = cl_abap_tabledescr=>create( struct_type ).
CREATE DATA dy_table TYPE HANDLE table_type.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
DATA: cond TYPE string,orderby TYPE string.
CLEAR:cond .
IF p_name1 IS NOT INITIAL AND s_val1[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name1 ` in s_val1 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name1 ` in s_val1` INTO cond.
ENDIF.
ENDIF.
IF p_name2 IS NOT INITIAL AND s_val2[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name2 ` in s_val2 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name2 ` in s_val2` INTO cond.
ENDIF.
ENDIF.
IF p_name3 IS NOT INITIAL AND s_val3[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name3 ` in s_val3 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name3 ` in s_val3` INTO cond.
ENDIF.
ENDIF.
IF p_name4 IS NOT INITIAL AND s_val4[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name4 ` in s_val4 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name4 ` in s_val4` INTO cond.
ENDIF.
ENDIF.
IF p_name5 IS NOT INITIAL AND s_val5[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name5 ` in s_val5 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name5 ` in s_val5` INTO cond.
ENDIF.
ENDIF.
IF p_name6 IS NOT INITIAL AND s_val6[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name6 ` in s_val6 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name6 ` in s_val6` INTO cond.
ENDIF.
ENDIF.
IF p_name7 IS NOT INITIAL AND s_val7[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name7 ` in s_val7 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name7 ` in s_val7` INTO cond.
ENDIF.
ENDIF.
IF p_name8 IS NOT INITIAL AND s_val8[] IS NOT INITIAL.
IF cond = ‘‘.
CONCATENATE p_name8 ` in s_val8 ` INTO cond.
ELSE.
CONCATENATE cond ` and ` p_name8 ` in s_val8` INTO cond.
ENDIF.
ENDIF.
DATA: str_len TYPE i.
str_len = STRLEN( ftp_path ).
str_len = str_len - 1.
REPLACE ALL OCCURRENCES OF `\` IN ftp_path WITH `/`.
CONDENSE ftp_path.
IF ftp_path+str_len = ‘/‘ AND p_dir_dt IS NOT INITIAL.
CONCATENATE ftp_path p_dir_dt INTO ftp_path.
ELSEIF p_dir_dt IS NOT INITIAL.
CONCATENATE ftp_path ‘/‘ p_dir_dt INTO ftp_path.
ENDIF.
IF ftp_path+str_len = ‘/‘ AND str_len <> 0.
ftp_path = ftp_path+0(str_len).
ENDIF.
FIELD-SYMBOLS: <fldvalue>,<key_constr>.
DATA: key_constr TYPE TABLE OF string WITH HEADER LINE,l_total TYPE string,lins TYPE i,lins2 TYPE i,strtmp TYPE string.
DATA:lt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE,wa_dd03l LIKE lt_dd03l.
SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
WHERE tabname = p_table AND keyflag = ‘X‘ .
SORT lt_dd03l BY position.
LOOP AT lt_dd03l.
CONCATENATE ` ` orderby ` ` lt_dd03l-fieldname INTO orderby.
ENDLOOP.
CONDENSE orderby.
DELETE lt_dd03l WHERE fieldname = ‘MANDT‘.
READ TABLE lt_dd03l INTO wa_dd03l INDEX 1."第一主键字段
DATA: counts TYPE i,diff_counts TYPE i.
DO.
g_count = sy-index.
CONCATENATE `_` g_count INTO g_count_c.
CLEAR:key_constr,key_constr[].
IF sy-index = 1."首次查
IF cond IS INITIAL.
IF wa_dd03l-inttype = ‘C‘.
CONCATENATE wa_dd03l-fieldname ` >= ‘‘` INTO key_constr.
ELSE.
CONCATENATE `( ` wa_dd03l-fieldname ` >= -128 )`INTO key_constr.
ENDIF.
ELSE.
IF wa_dd03l-inttype = ‘C‘.
CONCATENATE `( ` wa_dd03l-fieldname ` >= ‘‘ ) AND ( ` cond ` )` INTO key_constr.
ELSE.
CONCATENATE `( ` wa_dd03l-fieldname ` >= -128 ) AND ( ` cond ` )` INTO key_constr.
ENDIF.
ENDIF.
APPEND key_constr.
CLEAR key_constr.
ELSE.
IF <dyn_table> IS NOT INITIAL ."最近一次查到数据后
DESCRIBE TABLE lt_dd03l LINES lins.
IF lins > 1."如果主键字段个数大于1
PERFORM frm_key_constr TABLES <dyn_table> lt_dd03l key_constr.
LOOP AT key_constr ASSIGNING <key_constr>.
IF cond IS NOT INITIAL.
CONCATENATE `( ` <key_constr> ` ) AND ( ` cond ` )` INTO <key_constr>.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR <dyn_wa>.
DESCRIBE TABLE <dyn_table> LINES lins.
READ TABLE <dyn_table> INTO <dyn_wa> INDEX lins.
ASSIGN COMPONENT wa_dd03l-fieldname OF STRUCTURE <dyn_wa> TO <fldvalue>.
"非首次查询时,无论怎样第一主键字段大于条件需要
IF cond IS INITIAL.
CONCATENATE wa_dd03l-fieldname ` > ‘` <fldvalue> `‘` INTO key_constr.
ELSE.
CONCATENATE wa_dd03l-fieldname ` > ‘` <fldvalue> `‘ AND ( ` cond ` )` INTO key_constr.
ENDIF.
APPEND key_constr.
ENDIF.
ENDIF.
CONCATENATE `正在读取第 ` g_count ` 批数据...` INTO str.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
EXPORTING
percentage = 20
text = str.
FREE <dyn_table>.
LOOP AT key_constr.
DESCRIBE TABLE <dyn_table> LINES lins.
diff_counts = p_counts - lins.
IF diff_counts <= 0 .
EXIT.
ENDIF.
strtmp = key_constr.
GET RUN TIME FIELD tm1.
SELECT (lv_selflds) APPENDING CORRESPONDING FIELDS OF TABLE <dyn_table> FROM (p_table) UP TO diff_counts ROWS WHERE (strtmp) ORDER BY (orderby).
DESCRIBE TABLE <dyn_table> LINES lins2.
diff_counts = lins2 - lins.
IF psqllog = ‘X‘.
PERFORM frm_write_file2 USING strtmp diff_counts sy-tabix.
ENDIF.
ENDLOOP.
IF psqllog = ‘X‘.
PERFORM frm_write_file3 .
ENDIF.
"首次查询为空时,需要下传空文件
IF sy-index > 1 AND <dyn_table> IS INITIAL.
EXIT.
ENDIF.
DATA:dy_table_new TYPE REF TO data.
IF p_prog IS NOT INITIAL.
************************************
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
EXPORTING
percentage = 20
text = `输出字段逻辑扩展处理...`.
PERFORM frm_dyn IN PROGRAM (p_prog) TABLES <dyn_table> comp_tab[]
s_asist1 s_asist2 s_asist3 s_asist4 s_asist5
USING dy_table_new .
ASSIGN dy_table_new->* TO <dyn_table_new>.
IF p_fileno IS NOT INITIAL."分文件抛FTP
PERFORM to_ftptab TABLES <dyn_table_new>.
ELSE."不分文件
IF g_count = 1.
PERFORM to_ftptab TABLES <dyn_table_new>.
ELSE.
PERFORM frm_write_file TABLES <dyn_table_new>.
ENDIF.
ENDIF.
DESCRIBE TABLE <dyn_table_new> LINES lins.
************************************
ELSE.
IF p_fileno IS NOT INITIAL.
PERFORM to_ftptab TABLES <dyn_table>.
ELSE.
IF g_count = 1.
PERFORM to_ftptab TABLES <dyn_table>.
ELSE.
PERFORM frm_write_file TABLES <dyn_table>.
ENDIF.
ENDIF.
DESCRIBE TABLE <dyn_table> LINES lins.
ENDIF.
l_total = l_total + lins.
IF flg_ftp IS NOT INITIAL.
EXIT.
ENDIF.
ENDDO.
IF p_fileno IS INITIAL.
CONCATENATE `正在将SAP服务上文件Append到FTP:` gv_filename INTO str.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
EXPORTING
percentage = 20
text = str.
PERFORM frm_ftp_append.
CONCATENATE `/usr/sap/tmp/` p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
DELETE DATASET gv_filename.
ENDIF.
CHECK flg_ftp IS INITIAL AND pflgfile = ‘X‘.
DATA: codepage TYPE cpcodepage,
encoding TYPE abap_encoding,
convout TYPE REF TO cl_abap_conv_out_ce,
buffer TYPE xstring.
DATA: BEGIN OF dest_xtab OCCURS 0,
x(6144) TYPE x,
END OF dest_xtab.
CALL FUNCTION ‘SCP_CODEPAGE_BY_EXTERNAL_NAME‘
EXPORTING
external_name = p_encodi
IMPORTING
sap_codepage = codepage.
encoding = codepage.
CALL METHOD cl_abap_conv_out_ce=>create
EXPORTING
encoding = encoding
RECEIVING
conv = convout.
* CONCATENATE `数据总条数:` l_total INTO l_total.
CONDENSE l_total.
CALL METHOD convout->write
EXPORTING
data = l_total.
CALL METHOD convout->get_buffer
RECEIVING
buffer = buffer.
DATA: lv_binary_len TYPE i.
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY‘
EXPORTING
buffer = buffer
IMPORTING
output_length = lv_binary_len
TABLES
binary_tab = dest_xtab.
PERFORM f_ftp_connect.
PERFORM frm_cd_dir.
CONCATENATE p_fil_px2 `.` p_flgex INTO gv_filename.
CONDENSE gv_filename.
CALL FUNCTION ‘FTP_R3_TO_SERVER‘
EXPORTING
handle = thandle
fname = gv_filename
blob_length = lv_binary_len
TABLES
blob = dest_xtab
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
IF sy-subrc EQ 0.
WRITE:/ gv_filename,‘传输成功!‘.
ELSE.
WRITE:/ gv_filename,‘数据文件传输失败!‘.
ENDIF.
PERFORM f_ftp_disconnect.
ENDFORM. " f_get_data
*&---------------------------------------------------------------------*
*& Form to_ftptab
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_SRC_TAB text
* -->P_DEST_XTAB text
* -->OF text
* -->X text
*----------------------------------------------------------------------*
FORM to_ftptab TABLES p_src_tab.
DATA: BEGIN OF dest_xtab OCCURS 0,
x(6144) TYPE x,
END OF dest_xtab.
DATA: lv_binary_len TYPE i.
DATA:str TYPE string.
IF p_fileno IS NOT INITIAL.
CONCATENATE p_fil_px2 g_count_c `.` p_extens INTO gv_filename SEPARATED BY ``.
ELSE.
CONCATENATE p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
ENDIF.
CONCATENATE `正在准备文件:` gv_filename INTO str.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
EXPORTING
percentage = 20
text = str.
PERFORM frm_data_to_binary TABLES p_src_tab dest_xtab USING lv_binary_len ‘X‘.
CONCATENATE `正在上传文件:` gv_filename INTO str.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
EXPORTING
percentage = 20
text = str.
PERFORM f_ftp_connect.
PERFORM frm_mkdir.
PERFORM frm_cd_dir.
PERFORM f_ftp TABLES dest_xtab USING lv_binary_len.
PERFORM f_ftp_disconnect.
CLEAR:dest_xtab.
REFRESH:dest_xtab[].
ENDFORM. "to_ftptab
*&---------------------------------------------------------------------*
*& Form to_ftptab2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_SRC_TAB text
*----------------------------------------------------------------------*
FORM frm_data_to_binary TABLES p_src_tab dest_xtab USING lv_binary_len TYPE i first.
DATA:strct_type_ref TYPE REF TO cl_abap_structdescr,
tab_type_ref TYPE REF TO cl_abap_tabledescr,
t_component TYPE cl_abap_structdescr=>component_table,
wa_component LIKE LINE OF t_component.
FIELD-SYMBOLS: <fldvalue>.
DATA:time_stamp TYPE timestampl,timestamp_c(22).
DATA: l_str TYPE string,fldstr TYPE string,fldtype,firsttime VALUE ‘X‘.
DATA: str TYPE string.
DATA: len TYPE string.
DATA: codepage TYPE cpcodepage,
encoding TYPE abap_encoding,
convout TYPE REF TO cl_abap_conv_out_ce,
buffer TYPE xstring.
CALL FUNCTION ‘SCP_CODEPAGE_BY_EXTERNAL_NAME‘
EXPORTING
external_name = p_encodi
IMPORTING
sap_codepage = codepage.
encoding = codepage.
CALL METHOD cl_abap_conv_out_ce=>create
EXPORTING
encoding = encoding
RECEIVING
conv = convout.
tab_type_ref ?= cl_abap_tabledescr=>describe_by_data( p_src_tab[] ).
strct_type_ref ?= tab_type_ref->get_table_line_type( ).
t_component = strct_type_ref->get_components( ).
str = p_split.
REPLACE ALL OCCURRENCES OF `\t` IN str WITH c_tab.
REPLACE ALL OCCURRENCES OF `\T` IN str WITH c_tab.
REPLACE ALL OCCURRENCES OF ` ` IN str WITH ``.
IF p_header = ‘X‘ AND first IS NOT INITIAL.
PERFORM frm_find_table USING ‘X‘.
CLEAR:fldstr,l_str.
LOOP AT t_component INTO wa_component.
READ TABLE gt_dd03l WITH KEY fieldname = wa_component-name.
IF sy-subrc = 0.
len = gt_dd03l-leng + gt_dd03l-decimals.
CONDENSE len.
READ TABLE gt_vrm_values WITH KEY key = wa_component-name.
IF sy-subrc = 0.
REPLACE ALL OCCURRENCES OF str IN gt_vrm_values-text WITH ` `.
IF fldstr = ‘‘.
IF p_hdtlg IS NOT INITIAL.
CONCATENATE gt_vrm_values-text `(` len `)` INTO fldstr.
ELSE.
CLEAR: itab,itab[].
SPLIT gt_vrm_values-text AT `:` INTO TABLE itab.
READ TABLE itab INDEX 2.
fldstr = itab .
ENDIF.
ELSE.
IF p_hdtlg IS NOT INITIAL.
CONCATENATE fldstr str gt_vrm_values-text `(` len `)` INTO fldstr.
ELSE.
CLEAR: itab,itab[].
SPLIT gt_vrm_values-text AT `:` INTO TABLE itab.
READ TABLE itab INDEX 2.
CONCATENATE fldstr str itab INTO fldstr.
ENDIF.
ENDIF.
ELSE.
IF fldstr = ‘‘.
IF p_hdtlg IS NOT INITIAL.
CONCATENATE gt_dd03l-fieldname `(` len `)` INTO fldstr.
ELSE.
fldstr = gt_dd03l-fieldname.
ENDIF.
ELSE.
IF p_hdtlg IS NOT INITIAL.
CONCATENATE fldstr str gt_dd03l-fieldname `(` len `)` INTO fldstr.
ELSE.
CONCATENATE fldstr str gt_dd03l-fieldname INTO fldstr.
ENDIF.
ENDIF.
ENDIF.
ELSE.
elem_type ?= wa_component-type.
len = elem_type->length + elem_type->decimals.
CONDENSE len.
IF fldstr = ‘‘.
IF p_hdtlg IS NOT INITIAL.
CONCATENATE wa_component-name `(` len `)` INTO fldstr.
ELSE.
fldstr = wa_component-name.
ENDIF.
ELSE.
IF p_hdtlg IS NOT INITIAL.
CONCATENATE fldstr str wa_component-name `(` len `)` INTO fldstr.
ELSE.
CONCATENATE fldstr str wa_component-name INTO fldstr.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
CALL METHOD convout->write
EXPORTING
data = fldstr.
CALL METHOD convout->write
EXPORTING
data = cl_abap_char_utilities=>cr_lf.
ENDIF.
GET TIME STAMP FIELD time_stamp.
timestamp_c = time_stamp.
LOOP AT p_src_tab.
firsttime = ‘X‘.
CLEAR:fldstr,l_str.
LOOP AT t_component INTO wa_component.
IF wa_component-name = ‘ZTIMESTAMPL‘.
IF firsttime = ‘X‘.
fldstr = time_stamp.
CLEAR firsttime.
ELSE.
CONCATENATE fldstr timestamp_c INTO fldstr SEPARATED BY str.
ENDIF.
CONTINUE.
ENDIF.
fldtype = wa_component-type->type_kind.
ASSIGN COMPONENT wa_component-name OF STRUCTURE p_src_tab TO <fldvalue>.
l_str = <fldvalue>.
IF fldtype = ‘P‘ OR fldtype = ‘F‘
OR fldtype = ‘I‘ OR fldtype = ‘b‘
OR fldtype = ‘s‘.
CALL FUNCTION ‘CLOI_PUT_SIGN_IN_FRONT‘
CHANGING
value = l_str.
ENDIF.
REPLACE ALL OCCURRENCES OF str IN l_str WITH ` `.
IF firsttime = ‘X‘.
fldstr = l_str .
CLEAR firsttime.
ELSE.
CONCATENATE fldstr l_str INTO fldstr SEPARATED BY str.
ENDIF.
ENDLOOP.
CONDENSE fldstr.
CALL METHOD convout->write
EXPORTING
data = fldstr.
CALL METHOD convout->write
EXPORTING
data = cl_abap_char_utilities=>cr_lf.
ENDLOOP.
CALL METHOD convout->get_buffer
RECEIVING
buffer = buffer.
CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY‘
EXPORTING
buffer = buffer
IMPORTING
output_length = lv_binary_len
TABLES
binary_tab = dest_xtab.
ENDFORM. "frm_data_to_binary
*&---------------------------------------------------------------------*
*& Form f_ftp_connect
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_ftp_connect .
DATA: thosts(45),tusers(45),tpword(45).
thosts = p_host.
tusers = p_user.
tpword = p_pwd.
slen = STRLEN( tpword ).
***对密码值进行加密解析处理
CALL FUNCTION ‘HTTP_SCRAMBLE‘
EXPORTING
SOURCE = tpword
sourcelen = slen
key = key
IMPORTING
destination = tpword.
***定义RFC连接目标,前后台执行时不同
* IF sy-batch = ‘X‘.
trfcdest = ‘SAPFTPA‘.
* ELSE.
* trfcdest = ‘SAPFTP‘.
* ENDIF.
***该函数可以定义有网关是账户密码,一般公司内部访问无此设置
CALL FUNCTION ‘FTP_CONNECT‘
EXPORTING
user = tusers
password = tpword
host = thosts
rfc_destination = trfcdest
IMPORTING
handle = thandle
EXCEPTIONS
not_connected = 1
OTHERS = 2.
IF sy-subrc NE 0.
WRITE:/ ‘FTP连接失败!‘.
STOP.
ENDIF.
ENDFORM. " f_ftp_connect
*&---------------------------------------------------------------------*
*& Form frm_mkdir
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_mkdir .
DATA: dirstr TYPE string.
CLEAR:com,com[],res,res[].
CLEAR: itab, itab[].
SPLIT ftp_path AT `/` INTO TABLE itab .
DELETE itab WHERE table_line = ‘‘.
LOOP AT itab .
IF sy-tabix = 1.
CONCATENATE `/` itab INTO dirstr SEPARATED BY ``.
ELSE.
CONCATENATE dirstr `/` itab INTO dirstr SEPARATED BY ``.
ENDIF.
CONCATENATE `mkdir ` dirstr INTO com-cmd SEPARATED BY ``.
APPEND com.
ENDLOOP.
LOOP AT com.
CALL FUNCTION ‘FTP_COMMAND‘
EXPORTING
handle = thandle
command = com-cmd
TABLES
data = res
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
ENDLOOP.
ENDFORM. " frm_mkdir
*&---------------------------------------------------------------------*
*& Form frm_cd_dir
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_cd_dir .
CLEAR:com,com[],res,res[].
CONCATENATE ‘cd‘ ftp_path INTO com-cmd SEPARATED BY ‘‘.
CALL FUNCTION ‘FTP_COMMAND‘
EXPORTING
handle = thandle
command = com-cmd
TABLES
data = res
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
ENDFORM. " frm_cd_dir
*&---------------------------------------------------------------------*
*& Form f_ftp_disconnect
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_ftp_disconnect .
CALL FUNCTION ‘FTP_DISCONNECT‘
EXPORTING
handle = thandle.
ENDFORM. " f_ftp_disconnect
*&---------------------------------------------------------------------*
*& Form f_ftp
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_ftp TABLES p_ftptab USING lv_binary_len.
CONDENSE gv_filename.
* DATA:str TYPE string.
* CONCATENATE `正在上传文件:` gv_filename INTO str.
* CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
* EXPORTING
* percentage = 20
* text = str.
CALL FUNCTION ‘FTP_R3_TO_SERVER‘
EXPORTING
handle = thandle
fname = gv_filename
blob_length = lv_binary_len
TABLES
blob = p_ftptab
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
IF sy-subrc EQ 0.
WRITE:/ gv_filename,‘传输成功!‘.
ELSE.
WRITE:/ gv_filename,‘数据文件传输失败!‘.
flg_ftp = ‘X‘.
ENDIF.
ENDFORM. " f_ftp
*&---------------------------------------------------------------------*
*& Module STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1001 OUTPUT.
SET PF-STATUS ‘ST_1001‘.
SET TITLEBAR ‘1001‘.
CLEAR: texttable[],line,gt_YTEST300,gt_YTEST300[].
CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[],rtables,rtables[].
PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING ‘X‘.
SELECT * FROM YTEST300 INTO TABLE gt_YTEST300 WHERE username = p_varusr AND tabname = p_table ORDER BY sequence ASCENDING.
IF sy-subrc = 0.
LOOP AT gt_YTEST300.
READ TABLE gt_vrm_values WITH KEY key = gt_YTEST300-fldname.
CLEAR:itab[].
SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
CONCATENATE line c_crlf gt_YTEST300-fldname `:` c1 INTO line SEPARATED BY ``.
ENDLOOP.
ELSE.
LOOP AT gt_vrm_values.
CLEAR:itab[].
SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
CONCATENATE line c_crlf gt_vrm_values-key `:` c1 INTO line SEPARATED BY ``.
ENDLOOP.
ENDIF.
line = line+2.
APPEND line TO texttable.
IF editor_container IS NOT BOUND.
CREATE OBJECT editor_container
EXPORTING
container_name = ‘EDITOR‘.
CREATE OBJECT editor
EXPORTING
parent = editor_container
wordwrap_mode = 1
max_number_chars = 10000.
ENDIF.
editor->set_textstream( line ).
ENDMODULE. " STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
CASE sy-ucomm.
WHEN ‘RW‘.
LEAVE TO SCREEN 0.
WHEN ‘SAVE‘.
CALL METHOD editor->get_text_as_stream
IMPORTING
text = texttable[].
CLEAR: line.
LOOP AT texttable.
CONCATENATE line texttable-line INTO line SEPARATED BY ``.
ENDLOOP.
IF sy-subrc <> 0.
MESSAGE `请输入内容` TYPE ‘E‘.
ELSE.
CLEAR:itab[].
SPLIT line AT c_crlf INTO TABLE itab .
IF itab[] IS INITIAL.
MESSAGE `请输入内容` TYPE ‘E‘.
ELSE.
CLEAR:itab2[].
LOOP AT itab .
SPLIT itab AT `:` INTO itab c1.
CONDENSE itab.
TRANSLATE itab TO UPPER CASE.
APPEND itab TO itab2.
ENDLOOP.
LOOP AT itab .
g_tabix = sy-tabix.
SPLIT itab AT `:` INTO itab c1.
CONDENSE itab.
TRANSLATE itab TO UPPER CASE.
IF itab <> ‘‘.
CLEAR repeat.
LOOP AT itab2 WHERE table_line = itab.
repeat = repeat + 1.
ENDLOOP.
IF repeat > 1.
CONCATENATE itab ` 重复输入` INTO c1.
MESSAGE c1 TYPE ‘E‘.
EXIT.
ENDIF.
MODIFY itab INDEX g_tabix.
ELSE.
DELETE itab INDEX g_tabix.
ENDIF.
ENDLOOP.
IF itab[] IS INITIAL.
MESSAGE `请输入内容` TYPE ‘E‘.
ELSE.
CLEAR:gt_YTEST300[],gt_YTEST300.
LOOP AT itab.
gt_YTEST300-sequence = sy-tabix.
READ TABLE gt_vrm_values WITH KEY key = itab.
IF sy-subrc <> 0.
CONCATENATE itab ` 字段不存在` INTO c1.
CLEAR:gt_YTEST300[],gt_YTEST300.
MESSAGE c1 TYPE ‘E‘.
ENDIF.
gt_YTEST300-username = p_varusr.
gt_YTEST300-tabname = p_table.
gt_YTEST300-fldname = itab.
APPEND gt_YTEST300.
ENDLOOP.
DATA:lt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE,msg TYPE string.
CLEAR:msg,lt_dd03l,lt_dd03l[].
SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
WHERE tabname = p_table AND keyflag = ‘X‘.
LOOP AT lt_dd03l.
READ TABLE gt_YTEST300 WITH KEY fldname = lt_dd03l-fieldname.
IF sy-subrc <> 0.
CONCATENATE lt_dd03l-fieldname `为主键,不能删除` INTO msg.
MESSAGE msg TYPE ‘E‘.
ENDIF.
ENDLOOP.
DELETE FROM YTEST300 WHERE username = p_varusr AND tabname = p_table.
MODIFY YTEST300 FROM TABLE gt_YTEST300.
COMMIT WORK.
MESSAGE ‘保存成功‘ TYPE ‘I‘.
ENDIF.
ENDIF.
ENDIF.
WHEN ‘RE_LOAD‘.
DATA: l_answer.
CALL FUNCTION ‘POPUP_TO_CONFIRM‘
EXPORTING
text_question = ‘重置会将当前配置从YTEST300中删除,是否继续?‘
icon_button_1 = ‘是‘
icon_button_2 = ‘否‘
default_button = ‘2‘
display_cancel_button = ‘‘
IMPORTING
answer = l_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF l_answer = ‘1‘.
DELETE FROM YTEST300 WHERE username = p_varusr AND tabname = p_table.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
*& Form frm_val
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_val TABLES lt_vrm_values TYPE vrm_values rtables STRUCTURE
range_c35 lt_vrm_values_dt TYPE vrm_values lt_dd03l STRUCTURE dd03l
USING mandt.
DATA:lt_dd03t TYPE TABLE OF dd03t WITH HEADER LINE,
lt_dd04t TYPE TABLE OF dd04t WITH HEADER LINE.
DATA:ls_vrm_values LIKE LINE OF lt_vrm_values.
DATA:BEGIN OF fieldname OCCURS 0,
fieldname TYPE dd03t-fieldname ,
END OF fieldname.
DATA:BEGIN OF rollname OCCURS 0,
rollname TYPE dd04t-rollname ,
END OF rollname.
IF rtables[] IS INITIAL.
rtables-sign = ‘I‘.
rtables-option = ‘EQ‘.
rtables-low = p_table.
APPEND rtables.
ENDIF.
IF mandt IS NOT INITIAL.
SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
WHERE tabname IN rtables AND fieldname <> ‘.INCLU--AP‘ AND fieldname <> ‘.INCLUDE‘.
ELSE.
SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
WHERE tabname IN rtables AND fieldname <> ‘MANDT‘ AND fieldname <> ‘.INCLU--AP‘ AND fieldname <> ‘.INCLUDE‘.
ENDIF.
SORT lt_dd03l BY position.
LOOP AT lt_dd03l .
IF lt_dd03l-rollname = ‘‘.
APPEND lt_dd03l-fieldname TO fieldname.
ELSE.
APPEND lt_dd03l-rollname TO rollname.
ENDIF.
ENDLOOP.
IF fieldname[] IS NOT INITIAL.
SELECT fieldname ddtext INTO CORRESPONDING FIELDS OF TABLE lt_dd03t
FROM dd03t
FOR ALL ENTRIES IN fieldname
WHERE tabname = p_table
AND ddlanguage = ‘1‘
AND fieldname = fieldname-fieldname.
ENDIF.
IF rollname[] IS NOT INITIAL.
SELECT rollname ddtext INTO CORRESPONDING FIELDS OF TABLE lt_dd04t
FROM dd04t
FOR ALL ENTRIES IN rollname
WHERE ddlanguage = ‘1‘
AND rollname = rollname-rollname.
ENDIF.
REFRESH lt_vrm_values.
LOOP AT lt_dd03l.
ls_vrm_values-key = lt_dd03l-fieldname.
IF lt_dd03l-rollname = ‘‘.
READ TABLE lt_dd03t WITH KEY fieldname = lt_dd03l-fieldname.
IF sy-subrc = 0.
CONCATENATE lt_dd03l-fieldname `:` lt_dd03t-ddtext INTO ls_vrm_values-text SEPARATED BY ``.
ENDIF.
ELSE.
READ TABLE lt_dd04t WITH KEY rollname = lt_dd03l-rollname.
IF sy-subrc = 0.
CONCATENATE lt_dd03l-fieldname `:` lt_dd04t-ddtext INTO ls_vrm_values-text SEPARATED BY ``.
ENDIF.
ENDIF.
IF lt_dd03l-inttype = ‘D‘.
APPEND ls_vrm_values TO lt_vrm_values_dt.
ENDIF.
APPEND ls_vrm_values TO lt_vrm_values.
ENDLOOP.
ENDFORM. "frm_val
*&---------------------------------------------------------------------*
*& Module STATUS_1002 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1002 OUTPUT.
SET PF-STATUS ‘ST_1002‘.
SET TITLEBAR ‘1002‘.
CLEAR: texttable[],line,gt_YTEST300,gt_YTEST300[].
CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[],rtables,rtables[].
PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING ‘X‘.
CONCATENATE `CREATE TABLE IF NOT EXISTS SAP_R3_` p_table `(` INTO line.
SELECT * FROM YTEST300 INTO TABLE gt_YTEST300 WHERE username = p_varusr AND tabname = p_table ORDER BY sequence ASCENDING.
IF sy-subrc = 0.
LOOP AT gt_YTEST300.
READ TABLE gt_vrm_values WITH KEY key = gt_YTEST300-fldname.
CLEAR:itab[].
SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
REPLACE ALL OCCURRENCES OF `‘` IN c1 WITH ``.
REPLACE ALL OCCURRENCES OF `,` IN c1 WITH ``.
CONCATENATE line c_crlf gt_YTEST300-fldname ` STRING COMMENT ‘` c1 `‘,` INTO line SEPARATED BY ``.
ENDLOOP.
ELSE.
LOOP AT gt_vrm_values.
CLEAR:itab[].
SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
REPLACE ALL OCCURRENCES OF `‘` IN c1 WITH ``.
REPLACE ALL OCCURRENCES OF `,` IN c1 WITH ``.
CONCATENATE line c_crlf gt_vrm_values-key ` STRING COMMENT ‘` c1 `‘,` INTO line SEPARATED BY ``.
ENDLOOP.
ENDIF.
DATA: str_len TYPE i.
str_len = STRLEN( line ).
str_len = str_len - 1.
line = line+0(str_len).
CONCATENATE line c_crlf `);` INTO line.
APPEND line TO texttable.
IF editor_container2 IS NOT BOUND.
CREATE OBJECT editor_container2
EXPORTING
container_name = ‘EDITOR2‘.
CREATE OBJECT editor2
EXPORTING
parent = editor_container2
wordwrap_mode = 1
max_number_chars = 12000.
ENDIF.
editor2->set_textstream( line ).
ENDMODULE. " STATUS_1002 OUTPUT
*&---------------------------------------------------------------------*
*& Module user_command_1002 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1002 INPUT.
CASE sy-ucomm.
WHEN ‘RW‘.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " user_command_1002 INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_1003 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1003 OUTPUT.
SET PF-STATUS ‘ST_1003‘.
SET TITLEBAR ‘1003‘.
DATA: code TYPE TABLE OF string WITH HEADER LINE.
CLEAR: line,gt_YTEST300,gt_YTEST300[].
IF editor_container3 IS NOT BOUND.
CREATE OBJECT editor_container3
EXPORTING
container_name = ‘EDITOR3‘.
CREATE OBJECT editor3
EXPORTING
parent = editor_container3
wordwrap_mode = 1
max_number_chars = 600000.
ENDIF.
READ REPORT ‘YTEMPLET‘ INTO code.
LOOP AT code.
IF line = ‘‘.
line = code.
ELSE.
CONCATENATE line cl_abap_char_utilities=>cr_lf code INTO line.
ENDIF.
ENDLOOP.
editor3->set_textstream( line ).
ENDMODULE. " STATUS_1003 OUTPUT
*&---------------------------------------------------------------------*
*& Form frm_key_constr
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_SRC_TAB text
* -->LT_DD03L text
* -->P_KEY_CONSTR text
* -->P_ORDERBY text
*----------------------------------------------------------------------*
FORM frm_key_constr TABLES p_src_tab pt_dd03l STRUCTURE dd03l key_constr.
DATA:lin TYPE i.
DATA: counts TYPE i.
FIELD-SYMBOLS: <fldvalue>.
DATA: wa_dd03l LIKE lt_dd03l.
DATA: p_key_constr TYPE string.
DATA: lt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE.
lt_dd03l[] = pt_dd03l[].
READ TABLE lt_dd03l INTO wa_dd03l INDEX 1.
DELETE lt_dd03l INDEX 1.
DESCRIBE TABLE lt_dd03l LINES counts.
DESCRIBE TABLE p_src_tab LINES lin.
CHECK lin > 0.
READ TABLE p_src_tab INDEX lin.
DO.
DO counts TIMES.
READ TABLE lt_dd03l INDEX sy-index.
ASSIGN COMPONENT lt_dd03l-fieldname OF STRUCTURE p_src_tab TO <fldvalue>.
IF sy-index < counts.
IF p_key_constr <> ‘‘.
CONCATENATE p_key_constr lt_dd03l-fieldname ` = ‘` <fldvalue> `‘` INTO p_key_constr.
ELSE.
CONCATENATE lt_dd03l-fieldname ` = ‘` <fldvalue> `‘` INTO p_key_constr.
ENDIF.
CONCATENATE p_key_constr ` AND ` INTO p_key_constr.
ELSEIF sy-index = counts.
IF p_key_constr <> ‘‘.
CONCATENATE p_key_constr lt_dd03l-fieldname ` > ‘` <fldvalue> `‘` INTO p_key_constr.
ELSE.
CONCATENATE lt_dd03l-fieldname ` > ‘` <fldvalue> `‘` INTO p_key_constr.
ENDIF.
ENDIF.
ENDDO.
counts = counts - 1.
IF counts <= 0.
EXIT.
ELSE.
CONCATENATE p_key_constr ` OR ` INTO p_key_constr.
ENDIF.
ENDDO.
CLEAR: itab,itab[].
SPLIT p_key_constr AT ` OR ` INTO TABLE itab .
DESCRIBE TABLE itab LINES counts.
ASSIGN COMPONENT wa_dd03l-fieldname OF STRUCTURE p_src_tab TO <fldvalue>.
DO counts TIMES.
READ TABLE itab INDEX sy-index.
CONCATENATE wa_dd03l-fieldname ` = ‘` <fldvalue> `‘ AND ` itab INTO key_constr.
APPEND key_constr.
ENDDO.
ENDFORM. " frm_key_constr
*&---------------------------------------------------------------------*
*& Form frm_comp_tab
*&---------------------------------------------------------------------*
* 递归将某结构组件展开(如:由于BKPF表中.APPEND附加结构,通过
* struct_type ?= cl_abap_typedescr=>describe_by_name( ‘BKPF‘ )获得
* 的组件中就会有STRU类型的组件,而非基本类型组件,所以需递归展开)
*----------------------------------------------------------------------*
* -->COMP_TAB 某结构的组件
*----------------------------------------------------------------------*
FORM frm_comp_tab TABLES comp_tab TYPE cl_abap_structdescr=>component_table.
DATA: lt_comp_tab LIKE comp_tab[] WITH HEADER LINE.
DATA:struct_type3 TYPE REF TO cl_abap_structdescr,
comp_tab3 TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.
LOOP AT comp_tab .
IF comp_tab-name <> ‘‘.
APPEND comp_tab TO lt_comp_tab.
ELSE.
struct_type3 ?= comp_tab-type.
comp_tab3[] = struct_type3->get_components( ).
PERFORM frm_comp_tab TABLES comp_tab3.
APPEND LINES OF comp_tab3 TO lt_comp_tab.
ENDIF.
ENDLOOP.
comp_tab[] = lt_comp_tab[].
ENDFORM. " frm_comp_tab
*&---------------------------------------------------------------------*
*& Form frm_find_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_find_table USING p_tablex.
DATA: code TYPE TABLE OF string WITH HEADER LINE.
DATA: off TYPE i,
moff TYPE i,
mlen TYPE i,
diffoff TYPE i.
DATA: tmpstr TYPE string.
CLEAR:rtables,rtables[].
IF p_prog IS NOT INITIAL.
READ REPORT p_prog INTO code.
line = ‘‘.
LOOP AT code.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN code WITH ` `.
CONDENSE code.
CLEAR itab.
SPLIT code AT ` ` INTO TABLE itab .
LOOP AT itab WHERE table_line IS NOT INITIAL.
IF line = ‘‘.
line = itab.
ELSE.
CONCATENATE line ` ` itab INTO line SEPARATED BY ``.
ENDIF.
ENDLOOP.
ENDLOOP.
off = 0.
DO.
FIND ` FROM ` IN SECTION OFFSET off OF
line
IGNORING CASE
MATCH OFFSET moff
MATCH LENGTH mlen.
IF sy-subrc = 0.
off = moff + mlen.
FIND ` ` IN SECTION OFFSET off OF
line
IGNORING CASE
MATCH OFFSET moff
MATCH LENGTH mlen.
tmpstr = line.
diffoff = moff - off.
tmpstr = tmpstr+off(diffoff).
CONDENSE tmpstr.
rtables-sign = ‘I‘.
rtables-option = ‘EQ‘.
rtables-low = tmpstr.
SET LOCALE LANGUAGE ‘1‘ .
TRANSLATE rtables-low TO UPPER CASE.
APPEND rtables.
ELSE.
EXIT.
ENDIF.
ENDDO.
off = 0.
DO.
FIND ` JOIN ` IN SECTION OFFSET off OF
line
IGNORING CASE
MATCH OFFSET moff
MATCH LENGTH mlen.
IF sy-subrc = 0.
off = moff + mlen.
FIND ` ` IN SECTION OFFSET off OF
line
IGNORING CASE
MATCH OFFSET moff
MATCH LENGTH mlen.
tmpstr = line.
diffoff = moff - off.
tmpstr = tmpstr+off(diffoff).
CONDENSE tmpstr.
rtables-sign = ‘I‘.
rtables-option = ‘EQ‘.
rtables-low = tmpstr.
SET LOCALE LANGUAGE ‘1‘ .
TRANSLATE rtables-low TO UPPER CASE.
APPEND rtables.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
IF rtables[] IS NOT INITIAL AND p_tablex IS NOT INITIAL.
rtables-sign = ‘I‘.
rtables-option = ‘EQ‘.
rtables-low = p_table.
SET LOCALE LANGUAGE ‘1‘ .
TRANSLATE rtables-low TO UPPER CASE.
APPEND rtables.
ENDIF.
CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[].
PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING ‘X‘.
ENDFORM. "frm_find_table
*&---------------------------------------------------------------------*
*& Form frm_find_sel
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_find_sel .
DATA: code TYPE TABLE OF string WITH HEADER LINE.
DATA: off TYPE i,
moff TYPE i,
moff2 TYPE i,
mlen TYPE i,
diffoff TYPE i.
DATA: BEGIN OF lt_sel OCCURS 0,
sel TYPE string,
END OF lt_sel.
lt_sel-sel = ` IN S_ASIST1`.
APPEND lt_sel.
lt_sel-sel = ` IN S_ASIST2`.
APPEND lt_sel.
lt_sel-sel = ` IN S_ASIST3`.
APPEND lt_sel.
lt_sel-sel = ` IN S_ASIST4`.
APPEND lt_sel.
lt_sel-sel = ` IN S_ASIST5`.
APPEND lt_sel.
CLEAR:sel_flds,sel_flds[].
IF p_prog IS NOT INITIAL.
READ REPORT p_prog INTO code.
line = ‘‘.
LOOP AT code.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN code WITH ` `.
CONDENSE code.
CLEAR itab.
SPLIT code AT ` ` INTO TABLE itab .
LOOP AT itab WHERE table_line IS NOT INITIAL.
IF line = ‘‘.
line = itab.
ELSE.
CONCATENATE line ` ` itab INTO line SEPARATED BY ``.
ENDIF.
ENDLOOP.
ENDLOOP.
off = 0.
LOOP AT lt_sel.
DO.
FIND lt_sel-sel IN SECTION OFFSET off OF
line
IGNORING CASE
MATCH OFFSET moff
MATCH LENGTH mlen.
IF sy-subrc = 0.
moff2 = moff - 1.
WHILE line+moff2(1) <> ` `.
moff2 = moff2 - 1.
IF moff2 < 0.
EXIT.
ENDIF.
ENDWHILE.
diffoff = moff - moff2.
sel_flds-fld = line+moff2(diffoff).
SHIFT sel_flds-fld UP TO `~` LEFT.
REPLACE ALL OCCURRENCES OF `~` IN sel_flds-fld WITH ``.
CONDENSE sel_flds-fld.
TRANSLATE sel_flds-fld TO UPPER CASE.
CASE lt_sel-sel.
WHEN ` IN S_ASIST1`.
sel_flds-p_snam = ‘s_asist1‘.
WHEN ` IN S_ASIST2`.
sel_flds-p_snam = ‘s_asist2‘.
WHEN ` IN S_ASIST3`.
sel_flds-p_snam = ‘s_asist3‘.
WHEN ` IN S_ASIST4`.
sel_flds-p_snam = ‘s_asist4‘.
WHEN ` IN S_ASIST5`.
sel_flds-p_snam = ‘s_asist5‘.
ENDCASE.
APPEND sel_flds.
off = moff + mlen.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
ENDIF.
ENDFORM. "frm_find_table
*&---------------------------------------------------------------------*
*& Module user_command_1003 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1003 INPUT.
CASE sy-ucomm.
WHEN ‘RW‘.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " user_command_1003 INPUT
*&---------------------------------------------------------------------*
*& Form frm_write_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_SRC_TAB text
*----------------------------------------------------------------------*
FORM frm_write_file TABLES p_src_tab.
DATA:str TYPE string.
CONCATENATE `/usr/sap/tmp/` p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
CONCATENATE `正在向SAP服务上Append文件:` gv_filename INTO str.
IF g_count = 2.
DELETE DATASET gv_filename.
ENDIF.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR‘
EXPORTING
percentage = 20
text = str.
DATA buffer TYPE xstring.
PERFORM frm_buffer TABLES p_src_tab USING buffer.
OPEN DATASET gv_filename FOR APPENDING IN BINARY MODE.
TRANSFER buffer TO gv_filename.
CLOSE DATASET gv_filename.
ENDFORM. " frm_write_file
*&---------------------------------------------------------------------*
*& Form frm_ftp_append
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_ftp_append .
DATA: localfile TYPE string.
PERFORM f_ftp_connect.
PERFORM frm_cd_dir.
CONCATENATE p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
CONCATENATE `/usr/sap/tmp/` p_fil_px2 `.` p_extens INTO localfile SEPARATED BY ``.
CLEAR:com,com[],res,res[].
CONCATENATE ‘append ‘ localfile gv_filename INTO com-cmd SEPARATED BY ‘ ‘.
CALL FUNCTION ‘FTP_COMMAND‘
EXPORTING
handle = thandle
command = com-cmd
TABLES
data = res
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
PERFORM f_ftp_disconnect.
ENDFORM. " frm_ftp_append
*&---------------------------------------------------------------------*
*& Form frm_buffer
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_BUFFER text
*----------------------------------------------------------------------*
FORM frm_buffer TABLES p_src_tab USING p_buffer.
DATA:strct_type_ref TYPE REF TO cl_abap_structdescr,
tab_type_ref TYPE REF TO cl_abap_tabledescr,
t_component TYPE cl_abap_structdescr=>component_table,
wa_component LIKE LINE OF t_component.
FIELD-SYMBOLS: <fldvalue>.
DATA: l_str TYPE string,fldstr TYPE string,fldtype,firsttime VALUE ‘X‘.
DATA: str TYPE string.
DATA: codepage TYPE cpcodepage,
encoding TYPE abap_encoding,
convout TYPE REF TO cl_abap_conv_out_ce.
DATA:time_stamp TYPE timestampl,timestamp_c(22).
CALL FUNCTION ‘SCP_CODEPAGE_BY_EXTERNAL_NAME‘
EXPORTING
external_name = p_encodi
IMPORTING
sap_codepage = codepage.
encoding = codepage.
CALL METHOD cl_abap_conv_out_ce=>create
EXPORTING
encoding = encoding
RECEIVING
conv = convout.
tab_type_ref ?= cl_abap_tabledescr=>describe_by_data( p_src_tab[] ).
strct_type_ref ?= tab_type_ref->get_table_line_type( ).
t_component = strct_type_ref->get_components( ).
str = p_split.
REPLACE ALL OCCURRENCES OF `\t` IN str WITH c_tab.
REPLACE ALL OCCURRENCES OF `\T` IN str WITH c_tab.
REPLACE ALL OCCURRENCES OF ` ` IN str WITH ``.
GET TIME STAMP FIELD time_stamp.
timestamp_c = time_stamp.
LOOP AT p_src_tab.
firsttime = ‘X‘.
CLEAR:fldstr,l_str.
LOOP AT t_component INTO wa_component.
IF wa_component-name = ‘ZTIMESTAMPL‘.
IF firsttime = ‘X‘.
fldstr = time_stamp.
CLEAR firsttime.
ELSE.
CONCATENATE fldstr timestamp_c INTO fldstr SEPARATED BY str.
ENDIF.
CONTINUE.
ENDIF.
fldtype = wa_component-type->type_kind.
ASSIGN COMPONENT wa_component-name OF STRUCTURE p_src_tab TO <fldvalue>.
l_str = <fldvalue>.
IF fldtype = ‘P‘ OR fldtype = ‘F‘
OR fldtype = ‘I‘ OR fldtype = ‘b‘
OR fldtype = ‘s‘.
CALL FUNCTION ‘CLOI_PUT_SIGN_IN_FRONT‘
CHANGING
value = l_str.
ENDIF.
REPLACE ALL OCCURRENCES OF str IN l_str WITH ` `.
IF firsttime = ‘X‘.
fldstr = l_str .
CLEAR firsttime.
ELSE.
CONCATENATE fldstr l_str INTO fldstr SEPARATED BY str.
ENDIF.
ENDLOOP.
CONDENSE fldstr.
CALL METHOD convout->write
EXPORTING
data = fldstr.
CALL METHOD convout->write
EXPORTING
data = cl_abap_char_utilities=>cr_lf.
ENDLOOP.
CALL METHOD convout->get_buffer
RECEIVING
buffer = p_buffer.
ENDFORM. " frm_buffer
*&---------------------------------------------------------------------*
*& Form frm_write_file2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->STR1 text
* -->STR2 text
*----------------------------------------------------------------------*
FORM frm_write_file2 USING str1 lins tabix .
DATA:str TYPE string.
GET RUN TIME FIELD tm2.
tm = ( tm2 - tm1 ) / 1000 / 1000.
tm1 = tm2.
str = lins.
CONCATENATE `/usr/sap/tmp/` p_fil_px2 `.log` INTO gv_filename SEPARATED BY ``.
IF tabix = 1 AND g_count = 1.
DELETE DATASET gv_filename.
ENDIF.
OPEN DATASET gv_filename FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
CONCATENATE `【` str `条】` str1 ` : 【` tm `秒】`INTO str.
TRANSFER str TO gv_filename.
CLOSE DATASET gv_filename.
ENDFORM. "frm_write_file2
*&---------------------------------------------------------------------*
*& Form frm_write_file3
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_write_file3.
DATA:str TYPE string.
CONCATENATE `/usr/sap/tmp/` p_fil_px2 `.log` INTO gv_filename SEPARATED BY ``.
OPEN DATASET gv_filename FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
TRANSFER g_count TO gv_filename.
TRANSFER ` ` TO gv_filename.
CLOSE DATASET gv_filename.
ENDFORM. "frm_write_file3
|