Register Login

Uploading Files From Presentation To Application Server.

Updated May 18, 2018

REPORT  zupl_presentation_to_appl.

* Local data ----------------------------------------------------------

DATA: l_filelength      TYPE i.
types : begin of ty_dt_tab,
         txt(4096) TYPE c,
      end of ty_dt_tab.
DATA : lt_input TYPE ty_dt_tab OCCURS 0,
       wa_input TYPE ty_dt_tab.
DATA: l_filename        TYPE string.
DATA: l_auth_filename   LIKE authb-filename,
      e_flg_open_error  TYPE  boolean,
      e_os_message      TYPE  c,
      success(1),
      lv_string TYPE string.

FIELD-SYMBOLS : type ty_dt_tab.

CONSTANTS:
  sabc_act_read(4)               VALUE 'READ',
  sabc_act_write(5)              VALUE 'WRITE'.
CONSTANTS: lc_fileformat_ascii         LIKE rlgrap-filetype
                                       VALUE 'ASC'.

CONSTANTS: lc_fileformat_binary        LIKE rlgrap-filetype
                                       VALUE 'BIN'.

PARAMETERS : frnt_end TYPE rcgfiletr-ftfront,     "Front end path
             appl_ser TYPE rcgfiletr-ftappl,      "Application server path
             overwrit TYPE c AS CHECKBOX.         "Overwrite


START-OF-SELECTION.
* Function body -------------------------------------------------------
* init
  e_flg_open_error = ' '.
  CLEAR: e_os_message,success.

  l_filename = frnt_end.

* check the authority to write the file to the application server
  l_auth_filename = appl_ser.
  CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
       EXPORTING
*           PROGRAM          =
            activity         = sabc_act_write
            filename         = l_auth_filename
       EXCEPTIONS
            no_authority     = 1
            activity_unknown = 2
            OTHERS           = 3.
  IF NOT sy-subrc IS INITIAL.
    CASE sy-subrc.
      WHEN 1.
        STOP.
**       no auhtority
*      RAISE ap_no_authority.
      WHEN OTHERS.
        STOP.
*      RAISE ap_file_open_error.
    ENDCASE.
  ENDIF.

  TRY.

* open the file on the application server for reading to check if the
* file exists on the application server
      OPEN DATASET appl_ser FOR INPUT MESSAGE e_os_message
                   IN TEXT MODE ENCODING NON-UNICODE.
      IF sy-subrc IS INITIAL.
        IF overwrit = ' '.
          CLOSE DATASET appl_ser.
          STOP.
        ENDIF.
      ENDIF.
      CLOSE DATASET appl_ser.

*   catch exceptions
    CATCH cx_root.

      BREAK-POINT.
      EXIT.

  ENDTRY.


* open dataset for writing
  OPEN DATASET appl_ser FOR OUTPUT MESSAGE e_os_message
               IN TEXT MODE ENCODING NON-UNICODE.
  IF NOT sy-subrc IS INITIAL.

*  e_flg_open_error = true.
    STOP.

  ELSE.


    lv_string = frnt_end.


    CALL METHOD cl_gui_frontend_services=>gui_upload
       EXPORTING
         filename                = lv_string
         filetype                = 'ASC'
         has_field_separator     = ' '
*      IMPORTING
*        filelength              =
*        header                  =
      CHANGING
        data_tab                = lt_input
      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 'S' NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      stop.
    ENDIF.

*   write the file to the application server
    LOOP AT lt_input ASSIGNING .
      TRANSFER TO appl_ser.
*     transfer has no exceptions
*     if not sy-subrc is initial.
*       raise ap_file_write_error.
*     endif.
      success = 'X'.
    ENDLOOP.


*   close the dataset
      CLOSE DATASET appl_ser.


    ENDIF.


    IF success = 'X'.
      CLEAR success .
      MESSAGE 'successfully uploaded.' TYPE 'S'.

    ENDIF.

Thanks & Regards,


Comments

  • 14 Apr 2015 2:44 pm Guest

    Assignment on File Upload – Download from/to application and presentation servers

     

    1. On the selection screen, have two file paths one for application server and one for presentation server.
    2. Upload a file from presentation server which has sales order numbers.
    3. Read the file and fetch the header and item details for all the sales orders.
    4. Create a file with all the details and download it on the application servers.

    The file will contain following details

    1. Sales order number(vbak-vblen/vbap-vblen)
    2. Order type(vbak-bsark)
    3. Sold to party(VBAK-KUNnr)
    4. Item number(vbap-POSNR)
    5. Material(vbap-matnr)
    6. Quantity(vbap-kwmeng)
    7. Price(vbap-netpr)
    8. If the download is successful display a report with all the downloaded data.

    Report should be an ALV Grid display with the above fields.

    can you plz share me the code on the above requirement

    this is may mail id subbumf57@gmail.com

     

     

     

     


×