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: 

Error when adding an item to HU using FM ADD_TO_EXISTING_HU

Former Member
0 Kudos

Please I need help, could some tell me what I am doing wrong I keep an error when I try to add an item to a HU, here is the code:

FUNCTION zrf_hu_add_pack.

*"----


""Local Interface:

*" IMPORTING

*" VALUE(HU_HEADER) LIKE BAPIHUHDRPROPOSAL STRUCTURE

*" BAPIHUHDRPROPOSAL

*" VALUE(USERNAME) LIKE SY-UNAME OPTIONAL

*" VALUE(PRINTER) TYPE RSPOLNAME OPTIONAL

*" EXPORTING

*" VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2

*" TABLES

*" HU_ITEMS STRUCTURE BAPIHUITMPROPOSAL

*"----


DATA: ret TYPE STANDARD TABLE OF bapiret2,

header TYPE bapihuhdrproposal,

hukey TYPE bapihukey-hu_exid,

huheader TYPE bapihuheader,

itemsproposal TYPE STANDARD TABLE OF bapihuitmproposal,

itm TYPE STANDARD TABLE OF bapihuitem,

item_prop TYPE huitm_prop,

obj TYPE hum_object,

del_type TYPE vbtyp,

hu_ext TYPE hum_exidv_t,

hu_int TYPE hum_venum_t,

out_msg TYPE huitem_messages_t,

tmp_vbeln TYPE vbeln,

hu_hdr TYPE huhdr_proposal,

hu_mm TYPE hum_plant_stloc,

itm_wa LIKE LINE OF itm,

item_prop_wa LIKE LINE OF item_prop,

hui_wa LIKE LINE OF hu_items.

DATA: ls_handling_units TYPE hum_rehang_hu,

ls_high TYPE vekp-venum.

DATA: it_items LIKE huitm_proposal,

hm_obj TYPE hum_object,

hu_prop TYPE huhdr_proposal,

hu_add TYPE huhdr_add,

hu_add_wa LIKE LINE OF hu_add,

hu_items1 TYPE huitm_prop,

hu_items_wa LIKE LINE OF hu_items1.

DATA: hu_msg TYPE huitem_messages_t,

hu_msg_wa LIKE LINE OF hu_msg,

hu_hdr1 TYPE hum_hu_header_t,

hu_hdr1_wa LIKE LINE OF hu_hdr1.

DATA: i_mm_data LIKE hum_plant_stloc,

hu_internal TYPE hum_venum_t,

hu_external TYPE hum_exidv_t,

handling_unit TYPE huitem_from,

h_unit_l TYPE huitem_from,

is_item_proposal TYPE huitm_proposal,

i_delivery_type TYPE likp-vbtyp ,

et_messages TYPE huitem_messages_t.

DATA: venum TYPE venum.

DATA: lt_hu LIKE bapihunumber OCCURS 0 WITH HEADER LINE,

lt_huhdr LIKE bapihuheader OCCURS 0 WITH HEADER LINE.

DATA: t_return TYPE TABLE OF bapiret2.

  • get header

lt_hu-hu_exid = hu_header-hu_exid.

APPEND lt_hu.

  • get HU header

CALL FUNCTION 'BAPI_HU_GETLIST'

EXPORTING

onlykeys = ' '

TABLES

hunumbers = lt_hu

huheader = lt_huhdr

return = t_return

EXCEPTIONS

error_message = 2

OTHERS = 4.

IF sy-subrc NE 0.

CALL FUNCTION 'BALW_BAPIRETURN_GET2'

EXPORTING

type = sy-msgty

cl = sy-msgid

number = sy-msgno

par1 = sy-msgv1

par2 = sy-msgv2

par3 = sy-msgv3

par4 = sy-msgv4

IMPORTING

return = return.

ROLLBACK WORK.

ELSE.

  • get defaults

PERFORM get_user USING username.

  • handling unit

READ TABLE lt_huhdr INDEX 1.

APPEND hu_header-hu_exid TO hu_external.

APPEND lt_huhdr-hu_id TO hu_internal.

h_unit_l-exidv = lt_huhdr-hu_exid.

h_unit_l-venum = lt_huhdr-hu_id.

  • APPEND h_unit_l to handling_unit.

  • hold delivery number

tmp_vbeln = hu_header-pack_mat_customer.

  • convert or pad

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = tmp_vbeln

IMPORTING

output = tmp_vbeln.

  • set up object key

obj-object = '01'.

obj-objkey = tmp_vbeln.

CONDENSE obj-objkey.

  • get delivery type from delivery header

SELECT SINGLE vbtyp INTO del_type

FROM likp

WHERE vbeln = obj-objkey.

  • set status

hu_header-hu_status_init = '1'.

MOVE-CORRESPONDING hu_header TO hu_mm.

hu_mm-plant = hu_header-plant.

hu_mm-stge_loc = hu_header-stge_loc.

hu_mm-whse_no = '101'.

hu_mm-stge_type = '916'.

hu_mm-stge_bin = tmp_vbeln.

  • set up items

LOOP AT hu_items INTO hui_wa.

hu_items_wa-velin = '1'.

hu_items_wa-belnr = tmp_vbeln.

hu_items_wa-posnr = hui_wa-lower_level_exid.

MOVE hui_wa-pack_qty TO hu_items_wa-quantity.

MOVE hui_wa-base_unit_qty TO hu_items_wa-meins.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

EXPORTING

input = hui_wa-material

IMPORTING

output = hu_items_wa-matnr

EXCEPTIONS

length_error = 1

OTHERS = 2.

hu_items_wa-charg = hui_wa-batch.

hu_items_wa-werks = hui_wa-plant.

hu_items_wa-lgort = hui_wa-stge_loc.

  • APPEND hu_items_wa TO hu_items1.

  • sort items

  • SORT hu_items1 BY belnr posnr.

  • copy and change function ADD_TO_EXISTING_HU if neccessary

CALL FUNCTION 'ADD_TO_EXISTING_HU'

EXPORTING

i_hu_id = ''

i_hu_ref_doc = obj

i_mm_data = hu_mm

i_hu_internal = hu_internal

i_hu_external = hu_external

is_handling_unit = h_unit_l

is_item_proposal = hu_items_wa

i_delivery_type = del_type

IMPORTING

et_messages = hu_msg

EXCEPTIONS

not_possible = 1

delivery_update_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

CALL FUNCTION 'BALW_BAPIRETURN_GET2'

EXPORTING

type = sy-msgty

cl = sy-msgid

number = sy-msgno

par1 = sy-msgv1

par2 = sy-msgv2

par3 = sy-msgv3

par4 = sy-msgv4

IMPORTING

return = return.

ROLLBACK WORK.

ELSE.

COMMIT WORK AND WAIT.

ENDIF.

ENDLOOP.

ENDIF.

ENDFUNCTION.

5 REPLIES 5

Former Member
0 Kudos

What kind of error do you get ?

And where ?

Former Member
0 Kudos

when I use the ADD_TO_EXISTING_HU i get the error EHUFUNCTION 261 Processing of Hus for selected objects not possible

0 Kudos

It probably has something to do wit the kind of HU that you are using.

If you call a " where used " of the error message HUFUNCTIONS 261 you will see that there are several checks concerning the kind of HU.

The types of HU's can be found in domain VPOBJ.

Hope this helps,

Regards,

Dirk.

Former Member
0 Kudos

Fixed, Corrupted data issue sorted

0 Kudos

Hello Kinika Nyenke,

In our project simular requirement is given and i could see you have already did it with code. Can you please share what are the parameter should be passed to get the new material to be added to existing HU.

Also please confirm whether this logic works for HUs already assigned to HU.

Thank in advance, it will be great help if you can respond ASAP.

Best Regards

Sudheer