Application Development and Automation 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: 
Read only

Problem in BAPI_HU_CREATE

Former Member
0 Likes
2,909

Dear All,

Im using BAPI_HU_CREATE for creating the handling unit, but when i run the program, i m getting a message HU cannot be created and the HU is not getting created,pls find the below coding im using in my program and tell me what could be wrong in this.

DATA: st_huhdrpr TYPE bapihuhdrproposal,

st_huhdr TYPE bapihuheader,

st_huhdr_pack TYPE bapihuheader,

it_pr LIKE TABLE OF bapihuitmproposal WITH HEADER LINE,

it_huitem LIKE TABLE OF bapihuitem,

it_huitem_pack TYPE bapihuitem,

it_hunumber LIKE TABLE OF bapihunumber WITH HEADER LINE.

REFRESH it_ret.

st_huhdrpr-hu_status_init = 'C'.

st_huhdrpr-pack_mat = v_pac_matnr.

SELECT SINGLE * FROM lips WHERE vbeln EQ likp-vbeln

AND lfimg GT 0.

st_huhdrpr-plant = lips-werks.

st_huhdrpr-stge_loc = lips-lgort.

LOOP AT it_scan ASSIGNING <fs_scan> .

it_pr-hu_item_type = '1'.

it_pr-material = <fs_scan>-matnr.

it_pr-material_partner = <fs_scan>-j_3akordx.

it_pr-batch = <fs_scan>-charg.

it_pr-pack_qty = <fs_scan>-count.

it_pr-base_unit_qty = 'ST'.

it_pr-plant = st_huhdrpr-plant.

it_pr-stge_loc = st_huhdrpr-stge_loc.

it_pr-number_pack_mat = <fs_scan>-count.

APPEND it_pr.

ENDLOOP.

*Call to BAPI

CALL FUNCTION 'BAPI_HU_CREATE'

EXPORTING

headerproposal = st_huhdrpr

IMPORTING

huheader = st_huhdr

hukey = v_hukey

TABLES

itemsproposal = it_pr

return = it_ret

huitem = it_huitem.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

IF NOT v_hukey IS INITIAL.

APPEND v_hukey TO it_hukey.

LOOP AT it_scan ASSIGNING <fs_scan> .

MOVE-CORRESPONDING <fs_scan> TO it_hunit.

MOVE v_hukey TO it_hunit-hukey.

APPEND it_hunit.

CLEAR it_hunit.

ENDLOOP.

PERFORM packing_print.

ELSE.

MESSAGE e000(38) WITH

'HU Creation and Packing failed Click on LOG to see errors'.

ENDIF.

REFRESH : it_pr,it_huitem.

ENDFORM. " create_handling_unit

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,268

Hello Raja

Your "error" handling of the BAPI is somewhat strange. The returned messages (TABLES parameter RETURN) will tell you more about your problem. Therefore check the details of these error messages.


*Call to BAPI
CALL FUNCTION 'BAPI_HU_CREATE'
EXPORTING
headerproposal = st_huhdrpr
IMPORTING
huheader = st_huhdr
hukey = v_hukey
TABLES
itemsproposal = it_pr
return = it_ret
huitem = it_huitem.

" Error handling
LOOP AT it_ret TRANSPORTING NO FIELDS
               WHERE ( type CA 'AEX' ). " Abort, Error, or Dump message
  EXIT.
ENDLOOP.
IF ( syst-subrc = 0 ).
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
...

Regards

Uwe

Read only

0 Likes
1,268

hi,

I handled the error using your suggestions and i found the following error message in the IT_RET.

TYPE E

ID MM

NUMBER 328

MESSAGE Quantities cannot be converted for the material BP6007_NVY

LOG_NO

LOG_MSG_NO 000000

MESSAGE_V1 BP6007_NVY

MESSAGE_V2

MESSAGE_V3

MESSAGE_V4

PARAMETER

ROW 0

FIELD

SYSTEM

Kindly suggest me what is wrong with my value passing to the BAPI_HU_CREATE.

regs,

Raja

Read only

0 Likes
1,268

Try removing any comma or points from the field

it_pr-pack_qty = <fs_scan>-count.

Regards,

Atish

Read only

0 Likes
1,268

Please have a look at the below mentioned code.

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.

Please give points if useful.