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

String operations on error messages

Ranjith_D_Reddy
Participant
0 Likes
2,654

Hi Team,

i would to get only the SAP user id in the error message which would be 8 characters .

Could you please help me in getting the below output. I would require only the last 8 characters of the string.

  1. InputàMaterial 000000692122  is lock y PRESTOGE   (string having any number of characters)
  2. Outputà PRESTOGE

Regards,

Ranjith.

6 REPLIES 6
Read only

Former Member
0 Likes
1,881

Hi,

what you can do is getting the last 8 chars of your string.

data(lv_offset) = strlen(message_v1)

lv_offset = lv_offset - 8.

move message_v1+(lv_offset)  to lv_user_id

Read only

Former Member
0 Likes
1,881

Hi Ranjith,

Pass X_MSG_TAB data to FM

CALL FUNCTION 'FORMAT_MESSAGE' "

* EXPORTING

* id = SY-MSGID " Application Area

* lang = '-D' "

* no = SY-MSGNO "

* v1 = SY-MSGV1 " 1st parameter

* v2 = SY-MSGV2 " 2nd parameter

* v3 = SY-MSGV3 " 3rd parameter

* v4 = SY-MSGV4 " 4th Parameter

  IMPORTING

  msg =  MESSAGE

  EXCEPTIONS

  NOT_FOUND = 1 "

  . " FORMAT_MESSAGE

so you will get complete message "Input Material 000000692122  is locked by PRESTOGE" in Message variable.

After that Use Split command.

Data: text type string,

         username type sy-uname.

SPLIT MESSAGE AT 'by' into text username.

In Username variable you will get PRESTOGE.

Thanks.

Regards,

Ashish Desai

Read only

Former Member
0 Likes
1,881

Your assumption is wrong. The user ID maynot be always 8 characters ( It can be upto 12 characters )

Also looking at the message M3 023 - "The group data for the material & is locked by &" your population of MESSAGE_V1 and MESSAGE_V2 is not right.

Anyway.

I would not go for offset as I explained in the first paragraph.

I would use

1.concatenate MESSAGE_V1 and MESSAGE_V2 into a <string>.

2. Split string at space into table itab.

3. Will read the last line of Itab and get the user ID.

data(lv_lines) = LINES(itab).

read table itab index lv_lines.

R

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,881

My 2 cents ...

The message M3(022) is defined as -


The group data for the material & is locked by &

So basically the fields should be mapped as: MESSAGE_V1 = <material no.> & MESSAGE_V2 = <user name>.


I would suggest you to correct the source table X_MSG_TAB, because IMHO the content is false. The message text should be mapped to the field MESSAGE.


BR,

Suhas

Read only

Juwin
Active Contributor
0 Likes
1,881

I agree.

Also, looking at the structure, it seems to be a custom development - No standard message structure would have just MESSAGE_V1 & V2 fields. Standard structures for messages will always have V1, V2, V3 and V4 fields. So, please fix the custom code, to pass back the values correctly.

If you just need the name of the person who locked the object, you can also call the function module  ENQUEUE_READ.

Thanks,

Juwin

Read only

former_member182805
Active Participant
0 Likes
1,881

What transaction code are you running?

When does this error message occur in the program?

If it is a standard message, you can read the message class and number and go to the message table T100, read the message into a string variable and read the last 8 characters using the offset function.