Académique Documents
Professionnel Documents
Culture Documents
* Method attributes. *
**************************************************************************
Instantiation: Public
**************************************************************************
*&--------------------------------------------------------------------&*
*& Object Id : FS-SD-SLS-057 &*
*& Object Name : A utility program for automatic truck building &*
*& Program Name : ATTACH_SHIPMENT &*
*& Transaction Code: YV51N &*
*& Author : DHARMENDRA KUMAR &*
*& Module Name : Sales & Distribution &*
*& Program Type : Class Create Date : 03/05/2011 &*
*& SAP Release : 5.0 Transport No : RD1K939841 &*
*& SPR Number : ECC SD-HO#437/419 &*
*&--------------------------------------------------------------------&*
METHOD attach_shipment .
DATA: l_is_headerdata TYPE bapishipmentheader,
l_is_headerdataaction TYPE bapishipmentheaderaction,
l_it_itemdata TYPE TABLE OF bapishipmentitem,
l_it_itemdataaction TYPE TABLE OF bapishipmentitemaction,
l_is_itemdata TYPE bapishipmentitem,
l_is_itemdataaction TYPE bapishipmentitemaction.
FIELD-SYMBOLS : <l_fs_yvshipord> TYPE yvshipord,
<l_fs_return> TYPE bapiret2.
IF ch_it_yvshipord IS INITIAL.
RETURN.
ENDIF.
READ TABLE ch_it_yvshipord ASSIGNING <l_fs_yvshipord> INDEX 1.
IF sy-subrc IS NOT INITIAL.
RETURN.
ENDIF.
**********************************************************************
MESSAGE i000(ymsd) WITH '**************************************'(028)
INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log
EXPORTING
im_msgtyp = space.
MESSAGE i000(ymsd) WITH 'Shipment Attachement log for:'(046) <l_fs_yvshipord>-
tknum
INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log.
**********************************************************************
* open shipment for change ie planning to uncheck
l_is_headerdata-shipment_num = <l_fs_yvshipord>-tknum.
l_is_headerdata-status_plan = 'X'.
l_is_headerdataaction-status_plan = 'D'. " delete the plannind date
CALL FUNCTION 'BAPI_SHIPMENT_CHANGE'
EXPORTING
headerdata = l_is_headerdata
headerdataaction = l_is_headerdataaction
TABLES
return = ex_it_return.
READ TABLE ex_it_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc IS NOT INITIAL.
CLEAR: l_is_headerdata, l_is_headerdataaction.
REFRESH: l_it_itemdata, l_it_itemdataaction. " l_it_return.
* prepare shipment header for change.
l_is_headerdata-shipment_num = <l_fs_yvshipord>-tknum.
l_is_headerdata-status_plan = 'X'.
l_is_headerdataaction-status_plan = 'C'.
LOOP AT ch_it_yvshipord ASSIGNING <l_fs_yvshipord>.
** attach all the delivery to the line item for addition in shipment.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <l_fs_yvshipord>-delno
IMPORTING
output = <l_fs_yvshipord>-delno.
l_is_itemdata-delivery = <l_fs_yvshipord>-delno.
l_is_itemdata-itenerary = '0010'.
APPEND l_is_itemdata TO l_it_itemdata.
l_is_itemdataaction-delivery = 'A'.
l_is_itemdataaction-itenerary = 'A'.
APPEND l_is_itemdataaction TO l_it_itemdataaction.
ENDLOOP.
* attach the delivery's to the shipment..
CALL FUNCTION 'BAPI_SHIPMENT_CHANGE'
EXPORTING
headerdata = l_is_headerdata
headerdataaction = l_is_headerdataaction
TABLES
itemdata = l_it_itemdata
itemdataaction = l_it_itemdataaction
return = ex_it_return.
READ TABLE ex_it_return WITH KEY type = 'E'
TRANSPORTING NO FIELDS.
IF sy-subrc IS NOT INITIAL.
DATA : l_w_status_plan TYPE stdis.
IF ci_dyn_fixed_fill IS INITIAL. " fixed fill
l_w_status_plan = 'F'.
ELSE. " dynamic fill
l_w_status_plan = 'D'.
ENDIF.
LOOP AT ch_it_yvshipord ASSIGNING <l_fs_yvshipord>.
* fill the suppl3 by D or F
CALL METHOD change_shp_add_data
EXPORTING
im_tknum = <l_fs_yvshipord>-tknum
im_vstel = <l_fs_yvshipord>-vstel
im_hdr_status_plan = l_w_status_plan " D or F
im_hdra_status_plan = 'C' " value to change
IMPORTING
ex_it_return = ex_it_return
EXCEPTIONS
error_in_change = 1
OTHERS = 2.
IF sy-subrc IS NOT INITIAL.
ex_error = 'X'.
MESSAGE e000(ymsd) WITH 'Error in Changing suppl_3 data in shipment :'
(033)
<l_fs_yvshipord>-tknum INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log.
* put in error log.
LOOP AT ex_it_return ASSIGNING <l_fs_return>.
CALL METHOD ci_o_log->add_msg_to_log
EXPORTING
im_msgtyp = <l_fs_return>-type
im_msgid = <l_fs_return>-id
im_msgno = <l_fs_return>-number
im_msgv1 = <l_fs_return>-message_v1
im_msgv2 = <l_fs_return>-message_v2
im_msgv3 = <l_fs_return>-message_v3
im_msgv4 = <l_fs_return>-message_v4.
ENDLOOP.
ELSE.
<l_fs_yvshipord>-ship_attach = 'X'.
ENDIF.
ENDLOOP.
ELSE.
ex_error = 'X'.
MESSAGE e000(ymsd) WITH 'Delivery attached failed for :'(040) <l_fs_yvship
ord>-tknum
INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log.
* put in error log
LOOP AT ex_it_return ASSIGNING <l_fs_return>.
CALL METHOD ci_o_log->add_msg_to_log
EXPORTING
im_msgtyp = <l_fs_return>-type
im_msgid = <l_fs_return>-id
im_msgno = <l_fs_return>-number
im_msgv1 = <l_fs_return>-message_v1
im_msgv2 = <l_fs_return>-message_v2
im_msgv3 = <l_fs_return>-message_v3
im_msgv4 = <l_fs_return>-message_v4.
ENDLOOP.
ENDIF.
ELSE.
ex_error = 'X'.
MESSAGE e000(ymsd) WITH 'Planning Uncheck failed for shipment'(039) <l_fs_yv
shipord>-tknum
INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log.
LOOP AT ex_it_return ASSIGNING <l_fs_return>.
CALL METHOD ci_o_log->add_msg_to_log
EXPORTING
im_msgtyp = <l_fs_return>-type
im_msgid = <l_fs_return>-id
im_msgno = <l_fs_return>-number
im_msgv1 = <l_fs_return>-message_v1
im_msgv2 = <l_fs_return>-message_v2
im_msgv3 = <l_fs_return>-message_v3
im_msgv4 = <l_fs_return>-message_v4.
ENDLOOP.
ENDIF.
**********************************************************************
* irrespective of what change happened tick the planning again.
* open shipment for change ie planning to uncheck
CLEAR : l_is_headerdata, l_is_headerdataaction.
REFRESH : ex_it_return.
l_is_headerdata-shipment_num = <l_fs_yvshipord>-tknum.
l_is_headerdata-status_plan = 'X'.
l_is_headerdataaction-status_plan = 'C'. " set the planned date
CALL FUNCTION 'BAPI_SHIPMENT_CHANGE'
EXPORTING
headerdata = l_is_headerdata
headerdataaction = l_is_headerdataaction
TABLES
return = ex_it_return.
READ TABLE ex_it_return WITH KEY type = 'E'
TRANSPORTING NO FIELDS.
IF sy-subrc IS INITIAL. " found ie error
MESSAGE e000(ymsd) WITH 'Planning check failed for shipment'(027) <l_fs_yvsh
ipord>-tknum
INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log.
LOOP AT ex_it_return ASSIGNING <l_fs_return>.
CALL METHOD ci_o_log->add_msg_to_log
EXPORTING
im_msgtyp = <l_fs_return>-type
im_msgid = <l_fs_return>-id
im_msgno = <l_fs_return>-number
im_msgv1 = <l_fs_return>-message_v1
im_msgv2 = <l_fs_return>-message_v2
im_msgv3 = <l_fs_return>-message_v3
im_msgv4 = <l_fs_return>-message_v4.
ENDLOOP.
ENDIF.
**********************************************************************
MESSAGE i000(ymsd) WITH '**************************************'(028)
INTO ca_msg.
CALL METHOD ci_o_log->add_msg_to_log
EXPORTING
im_msgtyp = space.
**********************************************************************
ENDMETHOD.
--------------------------------------------------------------------------------
--