Sei sulla pagina 1di 7

<SIGNATURE>---------------------------------------------------------------------------------------

+
* | Instance Public Method /MVN/CL_MS_TO_UTIL->TO_WO_TASK_LIST_CREATE
*
+-------------------------------------------------------------------------------------------------
* | [--->] IV_ORDERID TYPE AUFNR
* | [--->] IV_DESCRIPTION TYPE PLANTEXT(optional)
* | [--->] IV_STATUS TYPE PLNST(optional)
* | [--->] IV_USAGE TYPE PLN_VERWE(optional)
* | [--->] IV_TASKLIST_TYPE TYPE PLNTY(optional)
* | [--->] IV_COPY_COMPONENT TYPE BOOLEAN(optional)
* | [--->] IV_COPY_PRT TYPE BOOLEAN(optional)
* | [--->] IT_OPERATION_IDS TYPE /MVN/MS_TT_OPERATION_ID(optional)
* | [<---] ET_RESPONSE TYPE /MVN/MS_TT_UPDATE_RESPONSE
* | [<---] ET_RETURN TYPE BAPIRET2_T
* +--------------------------------------------------------------------------------------
</SIGNATURE>
METHOD to_wo_task_list_create.

DATA:
ls_response TYPE /mvn/ms_st_update_response,
lt_operation_ids TYPE /mvn/ms_tt_operation_id,
lv_plnnr TYPE plnnr,
lv_plnal TYPE plnal,
ls_tl_header TYPE eam_s_hdr_ins,
lt_tl_operation TYPE eam_t_tl_opr,
lt_tl_component TYPE eam_t_component_ins,
lt_tl_prt TYPE eam_t_tl_prt,
lt_return TYPE bapiret2_t.

FIELD-SYMBOLS:
<fs_operation_id> TYPE /mvn/ms_st_operation_id.

lt_operation_ids = it_operation_ids.

"conversion
LOOP AT lt_operation_ids ASSIGNING <fs_operation_id>.
"orderid
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_operation_id>-orderid
IMPORTING
output = <fs_operation_id>-orderid.
"activity
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_operation_id>-sub_activity
IMPORTING
output = <fs_operation_id>-sub_activity.
"sub-activity
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_operation_id>-activity
IMPORTING
output = <fs_operation_id>-activity.

ENDLOOP.
SORT lt_operation_ids BY orderid activity sub_activity.

"prepare itab/structure to create tasklist from work order


CALL METHOD to_wo_task_list_prepare
EXPORTING
iv_orderid = iv_orderid
iv_description = iv_description
iv_status = iv_status
iv_usage = iv_usage
iv_tasklist_type = iv_tasklist_type
iv_copy_component = iv_copy_component
iv_copy_prt = iv_copy_prt
it_operation_ids = lt_operation_ids
IMPORTING
es_header = ls_tl_header
et_operation = lt_tl_operation
et_component = lt_tl_component
et_prt = lt_tl_prt
et_return = et_return.

"create task list


CALL FUNCTION 'EAM_TASKLIST_CREATE'
EXPORTING
is_header = ls_tl_header
IMPORTING
ev_plnnr = lv_plnnr
ev_plnal = lv_plnal
TABLES
it_operations = lt_tl_operation
it_components = lt_tl_component
it_prts = lt_tl_prt
et_return = lt_return.
"return message
APPEND LINES OF lt_return TO et_return.

"default error flag


ls_response-id = ls_tl_header-ktext.
ls_response-status = 'E'.

"save data
IF lv_plnnr IS NOT INITIAL.

CLEAR: lt_return.
CALL FUNCTION 'EAM_TASKLIST_POST'
EXPORTING
iv_plnty = ls_tl_header-plnty
iv_plnnr = lv_plnnr
IMPORTING
et_return = lt_return.

"return message
APPEND LINES OF lt_return TO et_return.

"success flag
READ TABLE et_return TRANSPORTING NO FIELDS WITH KEY type = 'E'.
IF sy-subrc <> 0.
ls_response-status = 'S'.
ENDIF.

ENDIF.

"response
APPEND ls_response TO et_response.

"commit changes
CALL METHOD commit_data
EXPORTING
it_return = et_return. " Return parameter table

ENDMETHOD. "to_wo_task_list_create

*
<SIGNATURE>---------------------------------------------------------------------------------------
+
* | Instance Protected Method /MVN/CL_MS_TO_UTIL->TO_WO_TASK_LIST_PREPARE
*
+-------------------------------------------------------------------------------------------------
+
* | [--->] IV_ORDERID TYPE AUFNR
* | [--->] IV_DESCRIPTION TYPE PLANTEXT
* | [--->] IV_STATUS TYPE PLNST
* | [--->] IV_USAGE TYPE PLN_VERWE
* | [--->] IV_TASKLIST_TYPE TYPE PLNTY
* | [--->] IV_COPY_COMPONENT TYPE BOOLEAN
* | [--->] IV_COPY_PRT TYPE BOOLEAN
* | [--->] IT_OPERATION_IDS TYPE /MVN/MS_TT_OPERATION_ID
* | [<---] ET_PRT TYPE EAM_T_TL_PRT
* | [<---] ES_HEADER TYPE EAM_S_HDR_INS
* | [<---] ET_OPERATION TYPE EAM_T_TL_OPR
* | [<---] ET_COMPONENT TYPE EAM_T_COMPONENT_INS
* | [<---] ET_RETURN TYPE BAPIRET2_T
* +--------------------------------------------------------------------------------------
</SIGNATURE>
METHOD to_wo_task_list_prepare.

"-----------------------------------------------------------------------------
"This Method will prepare itab with the information needed to create tasklist
"-----------------------------------------------------------------------------

TYPES:
BEGIN OF ty_tca01,
plnty TYPE plnty,
flg_equi TYPE ieqkz,
flg_ifl TYPE iflkz,
END OF ty_tca01.

DATA:
ls_tca01 TYPE ty_tca01,
lv_orderid TYPE aufnr,
ls_order_header TYPE bapi_alm_order_header_e,
ls_tl_operation TYPE eam_s_tl_opr,
ls_tl_component TYPE eam_s_tl_plmz_up,
ls_tl_prt TYPE eam_s_tl_prt,
ls_afvgd TYPE afvgd,
ls_resbd TYPE resbd,
lt_order_component_e TYPE TABLE OF bapi_alm_order_component_e,
ls_order_component_e TYPE bapi_alm_order_component_e,
lt_order_operation_e TYPE TABLE OF bapi_alm_order_operation_e,
ls_order_operation_e TYPE bapi_alm_order_operation_e,
ls_order_operation TYPE bapi_alm_order_operation,
ls_order_component TYPE bapi_alm_order_component,
lt_order_prt_e TYPE TABLE OF bapi_alm_order_prt_e,
ls_order_prt_e TYPE bapi_alm_order_prt_e,
ls_order_prt_i TYPE bapi_alm_order_prt_i,
ls_prt TYPE cose_s_prt_change.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = iv_orderid
IMPORTING
output = lv_orderid.

"read order details


CALL FUNCTION 'BAPI_ALM_ORDER_GET_DETAIL'
EXPORTING
number = lv_orderid
IMPORTING
es_header = ls_order_header
TABLES
et_operations = lt_order_operation_e
et_components = lt_order_component_e
et_prts = lt_order_prt_e
return = et_return.

CHECK et_return IS INITIAL.

"means order exits

"task list header


es_header-plnty = iv_tasklist_type.
es_header-verwe = iv_usage.
es_header-statu = iv_status.
es_header-ktext = iv_description.

"tasklist type
IF es_header-plnty IS INITIAL.
IF es_header-equnr IS INITIAL.
"fl usage
SELECT SINGLE param_value FROM /mvn/kb_c_syspar
INTO es_header-plnty
WHERE param_name = /mvn/if_ms_constants=>sys_params-fl_task_list_type.
ELSE.
"eq usage
SELECT SINGLE param_value FROM /mvn/kb_c_syspar
INTO es_header-plnty
WHERE param_name = /mvn/if_ms_constants=>sys_params-eq_task_list_type.
ENDIF.
ENDIF.
"fetch config
SELECT SINGLE plnty flg_equi flg_ifl
FROM tca01
INTO ls_tca01
WHERE
plnty = es_header-plnty AND plnaw = 'I'.
"updating fields
IF ls_tca01-flg_ifl = abap_true.
es_header-tplnr = ls_order_header-funct_loc.
ENDIF.
IF ls_tca01-flg_equi = abap_true.
es_header-equnr = ls_order_header-equipment.
ENDIF.

"task list operations


LOOP AT lt_order_operation_e INTO ls_order_operation_e.

"if operation is not specified, need to copy all operation

IF it_operation_ids IS NOT INITIAL.


"checking if this operation is required
READ TABLE it_operation_ids TRANSPORTING NO FIELDS
WITH KEY
orderid = lv_orderid
activity = ls_order_operation_e-activity
sub_activity = ls_order_operation_e-sub_activity BINARY SEARCH.
IF sy-subrc <> 0.
"no need to copy operation
CONTINUE.
ENDIF.
ENDIF.

"means operation is needed

CLEAR:
ls_tl_operation,
ls_afvgd,
ls_order_operation.

MOVE-CORRESPONDING ls_order_operation_e TO ls_order_operation.

"map to internal
CALL FUNCTION 'MAP2I_BAPI_ALM_ORDER_OPERATION'
EXPORTING
bapi_alm_order_operation = ls_order_operation
CHANGING
afvgd = ls_afvgd
EXCEPTIONS
error_converting_iso_code = 1
OTHERS = 2.

MOVE-CORRESPONDING ls_afvgd TO ls_tl_operation.


CLEAR: ls_tl_operation-ekorg,ls_tl_operation-sumnr.

APPEND ls_tl_operation TO et_operation.


ENDLOOP.

"components
IF iv_copy_component EQ abap_true.
LOOP AT lt_order_component_e INTO ls_order_component_e.

"checking if this operation is required


IF it_operation_ids IS NOT INITIAL.
READ TABLE it_operation_ids TRANSPORTING NO FIELDS
WITH KEY
orderid = lv_orderid
activity = ls_order_component_e-activity BINARY SEARCH.
IF sy-subrc <> 0.
"no need to copy operation
CONTINUE.
ENDIF.
ENDIF.

CLEAR:
ls_resbd,
ls_order_component,
ls_tl_component.

MOVE-CORRESPONDING ls_order_component_e TO ls_order_component.


"map to internal
CALL FUNCTION 'MAP2I_ALM_ORDER_COMPONENT'
EXPORTING
bapi_alm_order_component = ls_order_component
CHANGING
resbd = ls_resbd
EXCEPTIONS
error_converting_iso_code = 1
OTHERS = 2.

MOVE-CORRESPONDING ls_resbd TO ls_tl_component.

ls_tl_component-idnrk = ls_resbd-matnr.

APPEND ls_tl_component TO et_component.


ENDLOOP.
ENDIF.

"prt(s)
IF iv_copy_prt = abap_true.
LOOP AT lt_order_prt_e INTO ls_order_prt_e.

"checking if this operation is required


IF it_operation_ids IS NOT INITIAL.
READ TABLE it_operation_ids TRANSPORTING NO FIELDS
WITH KEY
orderid = lv_orderid
activity = ls_order_prt_e-activity BINARY SEARCH.
IF sy-subrc <> 0.
"no need to copy operation
CONTINUE.
ENDIF.
ENDIF.

CLEAR:
ls_resbd,
ls_prt,
ls_order_prt_i,
ls_tl_prt.

MOVE-CORRESPONDING ls_order_prt_e TO ls_order_prt_i.


"map to internal
CALL FUNCTION 'MAP2I_PRT_TO_PRT_CHANGE'
EXPORTING
bapi_alm_order_prt_i = ls_order_prt_i
CHANGING
cose_s_prt_change = ls_prt.

MOVE-CORRESPONDING ls_prt TO ls_tl_prt.

APPEND ls_tl_prt TO et_prt.

ENDLOOP.
ENDIF.

ENDMETHOD. "to_wo_task_list_prepare

*
<SIGNATURE>---------------------------------------------------------------------------------------
+
* | Instance Protected Method /MVN/CL_MS_TO_UTIL->COMMIT_DATA
*
+-------------------------------------------------------------------------------------------------
+
* | [--->] IT_RETURN TYPE BAPIRET2_T
* +--------------------------------------------------------------------------------------
</SIGNATURE>
METHOD commit_data.

READ TABLE it_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.


IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.

ENDMETHOD. "COMMIT_DATA

Potrebbero piacerti anche