*&---------------------------------------------------------------------* *& Form RESILIATION *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM resiliation .
DATA: xnotice TYPE TABLE OF bapi_re_cn_notice_dat, ls_notice LIKE LINE OF xnotice.
DATA: xreturn TYPE TABLE OF bapiret2, ls_return LIKE LINE OF xreturn.
DATA: l_tabix LIKE sy-tabix, l_error(1).
CLEAR ls_result.
LOOP AT xresult INTO ls_result.
IF ls_result-id = '@0A@'. CLEAR ls_result. CONTINUE. ENDIF.
l_tabix = sy-tabix.
CLEAR: xnotice[], xreturn[].
ls_notice-notice_number = '0001'. ls_notice-notice_subject = 'C'. ls_notice-notice_is_active = 'X'. ls_notice-notice_date = ls_result-notice_date. ls_notice-notice_receipt_date = ls_result-notice_receipt_date. ls_notice-notice_reason = ls_result-notice_reason. ls_notice-notice_reason_rejection = '00'. ls_notice-notice_request_date = ls_result-notice_request_date.
APPEND ls_notice TO xnotice.
CALL FUNCTION 'BAPI_RE_NOTICE_CREATE' EXPORTING compcode = p_bukrs contractnumber = ls_result-recnnr TABLES notice = xnotice return = xreturn.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.
DELETE xreturn WHERE type = 'W' OR type = 'I'.
* On fait un Sort pour avoir les 'E' en premier. SORT xreturn BY type DESCENDING.
LOOP AT xreturn INTO ls_return.
IF ls_return-type = 'E'. l_error = c_x. ENDIF.
* Ici c'est pour tous les cas avec une ligne erronée IF l_error = c_x. ls_result-id = '@0A@'. ENDIF.
IF sy-tabix = 1. ls_result-type = ls_return-type. ls_result-message = ls_return-message. APPEND ls_result TO xresult_f. ELSE.
CLEAR: ls_result-notice_date, ls_result-notice_receipt_date, ls_result-notice_reason, ls_result-notice_request_date.
ls_result-type = ls_return-type. ls_result-message = ls_return-message.
APPEND ls_result TO xresult_f.
ENDIF. ENDLOOP.
CLEAR: ls_result.
ENDLOOP.
CLEAR: xresult[].
xresult[] = xresult_f[].
ENDFORM. " RESILIATION
|