Skip to Content
0

Change header note ME21N depending on content of Account Assignment tab

Mar 24, 2017 at 09:41 AM

117

avatar image

Hi experts,

I have a requirement to change the header note in ME21N when saving the PO, the header note must be set to the value of a text from a Z-table that stores the PEP element along with its description. The note text must be set following these requirements only if the Account Assignment type is a PROJECT, the screen shot under explains what I mean.

I have read that I have to use the FM READ_TEXT and SET_TEXT and also that I have to use Badi, specifically tha Badi ME_PROCESS_PO_CUST. I am new to badis and I need to know what method of ME_PROCESS_PO_CUST would help me to get access to the data in Account Assignment so that I could get the PEP element to get the description from the Z-table, and then set the header note with that description, is this right? What are the steps to follow?

Any help would be much appreciated.

me21n.png (61.0 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Raymond Giuseppi
Mar 27, 2017 at 10:07 AM
1

Look at PO classic BAdI : ME_PROCESS_PO_CUST

In a method like PROCESS_ACCOUNT (and PROCES_ITEM if required) you can detect changes to the 'PEP' field (using methods like GET_DATA, GET_PREVIOUS_DATA and even GET_PERSISTENT_DATA in case of ME22N) from the IM_ACCOUNT parameter you can get a reference to item with method GET_ITEM and from this one a reference to header wirth method GET_HEADER.

values_of_accounting = im_account->get_data( ).
previous_values_of_accounting = im_account->get_previous_data( ).
ref_to_item = im_account->get_item( ).
values_of_item = ref_to_item->get_data( ).
ref_to_header = ref_toitem->get_header( ).
values_of_header = ref_header->get_data( ).

With the header reference you can read and change its long texts with methods of interface IF_LONGTEXTS_MM (GET_TEXT and SET_TEXT)

But It would be easier to use some text at item level, as you will have to manage change of an item accounting information that was already inserted in header text, find/replace or remove in PO header text. (Or adapt the form used to print/mail the PO) Also what do you code if user 'inadvertently' erase/overwrite the text?

You could also consider updating the long text once just before the save (in method CHECK) with a loop on items and then on accounting informations.

  list_of_items = im_header->get_items( ).
  loop at list_of_items assigning <item>.
    values_of_item = <item>-item->get_data( ).
    list_of_accountings = <item>-item->get_accountings( ).
    loop at list_of_accountings assigning <accounting>.
      values_of_accounting = <accounting>-accounting->get_data( ).
Show 3 Share
10 |10000 characters needed characters left characters exceeded

First of all, thank you so much for your answer Raymond,

I have followed your guides and now I have a header reference and also I have all data of the accounting of each item, in PROCESS_HEADER the code is:

loop at tl_items into wal_items.
    wal_item = wal_items-item->get_data( ).
    if wal_item is not initial and wal_item1-knttp eq 'P'. "This is only required for Projects
      tl_accounts = wal_items-item->get_accountings( ).
      loop at tl_accounts into wal_accounts.
        wl_mepoaccounting = wal_accounts-accounting->get_data( ).

Now I can have all peps of the items from wl_mepoaccounting-ps_psp_pnr, until here I consider you have answered my original question, I just hope you could give me a hint on formatting the long texts, following is the explanation:

I am now implementing a FM to get the description of each PEP, now one thing I am struggling with is how to format the text into the header note, for example how to add a new line so that each pep and its description are separated from the next one with a new line:

O/1100000/1: Description of item1;
O/1100000/2: Description of item2;
O/1100000/3: Description of item3;
0

Set TDFORMAT = '*' for new line.

0

Thank you so much Raymond for your help, I have all the requirement done.

0
Jürgen L
Mar 24, 2017 at 10:20 AM
0

Your idea could only work in a very restrictive environment, which means you would also need to restrict users to add a second item to a purchase order as this could lead to different header notes while there is just one field available. (why not using item notes?)

Also you would need to consider what you do with a note that was entered manually by a user.

Coding questions have to be asked with the tag "ABAP Development" . Long text is a very frequently discussed topic, make sure you searched before asking and make your question be different than any other.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Thank for your answer, I updated the tag to ABAP Development.

About your comment to consider if the user enters manually the note header they told me that it is not a problem, as they never fill that field, but you are right I will have to deal with it just in case.

About the multiple items restriction, they explained to me that if a PO has multiple items, they need, if possible to append the descriptions of those items with their pep element into the header note.

For example if a PO has multiple projects identified with their pep, then the header note should look like:

O/1100000/1: Description of item1; O/1100000/1/1/: description of item 2; O/1100000/1/2/: description of item 3<br>
0

everything possible with good ABAPers

0

Well, If think the steps I need to take are:

  1. loop at the items.
  2. for each item get the pep element from the Assignment Account data
  3. get the description of the pep element from the Z-table
  4. append the pep and the description into the note header

I just need a help on where to start to implement it.

I am new to ABAP so I am far from 'good ABAPers' that's why I am seeking help here.

0