*&---------------------------------------------------------------------*
*& Report Z_FORMA_UPLOAD_TRANSFER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_forma_upload_transfer.
DATA: p_file_aux TYPE string.
TYPES: BEGIN OF s_file,
* bldat(8),
* budat(8),
* bwartwa(3),
* werks_d(4),
* lgort_d(4),
* matnr(18),
* erfmg(10),
kunnr(16),
name1(35),
END OF s_file.
DATA: BEGIN OF st_file,
* bldat(8),
* budat(8),
* bwartwa(3),
* werks_d(4),
* lgort_d(4),
* matnr(18),
* erfmg(10),
kunnr(16),
name1(35),
END OF st_file.
DATA: t_file TYPE s_file OCCURS 0,
wa_file TYPE s_file.
PARAMETERS: p_file LIKE rlgrap-filename,
p_fserv LIKE rlgrap-filename DEFAULT '.\teste_upload.txt'.
PARAMETERS: p_up RADIOBUTTON GROUP rad1,
p_dow RADIOBUTTON GROUP rad1.
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
*&---------------------------------------------------------------------*
PERFORM f4_filename.
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*&---------------------------------------------------------------------*
IF p_up = 'X'.
PERFORM upload_file.
PERFORM transfer_to_server TABLES t_file.
ELSEIF p_dow = 'X'.
PERFORM download_from_server TABLES t_file.
perform escreve_ficheiro.
ENDIF.
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form f4_filename
*&---------------------------------------------------------------------*
FORM f4_filename .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
ENDFORM. " f4_filename
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_FILE text
* -->P_P_FILE text
*----------------------------------------------------------------------*
FORM upload_file.
p_file_aux = p_file.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = p_file_aux
filetype = 'ASC'
has_field_separator = 'X'
CHANGING
data_tab = t_file
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " upload_file
*&---------------------------------------------------------------------*
*& Form transfer_to_server
*&---------------------------------------------------------------------*
FORM transfer_to_server TABLES p_t_file STRUCTURE st_file.
* DELETE t_file INDEX 1.
OPEN DATASET p_fserv FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT t_file INTO wa_file.
TRANSFER wa_file TO p_fserv.
ENDLOOP.
CLOSE DATASET p_fserv.
ENDFORM. " transfer_to_server
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FROM_sERVER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_T_FILE text
*----------------------------------------------------------------------*
FORM download_from_server TABLES p_t_file STRUCTURE st_file.
OPEN DATASET p_fserv FOR INPUT IN TEXT MODE ENCODING DEFAULT.
DO.
READ DATASET p_fserv INTO wa_file.
IF sy-subrc = 0.
APPEND wa_file TO t_file.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET p_fserv.
ENDFORM. " DOWNLOAD_FROM_sERVER
*&---------------------------------------------------------------------*
*& Form escreve_ficheiro
*&---------------------------------------------------------------------*
form escreve_ficheiro .
loop at t_file into wa_file.
write:/ wa_file.
endloop.
endform. " escreve_ficheiro
Subscrever:
Enviar feedback (Atom)
Sem comentários:
Enviar um comentário