04-18-2008 5:43 PM
Dear Sir,
I implemented following BADI which is being called in ME21n transaction . The Syntax is :
method IF_EX_ME_PURCHDOC_POSTED~POSTED.
DATA: wa_ekpo like line of IM_EKPO .
DATA: wa_doctype TYPE EKKO-BSART.
if IM_EKPO[] is not initial .
LOOP AT IM_EKPO into wa_ekpo .
if im_ekko-bsart EQ 'ZIMP' .
SEARCH wa_ekpo-MATNR FOR '-I' .
IF SY-FDPOS EQ 0 .
IF wa_ekpo-BWTAR is INITIAL .
MESSAGE ID 'XXX' TYPE 'E' NUMBER '000' WITH 'Valuation Type'.
ENDIF.
ENDIF.
else.
SEARCH wa_ekpo-MATNR FOR '-I' .
IF SY-FDPOS NE 0 .
IF wa_ekpo-BWTAR is INITIAL .
MESSAGE ID 'XXX' TYPE 'E' NUMBER '000' WITH 'Valuation Type'.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
endif.
endmethod.
My problem is that when MESSAGE statement get executed , then a dialog box for the error message appear and subsequently on pressing enter key, the screen get cleared and all input values get lost .
Instead of complete screen getting cleared , it should retain the values so that user can make the necessary correction in the input .
Kindly help me , as how to resolve the problem .
Regards
B Mittal
04-18-2008 9:16 PM
For giving error message in your BADI use CALL METHOD cl_message_mm=>create.
G@urav.
04-19-2008 3:12 AM
Dear Mr Gaurav Gupta
Thanks for reply .
May I request you to kindly give the complete code for using suggested the CALL METHOD cl_message_mm .
It will be a great help please .
Regards
B Mittal
04-19-2008 5:48 AM
it is a simle method.. just pass approriate message attributes to its parameters...
G@urav.
04-19-2008 7:20 AM
Hi,
Use the Function Module POPUP_TO_CONFIRM and display the messages to user.
Refer
https://forums.sdn.sap.com/click.jspa?searchID=10926344&messageID=964905
https://forums.sdn.sap.com/click.jspa?searchID=10926344&messageID=5214757
Conclusion:You may send S-, I- or W-messages at any place within a BAdI but not A/E/X messages.
Regards
Kiran Sure
04-19-2008 7:06 PM
It's true that we should avoid any messages( other than success messages) in enhancement because these cause the implicit commit in transaction.
However for all enjoy transactions SAP has provided a way to display messages in message container.
ME21N is also SAP Enjoy transaction and
CALL METHOD cl_message_mm=>create
EXPORTING
im_msgid = 'ZTEST_MSG'
im_msgty = 'E'
im_msgno = '008'
im_msgv1 = v_error_body
IMPORTING
ex_message = v_message
.
is a factory method to provide that facility for ME21N transaction. It updates the entries in T160M table which is a table for Message Control: Purchasing (System Messages).
G@urav.
07-30-2014 10:44 PM
Dear Gaurav Gupta,
I implemented this method, and it works. I needed warning messages, not error messages. But when I have more than one item, it NOT returns me the messages per item.
In this case, T-code: ME51N.
Heres my include Exit bellow.
tks for your help.
*&---------------------------------------------------------------------*
*& Include ZXM02U12
*&---------------------------------------------------------------------*
FIELD-SYMBOLS <eban> TYPE eban.
FIELD-SYMBOLS <ebkn> TYPE ebkn.
DATA: BEGIN OF t_obj OCCURS 0,
knttp LIKE ekpo-knttp,
obj LIKE cosp-objnr,
kostl LIKE ekkn-kostl,
aufnr LIKE ekkn-aufnr,
END OF t_obj.
DATA: BEGIN OF t_cosp OCCURS 0.
INCLUDE STRUCTURE cosp.
DATA: END OF t_cosp.
DATA: BEGIN OF t_orca OCCURS 0,
obj LIKE cosp-objnr,
ebelp LIKE ekpo-ebelp,
vl_total LIKE cosp-wog001,
vl_real LIKE cosp-wog001,
vl_comp LIKE cosp-wog001,
vl_disp LIKE cosp-wog001,
END OF t_orca.
TYPES: BEGIN OF ty_msg,
msg type symsgv,
END OF ty_msg.
DATA: t_msg type table of ty_msg,
w_msg type ty_msg.
DATA: v_msg TYPE symsgv,
v_waers type ekko-waers,
v_waers_cont_area type tka01-waers.
IF sy-tcode = 'ME21N' OR sy-tcode = 'ME22N' OR sy-tcode = 'ME23N' OR
sy-tcode = 'ME51N' OR sy-tcode = 'ME52N' OR sy-tcode = 'ME53N' OR
sy-tcode = 'ME31K' OR sy-tcode = 'ME32K'.
LOOP AT im_t_eban ASSIGNING <eban>.
if <eban>-ebakz is initial.
LOOP AT im_t_ebkn ASSIGNING <ebkn> WHERE bnfpo = <eban>-bnfpo.
IF <eban>-knttp = 'K' OR <eban>-knttp = '2'.
CONCATENATE 'KS' <ebkn>-kokrs <ebkn>-kostl INTO t_obj-obj.
APPEND t_obj.
ELSEIF <eban>-knttp = 'F' OR <eban>-knttp = '1'.
CONCATENATE 'OR' <ebkn>-aufnr INTO t_obj-obj.
APPEND t_obj.
ENDIF.
ENDLOOP.
endif.
ENDLOOP.
SELECT *
INTO TABLE t_cosp
FROM cosp
FOR ALL ENTRIES IN t_obj
WHERE lednr = '00'
AND objnr = t_obj-obj
AND versn = '000'
AND gjahr = <eban>-lfdat(4).
.
LOOP AT im_t_eban ASSIGNING <eban>.
if <EBAN>-EBAKZ is initial.
LOOP AT im_t_ebkn ASSIGNING <ebkn> WHERE bnfpo = <eban>-bnfpo.
IF <eban>-knttp = 'K' OR <eban>-knttp = '2'.
READ TABLE t_obj WITH KEY kostl = <ebkn>-kostl.
ELSEIF <eban>-knttp = 'F' OR <eban>-knttp = '1'.
READ TABLE t_obj WITH KEY aufnr = <ebkn>-aufnr.
ENDIF.
t_orca-obj = t_obj-obj.
*** Valor total do orçamento
LOOP AT t_cosp WHERE objnr = t_obj-obj
AND wrttp = '01'.
t_orca-vl_total = t_orca-vl_total + t_cosp-wog001 + t_cosp-wog002 + t_cosp-wog003 +
t_cosp-wog004 + t_cosp-wog005 + t_cosp-wog006 +
t_cosp-wog007 + t_cosp-wog008 + t_cosp-wog009 +
t_cosp-wog010 + t_cosp-wog011 + t_cosp-wog012.
ENDLOOP.
** Valor Real
DELETE t_cosp WHERE ( kstar => '3000000000' AND kstar <= '3009999999')
AND wrttp = '04'.
LOOP AT t_cosp WHERE objnr = t_obj-obj
AND wrttp = '04'.
t_orca-vl_real = t_orca-vl_real + t_cosp-wog001 + t_cosp-wog002 + t_cosp-wog003 +
t_cosp-wog004 + t_cosp-wog005 + t_cosp-wog006 +
t_cosp-wog007 + t_cosp-wog008 + t_cosp-wog009 +
t_cosp-wog010 + t_cosp-wog011 + t_cosp-wog012.
ENDLOOP.
*** Valor Compromisso
LOOP AT t_cosp WHERE objnr = t_obj-obj
AND wrttp = '21'.
t_orca-vl_comp = t_orca-vl_comp + t_cosp-wog001 + t_cosp-wog002 + t_cosp-wog003 +
t_cosp-wog004 + t_cosp-wog005 + t_cosp-wog006 +
t_cosp-wog007 + t_cosp-wog008 + t_cosp-wog009 +
t_cosp-wog010 + t_cosp-wog011 + t_cosp-wog012.
ENDLOOP.
LOOP AT t_cosp WHERE objnr = t_obj-obj
AND wrttp = '22'.
t_orca-vl_comp = + t_orca-vl_comp + t_cosp-wog001 + t_cosp-wog002 + t_cosp-wog003 +
t_cosp-wog004 + t_cosp-wog005 + t_cosp-wog006 +
t_cosp-wog007 + t_cosp-wog008 + t_cosp-wog009 +
t_cosp-wog010 + t_cosp-wog011 + t_cosp-wog012.
ENDLOOP.
LOOP AT t_cosp WHERE objnr = t_obj-obj
AND wrttp = '23'.
t_orca-vl_comp = + t_orca-vl_comp + t_cosp-wog001 + t_cosp-wog002 + t_cosp-wog003 +
t_cosp-wog004 + t_cosp-wog005 + t_cosp-wog006 +
t_cosp-wog007 + t_cosp-wog008 + t_cosp-wog009 +
t_cosp-wog010 + t_cosp-wog011 + t_cosp-wog012.
ENDLOOP.
LOOP AT t_cosp WHERE objnr = t_obj-obj
AND wrttp = '24'.
t_orca-vl_comp = + t_orca-vl_comp + t_cosp-wog001 + t_cosp-wog002 + t_cosp-wog003 +
t_cosp-wog004 + t_cosp-wog005 + t_cosp-wog006 +
t_cosp-wog007 + t_cosp-wog008 + t_cosp-wog009 +
t_cosp-wog010 + t_cosp-wog011 + t_cosp-wog012.
ENDLOOP.
t_orca-ebelp = <eban>-bnfpo.
t_orca-vl_disp = t_orca-vl_total - t_orca-vl_real - t_orca-vl_comp.
APPEND t_orca.
endloop.
ENDIF.
ENDLOOP.
DATA vl_disp1 TYPE eban-preis.
LOOP AT im_t_eban ASSIGNING <eban>.
if <EBAN>-EBAKZ is initial.
LOOP AT im_t_ebkn ASSIGNING <ebkn> WHERE bnfpo = <eban>-bnfpo.
IF <eban>-knttp = 'K' OR <eban>-knttp = '2'.
READ TABLE t_obj WITH KEY kostl = <ebkn>-kostl.
ELSEIF <eban>-knttp = 'F' OR <eban>-knttp = '1'.
READ TABLE t_obj WITH KEY aufnr = <ebkn>-aufnr.
ENDIF.
READ TABLE t_orca WITH KEY obj = t_obj-obj
ebelp = <ebkn>-bnfpo.
vl_disp1 = <eban>-preis * <eban>-menge.
* Verifica a moeda do Pedido
v_waers = <eban>-waers.
* Verifica a moeda da Area de Contábilidade de Custo
SELECT SINGLE waers
from tka01
into v_waers_cont_area
where kokrs eq <EBKN>-KOKRS.
* Verifica se os valores estão na mesma moeda
IF v_waers ne v_waers_cont_area.
* Converte Valores
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = sy-datum
FOREIGN_CURRENCY = v_waers_cont_area
LOCAL_AMOUNT = VL_DISP1
LOCAL_CURRENCY = v_waers
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
IMPORTING
* EXCHANGE_RATE =
FOREIGN_AMOUNT = VL_DISP1
* FOREIGN_FACTOR =
* LOCAL_FACTOR =
* EXCHANGE_RATEX =
* DERIVED_RATE_TYPE =
* FIXED_RATE =
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
ENDIF.
IF t_orca-vl_disp < vl_disp1.
IF <eban>-knttp = 'K' OR <eban>-knttp = '2'.
CONCATENATE 'Orçamento excedido, Centro de Custo Nr: ' <ebkn>-kostl
INTO v_msg SEPARATED BY space.
CALL METHOD cl_message_mm=>create
EXPORTING
im_msgid = 'ZZ'
im_msgty = 'W'
im_msgno = '051'
im_msgv1 = v_msg
im_msgv2 = ' '
im_msgv3 = ' '
im_msgv4 = ' '
im_force_collect = mmpur_yes
EXCEPTIONS
failure = 01
dialog = 02.
ELSEIF <eban>-knttp = 'F' OR <eban>-knttp = '1'.
CONCATENATE 'Orçamento excedido, Ordem Nr: '
<ebkn>-aufnr
INTO v_msg
SEPARATED BY space.
CALL METHOD cl_message_mm=>create
EXPORTING
im_msgid = 'ZZ'
im_msgty = 'W'
im_msgno = '051'
im_msgv1 = v_msg
im_msgv2 = ' '
im_msgv3 = ' '
im_msgv4 = ' '
im_force_collect = mmpur_yes
EXCEPTIONS
failure = 01
dialog = 02.
ENDIF.
ENDIF.
ENDLOOP.
endif.
ENDLOOP.
ENDIF.
04-19-2008 9:40 PM
Hello
As the name of BAdI ME_PURCHDOC_POSTED implies we have passed already all checks and may just change the posted data here.
Thus, this is the wrong BAdI to make any final checks before posting the purchase document.
The correct BAdI for your purpose is ME_PROCESS_PO_CUST. Here you can use method IF_EX_ME_PROCESS_PO_CUST~CHECK to make closing checks BEFORE posting the document.
If you validations fail set the CHANGING parameter CH_FAILED = 'X'. And here you can probably use the message handling suggested by Gaurav.
Regards
Uwe
07-18-2013 9:21 PM
Hello:
Could try with:
MESSAGE ID 'XXX' TYPE 'S' NUMBER '000' WITH 'Valuation Type' LIKE 'E'.
Or Like Gaurav Gupta say, with cl_message_mm class.
Regards,
Jorge.
07-31-2014 6:56 AM
Hi Mittal,
Can you explain what exactly you are validating line lines ,account assignment etc.
Regards,
Madhu.