USE TABLES VTTP,VBFA.
USE INTERNAL TABLES I_VTTP,I_VBFA
For each record in I_VTTP table:
Select highest number of VBELN into wa_VBELN from VBFA table
Where VBELV = I_VTTP-VBELN
And VBTYP_N = M
And VTTYP_V = J.
Append WA_VBELN TO I_VBFA.
Concatenate Invoice Num : to WA_VBFA_STR(type string)and for every range in I_VBFA table concatenate From"Min Value(Current range) to Max Value(Current range) into WA_VBFA_STR
For example: If I_VBFA contains 1001, 1002, 1004,1006,1007,1008(you need to consider a continous range of invoice numbers since there is a break after 1002 thus write 1004 as it is) then you need to print as it is below :
Invoice Num: From 1001 to 1002, 1004, From 1006 to 1008.