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: 

How to duplicate a POITEM using BAPI_PO_CHANGE?

javier_alonso
Participant
0 Kudos
266

Hi there.

I am using BAPI_PO_CHANGE to duplicate an existing POITEM into a new line. Using the ME22N transaction, there is a button that does this automatically.

However, I am not really sure about how to do it properly via BAPI. I am retriving the details with BAPI_PO_GETDETAIL1 and appending a new line to poitem table with a new po_item index.

For the other data (account, schedule, conditions..), I am filling the whole X structure checking if the coppied value structure has a value or not.

FORM get_flag_struct USING data_struct TYPE any
flag_struct_name TYPE ddobjname
CHANGING filled_flag_struct TYPE any.
CLEAR filled_flag_struct.

cl_reca_ddic_tabl=>get_field_list( EXPORTING id_name = flag_struct_name
IMPORTING et_field_list = DATA(table_data) ).

LOOP AT table_data ASSIGNING FIELD-SYMBOL(<fs_field>).
ASSIGN COMPONENT <fs_field>-fieldname OF STRUCTURE data_struct TO FIELD-SYMBOL(<fs_data>).
IF sy-subrc <> 0.
CONTINUE.
ELSE.
ASSIGN COMPONENT <fs_field>-fieldname OF STRUCTURE filled_flag_struct TO FIELD-SYMBOL(<fs_datax>).
ENDIF.
IF <fs_data> IS NOT INITIAL.
<fs_datax> = SWITCH #( <fs_field>-rollname WHEN 'BAPIUPDATE' THEN 'X' ELSE <fs_data> ).
ENDIF.
ENDLOOP.
ENDFORM.

After that, I mark the root item as deleted and finally call the BAPI. Is there a standard way to do this? Because retriving all the additional tables (account, etc) seems a bit overkill.

Thanks.

0 REPLIES 0