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: 

BAPI_HU_CREATE

Former Member
0 Kudos

Hi,

Can someone give me the sample code for using the BAPI BAPI_HU_CREATE.

What I need to do is that ,I need to create the handling unit and pack it?

Please help.Its urgent.

Marks assured.

Thanks,

Sirisha Matta.

1 ACCEPTED SOLUTION

LOOP AT gt_final1 INTO gs_final1.

  • item proposal

gs_itemsproposal-hu_item_type = c_1. " material item

gs_itemsproposal-pack_qty = gs_final1-erfmg. " quantity

gs_itemsproposal-base_unit_qty = 'EA'. " unit of measure

IF NOT gs_final1-matnr IS INITIAL.

gs_itemsproposal-material = gs_final1-matnr. " zlpm material

ELSE.

gs_itemsproposal-material = gs_final1-matnr1. " material(component)

ENDIF.

gs_itemsproposal-plant = gs_final1-werks. " plant

gs_itemsproposal-stge_loc = gs_final1-lgort. " storage location

gs_itemsproposal-batch = gs_final1-charg. " batch

  • passing values into variables before AT NEW

gv_matnr = gs_final1-matnr.

AT NEW sernr.

  • populate no of sernr

gs_itemsproposal-no_of_serial_numbers = c_1.

  • read table to check if the 1st matnr of new

  • sernr is of type ZLPM or not

  • also populate pack_mat and pack inst

READ TABLE gt_mara INTO gs_mara WITH KEY matnr = gv_matnr

mtart = c_zlpm BINARY SEARCH.

IF sy-subrc = c_0.

  • populate pack_mat

IF gs_mara-magrv+0(2) = c_im.

gv_pack_mat = text-032. " IMPLANT_SET

ELSEIF gs_mara-magrv+0(2) = c_in.

gv_pack_mat = text-035. " INSTRUMENT_KIT

ENDIF.

  • pack inst

lv_pobjid = gv_matnr.

CALL FUNCTION 'VHUPODB_PACKOBJ_CONV_ID2GUID'

EXPORTING

pobjid_imp = lv_pobjid

packtyp_imp = c_p

IMPORTING

packnr_exp = gv_packg_instruct

EXCEPTIONS

prog_error = 1

pobjid_not_found = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE.

  • populate msg if 1st material of new sernr is

  • not of type ZLPM

gv_tabix = gv_tabix + c_1.

gs_error1-sno = gv_tabix.

gs_error1-matnr = gv_matnr.

gs_error1-sernr = gs_final1-sernr.

gs_error1-msg = text-037. " First material of this serial number is not of type ZLPM

APPEND gs_error1 TO gt_error1.

DELETE gt_final1 WHERE sernr = gs_final1-sernr.

CONTINUE.

ENDIF.

ENDAT.

APPEND gs_itemsproposal TO gt_itemsproposal.

CLEAR gs_itemsproposal.

gv_werks = gs_final1-werks.

gv_lgort = gs_final1-lgort.

  • bapi will be called only on the change of sernr

AT END OF sernr.

  • used for setting the local pack status

  • calculate no of items in itemsproposal table

DESCRIBE TABLE gt_itemsproposal LINES lv_no_lines.

  • read total materials available in this pack inst

  • here lv_pobjid contains the name of ZLPM material

READ TABLE gt_packkp INTO gs_packkp WITH KEY matnr = lv_pobjid.

IF sy-subrc = c_0.

  • if all material in pack inst are included in HU

IF gs_packkp-number = lv_no_lines.

gs_bapihuhdrproposal-l_packg_status_hu = c_3. " Local packing status of HU

  • if all material in pack inst are not included in HU

ELSEIF gs_packkp-number <> lv_no_lines.

gs_bapihuhdrproposal-l_packg_status_hu = c_2. " Local packing status of HU

ENDIF.

ENDIF.

  • header proposal

gv_sernr = gs_final1-sernr.

gs_bapihuhdrproposal-pack_mat = gv_pack_mat. " packaging material

gs_bapihuhdrproposal-plant = gv_werks. " plant

gs_bapihuhdrproposal-stge_loc = gv_lgort. " storage location

gs_bapihuhdrproposal-packg_instruct = gv_packg_instruct. " packaging instruction

  • serial number

gs_itemsserialno-row_index = c_1. " row index

gs_itemsserialno-serialno = gs_final1-sernr. " serial number

APPEND gs_itemsserialno TO gt_itemsserialno.

CLEAR gs_itemsserialno.

  • bapi for hu creation

----


CALL FUNCTION 'BAPI_HU_CREATE'

EXPORTING

headerproposal = gs_bapihuhdrproposal

IMPORTING

huheader = gs_huheader

hukey = gv_hukey

TABLES

itemsproposal = gt_itemsproposal

itemsserialno = gt_itemsserialno

return = gt_return

huitem = gt_huitem.

----


gv_tabix = gv_tabix + c_1.

gs_summary1-sno = gv_tabix.

  • here lv_pobjid contains the name of ZLPM material

gs_summary1-matnr = lv_pobjid.

gs_summary1-sernr = gs_final1-sernr.

SHIFT gs_summary1-sno LEFT DELETING LEADING space.

IF gt_return IS INITIAL. " HU created successfully

  • transaction commit

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = c_x.

4 REPLIES 4

Former Member
0 Kudos

Hi,

You have to declare a work area of type BAPIHUHDRPROPOSAL. This structur contains the values for the handling unit. You can see those by taking the structure in transaction SE11.

Then call the bapi BAPI_HU_CREATE passing the work area as input.

Then call the bapi BAPI_TRANSACTION_COMMIT

Hope this helps. Pls reward points if useful.

Regards,

Renjith Michael.

LOOP AT gt_final1 INTO gs_final1.

  • item proposal

gs_itemsproposal-hu_item_type = c_1. " material item

gs_itemsproposal-pack_qty = gs_final1-erfmg. " quantity

gs_itemsproposal-base_unit_qty = 'EA'. " unit of measure

IF NOT gs_final1-matnr IS INITIAL.

gs_itemsproposal-material = gs_final1-matnr. " zlpm material

ELSE.

gs_itemsproposal-material = gs_final1-matnr1. " material(component)

ENDIF.

gs_itemsproposal-plant = gs_final1-werks. " plant

gs_itemsproposal-stge_loc = gs_final1-lgort. " storage location

gs_itemsproposal-batch = gs_final1-charg. " batch

  • passing values into variables before AT NEW

gv_matnr = gs_final1-matnr.

AT NEW sernr.

  • populate no of sernr

gs_itemsproposal-no_of_serial_numbers = c_1.

  • read table to check if the 1st matnr of new

  • sernr is of type ZLPM or not

  • also populate pack_mat and pack inst

READ TABLE gt_mara INTO gs_mara WITH KEY matnr = gv_matnr

mtart = c_zlpm BINARY SEARCH.

IF sy-subrc = c_0.

  • populate pack_mat

IF gs_mara-magrv+0(2) = c_im.

gv_pack_mat = text-032. " IMPLANT_SET

ELSEIF gs_mara-magrv+0(2) = c_in.

gv_pack_mat = text-035. " INSTRUMENT_KIT

ENDIF.

  • pack inst

lv_pobjid = gv_matnr.

CALL FUNCTION 'VHUPODB_PACKOBJ_CONV_ID2GUID'

EXPORTING

pobjid_imp = lv_pobjid

packtyp_imp = c_p

IMPORTING

packnr_exp = gv_packg_instruct

EXCEPTIONS

prog_error = 1

pobjid_not_found = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ELSE.

  • populate msg if 1st material of new sernr is

  • not of type ZLPM

gv_tabix = gv_tabix + c_1.

gs_error1-sno = gv_tabix.

gs_error1-matnr = gv_matnr.

gs_error1-sernr = gs_final1-sernr.

gs_error1-msg = text-037. " First material of this serial number is not of type ZLPM

APPEND gs_error1 TO gt_error1.

DELETE gt_final1 WHERE sernr = gs_final1-sernr.

CONTINUE.

ENDIF.

ENDAT.

APPEND gs_itemsproposal TO gt_itemsproposal.

CLEAR gs_itemsproposal.

gv_werks = gs_final1-werks.

gv_lgort = gs_final1-lgort.

  • bapi will be called only on the change of sernr

AT END OF sernr.

  • used for setting the local pack status

  • calculate no of items in itemsproposal table

DESCRIBE TABLE gt_itemsproposal LINES lv_no_lines.

  • read total materials available in this pack inst

  • here lv_pobjid contains the name of ZLPM material

READ TABLE gt_packkp INTO gs_packkp WITH KEY matnr = lv_pobjid.

IF sy-subrc = c_0.

  • if all material in pack inst are included in HU

IF gs_packkp-number = lv_no_lines.

gs_bapihuhdrproposal-l_packg_status_hu = c_3. " Local packing status of HU

  • if all material in pack inst are not included in HU

ELSEIF gs_packkp-number <> lv_no_lines.

gs_bapihuhdrproposal-l_packg_status_hu = c_2. " Local packing status of HU

ENDIF.

ENDIF.

  • header proposal

gv_sernr = gs_final1-sernr.

gs_bapihuhdrproposal-pack_mat = gv_pack_mat. " packaging material

gs_bapihuhdrproposal-plant = gv_werks. " plant

gs_bapihuhdrproposal-stge_loc = gv_lgort. " storage location

gs_bapihuhdrproposal-packg_instruct = gv_packg_instruct. " packaging instruction

  • serial number

gs_itemsserialno-row_index = c_1. " row index

gs_itemsserialno-serialno = gs_final1-sernr. " serial number

APPEND gs_itemsserialno TO gt_itemsserialno.

CLEAR gs_itemsserialno.

  • bapi for hu creation

----


CALL FUNCTION 'BAPI_HU_CREATE'

EXPORTING

headerproposal = gs_bapihuhdrproposal

IMPORTING

huheader = gs_huheader

hukey = gv_hukey

TABLES

itemsproposal = gt_itemsproposal

itemsserialno = gt_itemsserialno

return = gt_return

huitem = gt_huitem.

----


gv_tabix = gv_tabix + c_1.

gs_summary1-sno = gv_tabix.

  • here lv_pobjid contains the name of ZLPM material

gs_summary1-matnr = lv_pobjid.

gs_summary1-sernr = gs_final1-sernr.

SHIFT gs_summary1-sno LEFT DELETING LEADING space.

IF gt_return IS INITIAL. " HU created successfully

  • transaction commit

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = c_x.

0 Kudos

Hi ..........

Are you still facing problem with this issue?

If yes then let me know, i can explain you the details..

If my previous message was of any help then please award points for the same.

Regards.

Edited by: Sharad Dubey on Mar 25, 2008 1:53 PM

0 Kudos

Hi,

do you know what parameter of 'BAPI_HU_CREATE' informs VEKP-VPOBJ?

Thanks in advance!

MayM