Skip to Content
0
Jun 03, 2013 at 08:32 AM

Production order is getting confirmed with zero quantity through bapi

376 Views

Hi All,

I am trying to confirm PO using bapi and wrote following code in my FM.This Fm works perfectly when no quantity is deficient in material BOM but when material BOM have deficient quantity then it is confirming with zero quantity(delivery quantity).Please find the code given below.

FUNCTION ZHAV_FM_CONFIRM_PRODORD_TEST.

*"--------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" REFERENCE(IV_ORDER_NUMBER) TYPE AUFNR

*" VALUE(IV_TO_BE_CONF_QUAN) TYPE RU_LMNGA OPTIONAL

*" REFERENCE(IV_CONF_FLAG) TYPE AUERU_VS DEFAULT 'X'

*" EXPORTING

*" REFERENCE(ET_RETURN) TYPE BAPIRET2_T

*"--------------------------------------------------------------------

TYPES : BEGIN OF ts_lbl_id ,

labelid TYPE /mvn/mdew_label_id,

sfg_matid TYPE matnr,

is_cnf TYPE zhav_t_subcmpdet-is_cnf,

END OF ts_lbl_id,

BEGIN OF ts_lbl_det ,

si_no TYPE /mvn/mdew_label_id,

item_code TYPE matnr,

prd_ord_no TYPE aufnr ,

END OF ts_lbl_det .

DATA: ls_propose TYPE bapi_pp_conf_prop,

ls_return TYPE bapiret1,

lt_timeticket TYPE TABLE OF bapi_pp_timeticket,

ls_timeticket TYPE bapi_pp_timeticket,

lt_item_create TYPE TABLE OF bapi2017_gm_item_create,

lt_goodsmov TYPE TABLE OF bapi_link_conf_goodsmov,

ls_goodsmov TYPE bapi_link_conf_goodsmov,

lt_detail_return TYPE TABLE OF bapi_coru_return,

ls_detail_return TYPE bapi_coru_return,

lv_conf_flag TYPE afru-aueru,

lv_error_flag TYPE c,

lt_label_id TYPE TABLE OF ts_lbl_id,

ls_label_id LIKE LINE OF lt_label_id,

* lt_lbl_det TYPE TABLE OF ts_lbl_det,

* ls_lbl_det LIKE LINE OF lt_lbl_det,

lt_subcmpdet TYPE TABLE OF zhav_t_subcmpdet,

lv_mat TYPE matnr,

lt_lbl_det TYPE TABLE OF zhav_t_lbl_det,

lv_upto TYPE i,

lv_material TYPE matnr,

lv_mat_material TYPE matnr.

FIELD-SYMBOLS : <fs_timeticket> TYPE bapi_pp_timeticket,

<fs_subcmfdet> TYPE zhav_t_subcmpdet,

<fs_lbl_det> TYPE zhav_t_lbl_det.

IF iv_conf_flag NE 'X' ."AND iv_conf_flag NE ''.

MESSAGE ID 'ZHAV_MSG_CL' TYPE 'E' NUMBER '029'

INTO ls_return-message.

ls_return-type = 'E'.

ls_return-id = 'ZHAV_MSG_CL'.

ls_return-number = '029' .

APPEND ls_return TO et_return.

lv_error_flag = 'X'.

EXIT.

ENDIF.

SELECT SINGLE aueru FROM afru INTO lv_conf_flag

WHERE aufnr = iv_order_number AND aueru = 'X'.

IF sy-subrc = 0. "" order already confirmed .....

MESSAGE ID 'ZHAV_MSG_CL' TYPE 'E' NUMBER '030' WITH iv_order_number

INTO ls_return-message.

ls_return-type = 'E'.

ls_return-id = 'ZHAV_MSG_CL'.

ls_return-number = '030' .

APPEND ls_return TO et_return.

lv_error_flag = 'X'.

EXIT.

ENDIF.

ls_propose-quantity = 'X'.

ls_propose-activity = 'X'.

ls_propose-date_and_time = 'X' .

ls_propose-personnel = 'X'.

ls_propose-goodsmovement = 'X'.

ls_timeticket-orderid = iv_order_number.

ls_timeticket-operation = '0010'.

APPEND ls_timeticket TO lt_timeticket.

CLEAR ls_timeticket.

CALL FUNCTION 'BAPI_PRODORDCONF_GET_TT_PROP'

EXPORTING

propose = ls_propose

IMPORTING

return = ls_return

TABLES

timetickets = lt_timeticket

* GOODSMOVEMENTS = lt_goodsmov

* LINK_CONF_GOODSMOV =

detail_return = lt_detail_return .

IF ls_return-type = 'E'.

APPEND ls_return TO et_return.

EXIT.

ENDIF.

LOOP AT lt_detail_return INTO ls_detail_return WHERE type = 'E'.

APPEND ls_detail_return TO et_return.

lv_error_flag = 'X'.

ENDLOOP.

IF lv_error_flag = 'X'.

EXIT.

ENDIF.

LOOP AT lt_timeticket ASSIGNING <fs_timeticket> ."INTO ls_timeticket.

<fs_timeticket>-ex_created_by = sy-uname." External creator of confirmation

<fs_timeticket>-ex_created_date = sy-datum." External date of entry for confirmation

<fs_timeticket>-ex_created_time = sy-uzeit.

<fs_timeticket>-fin_conf = iv_conf_flag.

* IF <fs_timeticket>-yield LT iv_to_be_conf_quan.

* MESSAGE ID 'ZHAV_MSG_CL' TYPE 'E' NUMBER '018'

* WITH iv_to_be_conf_quan ls_timeticket-yield

* INTO ls_return-message.

* ls_return-type = 'E'.

* ls_return-id = 'ZHAV_MSG_CL'.

* ls_return-number = '028' .

* APPEND ls_return TO et_return.

* lv_error_flag = 'X'.

* EXIT.

* ENDIF.

IF iv_to_be_conf_quan IS NOT INITIAL.

<fs_timeticket>-yield = iv_to_be_conf_quan.

ELSE.

iv_to_be_conf_quan = <fs_timeticket>-yield.

ENDIF.

ENDLOOP.

IF lv_error_flag = 'X'.

EXIT.

ENDIF.

CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_TT'

IMPORTING

return = ls_return

TABLES

timetickets = lt_timeticket

detail_return = lt_detail_return.

IF ls_return-type = 'E'.

APPEND ls_return TO et_return.

EXIT.

ENDIF.

LOOP AT lt_detail_return INTO ls_detail_return WHERE type = 'E'.

APPEND ls_detail_return TO et_return.

lv_error_flag = 'X'.

ENDLOOP.

IF lv_error_flag = 'X'.

EXIT.

ENDIF.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .

MESSAGE ID 'ZHAV_MSG_CL' TYPE 'S' NUMBER '018'

WITH iv_order_number INTO ls_return-message.

ls_return-type = 'S'.

ls_return-id = 'ZHAV_MSG_CL'.

ls_return-number = '018' .

APPEND ls_return TO et_return.

ENDFUNCTION.

Thanks and regards

Suraj