Loop:

SEROUT2 TXPIN, BAUD, ["AT+CMGF=1",13] (here you call for a sms)

SERIN2 RXPIN, BAUD,5000,Loop, [wait("^SMGR:"),str Data\5 ( Here you wait for the answer "^SMGR:" data[1] and data[4] are zero then no sms are present so you return to loop)

if Data[1]=48 and Data[4]=48 then Loop

SERIN2 RXPIN, BAUD,5000,NoSms, [wait("XYZ"),str Data\9] ( here you have skipped the if statement, so you have a sms , you wait for "XYZ" which is your password to be sure is your massage . following your pass you should write the coding massage. Remember to write a couple of word [any things you like minimum 10 characters] at the beginning of your massage. Any sms received that does not contain your pass will be ignored)

do here your decoding and actions

NoSms:'remove SMS

SEROUT2 TXPIN, BAUD, ["AT+CMGD=1",13] (Here you delete from phone memory the received sms)
Pause 1000
goto Loop

Hope to have cleared

Alberto