This rule in itself won't lock you out since it only causes some traffic to be accepted.
It is the right rule to allow traffic to port YYY. Make sure that there isn't an earlier rule that would block all traffic (rules are processed in order, the first match applies). Run
iptables -nvL INPUT to list the input rules.
INPUT is the name of the chain (i.e. a list of rules) that is applied to incoming packets.
You'll presumably a REJECT rule coming after this one to reject other incoming traffic. This is where you need to be careful. Set some firewall ports to only accept local network connections? contains an example of a firewall setting that should be suitable (but use at your own risk, I won't go and reset your server if you get locked out).
Make sure that you don't block output from the server; for a simple configuration, just leave output unrestricted.
To avoid getting locked out, a trick is to put a command to reset the firewall to wide open on a timer, e.g.
sleep 300; iptables -I INPUT -j accept
I recommend doing this from inside screen or tmux. If you do that directly from the ssh connection, there's a risk that the command you run will try to output something and fail because its terminal isn't available anymore.
Note that there is no security benefit in putting SSH on a non-standard port: it won't make SSH less prone to attacks. The only advantage is that you'll have fewer scanning attacks, so less flooding of your logs.