SAP ABAP - Download CDS View
*&---------------------------------------------------------------------*
*& Report Z_DOWNLOAD_CDS*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_download_cds.
TYPES: BEGIN OF ty_ddddlsrc,
ddlname TYPE ddddlsrc-ddlname,
source TYPE ddddlsrc-source,
END OF ty_ddddlsrc,
BEGIN OF ty_dd,
source TYPE ddddlsrc-source,
END OF ty_dd.
DATA: it_ddddlsrc TYPE STANDARD TABLE OF ty_ddddlsrc,
it_dd TYPE STANDARD TABLE OF ty_dd,
wa TYPE ty_ddddlsrc,
wa_dd TYPE ty_dd.
DATA: gv_filename TYPE string,
gv_filetype TYPE char10.
*&---------------------------------------------------------------------*
""""Selection Screen
*&---------------------------------------------------------------------*
PARAMETERS :
p_dev TYPE tadir-devclass,
filepath LIKE rlgrap-filename MEMORY ID mfolder.
DATA : src TYPE ddddlsrc,
dir TYPE tadir.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filepath.
DATA: objFile TYPE REF TO cl_gui_frontend_services.
DATA: pickedFolder TYPE string.
DATA: initialFolder TYPE string.
IF sy-batch IS INITIAL.
CREATE OBJECT objFile.
IF NOT filepath IS INITIAL.
initialFolder = filepath.
ELSE.
objFile->get_temp_directory( CHANGING temp_dir = initialFolder
EXCEPTIONS cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3 ).
ENDIF.
objFile->directory_browse( EXPORTING initial_folder = initialFolder
CHANGING selected_folder = pickedFolder
EXCEPTIONS cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3 ).
IF sy-subrc = 0.
filepath = pickedFolder.
ELSE.
WRITE: / 'An error has occured picking a folder'.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
""""Start of selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
SELECT d~ddlname
d~source
FROM tadir AS t JOIN ddddlsrc AS d
ON t~obj_name = d~ddlname
INTO TABLE it_ddddlsrc
WHERE t~pgmid = 'R3TR'
AND t~object = 'DDLS'
AND t~devclass = p_dev.
IF sy-subrc = 0.
WRITE ' File downloaded successfully'.
ENDIF.
*&---------------------------------------------------------------------*
""""End of selection
*&---------------------------------------------------------------------*
END-OF-SELECTION.
LOOP AT it_ddddlsrc INTO wa.
CONCATENATE filepath '\' wa-ddlname '.txt' INTO gv_filename.
wa_dd-source = wa-source.
APPEND wa_dd TO it_dd.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = gv_filename
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = it_dd.
CLEAR gv_filename.
CLEAR it_dd.
ENDLOOP.
I’m not that much of an internet reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back down the road sap pp training in hyderabad
ReplyDeleteThank You
Delete