02-28-2007 1:10 PM
Hello,
Im a new ABAP-Programmer.
I have to find a solution for the following problem.
In transaction ME21N a user put in the delivery-address.
I would like check these address-data, before the purchase will be saved.
How can I do it? Could you give the BADI, class and method?
It would be nice, when I get a coding.
03-01-2007 9:38 PM
Hello Peter
Here is the not yet saved delivery address of the PO items:
METHOD if_ex_me_process_po_cust~check.
* define local data
DATA:
lt_items TYPE purchase_order_items,
* ls_item LIKE LINE OF lt_items, " alternatively
ls_item TYPE purchase_order_item,
*
ls_header TYPE mepoheader,
ls_detail TYPE mepoitem,
lt_details TYPE tab_mepoitem,
*
ls_cmmda TYPE cmmda,
ls_addr1_complete TYPE szadr_addr1_complete,
ls_addr1 LIKE LINE OF ls_addr1_complete-addr1_tab.
" Get the order items
lt_items = im_header->get_items( ).
REFRESH: lt_details.
LOOP AT lt_items INTO ls_item.
ls_detail = ls_item-item->get_data( ).
" Ignore deleted items
IF ( ls_detail-loekz IS NOT INITIAL ).
CONTINUE.
ENDIF.
" Read current address handle of item
CLEAR: ls_cmmda.
CALL FUNCTION 'MM_DELIVERY_ADDRESS_READ'
EXPORTING
im_ebeln = ls_detail-ebeln
im_ebelp = ls_detail-ebelp
IMPORTING
* EX_ADDRESS_EXISTS =
EX_CMMDA = ls_cmmda
* EX_ERROR_TAB =
.
" Use address handle to read current delivery address
CLEAR: ls_addr1_complete.
REFRESH: ls_addr1_complete-addr1_tab.
CALL FUNCTION 'ADDR_GET_COMPLETE'
EXPORTING
* ADDRNUMBER =
addrhandle = ls_cmmda-addr_handle
* ARCHIVE_HANDLE =
* IV_CURRENT_COMM_DATA = 'X'
IMPORTING
addr1_complete = ls_addr1_complete
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
internal_error = 3
wrong_access_to_archive = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ls_addr1_complete-addr1_tab INTO ls_addr1.
CASE ls_addr1-data-country.
WHEN 'DE'.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDLOOP.
endmethod.
Regards
Uwe
02-28-2007 2:55 PM
Hello Peter
The BAdI you are looking for is <b>ME_PROCESS_PO_CUST</b> (Processing Purchase Order).
I assume that the delivery address is set at the header level, thus method IF_EX_ME_PROCESS_PO_CUST~CHECK (closing check) should be implemented, e.g:
DATA:
ls_header TYPE mepoheader.
ls_header = im_header->get_data( ).
IF ( <delivery address is not ok ).
ch_failed = abap_true. " abap_true is found in type pool ABAP
ENDIF.
Regards
Uwe
03-01-2007 5:59 AM
Hello Peter
For checking the delivery address of the PO items you could use the following approach:
METHOD if_ex_me_process_po_cust~check.
* define local data
DATA:
lt_items TYPE purchase_order_items,
* ls_item LIKE LINE OF lt_items, " alternatively
ls_item TYPE purchase_order_item,
*
ls_header TYPE mepoheader,
ls_detail TYPE mepoitem,
lt_details TYPE tab_mepoitem,
*
ls_adrc TYPE adrc,
lt_adrc TYPE STANDARD TABLE OF adrc.
* RETURN.
break uwe_sc.
* Get the order items
lt_items = im_header->get_items( ).
REFRESH: lt_details.
LOOP AT lt_items INTO ls_item.
ls_detail = ls_item-item->get_data( ).
CALL FUNCTION 'ADDR_SELECT_ADRC_SINGLE'
EXPORTING
addrnumber = ls_detail-adrnr
TABLES
et_adrc = lt_adrc
EXCEPTIONS
address_not_exist = 1
parameter_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT lt_adrc INTO ls_adrc.
" check if address is ok, set CH_FAILED = 'X' if not ok
ENDLOOP.
ENDLOOP.
ENDMETHOD.
Regards
Uwe
03-01-2007 12:57 PM
Hello,
thank you for your answer, but the solution wasn't successful.
The field "ls_detail-adrnr" was blank.
I suppose the field will be filled after the save of the purchase.
I would like check the address-fields before save.
Perhaps, to you have a other idea.
Thank You !!!
Best regards
P e t e r
03-01-2007 1:01 PM
Hello Uwe,
Addition:
I would like check the field address-country.
Best regards
P e t e r
03-01-2007 9:38 PM
Hello Peter
Here is the not yet saved delivery address of the PO items:
METHOD if_ex_me_process_po_cust~check.
* define local data
DATA:
lt_items TYPE purchase_order_items,
* ls_item LIKE LINE OF lt_items, " alternatively
ls_item TYPE purchase_order_item,
*
ls_header TYPE mepoheader,
ls_detail TYPE mepoitem,
lt_details TYPE tab_mepoitem,
*
ls_cmmda TYPE cmmda,
ls_addr1_complete TYPE szadr_addr1_complete,
ls_addr1 LIKE LINE OF ls_addr1_complete-addr1_tab.
" Get the order items
lt_items = im_header->get_items( ).
REFRESH: lt_details.
LOOP AT lt_items INTO ls_item.
ls_detail = ls_item-item->get_data( ).
" Ignore deleted items
IF ( ls_detail-loekz IS NOT INITIAL ).
CONTINUE.
ENDIF.
" Read current address handle of item
CLEAR: ls_cmmda.
CALL FUNCTION 'MM_DELIVERY_ADDRESS_READ'
EXPORTING
im_ebeln = ls_detail-ebeln
im_ebelp = ls_detail-ebelp
IMPORTING
* EX_ADDRESS_EXISTS =
EX_CMMDA = ls_cmmda
* EX_ERROR_TAB =
.
" Use address handle to read current delivery address
CLEAR: ls_addr1_complete.
REFRESH: ls_addr1_complete-addr1_tab.
CALL FUNCTION 'ADDR_GET_COMPLETE'
EXPORTING
* ADDRNUMBER =
addrhandle = ls_cmmda-addr_handle
* ARCHIVE_HANDLE =
* IV_CURRENT_COMM_DATA = 'X'
IMPORTING
addr1_complete = ls_addr1_complete
EXCEPTIONS
parameter_error = 1
address_not_exist = 2
internal_error = 3
wrong_access_to_archive = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT ls_addr1_complete-addr1_tab INTO ls_addr1.
CASE ls_addr1-data-country.
WHEN 'DE'.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDLOOP.
endmethod.
Regards
Uwe
03-02-2007 1:35 PM
Hello Uwe,
your solutions was perfekt.
Thank you very much.
Best regards.
P e t e r