跨系统传输请求程序

内容: 当某公司有多个平行系统时,比如 多个dev ,但是部署在不同服务器。有时候需要传输请求至其它系统。

PS:传输至同系统中的不同client 用TCODE: SCC1.

*&---------------------------------------------------------------------*
*& Report ZTRANS_TR
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ztrans_tr.

INCLUDE ztrans_tr_top.
INCLUDE ztrans_tr_form.





AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_tr-low.
  PERFORM frm_value_trkorr.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dfname.
*  PERFORM frm_upload_file.

* call f4-help
  PERFORM frm_valreq_ftfront USING
                            '1000'
                            'Quelldatei auf Frontend'(007).

START-OF-SELECTION.

  PERFORM frm_get_data.
  PERFORM frm_down_file.
*&---------------------------------------------------------------------*
*&      Form  FRM_VALUE_TRKORR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_value_trkorr .

  DATA: lv_trfunctions  LIKE  trpari-w_longstat,
        lv_trstatus     LIKE  trpari-w_longstat,
        lv_trkorr       TYPE  e070-trkorr,
        ls_dynpfield  LIKE dynpread,
        lt_dynpfields LIKE dynpread    OCCURS 0.

  lv_trfunctions = sctsc_types_all.
  lv_trstatus    = sctsc_states_changeable.

  GET CURSOR FIELD ls_dynpfield-fieldname.
  APPEND ls_dynpfield TO lt_dynpfields.

  CALL FUNCTION 'DYNP_VALUES_READ'
       EXPORTING
            dyname     = 'ZTRANS_TR'
            dynumb     = sy-dynnr
       TABLES
            dynpfields = lt_dynpfields.

  READ TABLE lt_dynpfields INTO ls_dynpfield INDEX 1.
  lv_trkorr = ls_dynpfield-fieldvalue.

  CALL FUNCTION 'TR_F4_REQUESTS'
       EXPORTING
            iv_username         = space
            iv_trkorr_pattern   = lv_trkorr
            iv_trfunctions      = lv_trfunctions
            iv_trstatus         = lv_trstatus
       IMPORTING
            ev_selected_request = lv_trkorr.

  ls_dynpfield-fieldvalue = lv_trkorr.
  MODIFY lt_dynpfields FROM ls_dynpfield
                       INDEX 1
                       TRANSPORTING fieldvalue.
  CALL FUNCTION 'DYNP_VALUES_UPDATE'
       EXPORTING
            dyname     = 'ZTRANS_TR'
            dynumb     = sy-dynnr
       TABLES
            dynpfields = lt_dynpfields.
ENDFORM.
**&---------------------------------------------------------------------*
**&      Form  FRM_UPLOAD_FILE
**&---------------------------------------------------------------------*
**       从本地打开文件并读取数据到内表
**----------------------------------------------------------------------*
**  -->  p1        text
**  <--  p2        text
**----------------------------------------------------------------------*
*FORM frm_upload_file .
*
*   DATA:
*     lw_file_names TYPE file_table,
*     lv_path       TYPE rlgrap-filename,
*     lv_subrc      TYPE i.
*
*   CALL METHOD cl_gui_frontend_services=>file_open_dialog
*     EXPORTING
**      initial_directory       = 'e:study'
*      default_filename = '*.xls'
**      multiselection          = 'X'
*    CHANGING
*       file_table              = gt_file_names[]
*       rc                      = lv_subrc
*     EXCEPTIONS
*       file_open_dialog_failed = 1
*       cntl_error              = 2
*       error_no_gui            = 3
*       not_supported_by_gui    = 4
*       OTHERS                  = 5.
*
*   READ TABLE gt_file_names INTO lw_file_names INDEX 1.
*   p_dfname = lw_file_names-filename.
*
* ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DOWN_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_down_file .
  DATA: l_flg_open_error  TYPE boolean.
  DATA: l_os_message(100) TYPE c.
  DATA: l_ftappl TYPE rcgfiletr-ftappl.
  DATA: lv_tr TYPE char30.
  DATA: l_overwrite TYPE rcgfiletr-iefow.
  DATA: ls_tr TYPE ty_tr.
  DATA: lv_ERR TYPE char1.

  LOOP AT gt_tr INTO ls_tr.

    CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'
     EXPORTING
       path                  = ls_tr-server_path
       targetpath            = ls_tr-local_path
     EXCEPTIONS
       error_file             = 1
       no_authorization       = 2
       OTHERS                 = 3.

    IF SY-SUBRC <> 0.
      lv_ERR = 'X'.
    ENDIF.
  ENDLOOP.
  IF LV_ERR IS INITIAL.
    MESSAGE 'DOWNLOAD SUCCESS' TYPE 'S'.
  ELSE.
    MESSAGE 'DOWNLOAD FAILURE' TYPE 'E' DISPLAY LIKE 'E'.
  ENDIF.

  IF P_E1D = 'X'.
    CALL FUNCTION 'ZFM_TR_TRANSPORT' DESTINATION 'E1DCLNT200'
      STARTING NEW TASK 'TRANS2'
      TABLES
        it_tr         = gt_tr.
  ENDIF.

  IF P_E2D = 'X'.
    CALL FUNCTION 'ZFM_TR_TRANSPORT' DESTINATION 'E2DCLNT200'
      STARTING NEW TASK 'TRANS2'
      TABLES
        it_tr         = gt_tr.
  ENDIF.

  IF P_E3D = 'X'.
    CALL FUNCTION 'ZFM_TR_TRANSPORT' DESTINATION 'E3DCLNT200'
      STARTING NEW TASK 'TRANS3'
      TABLES
        it_tr         = gt_tr.
  ENDIF.

  IF P_E4D = 'X'.
    CALL FUNCTION 'ZFM_TR_TRANSPORT' DESTINATION 'E4DCLNT200'
      STARTING NEW TASK 'TRANS4'
      TABLES
        it_tr         = gt_tr.
  ENDIF.

  IF P_E5D = 'X'.
    CALL FUNCTION 'ZFM_TR_TRANSPORT' DESTINATION 'E5DCLNT200'
      STARTING NEW TASK 'TRANS5'
      TABLES
        it_tr         = gt_tr.
  ENDIF.


*  if sy-subrc = 0.
*    MESSAGE 'DOWNLOAD SUCCESS' TYPE 'S'.
*  ELSE.
*    MESSAGE 'DOWNLOAD FAILURE' TYPE 'E' DISPLAY LIKE 'E'.
*  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_VALREQ_FTFRONT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0036   text
*      -->P_0037   text
*----------------------------------------------------------------------*
FORM frm_valreq_ftfront
* Purpose: f4-help for the filename on the front end
  USING
    i_dynpro LIKE d020s-dnum
    i_title  TYPE string.

* Local data ----------------------------------------------------------

  DATA: l_strlen    TYPE i.
  DATA: l_ftfront   LIKE dynpread-fieldvalue.
  DATA: l_filename  TYPE string.
  DATA: l_new_filename LIKE rcgfiletr-ftfront.
  DATA: l_path      TYPE string.
  DATA: l_char      TYPE c.
  DATA: l_file_extension_tab TYPE filetable WITH HEADER LINE.

* Function body--------------------------------------------------------

* read value of field from dynpro
  CALL FUNCTION 'C14Z_DYNP_READ_FIELD'
    EXPORTING
      i_program      = 'ZTRANS_TR'
      i_dynpro       = i_dynpro
      i_fieldname    = 'P_DFNAME'
      i_flg_steploop = space
    CHANGING
      e_value        = l_ftfront
    EXCEPTIONS
      OTHERS         = 1.

  IF sy-subrc = 0.

*   split filename into path and filename
    l_strlen = strlen( l_ftfront ).
    CLEAR: l_filename.
    l_path = l_ftfront.
    WHILE l_strlen > 0.
      l_char = l_ftfront+l_strlen(1).
* Begin Correction 30.03.2010 1454105 **********************************
      IF l_char = '\' OR l_char = '/'.
* End Correction 30.03.2010 1454105 ************************************
        l_strlen = l_strlen + 1.
        l_path     = l_ftfront(l_strlen).
        l_filename = l_ftfront+l_strlen.
        EXIT.
      ELSE.
        l_strlen = l_strlen - 1.
      ENDIF.
    ENDWHILE.

  ENDIF.

* build extension list of file types
  APPEND 'dat' TO l_file_extension_tab.
  APPEND 'doc' TO l_file_extension_tab.
  APPEND 'key' TO l_file_extension_tab.
  APPEND 'txt' TO l_file_extension_tab.
  APPEND '*'   TO l_file_extension_tab.

  l_filename = 'FILENAME'.
* call help
  CALL FUNCTION 'C13Z_FRONTEND_FILENAME_GET'
    EXPORTING
      i_window_title       = i_title
      i_default_filename   = l_filename
      i_initial_directory  = l_path
    IMPORTING
      e_filename           = l_new_filename
    TABLES
      i_file_extension_tab = l_file_extension_tab
    EXCEPTIONS
      internal_error       = 1
      OTHERS               = 2.
  IF NOT sy-subrc IS INITIAL.
    " nothing to do

* Begin Correction 30.03.2010 1454105 **********************************
  ELSEIF NOT l_new_filename IS INITIAL.
* End Correction 30.03.2010 1454105 ************************************
    p_dfname = l_new_filename.
  ENDIF.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_data .

  DATA: lt_trange TYPE RANGE OF trdyse01sn-tr_trkorr.
  DATA ls_trange LIKE LINE OF lt_trange.
  DATA: ls_tr TYPE ty_tr,
        lv_filename    TYPE char20,
        lv_dfname      TYPE rlgrap-filename,
        lv_server_path TYPE saepfad.

  lv_dfname = p_dfname.
  LOOP AT s_tr INTO ls_trange.

    lv_filename = 'R' && s_tr-low+4(6) && '.E1D'.
    lv_server_path = '/usr/sap/trans/data/' && lv_filename.
    REPLACE 'FILENAME' WITH lv_filename INTO lv_dfname.
    CONDENSE  lv_dfname  NO-GAPS .
*    CONCATENATE
    ls_tr-local_path  = lv_dfname.
    ls_tr-server_path = lv_server_path.
    ls_tr-filenam = lv_filename.
    ls_tr-TR_CODE     = s_tr-low.
    APPEND ls_tr TO gt_tr.
    CLEAR ls_tr.

    lv_dfname = p_dfname.
    lv_filename = 'K' && s_tr-low+4(6) && '.E1D'.
    lv_server_path = '/usr/sap/trans/cofiles/' && lv_filename.
    REPLACE 'FILENAME' WITH lv_filename INTO lv_dfname.
    CONDENSE  lv_dfname  NO-GAPS .
    ls_tr-local_path  = lv_dfname.
    ls_tr-server_path = lv_server_path.
    ls_tr-filenam = lv_filename.
    ls_tr-TR_CODE     = s_tr-low.
    APPEND ls_tr TO gt_tr.
    CLEAR ls_tr.

  ENDLOOP.


ENDFORM.

" ”“”“”“”“”“”相关 function :ZFM_TR_TRANSPORT***************************

你可能感兴趣的:(ABAP开发,SAP,ABAP,sap,ABAP)