SAP ABAP - Download CDS View


*&---------------------------------------------------------------------*

*& Report Z_DOWNLOAD_CDS
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_download_cds.

TYPESBEGIN 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.

DATAit_ddddlsrc TYPE STANDARD TABLE OF ty_ddddlsrc,
      it_dd       TYPE STANDARD TABLE OF ty_dd,
      wa          TYPE ty_ddddlsrc,
      wa_dd       TYPE ty_dd.


DATAgv_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.
  DATAobjFile TYPE REF TO cl_gui_frontend_services.
  DATApickedFolder TYPE string.
  DATAinitialFolder TYPE string.

  IF sy-batch IS INITIAL.
    CREATE OBJECT objFile.

    IF NOT filepath IS INITIAL.
      initialFolder filepath.
    ELSE.
      objFile->get_temp_directoryCHANGING temp_dir initialFolder
                                   EXCEPTIONS cntl_error 1
                                             error_no_gui 2
                                             not_supported_by_gui ).
    ENDIF.

    objFile->directory_browseEXPORTING initial_folder initialFolder
                               CHANGING selected_folder pickedFolder
                               EXCEPTIONS cntl_error 1
                                          error_no_gui 2
                                          not_supported_by_gui ).

    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 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.

Comments

  1. 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

    ReplyDelete

Post a Comment

Popular posts from this blog

PHP MySql CRUD Dengan Konsep MVC

Laravel - Sistem Informasi Perpustakaan Sederhana Laravel

IT Asset Management Dengan PHP MySQL