Hi S SB
This can be done by simply transforming steps mentioned by you into macro code. I do no think this is case of nested IF conditioning.
Please start writing new macro
Create Step having required number iterations
Add Control Statement
Add Condition (add operator as part of condition )
Add Row from Planning Table
Add Control Statement and So on...
Refer SAP Help on Macros.
Hope this will help
Thank you
Satish Waghmare