SAP传输请求自动发布
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAP传输请求自动发布相关的知识,希望对你有一定的参考价值。
最近公司服务器做迁移,原R3 PRE需要迁到另外的地方,迁移后一段时间内,需要两套PRE环境同时运行,过一段时间后才将传输路线切换到新的PRE。在切换前,要求新PRE环境也要正常同步发布请求,但传输路线只有一条,这需要在发原PRE时,同时手工发布新PRE,这样每次手工很麻烦(手工导入传输请求过程参考这篇文章)。本文就是来通过程序实现这种手工全过程,实现同步自动发布新PRE。实现过程也算简单,通过一台中间Java Web服务器进行传输请求的中转,将DEV上的传输请求文件下载后,上传到新PRE服务器上,然后在新PRE服务器上导入新的请求即可。这就需要在DEV上写个远程RFS接口,将需要传输的请求所对应的数据与配置文件下载下来;在新PRE上写个远程接口,将从DEV上下载下来的传输请求文件上传到新PRE服务器上,其后通过调用发布函数进行请求发布。代码涉及到三台机器:SAP DEV ——> Java Web中转服务器 ——> SAP PRE,之间采用JCO进行连接。最新的SAP JCO包请点击这里下载,Linux上So动态链接库以及Windows的Dll部署请百度
1、DEV远程接口:
FUNCTION zxg_pre_fuc.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(REQUESTNO) TYPE STRING
*" EXPORTING
*" VALUE(FILES) TYPE ZXG_PRE_TABLE_TYPE
*" VALUE(REQUESTNOS) TYPE STRING
*"----------------------------------------------------------------------
DATA: result_tab TYPE TABLE OF string WITH HEADER LINE.
"多个请求以逗号分隔
SPLIT requestno AT \',\' INTO TABLE result_tab IN CHARACTER MODE.
DATA: lt_data_binary TYPE TABLE OF sdokcntbin WITH HEADER LINE.
DATA: lv_binary_len TYPE i,lv_lines TYPE i,lv_total_len TYPE i.
DATA: v_filename TYPE string.
DATA: lw_files LIKE LINE OF files.
LOOP AT result_tab.
DO 2 TIMES.
CLEAR:lw_files,lv_total_len,lt_data_binary[].
IF sy-index = 1.
"传输请求所对应的数据文件
CONCATENATE `/usr/sap/trans/data/R` result_tab+4 `.DEV` INTO v_filename.
ELSE.
"传输请求所对应的配置文件
CONCATENATE `/usr/sap/trans/cofiles/K` result_tab+4 `.DEV` INTO v_filename.
ENDIF.
"从服务器上读取文件
lw_files-filename = v_filename.
OPEN DATASET v_filename FOR INPUT IN BINARY MODE.
DO.
CLEAR: lt_data_binary,lv_binary_len.
READ DATASET v_filename INTO lt_data_binary ACTUAL LENGTH lv_binary_len.
IF lv_binary_len > 0.
lv_total_len = lv_total_len + lv_binary_len.
APPEND lt_data_binary.
lw_files-last_line_size = lv_binary_len.
ELSE.
lw_files-total_size = lv_total_len.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET v_filename.
lw_files-data = lt_data_binary[].
APPEND lw_files TO files.
ENDDO.
ENDLOOP.
"返回给Java Web服务器
requestnos = requestno.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(REQUESTNO) TYPE STRING
*" EXPORTING
*" VALUE(FILES) TYPE ZXG_PRE_TABLE_TYPE
*" VALUE(REQUESTNOS) TYPE STRING
*"----------------------------------------------------------------------
DATA: result_tab TYPE TABLE OF string WITH HEADER LINE.
"多个请求以逗号分隔
SPLIT requestno AT \',\' INTO TABLE result_tab IN CHARACTER MODE.
DATA: lt_data_binary TYPE TABLE OF sdokcntbin WITH HEADER LINE.
DATA: lv_binary_len TYPE i,lv_lines TYPE i,lv_total_len TYPE i.
DATA: v_filename TYPE string.
DATA: lw_files LIKE LINE OF files.
LOOP AT result_tab.
DO 2 TIMES.
CLEAR:lw_files,lv_total_len,lt_data_binary[].
IF sy-index = 1.
"传输请求所对应的数据文件
CONCATENATE `/usr/sap/trans/data/R` result_tab+4 `.DEV` INTO v_filename.
ELSE.
"传输请求所对应的配置文件
CONCATENATE `/usr/sap/trans/cofiles/K` result_tab+4 `.DEV` INTO v_filename.
ENDIF.
"从服务器上读取文件
lw_files-filename = v_filename.
OPEN DATASET v_filename FOR INPUT IN BINARY MODE.
DO.
CLEAR: lt_data_binary,lv_binary_len.
READ DATASET v_filename INTO lt_data_binary ACTUAL LENGTH lv_binary_len.
IF lv_binary_len > 0.
lv_total_len = lv_total_len + lv_binary_len.
APPEND lt_data_binary.
lw_files-last_line_size = lv_binary_len.
ELSE.
lw_files-total_size = lv_total_len.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET v_filename.
lw_files-data = lt_data_binary[].
APPEND lw_files TO files.
ENDDO.
ENDLOOP.
"返回给Java Web服务器
requestnos = requestno.
ENDFUNCTION.
2、新PRE远程接口:
此服务器上的ZXG_PRE_TABLE_TYPE类型与DEV上是一样的,这里就不再截图
FUNCTION zxg_pre_fuc.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(FILES) TYPE ZXG_PRE_TABLE_TYPE
*" VALUE(REQUESTNOS) TYPE STRING
*"----------------------------------------------------------------------
DATA: lw_files TYPE zxg_pre_strc_type.
DATA: lw_data TYPE sdokcntbin.
DATA: lines TYPE i.
DATA: indx TYPE i .
LOOP AT files INTO lw_files .
indx = 0.
OPEN DATASET lw_files-filename FOR OUTPUT IN BINARY MODE.
DESCRIBE TABLE lw_files-data LINES lines.
LOOP AT lw_files-data INTO lw_data.
indx = indx + 1.
IF indx <> lines.
TRANSFER lw_data-line TO lw_files-filename.
ELSE.
TRANSFER lw_data-line+(lw_files-last_line_size) TO lw_files-filename.
ENDIF.
ENDLOOP.
CLOSE DATASET lw_files-filename.
ENDLOOP.
DATA: result_tab TYPE TABLE OF string WITH HEADER LINE.
SPLIT requestnos AT \',\' INTO TABLE result_tab IN CHARACTER MODE.
DATA: req TYPE tmsbuffer-trkorr.
LOOP AT result_tab.
req = result_tab.
PERFORM frm_stms USING req.
ENDLOOP.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(FILES) TYPE ZXG_PRE_TABLE_TYPE
*" VALUE(REQUESTNOS) TYPE STRING
*"----------------------------------------------------------------------
DATA: lw_files TYPE zxg_pre_strc_type.
DATA: lw_data TYPE sdokcntbin.
DATA: lines TYPE i.
DATA: indx TYPE i .
LOOP AT files INTO lw_files .
indx = 0.
OPEN DATASET lw_files-filename FOR OUTPUT IN BINARY MODE.
DESCRIBE TABLE lw_files-data LINES lines.
LOOP AT lw_files-data INTO lw_data.
indx = indx + 1.
IF indx <> lines.
TRANSFER lw_data-line TO lw_files-filename.
ELSE.
TRANSFER lw_data-line+(lw_files-last_line_size) TO lw_files-filename.
ENDIF.
ENDLOOP.
CLOSE DATASET lw_files-filename.
ENDLOOP.
DATA: result_tab TYPE TABLE OF string WITH HEADER LINE.
SPLIT requestnos AT \',\' INTO TABLE result_tab IN CHARACTER MODE.
DATA: req TYPE tmsbuffer-trkorr.
LOOP AT result_tab.
req = result_tab.
PERFORM frm_stms USING req.
ENDLOOP.
ENDFUNCTION.
&nbs
以上是关于SAP传输请求自动发布的主要内容,如果未能解决你的问题,请参考以下文章
如何阻止SAP CRM订单创建好之后,自动被置为传输状态这一行为