I have this requirement to assign a number range to billing document based on below conditions:
1. IF ( region code at Header Level is same as region code at Item Level ) AND ( Account Assignment Group is '08' ), then a new number range to billing document. ( Ex: KAA9000000 - KAA9999999 )
2. Otherwise, the already used number range will be taken. ( Ex: KAA8400000 - KAA8499999 )
In both the cases, the prefix will be same.
The problem is there are already so many enhancements, and the Number Range FM is NUMBER_GET_NEXT. This FM picks from and updates to NRIV table. Below is the code in FM. Now, what I need is to put a condition before in the select statement.
IF i_gst_odn EQ 'X'. SELECT * FROM j_1ig_ofnum INTO TABLE lt_j1ig_ofnum WHERE bukrs = i_bukrs AND bupla = i_bupla AND docclass = i_docclass AND ( VALIDFROM <= i_PostDate and VALIDTO >= i_PostDate ) ORDER BY PRIMARY KEY. IF sy-subrc EQ 0. ***Sort the number range configuration table in descending order by fromdate "2535105 SORT lt_j1ig_ofnum BY validfrom DESCENDING. "2535105 ** LOOP AT lt_j1ig_ofnum into wa_j1ig_ofnum. READ TABLE lt_j1ig_ofnum INTO wa_j1ig_ofnum INDEX 1. "2490434 IF sy-subrc EQ 0. "2490434 CLEAR:wa_ofnum_tw_2,lv_from_number. MOVE-CORRESPONDING wa_j1ig_ofnum TO wa_ofnum_tw_2. SELECT SINGLE * FROM nriv INTO wa_nriv WHERE object = gst_nr_object AND subobject = wa_ofnum_tw_2-subobject AND nrrangenr = wa_ofnum_tw_2-groupnumber AND toyear = i_gjahr. lv_from_number = wa_nriv-nrlevel+10(10). IF lv_from_number < wa_nriv-tonumber. CALL FUNCTION 'NUMBER_GET_NEXT' EXPORTING object = gst_nr_object subobject = wa_ofnum_tw_2-subobject nr_range_nr = wa_ofnum_tw_2-groupnumber toyear = i_gjahr "2490434 IMPORTING number = lv_gst_number returncode = lv_retcode EXCEPTIONS interval_not_found = 1 number_range_not_intern = 2 object_not_found = 3 quantity_is_0 = 4 quantity_is_not_1 = 5 interval_overflow = 6 OTHERS = 7.