Hello Gurus,
i wanted to maek some custom actions in PO ME22N transction by adding some buttons into Screen and trigering COPY data action.
I chose EXIT_SAPMM06E_018 to be able to performe my requirements.
During the code i initialize PO header and then the reading of it.
Then im getting line items with the PO document header.
Afterwards the loop starts to run where i need to assign Custom field ZAUFNR into mepoitem-ZAUFNR structure.
In conclusion the SET_DATA method is beeing trigered. Everything seems ok, but the line item fields arent getting copied and transfered to other line items.
Bellow is my code. I think im missing something.
Please advise, what could be my problem.
if I_UCOMM = 'ZCOPY'.
* BREAK-POINT.
DATA:
L_ITEM TYPE REF TO CL_PO_ITEM_HANDLE_MM,
L_HEADER TYPE REF TO CL_PO_HEADER_HANDLE_MM,
LS_MEPOITEM TYPE mepoitem,
LS_HEADER TYPE mepoheader,
L_RESULT TYPE MMPUR_BOOL,
LT_ITEMS TYPE purchase_order_items,
LS_ITEM TYPE purchase_order_item.
*--------------------------------------------------------------------*
* data have to be transported to business logic
*--------------------------------------------------------------------*
CREATE OBJECT L_HEADER
EXPORTING
im_po_number = gl_ekpo-ebeln
EXCEPTIONS
failure = 1
OTHERS = 9.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*--------------------------------------------------------------------*
* initialize PO Header READ
*--------------------------------------------------------------------*
L_HEADER->PO_INITIALIZE( ).
CALL METHOD L_HEADER->PO_READ
EXPORTING
im_tcode = 'ME23N'
im_trtyp = 'A'
im_aktyp = 'A'
im_po_number = gl_ekpo-ebeln
IMPORTING
ex_result = L_RESULT
EXCEPTIONS
OTHERS = 9.
CHECK L_RESULT EQ 'X'.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*--------------------------------------------------------------------*
* GET PO Header
*--------------------------------------------------------------------*
CALL METHOD L_HEADER->get_data
IMPORTING
ex_data = ls_header
EXCEPTIONS
failure = 1
OTHERS = 2.
*--------------------------------------------------------------------*
* GET and SET PO Line Items
*--------------------------------------------------------------------*
REFRESH: LT_ITEMS.
LT_ITEMS = L_HEADER->if_purchase_order_mm~get_items( ).
LOOP AT LT_ITEMS INTO LS_ITEM.
L_ITEM ?= LS_ITEM-ITEM.
L_ITEM->my_parent ?= L_HEADER.
IF LS_ITEM-ITEM IS BOUND.
CALL METHOD L_ITEM->GET_DATA
IMPORTING
EX_DATA = LS_MEPOITEM.
MOVE gl_ekpo-ZAUFNR TO LS_MEPOITEM-ZAUFNR.
CALL METHOD LS_ITEM-ITEM->SET_DATA
EXPORTING
IM_DATA = LS_MEPOITEM.
ENDIF.
ENDLOOP.
endif.
Regards
Laurynas