Application Development 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: 

How to read user - logon language (Urgent)

Former Member
0 Kudos

Hi All,

I have written the below code to display the language in english if it exists if not in french & so on, but i would like to know how i can read the language in which the user has logged on & use that as the first criteria.

Eg: S_SPRAS = User Logon language

SELECT SINGLE MAKTX FROM MAKT INTO Y_MAKTX

WHERE MATNR = MARC-MATNR

AND SPRAS IN (S_SPRAS,'EN','FR','IT',' ').

Hope my problem is clear, await inputs.

Vivek

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Hope this works...

First

data: s_langu type sy-langu,

y_maktx type makt-maktx,

s_langu1(1) type c.

s_langu = sy-langu.

s_langu1 = sy-langu+(1).

  • say there is a desc in Italian. then y_maktx has a desc in italian.

select single maktx from makt into y_maktx

where matnr eq marc-matnr

and spras eq s_langu1.

*if there is no desc in italian.

if y_maktx is initial.

select single maktx from makt into y_maktx

where matnr eq marc-matnr

and spras eq 'E'

or spras eq 'I'

or spras eq 'F'.

endif.

This should work. Try out.

reward points if helpful.

Arul.

16 REPLIES 16

Former Member
0 Kudos

Hi, Vivek.

You can use SY-LANGU(SAP logon language key).

Regards,

feng.

Former Member
0 Kudos

SY-LANGU

former_member156446
Active Contributor
0 Kudos

SELECT SINGLE MAKTX FROM MAKT INTO Y_MAKTX

WHERE MATNR = MARC-MATNR

AND SPRAS EQ Sy-langu.

Former Member
0 Kudos

Hi All

Thanks for the inputs, but if i use SY-LANGU, it will pick up the default language which is set for the user.

Eg: User 1 default lang - EN (i.e. SY-LANGU = EN)

But if the user while logging into SAP chooses FR, the code will still read EN language description, as the system language is EN. What i wanted is if user logs in FR, the description should be FR.

Hope i am able to put across my problem clearly.

Await inputs.

Vivek

0 Kudos

SY-LANGU will solve ur problem.

SY-LANGU will be the logon language, and not any language associated to a user.

Just write this in a program in SE38.

logon into your account using FR language

write : SY-LANGU.

You will see FR.

Hope this is clear

Regards

Gopi

0 Kudos

Hi,

Thanks for the info, it works only when i use

SPRAS Eq SY-LANGU.

But when i use

SPRAS IN (SY-LANGU, 'En', 'Fr').

The system picks up the english translation. Is there anything wrong in my IN statement?

Any suggestions?

Edited by: Vivek on Jan 7, 2008 5:04 PM

0 Kudos

Friend,

Try by giving all in caps....

SPRAS IN (SY-LANGU, 'EN', 'FR').

0 Kudos

You have to specify single character values in SPRAS.

Check Tabl2 T002 for the language keys.

u can use as follows:

SPRAS IN (SY-LANGU, 'E', 'F').

awrd points if useful

Bhupal

Former Member
0 Kudos

It is not working. The moment i use IN syntax the output shows in EN which is the default language. But when i use EQ syntax & then logon in different language it reads the logon language.

Is there any other way i can manage to resolve my problem?

I want to read the description in the logon language first, if the mtl description is not maintained in the lang in which the user has logged on then check for the others.

Await inputs.

Vivek

0 Kudos

Hi, Vivek.

I can't understand your meaning fully. You just want to select only one record. I think first we can select the record which 'language EQ sy-langu', if we get nothing, then we can use 'select single' to get a record.

May be I'm wrong, just a advice.

Regards,

feng.

0 Kudos

Hi,

Let me try to explain the problem

Mtl-A, has description in 3 languages. (En, Fr, It)

Mtl-B, has description in 1 language only. (It)

Mtl-C, has no description

First i want to check for a given mtl if description exists in the user's logon lang, if it does not, then check if description is maintained in English, if not check in French, if not Italian.

Eg1: User logs-in with En language,

Then the description for mtl-A is displayed in english, for Mtl-b description is displayed in Italian (as only italian description is maintained) & for mtl-c no description is displayed as it is not maintained.

Eg2: User logs-in with It language.

Then description for Mtl-A & B is displayed in Italian & for mtl-c it is blank as no description exists

But when i use the below code, the system by default picks up EN which is my default lang, even if i login in French or Italian lang, the description is shown in english only.

SELECT SINGLE MAKTX FROM MAKT INTO Y_MAKTX

WHERE MATNR = MARC-MATNR

AND SPRAS IN (SY-LANGU, 'EN', 'FR', 'IT').

Hope i was able to put across my problem clearly.

Await inputs.

Former Member
0 Kudos

Hi Vivek,

Use the following .

SELECT SINGLE MAKTX FROM MAKT INTO Y_MAKTX

WHERE MATNR = MARC-MATNR

AND SPRAS = sy-langu.

No ways.

Regards

Srimanta

Former Member
0 Kudos

Hi,

Hope this works...

First

data: s_langu type sy-langu,

y_maktx type makt-maktx,

s_langu1(1) type c.

s_langu = sy-langu.

s_langu1 = sy-langu+(1).

  • say there is a desc in Italian. then y_maktx has a desc in italian.

select single maktx from makt into y_maktx

where matnr eq marc-matnr

and spras eq s_langu1.

*if there is no desc in italian.

if y_maktx is initial.

select single maktx from makt into y_maktx

where matnr eq marc-matnr

and spras eq 'E'

or spras eq 'I'

or spras eq 'F'.

endif.

This should work. Try out.

reward points if helpful.

Arul.

0 Kudos

Hi Arul,

I think your suggestion should work, will check & let you know. But can you please let me know why you have declared 2 variables s_langu & s_langu1 unable to figure what is the need & benefit of it.

Vivek

0 Kudos

Hi Vivek,

I have declared two variables because, s_langu had the value 'EN' but the table will not recognise EN, it only recognises 'E'

so I gave taken another variable: s_langu1 = s_langy+(1).

which has 'E'.

Now you can write the query.

Hope it was helpful.

Regards

Arul.

0 Kudos

Mr. Arul,

Thank you very much for your guidance, keep the good work going. Your suggestion works.

Regards,

Vivek