Receiving SMS in Arduino ( AT Commands)

char inchar; 


 int led1 =11;
 int led2 = 12;
 int led3 = 13;

 void setup()
 {

 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 pinMode(led3, OUTPUT);
 digitalWrite(led1, LOW);
 digitalWrite(led2, LOW);
 digitalWrite(led3, LOW);
 Serial.begin(9600);
 delay(3000); 
 Serial.println("AT+CMGF=1\r"); 
 delay(200);
 Serial.println("AT+CSMS=1\r"); 
 delay(200);
 Serial.println("AT+CNMI=2,2,0,0,0"); 
 delay(200);
 }
 void loop() 
 {
 if(Serial.available() >0)
 {  

 delay(10);
 inchar=Serial.read(); 
 if (inchar=='0')   
 {     
      
       inchar=Serial.read(); 
       if (inchar=='#')
       {
             inchar=Serial.read(); 
             if (inchar=='0')
             {
                 digitalWrite(led1, LOW);
             } 
             else if (inchar=='1')
             {
                 digitalWrite(led1, HIGH);
                 
             }
             
        delay(10);
             inchar=Serial.read(); 
             if (inchar=='0')
             {
                 digitalWrite(led2, LOW);
             } 
             else if (inchar=='1')
             {
                 digitalWrite(led2, HIGH);
                
             }
             
       delay(10);
             inchar=Serial.read(); 
             if (inchar=='0')
             {
                 digitalWrite(led3, LOW);
             } 
             else if (inchar=='1')
             {
                 digitalWrite(led3, HIGH);
             }      
       } 
       }
Serial.println("AT+CMGD=1,4");
     } 
     
   }

When I use AT+CMGD command the code gets compiled but the messages are not deleted. What is the error?

What is the error?

The phone told you. Too bad you didn't read the response. Too bad you have the phone connected to the hardware serial port. Makes debugging a real challenge.

Sorry , I am not able to understand. Could you explain it a bit??.
I am using Sim900 Module.