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

Query Windows XP environmental variable from ABAP

Former Member
0 Likes
1,119

Hi!

I would like to know, is there a way to query the logged user's documents and settings directory in Windows XP.

For example if Bill Gates is using his Windows XP home (and not his Linux ), his documents directory will be on the following path: "C:Documents and settingsBill GatesDocuments".

I would like to get this path from ABAP (with a FM or with a class maybe).

Thank you in advance

Tamá

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
820

Hello:

use the method GET_SAPGUI_WORKDIR of class CL_GUI_FRONTEND_SERVICES. This method will return the SAP Working directory which will be C:\Documents and Settings\User\SAPWorkdir

GET_DESKTOP_DIRECTORY will return the desktop directory.

ENVIRONMENT_GET_VARIABLE will get the value of an environment variable.

Manoj

6 REPLIES 6
Read only

Former Member
0 Likes
821

Hello:

use the method GET_SAPGUI_WORKDIR of class CL_GUI_FRONTEND_SERVICES. This method will return the SAP Working directory which will be C:\Documents and Settings\User\SAPWorkdir

GET_DESKTOP_DIRECTORY will return the desktop directory.

ENVIRONMENT_GET_VARIABLE will get the value of an environment variable.

Manoj

Read only

0 Likes
820

Thanx for the answer... Sadly I receive only a blank field, I'll attach my coding, did I forget sg?



DATA: go_gui_frontend type ref to CL_GUI_FRONTEND_SERVICES.
DATA: lv_sapworkdir TYPE string.
...

    CREATE OBJECT go_gui_frontend.

    CLEAR lv_sapworkdir.
    CALL METHOD go_gui_frontend->GET_SAPGUI_WORKDIR
      CHANGING sapworkdir = lv_sapworkdir.


Thank you

Tamá

Read only

0 Likes
820

You dont need to create an object for the class since it is a static method. You can use the class name directly to call the method.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_SAPGUI_WORKDIR

CHANGING sapworkdir = lv_sapworkdir.

Manoj

Read only

0 Likes
820

Seems this method is not working... It gives only a blank field for me...

Read only

Former Member
0 Likes
820

Does anyone know why this is not working?

Or another solution?

Read only

0 Likes
820

Probably need to add a flush. I was trying to figure this out myself, here is the example I got to work:

REPORT ztest_enviromentalvariable .

DATA: go_gui_frontend TYPE REF TO cl_gui_frontend_services.

DATA: lv_tmp TYPE string.

...

CREATE OBJECT go_gui_frontend.

CLEAR lv_tmp.

CALL METHOD cl_gui_frontend_services=>environment_get_variable

EXPORTING

variable = 'TMP'

IMPORTING

value = lv_tmp

EXCEPTIONS

cntl_error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL METHOD CL_GUI_CFW=>FLUSH

EXCEPTIONS

CNTL_SYSTEM_ERROR = 1

CNTL_ERROR = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

  • Error handling

ENDIF.

WRITE: / lv_tmp.