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: 

BADI for ME22N

Former Member
0 Kudos
3,293

Dear all,

i have a very tricky requirement

i want to restrict ME22N transaction to certain users according to particular document type.

Now i have found out BADI ME_PROCESS_PO_CUST and have written code according to requirement which is working fine and the system is throwing error message as required. Then after clicking on error message when user presses the BACK button ,it is showing a popup "

do u want to save the document"

here if the user clicks on "YES"

than its allowing changes which shouldnt be the case can u plz help me out as to what should be done so that after the first error mesage

the popup for "do u want to Save" shouldnt com or it shouldnt allow to change the document

my code is as below

method IF_EX_ME_PROCESS_PO_CUST~CLOSE.

IF SY-TCODE = 'ME22N'.

DATA: IT_MEPOHEADER TYPE MEPOHEADER.

IT_MEPOHEADER = IM_HEADER->GET_DATA( ).

IF SY-SUBRC = 0.

IF SY-UNAME = 'ABAP05' OR SY-UNAME = 'FUNC57' .

IF SY-UCOMM = 'MECHECKDOC' OR SY-UCOMM = 'MESAVE' .

MESSAGE e000(0) WITH 'you are not authorized to use ME22N for the given document type'.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

endmethod.

here sy-ucomm MECHECKDOC is for checking

and MESAVE' is for saving

1 ACCEPTED SOLUTION

Former Member
0 Kudos
769

Hi All,

I have done the same object.

In ME_PROCESS_PO_CUST, there is a method PROCESS_HEADER.

In that u have used GET DATA. method.

If u do not want the changes depending on the conditions, U have to set back the old values.

For that purpose, u have to use GET PREVIOUS DATA method to hold the old values (before changes)

Then depending on the condition, if u do not want changes, U can set back those changes using the SET DATA method.

In SET DATA method, u can use the values of GET PREVIOUS DATA.

I hope u can do this.

If u need code help, contact me on mnpss@yahoo.com

Reward if useful

Narendra

11 REPLIES 11

former_member188827
Active Contributor
0 Kudos
769

method IF_EX_ME_PROCESS_PO_CUST~CLOSE.

IF SY-TCODE = 'ME22N'.

DATA: IT_MEPOHEADER TYPE MEPOHEADER.

IT_MEPOHEADER = IM_HEADER->GET_DATA( ).

IF SY-SUBRC = 0.

IF SY-UNAME = 'ABAP05' OR SY-UNAME = 'FUNC57' .

IF SY-UCOMM = 'MECHECKDOC' OR SY-UCOMM = 'MESAVE' .

Leave to transaction 'ME22N'.

MESSAGE e000(0) WITH 'you are not authorized to use ME22N for the given document type'.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

endmethod.

try using leave to transaction stmt b4 or after message and see if dis works...

former_member188827
Active Contributor
0 Kudos
769

also if u give message stmt like:

Message 'you are not authorized to use ME22N for the given document type' type 'E'.

the transaction will terminate but if u provide message as u had mentioned with message class, this kind of abnormal behavior is encountered which u mentioned..

plz reward points if dis helps

Former Member
0 Kudos
769

Thanks for ur reply

but still it is not working as after all the code written finally while leaving the transaction the popup comes and it allows all the changed code to be saved i had also previously tried using leave , set screen keyword but of no use.

anyway thanks once again

Former Member
0 Kudos
769

hi,

try to add info message if possible as aftererror message control wont move further

IF SY-UCOMM = 'MECHECKDOC' OR SY-UCOMM = 'MESAVE' .

MESSAGE i000(0) WITH 'you are not authorized to use ME22N for the given document type'.

exit.

ENDIF.

revert back

regards,

naveen

Former Member
0 Kudos
769

Thanks for ur reply

Even exit doesnot work

the thing that is happning is system is asking popup irrespective of the code at the final stage and here if clicked on yes the unwanted data gets saved.

0 Kudos
769

hi,,,

try this way..

IF SY-UCOMM = 'MECHECKDOC' OR SY-UCOMM = 'MESAVE' .

MESSAGE i000(0) WITH 'you are not authorized to use ME22N for the given document type'.

leave transaction.

ENDIF

revert back...

regards,

naveen

former_member188827
Active Contributor
0 Kudos
769

try using

SUPPRESS DIALOG stmt after message.

0 Kudos
769

Thanks once again

neither does suppress dialog or leave transaction work

i dont know how to prevent that final popup to appear as irrespective of the code the final popup comes and every validation goes into mess.

0 Kudos
769

try giving message type 'A' and see what happens

Former Member
0 Kudos
770

Hi All,

I have done the same object.

In ME_PROCESS_PO_CUST, there is a method PROCESS_HEADER.

In that u have used GET DATA. method.

If u do not want the changes depending on the conditions, U have to set back the old values.

For that purpose, u have to use GET PREVIOUS DATA method to hold the old values (before changes)

Then depending on the condition, if u do not want changes, U can set back those changes using the SET DATA method.

In SET DATA method, u can use the values of GET PREVIOUS DATA.

I hope u can do this.

If u need code help, contact me on mnpss@yahoo.com

Reward if useful

Narendra

Former Member
0 Kudos
769

Thank u all,

mypurpose has finally been solved here is the code for the same

method IF_EX_ME_PROCESS_PO_CUST~CHECK.

IF SY-TCODE = 'ME22N'.

DATA: IT_MEPOHEADER TYPE MEPOHEADER.

IT_MEPOHEADER = IM_HEADER->GET_DATA( ).

IF SY-SUBRC = 0.

IF SY-UNAME = 'ABAP05' OR SY-UNAME = 'FUNC57' .

Message 'you are not authorized to use ME22N for the given document type' type 'E'.

ENDIF.

ENDIF.

ENDIF.

endmethod.

here previously i used sy-ucomm as a filter which was preventing as sy-ucomm was getting changed to "YES"

after clicking on th popup and the check was not working.

Thanks to all.