Skip to Content
0

parlel processing for creating order(iw31) using BAPI

Jan 05 at 07:47 AM

52

avatar image
Former Member

Hi Guys,

Tried to create order(IW31) through parlel processing but could not able to create it.

Could able to create service order with out using parlel processing.

Kindly help me to create same through parlel processing.

Pasted my code below.

DATA:lt_ret TYPE TABLE OF bapiret2,
gt_ret TYPE TABLE OF bapiret2.
DATA:gv_callback TYPE char1,
gv_error TYPE char1,
gv_finish TYPE i.

DATA:lt_methods TYPE TABLE OF BAPI_ALM_ORDER_METHOD,
ls_methods TYPE BAPI_ALM_ORDER_METHOD,
lt_header TYPE TABLE OF BAPI_ALM_ORDER_HEADERS_I,
ls_header TYPE BAPI_ALM_ORDER_HEADERS_I,
lt_headerx TYPE TABLE OF BAPI_ALM_ORDER_HEADERS_UP,
ls_headerx TYPE BAPI_ALM_ORDER_HEADERS_UP,
lt_operation TYPE TABLE OF BAPI_ALM_ORDER_OPERATION,
ls_operation TYPE BAPI_ALM_ORDER_OPERATION,
lt_operationx TYPE TABLE OF BAPI_ALM_ORDER_OPERATION_UP,
ls_operationx TYPE BAPI_ALM_ORDER_OPERATION_UP.

DATA lv_temp TYPE char12.
DATA lv_time TYPE i VALUE '3'.

DATA:lv_total TYPE i,
lv_avail TYPE i,
lv_taskid TYPE char8.



DO 5 TIMES.

lv_temp = |DL000Z02EVB| && sy-index.

ls_methods-refnumber = '000001'.
ls_methods-objecttype = 'HEADER'.
ls_methods-objectkey = lv_temp.
ls_methods-method = 'CREATE'.
APPEND ls_methods TO lt_methods.

ls_methods-refnumber = '000001'.
ls_methods-objecttype = 'OPERATION'.
ls_methods-objectkey = lv_temp.
ls_methods-method = 'CREATE'.
APPEND ls_methods TO lt_methods.

ls_methods-refnumber = '000001'.
ls_methods-objecttype = ''.
ls_methods-objectkey = lv_temp.
ls_methods-method = 'SAVE'.
APPEND ls_methods TO lt_methods.



ls_header-ORDERID = lv_temp.
ls_header-ORDER_TYPE = 'ZMM1'.
ls_header-planplant = 'IN01'.
ls_header-MN_WK_CTR = 'IN01-M51'.
ls_header-plant = 'IN01'.
ls_header-maintplant = 'IN01'.
ls_header-equipment = '21454926'.
UNPACK ls_header-equipment TO ls_header-equipment.
ls_header-FUNCT_LOC = 'USSYSCITA2PP86'.
ls_header-PMACTTYPE = 'RQ'.
ls_header-serialno = 'G06UPS673M'.
ls_header-material = '186015005'.
ls_header-start_date = sy-datum.
ls_header-finish_date = sy-datum + 365.
APPEND ls_header TO lt_header.



ls_operation-activity = '0010'.
ls_operation-control_key = 'SM01'.
ls_operation-work_cntr = 'IN01-M51'.
ls_operation-plant = 'IN01'.
ls_operation-description = 'testing'.
ls_operation-quantity = 1.
ls_operation-calc_key = 1.
ls_operation-acttype = 'SRC'.
APPEND ls_operation TO lt_operation.

DATA(lv_index) = sy-index.
CLear lv_taskid.
lv_taskid = |task| && lv_index.

CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
STARTING NEW TASK lv_taskid
DESTINATION IN GROUP DEFAULT
PERFORMING f_read_bapiret ON END OF TASK
TABLES
it_methods = lt_methods
IT_HEADER = lt_header
IT_OPERATION = lt_operation
RETURN = lt_ret .

ENDDO.

WAIT UNTIL gv_callback = 'X'.

IF gv_error = `X`.
WRITE gv_error.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
*
WAIT UNTIL gv_finish = lv_avail.

if gt_ret IS NOT INITIAL.
DATA lo_alv TYPE REF TO cl_salv_table.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = gt_ret
).

lo_alv->display( ).
ELSE.
WRITE: gv_finish.
ENDIF.



FORM f_read_bapiret USING task_id TYPE clike.

* RECEIVE results from the asynch-RFC(aRFC)
add 1 to gv_finish.

* Read BAPIRET & check error message
READ TABLE lt_ret Into DATA(ls_ret) WITH KEY type = `E`.
IF sy-subrc = 0.
* Set the callback flag
gv_callback = `X`.
gv_error = `X`.
RETURN.
ENDIF.
APPEND LINES OF lt_ret TO gt_ret.

* Set the callback flag
gv_callback = `X`.
ENDFORM.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Raymond Giuseppi
Jan 05 at 10:31 AM
1

The COMMIT must be executed in same LUW than the BAPI call...

Hint: easiest solution, build a wrapper for BAPI call + LOOP AT RETURN + COMMIT or ROLLBACK.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 09 at 02:29 AM
0

1. Call Function "SPBT_INITIALIZE" to check free work processors

Based on data volume and free work process determine how many work processors need to generate

2. Create a RFC function module to start new task. Call Function "ZFM_XXXX" STARTING NEW TASK lv_task(Create task with increment number like Are_Work_Order_<1>) performing "callback_form" on END OF TASK.

call bapi in function module with commit work.

3. Create Form and enform.

Form callback_form.

RECEIVE RESULTS FROM FUNCTION "ZFM_XXXX"

endform

Note Refer Syntax

Syntax

CALL FUNCTION func STARTING NEW TASK task
[DESTINATION {dest|{IN GROUP {group|DEFAULT}}}]
[{CALLING meth}|{PERFORMING subr} ON END OF TASK]
parameter_list.

Share
10 |10000 characters needed characters left characters exceeded