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: 

Copying header text from PR to PO using BAdI: ME_PROCESS_PO_CUST -> Method: PROCESS_HEADER

former_member563268
Participant
0 Kudos

Hi,

I have a requirement to copy the header data from the 'Emergency justification header text ' (Custom created) in PR to header text in PO,

·        If more than one PR is referred, then adopt the ‘’Emergency Justification Note’’ of all the PRs into the PO Header text. I am learning BADI and needed help. Could you please help me to build the logic to copy the PR custom header text Emergency Justification Noteto PO header text using BAdI: ME_PROCESS_PO_CUST -> Method: PROCESS_HEADER.

Thanks and Regards,

J

2 REPLIES 2

former_member563268
Participant
0 Kudos

Just to add, I am trying to achieve this through READ_TEXT and SET_TEXT, But i am not exactly sure how to getthe header data first and then each of the line item data from the header text. Experts, request your advise.

0 Kudos

Hi J ABAP,

In the PROCESS_HEADER method, you can access all the PO items by calling the method im_header->get_items. See the codes below.

        DATA: lt_item TYPE  purchase_order_items.

    DATA: lw_item LIKE LINE OF lt_item.

    DATA: lw_previtem TYPE mepoitem.

    DATA: lv_tdname TYPE thead-tdname.

    CALL METHOD im_header->get_items

      RECEIVING

        re_items = lt_item.

    LOOP AT lt_item INTO lw_item.

      CALL METHOD lw_item-item->get_data

        RECEIVING

          re_data = lw_previtem.

          lv_tdname = lw_previtem-banfn.

    ENDLOOP.

In the LOOP, you can access the components of each PO item such as the PR number (banfn). For my case, I need to copy the Header Note of each PR to the newly created PO Header Note. Then, I will use the READ_TEXT function module to read the Header Note from the PR using the codes below. You need to identify the TDID and TDOBJECT of the text you need to read. Google it.

       DATA: lt_hn_tline TYPE TABLE OF tline,

            lw_hn_tline TYPE tline.

     CALL FUNCTION 'READ_TEXT'

        EXPORTING

          id                          = 'B01'

          language                    = sy-langu

          name                        = lv_tdname

          object                      = 'EBANH'

        TABLES

          lines                       = lt_hn_tline

        EXCEPTIONS

          id                          = 1

          language                    = 2

          name                        = 3

          not_found                   = 4

          object                      = 5

          reference_check             = 6

          wrong_access_to_archive     = 7

          OTHERS                      = 8.

      IF sy-subrc <> 0.

        CLEAR lt_hn_tline.

      ENDIF.

After that, the following codes will append the text into an internal table to be passed to a method im_header->if_longtexts_mm~set_text to set the Header Note in PO (in my case).

CONSTANTS: lc_tdid_pohn TYPE tdid VALUE 'F02',

           lc_obj_pohn TYPE THEAD-TDOBJECT VALUE 'EKKO'.

                                                        

     DATA: lw_textlines TYPE mmpur_textlines,

           lt_textlines TYPE mmpur_t_textlines.

     LOOP AT lt_hn_tline INTO lw_hn_tline.

        lw_textlines-tdobject = lc_obj_pohn.

        lw_textlines-tdid     = lc_tdid_pohn.

        lw_textlines-tdline   = lw_hn_tline-tdline.

        APPEND lw_textlines TO lt_textlines[].

     ENDLOOP.

      CALL METHOD im_header->if_longtexts_mm~set_text

        EXPORTING

          im_tdid      = lc_tdid_pohn

          im_textlines = lt_textlines[].

Depending on the text you wanted to set in the PO, your TDID for Text in PO items might be different from the Header text. Again, Google shall provide you the details you need.

Cheers & Best Regards,

Kah Ming