Quantcast
Channel: SCN: Message List - ABAP Connectivity
Viewing all articles
Browse latest Browse all 3125

Re: How to get data from Application layer to Presentation layer?

$
0
0

Hi Pavan,

 

Please use below code :-

 

 

***********************************************************************************************

************************** Code Starts *****************************************************

REPORT  zupload_al11_test.

 

******************** Data Declaration Starts ***************************

DATA: ifile TYPE filetable,

       l_pcfile TYPE sapb-sappfad,

       lv_len TYPE i,

       lv_len1 TYPE i,

       counter TYPE i,

       lv_c(1)   TYPE c,

       lv_total TYPE i,

       xfile LIKE LINE OF ifile,

       rc TYPE i.

******************** Data Declaration Ends *****************************

******************** Declaration for Selction Screen Starts ************

***Test start

SELECTION-SCREEN BEGIN OF SCREEN 200 AS WINDOW.

PARAMETERS:             p_file TYPE localfile.

DATA:l_serfil TYPE sapb-sappfad.

SELECTION-SCREEN END OF SCREEN 200.

 

CALL SELECTION-SCREEN '0200' STARTING AT 10 10.

 

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

******************** Declaration for Selction Screen Ends ***************

   IF p_file IS INITIAL.

     CALL METHOD cl_gui_frontend_services=>file_open_dialog

       EXPORTING

         initial_directory = 'C:\'             " Default drive C for F4 help

       CHANGING

         file_table        = ifile

         rc                = rc.

     READ TABLE ifile INTO xfile INDEX 1.

     CHECK sy-subrc = 0.

 

     p_file = xfile-filename.

   ENDIF.

 

START-OF-SELECTION.

   l_pcfile = p_file.

 

 

   IF l_pcfile IS NOT INITIAL.

       lv_len = strlen( l_pcfile ).

       lv_total = lv_len.

       lv_len1 = lv_len - 1.

 

       lv_c    = l_pcfile+lv_len1(1).

       counter = 0.

       WHILE lv_c <> '\'.

         lv_len = lv_len - 1.

         lv_len1 = lv_len1 - 1.

 

         lv_c    = l_pcfile+lv_len1(1).

         counter = counter + 1.

       ENDWHILE.

 

       lv_total = lv_total - counter.

       CONCATENATE '/usr/sap/tmp'  l_pcfile+lv_total(counter) INTO l_serfil.

 

DATA : LD_TGT_FILE TYPE STRING,

        LD_SRC_FILE TYPE STRING.

   LD_SRC_FILE = l_serfil.

CONCATENATE '/oracle/' l_pcfile+lv_total(counter)'_' SY-DATUM '_' SY-UZEIT '_' SY-UNAME INTOLD_TGT_FILE.

"

PERFORM COPY_FILE_IN_APP_SERVER USING LD_SRC_FILE

                                       LD_TGT_FILE.

 

     CALL FUNCTION 'ARCHIVFILE_CLIENT_TO_SERVER'

       EXPORTING

         path       = l_pcfile          " SOURCE FILE NAME

         targetpath = l_serfil          " TARGET FILE NAME

       EXCEPTIONS

         error_file = 1

         OTHERS     = 2.

 

     IF sy-subrc EQ 0.

       MESSAGE 'File Uploaded Successfully.....' TYPE 'S'.

 

     ELSE.

       MESSAGE : 'File Uploaded With Errors.....' TYPE 'S' .

     ENDIF.

   ELSE.

     MESSAGE: 'Source or Target File Path is Empty.......' TYPE 'S'   .

 

   ENDIF.

 

   FORM COPY_FILE_IN_APP_SERVER USING LV_SRC_FILE TYPE STRING

                                      LV_TGT_FILE TYPE STRING.

    DATA: LV_STR TYPE STRING.

    " OPEN DATASET FILE FROM SERVER FOR READING

    OPEN DATASET LV_SRC_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.

    IF SY-SUBRC = 0.

       OPEN DATASET LV_TGT_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

          DO.

            READ DATASET LV_SRC_FILE INTO LV_STR.

              IF SY-SUBRC = 0.

                 TRANSFER LV_STR TO LV_TGT_FILE.

                 CLEAR LV_STR.

              ELSE.

                 EXIT.

              ENDIF.

          ENDDO.

    ENDIF.

 

     CLOSE DATASET LV_SRC_FILE.

     CLOSE DATASET LV_TGT_FILE.

 

   ENDFORM.


******************************** Code Ends ****************************************************

******************************************************************************************


Copy and paste above code in SE38.


1) select file from desktop using F4 help


2) Execute Program----->The file will get on AL11 folder "/usr/sap/tmp"

 

You need to change the folder path as per your requirement...

 

Regards,

Hitesh Gavande




Viewing all articles
Browse latest Browse all 3125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>