S 9912290449 00005941^B{TT} D S 9912290450 00005941^B{TT} R S 9912290451 00005941^B{TT} D But I want to print only the statemtents which has 'D' and its above line. Yhe output should be something like this S 9912290449 00005941^B{TT} D S 9912290451 00005941^B{TT} D