Practically it occurs when there are dealings relating to trade receivables & trade payables with foreign countries..
Suppose you sold certain goods/ services to foreign country & the USD vs INR changes or other currency changes then there can be gain or profit due to currency fluctuation.
Since profit / the loss is on account of foreign currency transactions , it can be credited or debited to P & L through foreign exchange gain or loss ledger
There are many foreign currencies like USD , €,¥, S$, Chinese Dollar etc .If Indian entities have dealings with foreign entities and the invoice amount is in foreign currency then only these foreign exchange gain or loss occurs relating to trade payables or receivables.
If the invoice is in Rupees then there won't be any gain or loss even if there is dealings with foreign country