25/06/2015
ABAP Change settlement rules on IW31 or IW32 save Code Gallery SCN Wiki
Getting Started Newsletters
Welcome, Guest
Login
Register
Search the Community
Products
Services & Support
About SCN
Downloads
Industries
Training & Education
Partnership
Developer Center
Lines of Business
University Alliances
Events & Webinars
Innovation
Store
Code Gallery
ABAP Change settlement rules on IW31 or IW32 save Added by Guest, last edited by Manish Kumar on Jun 18, 2013 Author: Danni Cullen Submitted: 14.03.2011 Related Links: None This code demonstrates how to update settlement rules when saving IW31/IW32. It was created in the 'AT_SAVE' method of BAdI 'WORKORDER_UPDATE'.
METHOD if_ex_workorder_update~at_save. *‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐* * Data declarations *‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐* * Types types: begin of ty_cobra_buf. include type cobra. types: uflag type dkobr‐upd_flag. types: end of ty_cobra_buf. types: ty_t_cobra_buf type standard table of ty_cobra_buf. types: begin of ty_cobrb_buf. include type cobrb. types: uflag type dkobr‐upd_flag. types: end of ty_cobrb_buf. types: ty_t_cobrb_buf type standard table of ty_cobrb_buf. * Internal tables and work areas DATA: lt_cobra TYPE STANDARD TABLE OF cobra, ls_cobra type cobra, lt_cobrb TYPE STANDARD TABLE OF cobrb, ls_cobrb TYPE cobrb, lt_objnr type standard table of IONRB, lt_mem_cobrb type ty_t_cobrb_buf, ls_mem_cobrb type ty_cobrb_buf, lt_mem_cobra type ty_t_cobra_buf, ls_mem_cobra type ty_cobra_buf. * Variables data: l_tabix type sy‐tabix. *‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐* * Main processing *‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐* * Set the objnr value of settlement rules to be modified append is_header_dialog‐objnr to lt_objnr. * Clear old memory refresh lt_mem_cobra.
http://wiki.scn.sap.com/wiki/display/Snippets/ABAP++Change+settlement+rules+on+IW31+or+IW32+save
1/3
25/06/2015
ABAP Change settlement rules on IW31 or IW32 save Code Gallery SCN Wiki
refresh lt_mem_cobrb. export l_mem_cobra from lt_mem_cobra l_mem_cobrb from lt_mem_cobrb to memory id 'K_SRULE'. CALL FUNCTION 'K_SRULE_PRE_READ' TABLES T_SENDER_OBJNR = lt_objnr EXCEPTIONS WRONG_PARAMETERS = 1 OTHERS = 2 . IF SY‐SUBRC <> 0. *****Add error handling here ENDIF. CALL FUNCTION 'K_SETTLEMENT_RULE_GET' EXPORTING objnr = is_header_dialog‐objnr TABLES e_cobra = lt_cobra e_cobrb = lt_cobrb EXCEPTIONS NOT_FOUND = 1 OTHERS = 2. IF sy‐subrc <> 0. *****Add error handling here ENDIF. * Save settlement rule in ABAP‐Memory call function 'K_SRULE_EXPORT_IMPORT' EXPORTING i_mode = 'EX' EXCEPTIONS wrong_mode = 1 others = 2. if sy‐subrc ne 0. *****Add error handling here endif. * Read ABAP‐Memory import l_mem_cobra to lt_mem_cobra l_mem_cobrb to lt_mem_cobrb from memory id 'K_SRULE'. * Manipulate data LOOP AT lt_mem_cobrb INTO ls_mem_cobrb. l_tabix = sy‐tabix. CALL METHOD zcl_common_methods=>get_ctr_wbs_mapping EXPORTING i_kostl = ls_mem_cobrb‐kostl i_datum = sy‐datum RECEIVING e_posid = ls_mem_cobrb‐ps_psp_pnr. ls_mem_cobrb‐uflag = 'U'. “Important – this needs to be set to ‘U’ modify lt_mem_cobrb from ls_mem_cobrb index l_tabix. ENDLOOP. * Clear internal buffer call function 'K_SETTLEMENT_RULE_REFRESH' EXPORTING objnr = is_header_dialog‐objnr. * Fill the settlement tules with new values CALL FUNCTION 'K_SETTLEMENT_RULE_FILL' TABLES i_cobra = lt_mem_cobra i_cobrb = lt_mem_cobrb. * Fill ABAP‐Memory with new rules export l_mem_cobra from lt_mem_cobra l_mem_cobrb from lt_mem_cobrb to memory id 'K_SRULE'.
http://wiki.scn.sap.com/wiki/display/Snippets/ABAP++Change+settlement+rules+on+IW31+or+IW32+save
2/3
25/06/2015
ABAP Change settlement rules on IW31 or IW32 save Code Gallery SCN Wiki
* Fill internal buffer with new rules call function 'K_SRULE_EXPORT_IMPORT' EXPORTING i_mode = 'IM' EXCEPTIONS wrong_mode = 1 others = 2. if sy‐subrc ne 0. ****Add error handling here endif. * Save new rules call function 'K_SETTLEMENT_RULE_SAVE' EXPORTING dialog = 'X' objnr = is_header_dialog‐objnr i_status_update = ' ' EXCEPTIONS no_rule_for_objnr = 1 others = 2. if sy‐subrc ne 0. *****Add error handling here endif. * Commit work commit work. ENDMETHOD. abap Contact Us Privacy
SAP Help Portal Terms of Use
Legal Disclosure
Copyright
http://wiki.scn.sap.com/wiki/display/Snippets/ABAP++Change+settlement+rules+on+IW31+or+IW32+save
pm
iw31
iw32
settlement
rules
Follow SCN
3/3