Hi,
Instead of using select in loop everytime in your case2, can you get the details of matnr, mtart, imatn, mrfpn when you actually fill lt_mara table from mara and then check in internal table and consider only the required?
Or if MRFPN is constant value which you should look in MARA, you can do as below in the sample code.
types : begin of ty,
pernr type pa0000-pernr,
end of ty.
data itab type standard table of ty.
data wa type ty.
data lv_pernr(8) type c.
lv_pernr = '000000%'.
select pernr from pa0000 into table itab where pernr like lv_pernr.
loop at itab into wa.
write :/ wa-pernr.
endloop.