ABAP Development

Simplify your life: An ABAP tool to upload and download transport requests to import in other systems

Introduction

Any developer who needs to develop in separate systems has had the question to copy reports, or more advanced work to other systems. Copying by hand takes a lot of time and has the risk on errors. Wouldn’t it be more easy to put everything in a transport request and import this?

When visiting a training from SAP, refreshing my knowledge, a program was distributed to download an upload transport requests. I want to share this program to simplify our lives. It’s not my own code, but I cannot give credits to the programmer because he/she is unknown to me. I’ve used the program frequently and it works absolutely fine.

ATTENTION: when importing transportrequests from an other systems code in the system might be overwritten. MAKE SURE YOU KNOW WHAT”S IN THE TRANSPORTREQUEST. ONLY TRANSPORT NEW CUSTOM OBJECTS.

The code

*&———————————————————————*
*& Report Z_UP_DL_TRANSPORT
*&
*&———————————————————————*
*& Up- & download of transports
*&
*&———————————————————————*
REPORT Z_UP_DL_TRANSPORT LINE-SIZE 170. “#EC

* Selection screen *
PARAMETERS p_trkorr TYPE e070-trkorr
OBLIGATORY.
PARAMETERS p_path TYPE rlgrap-filename
OBLIGATORY
DEFAULT ‘c:\temp\’.
SELECTION-SCREEN SKIP.
PARAMETERS p_down RADIOBUTTON GROUP func
DEFAULT ‘X’.
PARAMETERS p_up RADIOBUTTON GROUP func.

* Global data *
TYPE-POOLS sabc.

DATA gv_path TYPE rlgrap-filename.
DATA gv_path_cofile TYPE rlgrap-filename.
DATA gv_path_data TYPE rlgrap-filename.
DATA gv_path_bin TYPE rlgrap-filename.

DATA gv_file_k TYPE rlgrap-filename.
DATA gv_file_r TYPE rlgrap-filename.
DATA gv_file_d TYPE rlgrap-filename.

DATA gv_separator TYPE c.

* Complete local path *
AT SELECTION-SCREEN.
PERFORM check_path.

START-OF-SELECTION.
* Determine transport base directory *
CALL ‘C_SAPGPARAM’
ID ‘NAME’ FIELD ‘DIR_TRANS’
ID ‘VALUE’ FIELD gv_path.

* Determine file/path separator *
IF sy-opsys = ‘Windows NT’.
gv_separator = ‘\’.
ELSE.
gv_separator = ‘/’.
ENDIF.

* Determine transport directories *
CONCATENATE gv_path gv_separator ‘cofiles’ gv_separator
INTO gv_path_cofile.

CONCATENATE gv_path gv_separator ‘data’ gv_separator
INTO gv_path_data.

CONCATENATE gv_path gv_separator ‘data’ gv_separator
INTO gv_path_bin.

WRITE / ‘Download files from paths:'(t01).
WRITE / gv_path_cofile.
WRITE / gv_path_data.
WRITE / gv_path_bin.
SKIP.

* Build filenames *
CONCATENATE p_trkorr+3(7) p_trkorr+0(3)
INTO gv_file_k
SEPARATED BY ‘.’.

CONCATENATE ‘R’ p_trkorr+4(6) ‘.’ p_trkorr+0(3)
INTO gv_file_r.

CONCATENATE ‘D’ p_trkorr+4(6) ‘.’ p_trkorr+0(3)
INTO gv_file_d.

* Up- or download transport request *
IF p_down = ‘X’.
PERFORM download
USING gv_path_cofile
p_path
gv_file_k.
PERFORM download
USING gv_path_data
p_path
gv_file_r.
PERFORM download
USING gv_path_data
p_path
gv_file_d.
ELSE.
PERFORM upload
USING p_path
gv_path_cofile
gv_file_k.

PERFORM upload
USING p_path
gv_path_data
gv_file_r.

PERFORM upload
USING p_path
gv_path_data
gv_file_d.
ENDIF.

*&———————————————————————*
*& Form download
*&———————————————————————*
* Download transport file(s)
*———————————————————————-*
* –>VALUE(P_SRCPATH) Source path
* –>VALUE(p_DSTPATH) Destination path
* –>VALUE(P_FILE) Filename
*———————————————————————-*
FORM download
USING value(p_srcpath) TYPE rlgrap-filename
value(p_dstpath) TYPE rlgrap-filename
value(p_file) TYPE rlgrap-filename.

TYPES BEGIN OF lst_buffer.
TYPES data TYPE x LENGTH 1024.
TYPES END OF lst_buffer.

DATA lt_buffer TYPE TABLE OF lst_buffer.
DATA ls_buffer TYPE lst_buffer.
DATA lv_filename TYPE rlgrap-filename.
DATA lv_reclen TYPE i.
DATA lv_filelen TYPE i.

* Read input file *
CONCATENATE p_srcpath p_file
INTO lv_filename.

OPEN DATASET lv_filename FOR INPUT IN BINARY MODE.

CHECK sy-subrc = 0.

DO.
READ DATASET lv_filename
INTO ls_buffer
LENGTH lv_reclen.

IF lv_reclen = 0.
EXIT.
ENDIF.

lv_filelen = lv_filelen + lv_reclen.

APPEND ls_buffer TO lt_buffer.
ENDDO.

CLOSE DATASET lv_filename.

* Download file *
CONCATENATE p_dstpath p_file
INTO lv_filename.

CALL FUNCTION ‘WS_DOWNLOAD’
EXPORTING
bin_filesize = lv_filelen
filename = lv_filename
filetype = ‘BIN’
TABLES
data_tab = lt_buffer
EXCEPTIONS
OTHERS = 1.

CHECK sy-subrc = 0.

WRITE / ‘Downloaded:'(t02).
WRITE (150) p_file.
ENDFORM. “download

*&———————————————————————*
*& Form upload
*&———————————————————————*
* Upload transport file(s)
*———————————————————————-*
* –>VALUE(P_SRCPATH) Source path
* –>VALUE(p_DSTPATH) Destination path
* –>VALUE(P_FILE) Filename
*———————————————————————-*
FORM upload
USING value(p_srcpath) TYPE rlgrap-filename
value(p_dstpath) TYPE rlgrap-filename
value(p_file) TYPE rlgrap-filename.

TYPES BEGIN OF lst_buffer.
TYPES data TYPE x LENGTH 1024.
TYPES END OF lst_buffer.

DATA lt_buffer TYPE TABLE OF lst_buffer.
DATA ls_buffer TYPE lst_buffer.
DATA lv_filename TYPE rlgrap-filename.
DATA lv_reclen TYPE i.
DATA lv_filelen TYPE i.
DATA lv_result TYPE c.

* Check if file exists *
CONCATENATE p_srcpath p_file
INTO lv_filename.

CALL FUNCTION ‘WS_QUERY’
EXPORTING
filename = lv_filename
query = ‘FE’
IMPORTING
return = lv_result
EXCEPTIONS
OTHERS = 1.
CHECK sy-subrc = 0
AND lv_result = ‘1’.

* Upload file *
CALL FUNCTION ‘WS_UPLOAD’
EXPORTING
filename = lv_filename
filetype = ‘BIN’
IMPORTING
filelength = lv_filelen
TABLES
data_tab = lt_buffer
EXCEPTIONS
OTHERS = 1.

* Write file to server *
CONCATENATE p_dstpath p_file
INTO lv_filename.

OPEN DATASET lv_filename FOR OUTPUT IN BINARY MODE.
CHECK sy-subrc = 0.

LOOP AT lt_buffer INTO ls_buffer.
DESCRIBE FIELD ls_buffer-data
LENGTH lv_reclen IN BYTE MODE.

IF lv_filelen > lv_reclen.
lv_filelen = lv_filelen – lv_reclen.
ELSE.
lv_reclen = lv_filelen.
ENDIF.

TRANSFER ls_buffer TO lv_filename LENGTH lv_reclen.
ENDLOOP.

CLOSE DATASET lv_filename.

WRITE / ‘Uploaded:'(t03).
WRITE (150) p_file.
ENDFORM. “upload

*&———————————————————————*
*& Form CHECK_PATH
*&———————————————————————*
* Check path
*———————————————————————-*
FORM check_path .
DATA lv_pos TYPE i.
DATA lv_temp TYPE c.

lv_pos = STRLEN( p_path ) – 1.
lv_temp = p_path+lv_pos(1).

CHECK NOT lv_temp = ‘\’.

CONCATENATE p_path ‘\’
INTO p_path.
ENDFORM. ” CHECK_PATH

Result

 ABAP Development

Make sure this program is on the separate development systems.

Use download to write transport request to files.

Use upload to upload the files to the development server.

When uploaded use transaction STMS to add transport to the development import queue.

 ABAP Development

Leave a Reply

Your email address will not be published. Required fields are marked *