✒️ABAP Los archivos en el servidor y las sentencias TRANSFER, DELETE y CLOSE
ABAP Los archivos en el servidor y las sentencias TRANSFER, DELETE y CLOSE
Server Files - ABAP Statements TRANSFER, DELETE, and CLOSE
File Transfer to the Server
The TRANSFER statement facilitates the transfer of data from ABAP programs to files located on the SAP application server. The syntax for this operation is as follows:
TRANSFER <structure> TO <file>.
The transfer mode aligns with the file's opening mode. If the file is not open for writing, the system attempts to open it in BINARY MODE or utilizes the latest execution of the OPEN DATASET statement.
DATA: wa_structure TYPE type.
OPEN DATASET 'MyFile.txt' FOR OUTPUT IN BINARY MODE.
TRANSFER wa_structure TO 'MyFile.txt'.
In transaction CG3Y, files on the server can be copied to the local computer. The complete source and destination paths are selected, along with the transfer format (ASCII or binary).
File Deletion from the Server
The DELETE DATASET statement is employed to delete files from the SAP application server, with the syntax:
DELETE DATASET <file>.
Before deletion, the file must be open. Successful deletion results in SY-SUBRC being 0; otherwise, it is set to 4.
OPEN DATASET 'MyFile.txt' FOR OUTPUT IN BINARY MODE.
DELETE DATASET 'MyFile.txt'.
Closing Files on the Server
The CLOSE DATASET statement is used to close files on the SAP application server, with the syntax:
CLOSE DATASET <file>.
Searching for Files on the Server
The function module /SAPDMC/LSM_F4_SERVER_FILE creates a navigation window on the SAP application server to select the desired file.
*&---------------------------------------------------------------------*
*& Form OPEN_FILE_WINDOW
*&---------------------------------------------------------------------*
* This subroutine opens a window to navigate server files.
*----------------------------------------------------------------------*
FORM open_file_window.
DATA: lv_selected_file(500) TYPE c.
" Call function to open server file window
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = p_path " Specify the directory path
filemask = '*' " Use '*' for all files or specify a mask
IMPORTING
serverfile = lv_selected_file
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
" Check if the function call was successful
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
" Update the path with the selected file
MOVE lv_selected_file TO p_path.
ENDIF.
ENDFORM. " OPEN_FILE_WINDOW
If the code is executed in a SAP system without an application server, a popup window will display the message:
Operating system message: opendir.
In a system with an application server, a popup window emerges, displaying the directory of server files, allowing users to search for the desired file.
 
 
 
Sobre el autor
Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.
Jaime Eduardo Gomez Arango
Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C
✒️Autor de: 99 Publicaciones Académicas
🎓Cursando Actualmente: Consultor ABAP Nivel Avanzado
🎓Egresado del módulo:
Disponibilidad Laboral: FullTime
Presentación:
Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.
Certificación Académica de Jaime Gomez