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: 

ME21N, BADI ME_PROCESS_PO_CUST, compare delivery address in each line item

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

9 REPLIES 9

Former Member
0 Kudos

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

uwe_schieferstein
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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!

0 Kudos

Hi Bruce,

Did you get it to work?

0 Kudos

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

0 Kudos

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

uwe_schieferstein
Active Contributor
0 Kudos

Hello Bruce

Perhaps the discussion between Peter Müller and me in thread

may be useful to you.

Regards

Uwe

0 Kudos

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