To create Settlement Rules via ABAP use the K_SRULE_SAVE_UTASK function module. View code:
| DATA: t_prps TYPE TABLE OF prps, wa_prps TYPE prps, t_cobrb TYPE TABLE OF cobrb, wa_cobrb TYPE cobrb. "Select WBS Elements SELECT * FROM prps INTO TABLE t_prps WHERE psphi EQ im_projectdefinition-pspnr. LOOP AT t_prps INTO wa_prps. wa_cobrb-objnr = im_projectdefinition-objnr. ADD 1 TO wa_cobrb-lfdnr.
*** USE THE CONVERSION EXITS !!! CALL FUNCTION 'CONVERSION_EXIT_PERBZ_INPUT' EXPORTING input = 'PER' IMPORTING output = wa_cobrb-perbz. CALL FUNCTION 'CONVERSION_EXIT_OBART_INPUT' EXPORTING input = 'PEP' IMPORTING output = wa_cobrb-konty EXCEPTIONS not_found = 1 OTHERS = 2. IF sy-subrc NE 0. ENDIF. wa_cobrb-prozs = '100.00'. wa_cobrb-kokrs = wa_prps-pkokr. wa_cobrb-bukrs = wa_prps-pbukr. wa_cobrb-ps_psp_pnr = wa_prps-pspnr. wa_cobrb-rec_objnr1 = wa_prps-objnr. APPEND wa_cobrb TO t_cobrb. ENDLOOP.
"Create Settlement Rule CALL FUNCTION 'K_SRULE_SAVE_UTASK' TABLES t_cobrb_insert = t_cobrb EXCEPTIONS srule_utask_error = 1 OTHERS = 2. IF sy-subrc NE 0. "Implement suitable error handling here ENDIF. |
This code can be used in Z report program or in BADI PROJECTDEF_UPDATE.
Best Regards,
Rodrigo Abreu Costa
@digoabreu
Galo Doido!