Skip to Content
Author's profile photo Former Member

Program to load CSV file from local desktop to Application server(For flat file Data extraction)

In many occasion, data needs to be loaded to SAP BW through flat file.

But flat file load from local desktop is not possible through process chain(Process chain will failed to extract from Local desktop).

In order to resolve this issue, flat file needs to be uploaded to application server and then process chain can be triggered at its scheduled time.

Process chain will not fail if flat file is loaded from application server.

Program to load file to application server:

TYPE-POOLS : vrm.

DATA:  param TYPE vrm_id,
       values     TYPE vrm_values,
       value LIKE LINE OF values.

*Parameter Declaration

PARAMETERS: p_file TYPE localfile OBLIGATORY.

*File selection from local desktop

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  DATA: ifile TYPE filetable.
  DATA: xfile LIKE LINE OF ifile.
  DATA: rc TYPE i.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      initial_directory = ‘C:\’
    CHANGING
      file_table        = ifile
      rc                = rc.

  READ TABLE ifile INTO xfile INDEX 1.
  CHECK sy-subrc = 0.
  p_file = xfile-filename.

*Local file upload to Application server

END-OF-SELECTION.
  DATA: p_file_path LIKE sapb-sappfad.

  p_file_path = p_file.

      CALL FUNCTION ‘ARCHIVFILE_CLIENT_TO_SERVER’
      EXPORTING
        path             = p_file_path
       targetpath       = ‘abc.CSV’

*     EXCEPTIONS

*       ERROR_FILE       = 1

*       OTHERS           = 2

.

While executing the above program, selection screen displayed to choose the file from local desktop as shown below:

/wp-content/uploads/2012/10/img1_143817.jpg

Click on F4 option to choose the file from desktop.

/wp-content/uploads/2012/10/img2_143818.jpg

Click on Execute.

/wp-content/uploads/2012/10/img3_143819.jpg

In order to check the file is successfully loaded, please goto T-code AL11.

/wp-content/uploads/2012/10/img4_143820.jpg

Docubel click the directory “DIR_SAPUSERS”

/wp-content/uploads/2012/10/img5_143821.jpg

Now, we can able to see the flat file that has been loaded to application server.

Now this file can be used to load through process chain.

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Suman Chakravarthy K
      Suman Chakravarthy K

      Fantastic code 🙂 🙂 . Thanks a lot for sharing!!

      Author's profile photo amine lamkaissi
      amine lamkaissi

      Very useful,

      Thanks Karthick.

      Amine

      Author's profile photo Former Member
      Former Member

      Hello Karthick,

      May I copy this code to address my requirement?

      Regards

      Shirley

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Yes. You can use it. But please test your code and use it based on your requirement. I will not be responsible for any outcome by using this code. Its just my way of developing code.

      Regards

      Karthick.

      Author's profile photo Harish Allachervu
      Harish Allachervu

      As SAP already given FM ARCHIVFILE_CLIENT_TO_SERVER for this purpose,

      what is point of creating Z program? are automating flat-file upload with your program?

      Thanks & Regards,

      Harish

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      I have designed this based on end user perspective to make user friendly..just to remember T-code for flat file upload..not to remember the FM name.

      Regards

      Karthick.

      Author's profile photo Former Member
      Former Member

      Really very helpful document.. 🙂

      Author's profile photo Former Member
      Former Member

      Hi, ECC has tcode CG3Z to achieve this, but not in BW. So this is helpful....

      Author's profile photo Avinash point
      Avinash point

      Hi,

      If we do this file will saved in SAP home directory, so what if I want to save it in some other directory?

      Regards,

      Avinash