Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI_HU_CREATE

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.

Tags:
Former Member
Former Member replied

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 View this answer in context
Not what you were looking for? View more on this topic or Ask a question