12-22-2006 1:24 AM
Hello all,
When creating or changing purchase orders using the enjoy transactions ME21N and ME22N, I want to force the users to have the same delivery address on every line item. I have found and activated the BADI ME_PROCESS_PO_CUST. I have added some code in method CHECK and put a breakpoint on that code. The transaction is stopping on my breakpoint. So far so good.
Now for my question, how do I access all of the delivery address fields for each of the line items to ensure that they are the same? Since the actual delivery address fields are stored in table ADRC using ADDRNUMBER, it seems like this is the field that I should be comparing for all the line items.
Method CHECK has attribute IM_HEADER. From that method, using that attribute, how do I programmatically get to the delivery address fields (or ADDRNUMBER) for all the line items?
Thanks
Bruce
01-30-2007 10:45 PM
Hi Bruce,
You can use exit EXIT_SAPMM06E_012 and loop on table TEKPO and check for field ADRN2 - This has the delivery address number. You can then either compare the ADRN2 or check against ADRC to match address line 1, line2 , city , state , etc...as per your requirement.
Thanks
Anirban
01-30-2007 10:45 PM
Hi Bruce,
You can use exit EXIT_SAPMM06E_012 and loop on table TEKPO and check for field ADRN2 - This has the delivery address number. You can then either compare the ADRN2 or check against ADRC to match address line 1, line2 , city , state , etc...as per your requirement.
Thanks
Anirban
01-31-2007 3:37 AM
Hello Bruce
Assuming that field MEPOITEM-ADRNR is the one you want to check for then here is a possible solution:
METHOD if_ex_me_process_po_cust~check.
* define local data
DATA:
lt_items TYPE purchase_order_items,
ls_item TYPE purchase_order_item,
*
ls_header TYPE mepoheader,
ls_detail TYPE mepoitem,
lt_details TYPE tab_mepoitem.
* 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( ).
APPEND ls_detail TO lt_details.
ENDLOOP.
READ TABLE lt_details INTO ls_detail INDEX 1. " read 1st entry
* Check for single entry with different address number
LOOP AT lt_details TRANSPORTING NO FIELDS
WHERE ( adrnr NE ls_detail-adrnr ).
EXIT.
ENDLOOP.
IF ( syst-subrc = 0 ).
MESSAGE 'Error: Items do no have same delivery address' TYPE 'E'.
ch_failed = 'X'.
ENDIF.
ENDMETHOD.
If you use the CHECK function in ME21N then you will see the error message there.
Regards
Uwe
01-31-2007 7:02 PM
Anirban / Uwe,
Both of your suggestions would work if the address always contains the system assigned address. In our case we allow the users to override the system supplied address with an ad hoc address. The address that they enter on the screen, overlaying the system default address, does not create an address number until the PO is actually committed to the database. At the point where this method is called the address number is blank for any addresses that are manually entered by the user.
Thanks
Bruce
02-01-2007 1:41 AM
Read structure (SAPLMMDA)T_CMMDA[] for each PO line and get the addr_handle.
Use this ADDR_HANDLE (address handle) and read (SAPLSZA0)IADRC[] to get the address details.
Hope this helps you!
02-02-2007 5:52 PM
02-02-2007 8:57 PM
Anirban,
Thanks for the inquiry. Unfortunately I've been pulled into some other things and don't expect to get back to this for a couple of weeks. When I do I will update this thread.
Again, thanks
Bruce
08-21-2007 10:06 PM
I finally am getting back to this thread.
I wasn't able to validate the delivery address is before the purchase order actually posted. Instead I created an implementation of the BADI definition ME_PURCHDOC_POSTED, comparing delivery addresses after the document had posted. At that point if there were any differences sent an e-mail.
Thanks
Bruce
08-21-2007 10:42 PM
Hello Bruce
Perhaps the discussion between Peter Müller and me in thread
may be useful to you.
Regards
Uwe
08-21-2007 11:14 PM
Uwe,
<b>szadr_addr1_complete</b> does not exist in our version 4.7. You must be using Netweaver. Is <b>szadr_addr1_complete</b> small enough in scope that it might make sense to create a customer version of this at my site? We won't be on Netweaver for at least 2 years.
Thanks
Bruce