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

Pass System Variable value into variable

former_member212148
Participant
0 Likes
2,629

Hello Experts,

My requirement is I am using dynamic where condition in select statement.

in where clause I ll pass system variable with field and it may be without system variable.

If my where condition contains system variable I want its value in variable.

I dont want to hard code of system variable as SY-DATUM, SY-UNAME.

DATA: SDATE TYPE STRING,
       STR_DATE TYPE STRING,
       V_STR TYPE STRING.
V_STR = 'sy-datum'.
STR_DATE = ' ersda = sy-datum'.
IF STR_DATE CS V_STR.
   SDATE = V_STR.
ENDIF.
WRITE😕 SDATE.

Output is : SY-DATUM.

but i want to output current date as 20130912.

Kindly consider my request.

Thanks & regrads,

Ranjit Kumar


1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,850

Hi,

Use field symbols. I have modified your code and its working now.

DATA: SDATE TYPE STRING,
        STR_DATE TYPE STRING,
        V_STR TYPE STRING.
FIELD-SYMBOLS <a> type sy-datum.

V_STR = 'sy-datum'.
ASSIGN (v_str) to <a>.
STR_DATE = ' ersda = sy-datum'.
IF STR_DATE CS V_STR.
    SDATE = <a>.
ENDIF.
WRITE:/ SDATE.

This way you can store any system variable in V_STR and SDATE will get its value and not the name of the variable.

regards,

Ashish Rawat


10 REPLIES 10
Read only

Former Member
0 Likes
1,850

Hi Ranjit ,

    According to my understanding you are not able to populate the sy-datum in the variable sdate.

    If thats the case then change the statment to v_str = sy-datum.

     If your requirment is someother just give a clear explanation , i couldnt understand from above explanation.

Regards,

Aditya.

Read only

Former Member
0 Likes
1,851

Hi,

Use field symbols. I have modified your code and its working now.

DATA: SDATE TYPE STRING,
        STR_DATE TYPE STRING,
        V_STR TYPE STRING.
FIELD-SYMBOLS <a> type sy-datum.

V_STR = 'sy-datum'.
ASSIGN (v_str) to <a>.
STR_DATE = ' ersda = sy-datum'.
IF STR_DATE CS V_STR.
    SDATE = <a>.
ENDIF.
WRITE:/ SDATE.

This way you can store any system variable in V_STR and SDATE will get its value and not the name of the variable.

regards,

Ashish Rawat


Read only

0 Likes
1,850

Thanks Ashish,

My problem is solved. Thanks for quick response.

regards,

Ranjit

Read only

0 Likes
1,850

hi,

a little editing needed in above code to allow it to work for all variables.

In declaring field symbol,

FIELD-SYMBOLS <a> TYPE DATA.

I used type sy-datum above so it will work for only that field. Declare as TYPE DATA then it will work for all variables.

And 1 more important thing,

do not use str_date = 'ersda = sy-datum' directly,

Instead use,

CONCATENATE 'ersda = ' sy-datum INTO str_date.

regards,

Ashish Rawat

Read only

0 Likes
1,850

hI,

I have done it already.

Thanks for solution.

Read only

Arun_Prabhu_K
Active Contributor
0 Likes
1,850

Hello Ranjit.

This statement

     STR_DATE = ' ersda = sy-datum'

will not pass the value of current date.

Make use of concatenate statement.

CONCATENATE ' Ersda '  sy-datum into STR_DATE.

Regards.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,850

Don't sure to understand you requirement, are you willing to dynamically interpret a string which contains reference to system variables ?

If yes then search the string for occurence of "SY-" (converting to uppercase) then extract the full name(s) of system field (e.g. SY-DATUM) by searching next separator (space, ")" or end of string). Then replace this string with the actual value (using an ASSIGN and a WRITE (ASSIGN (stringfound) to <fs> and WRITE <fs> to a character field)

Regards,

Raymond

Read only

sivaganesh_krishnan
Contributor
0 Likes
1,850

Hi Ranjit,

I am not sure of what you really want , But i can interpret that u want  the date to be showed  as 20130912 from a variable . If you want that , then the following code will do the job

DATA: V_STR TYPE STRING.

    V_STR = sy-datum.
    WRITE:/  V_STR.

Regards,

Sivaganesh.K

Read only

0 Likes
1,850

Hi Sivaganesh,

I have not to pass SY-DATUM directly to any variable.

basically SY-DATUM is a part of my string stored in variable.

like that

v_str = 'ersda = sy-datum'.

get the sy-datum from v_ster and pass it another variable .

Here i need system date but i get string sy-datum in stead of its value. thats the reason.

I use field symbol.

Thanks,

Ranjit K.

Read only

Former Member
0 Likes
1,850

Dear Ranjith,

Please try this.

DATA: SDATE TYPE SYDATUM,
        STR_DATE TYPE STRING,
        V_STR TYPE SYDATUM.


V_STR = 'sy-datum'.
STR_DATE = 'ersda=sy-datum'."
IF STR_DATE CS V_STR.
    V_STR = sy-datum.
    SDATE = V_STR.""sy-datum.".
ENDIF.
WRITE:/ SDATE.

Thanks and Regrads,

buz_sap