2012 Nov 26 11:48 AM
Hi,
How can we create multiple work orders using the bapi BAPI_ALM_ORDER_MAINTAIN.
I am able to create single order perfectly, but when i am uploading the data for multiple orders. I am getting a message into the BAPIRET2 as ''Error reading the order header %00000000001 from the document tables".
Here is the code which i wrote. Please correct me where i am wrong.
Thanks in Advance.
TYPES:BEGIN OF ty_data,
order_type TYPE aufart, "Initial Screen
funct_loc TYPE tplnr,
equipment TYPE equnr,
priority TYPE priok,
planplant TYPE iwerk,
short_text TYPE auftext, "Header Data
activity_type TYPE ila,
start_date TYPE co_gstrp,
activity TYPE vornr,
work_cntr TYPE arbpl,
plant TYPE werks_d,
control_key TYPE steus,
description TYPE ltxa1,
work_activity TYPE arbeit,
un_work TYPE arbeite,
number TYPE anzkap,
activity_c TYPE aposn,"vornr,
material TYPE matnr,
req_qty TYPE co_menge,
uom TYPE meins,
item_cat TYPE postp,
END OF ty_data.
* finish_date TYPE co_gltrp,
DATA:t_data TYPE TABLE OF ty_data,
w_data TYPE ty_data.
DATA:t_header TYPE TABLE OF bapi_alm_order_headers_i,
w_header TYPE bapi_alm_order_headers_i.
DATA:t_operation TYPE TABLE OF bapi_alm_order_operation,
w_operation TYPE bapi_alm_order_operation.
DATA:t_component TYPE TABLE OF bapi_alm_order_component,
w_component TYPE bapi_alm_order_component.
DATA:t_methods TYPE TABLE OF bapi_alm_order_method,
w_methods TYPE bapi_alm_order_method.
DATA:w_return TYPE bapiret2,
t_return TYPE TABLE OF bapiret2.
DATA:w_number TYPE bapi_alm_numbers,
t_number TYPE TABLE OF bapi_alm_numbers.
DATA:order TYPE aufnr.
DATA:w_loc TYPE tplnr.
DATA:w_matnr TYPE matnr.
DATA:w_equi TYPE equnr.
DATA:refno TYPE n LENGTH 6 VALUE '000001'.
DATA:seqno TYPE n LENGTH 11 VALUE '00000000001'.
***********************************************************************************
*DATA:path TYPE string.
*
*PARAMETERS:w_path TYPE ibipparms-path.
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR w_path.
* CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* program_name = syst-cprog
* dynpro_number = syst-dynnr
** FIELD_NAME = ' '
* IMPORTING
* file_name = w_path.
*
*AT SELECTION-SCREEN.
* path = w_path.
*
*START-OF-SELECTION.
* path = w_path.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = '_______'
filetype = 'DAT'
TABLES
data_tab = t_data
************************** Filling the internal Table ****************************************
DATA:key TYPE c LENGTH 12.
LOOP AT t_data INTO w_data.
CONCATENATE '%' seqno INTO key.
w_methods-refnumber = refno.
w_methods-objecttype = 'HEADER'.
w_methods-method = 'CREATE'.
w_methods-objectkey = key."'%00000000001'.
APPEND w_methods TO t_methods.
CLEAR w_methods.
CALL FUNCTION 'CONVERSION_EXIT_TPLNR_INPUT'
EXPORTING
input = w_data-funct_loc
i_flg_check_internal = 'X'
IMPORTING
output = w_loc
EXCEPTIONS
not_found = 1
OTHERS = 2.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_data-equipment
IMPORTING
output = w_equi.
**************************************************************************************************
w_header-orderid = key."'%00000000001'.
w_header-order_type = w_data-order_type. "'PM01'.
w_header-planplant = w_data-planplant. "'1000'."
w_header-funct_loc = w_loc.
w_header-equipment = w_equi."w_data-equipment.
w_header-short_text = w_data-short_text. "'test'.
w_header-start_date = w_data-start_date. "SY-DATUM
APPEND w_header TO t_header.
******************************************************************************************************
w_methods-refnumber = refno. "'000001'.
w_methods-objecttype = 'OPERATION'.
w_methods-method = 'CREATE'.
w_methods-objectkey = key."'%000000000010010'.
APPEND w_methods TO t_methods.
CLEAR w_methods.
******************************************************************************************************
w_operation-activity = w_data-activity . "0010
w_operation-work_cntr = w_data-work_cntr. "'MECHANIK'.
w_operation-plant = w_data-plant. "1000
w_operation-description = w_data-description. "TEST
w_operation-control_key = w_data-control_key. "PM01
w_operation-work_activity = w_data-work_activity. "2
w_operation-un_work = w_data-un_work . "H
w_operation-number_of_capacities = w_data-number. "1
APPEND w_operation TO t_operation.
*********************************************************************************************
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = w_data-material
IMPORTING
output = w_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
*********************************************************************************************
w_methods-refnumber = refno. "'000001'.
w_methods-objecttype = 'COMPONENT'.
w_methods-method = 'CREATE'.
w_methods-objectkey = key."'%00000000001'.
APPEND w_methods TO t_methods.
CLEAR w_methods.
*********************************************************************************************
w_component-activity = w_data-activity_c. "'0010'.
w_component-material = w_matnr.
w_component-requirement_quantity = w_data-req_qty. "2
w_component-requirement_quantity_unit = w_data-uom. "M3
w_component-item_cat = w_data-item_cat. "L
APPEND w_component TO t_component.
*********************************************************************************************
w_methods-refnumber = refno."'000001'.
w_methods-objecttype = ''.
w_methods-method = 'SAVE'.
w_methods-objectkey = key."'%00000000001'.
APPEND w_methods TO t_methods.
CLEAR w_methods.
*********************************************************************************************
ADD 1 TO seqno.
ADD 1 TO refno.
clear w_component.
clear w_operation.
clear w_header.
ENDLOOP.
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = t_methods
it_header = t_header
it_operation = t_operation
it_component = t_component
return = t_return
et_numbers = t_number
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
* IMPORTING
* RETURN = t_return
.
2013 Jan 09 12:59 PM
Hi Shravan,
Please include the 'BAPI_ALM_ORDER_MAINTAIN' & BAPI_TRANSACTION_COMMIT inside the loop for creating multiple work orders.
Thanks,
Tooshar Bendale
2013 Jan 09 1:18 PM
2013 Jan 10 4:51 AM
Hi Tooshar Bendale,
I know that to keep that in a loop. my question is why this header is in tables as there will be single entry for one order. Anyways thanks for your reply but i finished this long time ago.
2013 Jan 10 5:33 AM
Hi Shravan,
For mass uploading purpose "HEADER" is available in Tables.
take Example of Material Master .
if you Create/Change a Material using "BAPAI_MATERIAL_SAVEDATA" , here operation is 1:1 ration so "HEADER" is available in Import Parameter.
but when u go for Mass Uploading then we use "BAPI_MATERIAL_SAVEREPLICA " , here Many:Many ration so "HEADER" is available in Tables .
Regard's
Smruti