Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Find SapWorkDir path

Former Member
0 Likes
9,012

I am using the following fn module:

CALL FUNCTION 'DOWNLOAD'

EXPORTING

filename = 'C:\LOG.TXT'

filetype = 'ASC'

TABLES

data_tab = it_log

In the paramater <b>filename</b> I want to give default as the path to the SapWorkDir of the user logged in currently. (Usually it is c:\Documents and Settings\<username>\SapWorkDir\).

But do we have a neat way.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
7,129

Hi Flora lab... You may also use the class CL_GUI_FRONTEND_SERVICES, Method GET_SAPGUI_WORKDIR:

DATA: workdir TYPE string.

CALL METHOD cl_gui_frontend_services->get_sapgui_workdir

IMPORTING

SAPWORKDIR = workdir.

8 REPLIES 8
Read only

Former Member
0 Likes
7,129

hi flora ,

declare

data :filename LIKE rlgrap-filename default value 'C:\path..... ' modif id d1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

mask = '.xls' (/ '.txt')

static = 'X'

CHANGING

file_name = filename.

hope this helps ,

vikky.

Message was edited by: Vikky

Read only

Former Member
0 Likes
7,129

The system variable sy-uname has the name of the user logged on.

You can get this value into a variable and substitute into the <username> part of the URL.


DATA: v_filename(100).

concatenate 'c:Documents and Settings' sy-uname separated by '' into v_filename.

concatenate v_filename 'SapWorkDir' into v_filename.
*Now call the FM

CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = v_filename
filetype = 'ASC'
TABLES
data_tab = it_log

Hope this helps.

Sudha

Message was edited by: Sudha Mohan

Read only

0 Likes
7,129

Hi Sudha, it may be possibel that the windows is installed in some other drive than C:\ or the user has set her SapWorkDir to some other folder

Read only

0 Likes
7,129

If the user needs to select the directory in which to put the file, its better you get it as input from the selection screen and then assign it to the FM.

Sudha

Read only

Former Member
0 Likes
7,129

hi flora,

1. The neat way is to DETECT

which is the SAP Directory.

2.

report abc.

data : ret(100) type c.

<b>CALL FUNCTION 'GUI_GET_DESKTOP_INFO'

EXPORTING

type = 11 " <----


Important

changing

return = RET

.</b>

BREAK-POINT.

RET will contain the FULL PATH.

*----


1: Host name (host name of current system)

2: Windows directory

3: System directory

4: Temp. directory

5: Domain user name

6: Platform

7: Windows build number

8: Windows version

9: Program name

10: Program path

11: Current directory (Directory for current process)

regards,

amit m.

Read only

Former Member
0 Likes
7,130

Hi Flora lab... You may also use the class CL_GUI_FRONTEND_SERVICES, Method GET_SAPGUI_WORKDIR:

DATA: workdir TYPE string.

CALL METHOD cl_gui_frontend_services->get_sapgui_workdir

IMPORTING

SAPWORKDIR = workdir.

Read only

Former Member
0 Likes
7,129

HI Flora,

The best way is to let the user choose the path like this..

DATA itab LIKE TABLE OF FILE_TABLE WITH HEADER LINE.
data : filename type string.
PARAMETERS : DATASET(128).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR DATASET.
CALL FUNCTION 'TMP_GUI_FILE_OPEN_DIALOG'
  TABLES
    FILE_TABLE              = itab
.

 READ TABLE ITAB index 1.
  DATASET = itab-FILENAME.
  fielname = DATASET.

and then call..

CALL FUNCTION 'DOWNLOAD'
EXPORTING
filename = fielname
filetype = 'ASC'
TABLES
data_tab = it_log

regards

satesh

Read only

Former Member
0 Likes
7,129
this works good

*&---------------------------------------------------------------------*
*& Report  YCHATEST                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ychatest                                .


DATA : sapworkdir TYPE string.
PARAMETERS : workdir TYPE rlgrap-filename.



INITIALIZATION.

  CALL METHOD cl_gui_frontend_services=>registry_get_value
      EXPORTING
        root         = cl_gui_frontend_services=>hkey_current_user
        key          =
        'SoftwareSAPSAPGUI FrontSAP Frontend ServerFiletransfer'
        value        = 'PathDownload'
       IMPORTING
         reg_value   = sapworkdir
         EXCEPTIONS
         get_regvalue_failed  = 1
         cntl_error           = 2
         error_no_gui         = 3
         not_supported_by_gui = 4
         OTHERS               = 5.

  IF sy-subrc <> 0 OR sapworkdir = ''.
    CALL METHOD cl_gui_frontend_services=>directory_get_current
      CHANGING
        current_directory            = sapworkdir
      EXCEPTIONS
        directory_get_current_failed = 1
        cntl_error                   = 2
        error_no_gui                 = 3
        not_supported_by_gui         = 4
        OTHERS                       = 5.
    CALL METHOD cl_gui_cfw=>flush.
  ENDIF.

  workdir = sapworkdir.