39 Replies Latest reply: Jun 20, 2006 9:02 AM by Craig Cmehil RSS

calling php functions from sap

Kumar garg
Currently Being Moderated

hi all,

   I have to call the php functions from the r/3. my requirement is that I have to read the mail from the internet adress(ashish@yahoo.com) through php and then send its content in r/3.For that I have to write function in php which are rfc enabled and then call those function in r/3. Can anyone help me in calling the php function from r/3 and how to get the content of mail in r/3.I have to create php as a server and r/3 as client.

regards

ashish

  • Re: calling php functions from sap
    Anton Wenzelhuemer
    Currently Being Moderated

    hi there,

     

    if you've got a more recent release of WAS ABAP (6.40+) you can easily do your task by creating a webservice in PHP and a webservice client in ABAP.

     

    This simple <a href="/people/anton.wenzelhuemer/blog/2006/03/05/integrating-php-and-abap-using-webservices of mine might help you to accomplish your task.

     

    regards,

    anton

    • Re: calling php functions from sap
      Kumar garg
      Currently Being Moderated

      hi anton,

           I am new to php so I am not able to use your blog . I want to know that how we register the functions of php to call them in sap.

      regards

      ashish

      • Re: calling php functions from sap
        Anton Wenzelhuemer
        Currently Being Moderated

        ouch. that hurts. I thought it couldn't be any simpler than the example shown in the blog.

         

        Hwever, server.php Warning: RFC Error Info you can find some discussion about it as well as some simplified version of it (at least I think so ).

         

        If that doesn't help, I suppose you got to learn just a little bit of PHP first.

         

        regards,

        anton

        • Re: calling php functions from sap
          Alvaro Tejada Galindo
          Currently Being Moderated

          > ouch. that hurts. I thought it couldn't be any

          > simpler than the example shown in the blog.

           

          Hehehe...Yeah...It hurts -:P You're blog is great Anton but I don't think is recommended for a PHP newbie -;) Even I'm a newbie to WebServices -:'(

           

          I think that you can read my blog <a href="/people/alvaro.tejadagalindo/blog/2006/05/17/tasting-the-mix-of-php-and-sap--volume-5">/people/alvaro.tejadagalindo/blog/2006/05/17/tasting-the-mix-of-php-and-sap--volume-5</a> It's a SBWP Emulation...That can give and idea of how to send the Yahoo content to the SAP Mail -;)

           

          Greetings,

           

          Blag.

          • Re: calling php functions from sap
            Anton Wenzelhuemer
            Currently Being Moderated

            Alvaro!

             

            This is the whole PHP script for the server:

             

            [code]<?

             

            function ZtwFub1($name) {

                 return (array(POut => "PHP says: Hello " . $name->PIn . "!"));

            }

             

            $server = new SoapServer("soapserver1.wsdl");

            $server->addFunction("ZtwFub1");

            $server->handle();

             

            ?>

             

            [/code]

             

            Maybe the WSDL is difficult to understand, the script definitely is not.

            I think in a service oriented world we all should be able to roughly understand a trivial WSDL. At least us developers or consultants familiar with actual code.

             

            regards,

            anton

             

            btw, of course your blog serves as a good example too.

            • Re: calling php functions from sap
              Alvaro Tejada Galindo
              Currently Being Moderated

              You're right Anton...The code is fair easy to understand -;) But I just never used WebServices -:'( Shame on me -:(

               

              Greetings,

               

              Blag.

            • Re: calling php functions from sap
              Kumar garg
              Currently Being Moderated

              hi Anton,

              I have get have to read the read the internert mail in php hrough this class . I am sending you that code test_pop3.php. For this you even need pop3 class. I am  even sending you that code.It will be better if you give me your mail id. But I donot know how to create a rfc enabled function in php that can be read in r/3 .

              <?php

              /*

               

              • test_pop3.php

              *

               

              • @(#) $Header: /home/mlemos/cvsroot/pop3/test_pop3.php,v 1.6 2005/10/18 17:44:46 mlemos Exp $

              *

              */

               

              ?><HTML>

              <HEAD>

              <TITLE>Read email attachments from pop3 server</TITLE>

              </HEAD>

              <BODY>

              <?php

               

                   require("pop3.php");

               

                /* Uncomment when using SASL authentication mechanisms */

                   /*

                   require("sasl.php");

                   */

               

                   $pop3=new pop3_class;

                   $pop3->hostname="";             /* POP 3 server host name                      */

                   $pop3->port=110;                         /* POP 3 server host port                      */

                   $user="";          /* Authentication user name                    */

                   $password="";                    /* Authentication password                     */

                   $pop3->realm="";                         /* Authentication realm or domain              */

                   $pop3->workstation="";                   /* Workstation for NTLM authentication         */

                   $apop=0;                                 /* Use APOP authentication                     */

                   $pop3->authentication_mechanism="USER";  /* SASL authentication mechanism               */

                   $pop3->debug=0;                          /* Output debug information                    */

                   $pop3->html_debug=0;                     /* Debug information is in HTML                */

                   $pop3->join_continuation_header_lines=1; /* Concatenate headers split in multiple lines */

               

                   if(($error=$pop3->Open())=="")

                   {

                        echo "<PRE>Connected to the POP3 server "".$pop3->hostname."".</PRE>\n";

                        if(($error=$pop3->Login($user,$password,$apop))=="")

                        {

                             echo "<PRE>User "$user" logged in.</PRE>\n";

                             if(($error=$pop3->Statistics($messages,$size))=="")

                             {

                                  echo "<PRE>There are $messages messages in the mail box with a total of $size bytes.</PRE>\n";

                                  $result=$pop3->ListMessages("",0);

                                  if(GetType($result)=="array")

                                  {

                                       for(Reset($result),$message=0;$message<count($result);Next($result),$message++)

                                            echo "<PRE>Message ",Key($result)," - ",$result[Key($result)]," bytes.</PRE>\n";

                                       $result=$pop3->ListMessages("",1);

                                       if(GetType($result)=="array")

                                       {

                                            for(Reset($result),$message=0;$message<count($result);Next($result),$message++)

                                                 echo "<PRE>Message ",Key($result),", Unique ID - \"",$result[Key($result)],"\"</PRE>\n";

                                            if($messages>0)

                                            {

                                                      $var = 1;     

                                                 if(($error=$pop3->RetrieveMessage($var,$headers,$body,-1))=="")

                                                      for($line=0;$line<count($headers);$line++)

                                                 {

                                                  

                                                 }

                                            }

               

                                                                 

                                                 if(($error=$pop3->RetrieveMessage(34,$headers,$body,-1))=="")

                                                 {

                                                      echo "<PRE>Message 1:\n-Message headers starts below-</PRE>\n";

                                                      for($line=0;$line<count($headers);$line++)

                                                           echo "<PRE>",HtmlSpecialChars($headers[$line]),"</PRE>\n";

                                                           echo "<PRE>-Message headers ends above-\n-Message body starts below-</PRE>\n";

                                                      for($line=0;$line<count($body);$line++)

                                                           echo "<PRE>",HtmlSpecialChars($body[$line]),"</PRE>\n";

                                                      echo "<PRE>-Message body ends above-</PRE>\n";

                                                      if(($error=$pop3->DeleteMessage(1))=="")

                                                      {

                                                           echo "<PRE>Marked message 1 for deletion.</PRE>\n";

                                                           if(($error=$pop3->ResetDeletedMessages())=="")

                                                           {

                                                                echo "<PRE>Resetted the list of messages to be deleted.</PRE>\n";

                                                           }

                                                      }

                                                 }

                                            }

                                            if($error==""

                                            && ($error=$pop3->Close())=="")

                                                 echo "<PRE>Disconnected from the POP3 server "".$pop3->hostname."".</PRE>\n";

                                             

                                       }

                                       else

                                            $error=$result;

                                  }

                                  else

                                       $error=$result;

                             }

                        }

                   }

                   if($error!="")

                        echo "<H2>Error: ",HtmlSpecialChars($error),"</H2>";

              ?>

               

              </BODY>

              </HTML>

               

              *******start of new php file********

              <?php

              /*

               

              • pop3.php

              *

               

              • @(#) $Header: /home/mlemos/cvsroot/pop3/pop3.php,v 1.15 2005/10/18 17:43:25 mlemos Exp $

              *

              */

               

              class pop3_class

              {

                   var $hostname="";

                   var $port=110;

                   var $quit_handshake=0;

                   var $error="";

                   var $authentication_mechanism="USER";

                   var $realm="";

                   var $workstation="";

                   var $join_continuation_header_lines=1;

               

                   /* Private variables - DO NOT ACCESS */

               

                   var $connection=0;

                   var $state="DISCONNECTED";

                   var $greeting="";

                   var $must_update=0;

                   var $debug=0;

                   var $html_debug=0;

                   var $next_token="";

               

                   /* Private methods - DO NOT CALL */

               

                   Function Tokenize($string,$separator="")

                   {

                        if(!strcmp($separator,""))

                        {

                             $separator=$string;

                             $string=$this->next_token;

                        }

                        for($character=0;$character<strlen($separator);$character++)

                        {

                             if(GetType($position=strpos($string,$separator[$character]))=="integer")

                                  $found=(IsSet($found) ? min($found,$position) : $position);

                        }

                        if(IsSet($found))

                        {

                             $this->next_token=substr($string,$found+1);

                             return(substr($string,0,$found));

                        }

                        else

                        {

                             $this->next_token="";

                             return($string);

                        }

                   }

               

                   Function SetError($error)

                   {

                        return($this->error=$error);

                   }

               

                   Function OutputDebug($message)

                   {

                        $message.="\n";

                        if($this->html_debug)

                             $message=str_replace("\n","<br />\n",HtmlEntities($message));

                        echo $message;

                        flush();

                   }

               

                   Function GetLine()

                   {

                        for($line="";;)

                        {

                             if(feof($this->connection))

                                  return(0);

                             $line.=fgets($this->connection,100);

                             $length=strlen($line);

                             if($length>=2

                             && substr($line,$length-2,2)=="\r\n")

                             {

                                  $line=substr($line,0,$length-2);

                                  if($this->debug)

                                       $this->OutputDebug("S $line");

                                  return($line);

                             }

                        }

                   }

               

                   Function PutLine($line)

                   {

                        if($this->debug)

                             $this->OutputDebug("C $line");

                        return(fputs($this->connection,"$line\r\n"));

                   }

               

                   Function OpenConnection()

                   {

                        if($this->hostname=="")

                             return($this->SetError("2 it was not specified a valid hostname"));

                        if($this->debug)

                             $this->OutputDebug("Connecting to ".$this->hostname." ...");

                        if(($this->connection=@fsockopen($this->hostname,$this->port,$error))==0)

                        {

                             switch($error)

                             {

                                  case -3:

                                       return($this->SetError("-3 socket could not be created"));

                                  case -4:

                                       return($this->SetError("-4 dns lookup on hostname \"$hostname\" failed"));

                                  case -5:

                                       return($this->SetError("-5 connection refused or timed out"));

                                  case -6:

                                       return($this->SetError("-6 fdopen() call failed"));

                                  case -7:

                                       return($this->SetError("-7 setvbuf() call failed"));

                                  default:

                                       return($this->SetError($error." could not connect to the host \"".$this->hostname."\""));

                             }

                        }

                        return("");

                   }

               

                   Function CloseConnection()

                   {

                        if($this->debug)

                             $this->OutputDebug("Closing connection.");

                        if($this->connection!=0)

                        {

                             fclose($this->connection);

                             $this->connection=0;

                        }

                   }

               

                   /* Public methods */

               

                   /* Open method - set the object variable $hostname to the POP3 server address. */

               

                   Function Open()

                   {

                        if($this->state!="DISCONNECTED")

                             return($this->SetError("1 a connection is already opened"));

                        if(($error=$this->OpenConnection())!="")

                             return($error);

                        $this->greeting=$this->GetLine();

                        if(GetType($this->greeting)!="string"

                        || $this->Tokenize($this->greeting," ")!="+OK")

                        {

                             $this->CloseConnection();

                             return($this->SetError("3 POP3 server greeting was not found"));

                        }

                        $this->Tokenize("<");

                        $this->must_update=0;

                        $this->state="AUTHORIZATION";

                        return("");

                   }

               

                   /* Close method - this method must be called at least if there are any

                   messages to be deleted */

               

                   Function Close()

                   {

                        if($this->state=="DISCONNECTED")

                             return($this->SetError("no connection was opened"));

                        if($this->must_update

                        || $this->quit_handshake)

                        {

                             if($this->PutLine("QUIT")==0)

                                  return($this->SetError("Could not send the QUIT command"));

                             $response=$this->GetLine();

                             if(GetType($response)!="string")

                                  return($this->SetError("Could not get quit command response"));

                             if($this->Tokenize($response," ")!="+OK")

                                  return($this->SetError("Could not quit the connection: ".$this->Tokenize("\r\n")));

                        }

                        $this->CloseConnection();

                        $this->state="DISCONNECTED";

                        return("");

                   }

               

                   /* Login method - pass the user name and password of POP account.  Set

                   $apop to 1 or 0 wether you want to login using APOP method or not.  */

               

                   Function Login($user,$password,$apop=0)

                   {

                        if($this->state!="AUTHORIZATION")

                             return($this->SetError("connection is not in AUTHORIZATION state"));

                        if($apop)

                        {

                             if(!strcmp($this->greeting,""))

                                  return($this->SetError("Server does not seem to support APOP authentication"));

                             if($this->PutLine("APOP $user ".md5("<".$this->greeting.">".$password))==0)

                                  return($this->SetError("Could not send the APOP command"));

                             $response=$this->GetLine();

                             if(GetType($response)!="string")

                                  return($this->SetError("Could not get APOP login command response"));

                             if($this->Tokenize($response," ")!="+OK")

                                  return($this->SetError("APOP login failed: ".$this->Tokenize("\r\n")));

                        }

                        else

                        {

                             $authenticated=0;

                             if(strcmp($this->authentication_mechanism,"USER")

                             && function_exists("class_exists")

                             && class_exists("sasl_client_class"))

                             {

                                  if(strlen($this->authentication_mechanism))

                                       $mechanisms=array($this->authentication_mechanism);

                                  else

                                  {

                                       $mechanisms=array();

                                       if($this->PutLine("CAPA")==0)

                                            return($this->SetError("Could not send the CAPA command"));

                                       $response=$this->GetLine();

                                       if(GetType($response)!="string")

                                            return($this->SetError("Could not get CAPA command response"));

                                       if(!strcmp($this->Tokenize($response," "),"+OK"))

                                       {

                                            for(;;)

                                            {

                                                 $response=$this->GetLine();

                                                 if(GetType($response)!="string")

                                                      return($this->SetError("Could not retrieve the supported authentication methods"));

                                                 switch($this->Tokenize($response," "))

                                                 {

                                                      case ".":

                                                           break 2;

                                                      case "SASL":

                                                           for($method=1;strlen($mechanism=$this->Tokenize(" "));$method++)

                                                                $mechanisms[]=$mechanism;

                                                           break;

                                                 }

                                            }

                                       }

                                  }

                                  $sasl=new sasl_client_class;

                                  $sasl->SetCredential("user",$user);

                                  $sasl->SetCredential("password",$password);

                                  if(strlen($this->realm))

                                       $sasl->SetCredential("realm",$this->realm);

                                  if(strlen($this->workstation))

                                       $sasl->SetCredential("workstation",$this->workstation);

                                  do

                                  {

                                       $status=$sasl->Start($mechanisms,$message,$interactions);

                                  }

                                  while($status==SASL_INTERACT);

                                  switch($status)

                                  {

                                       case SASL_CONTINUE:

                                            break;

                                       case SASL_NOMECH:

                                            if(strlen($this->authentication_mechanism))

                                                 return($this->SetError("authenticated mechanism ".$this->authentication_mechanism." may not be used: ".$sasl->error));

                                            break;

                                       default:

                                            return($this->SetError("Could not start the SASL authentication client: ".$sasl->error));

                                  }

                                  if(strlen($sasl->mechanism))

                                  {

                                       if($this->PutLine("AUTH ".$sasl->mechanism.(IsSet($message) ? " ".base64_encode($message) : ""))==0)

                                            return("Could not send the AUTH command");

                                       $response=$this->GetLine();

                                       if(GetType($response)!="string")

                                            return("Could not get AUTH command response");

                                       switch($this->Tokenize($response," "))

                                       {

                                            case "+OK":

                                                 $response="";

                                                 break;

                                            case "+":

                                                 $response=base64_decode($this->Tokenize("\r\n"));

                                                 break;

                                            default:

                                                 return($this->SetError("Authentication error: ".$this->Tokenize("\r\n")));

                                       }

                                       for(;!$authenticated;)

                                       {

                                            do

                                            {

                                                 $status=$sasl->Step($response,$message,$interactions);

                                            }

                                            while($status==SASL_INTERACT);

                                            switch($status)

                                            {

                                                 case SASL_CONTINUE:

                                                      if($this->PutLine(base64_encode($message))==0)

                                                           return("Could not send message authentication step message");

                                                      $response=$this->GetLine();

                                                      if(GetType($response)!="string")

                                                           return("Could not get authentication step message response");

                                                      switch($this->Tokenize($response," "))

                                                      {

                                                           case "+OK":

                                                                $authenticated=1;

                                                                break;

                                                           case "+":

                                                                $response=base64_decode($this->Tokenize("\r\n"));

                                                                break;

                                                           default:

                                                                return($this->SetError("Authentication error: ".$this->Tokenize("\r\n")));

                                                      }

                                                      break;

                                                 default:

                                                      return($this->SetError("Could not process the SASL authentication step: ".$sasl->error));

                                            }

                                       }

                                  }

                             }

                             if(!$authenticated)

                             {

                                  if($this->PutLine("USER $user")==0)

                                       return($this->SetError("Could not send the USER command"));

                                  $response=$this->GetLine();

                                  if(GetType($response)!="string")

                                       return($this->SetError("Could not get user login entry response"));

                                  if($this->Tokenize($response," ")!="+OK")

                                       return($this->SetError("User error: ".$this->Tokenize("\r\n")));

                                  if($this->PutLine("PASS $password")==0)

                                       return($this->SetError("Could not send the PASS command"));

                                  $response=$this->GetLine();

                                  if(GetType($response)!="string")

                                       return($this->SetError("Could not get login password entry response"));

                                  if($this->Tokenize($response," ")!="+OK")

                                       return($this->SetError("Password error: ".$this->Tokenize("\r\n")));

                             }

                        }

                        $this->state="TRANSACTION";

                        return("");

                   }

               

                   /* Statistics method - pass references to variables to hold the number of

                   messages in the mail box and the size that they take in bytes.  */

               

                   Function Statistics(&$messages,&$size)

                   {

                        if($this->state!="TRANSACTION")

                             return($this->SetError("connection is not in TRANSACTION state"));

                        if($this->PutLine("STAT")==0)

                             return($this->SetError("Could not send the STAT command"));

                        $response=$this->GetLine();

                        if(GetType($response)!="string")

                             return($this->SetError("Could not get the statistics command response"));

                        if($this->Tokenize($response," ")!="+OK")

                             return($this->SetError("Could not get the statistics: ".$this->Tokenize("\r\n")));

                        $messages=$this->Tokenize(" ");

                        $size=$this->Tokenize(" ");

                        return("");

                   }

               

                   /* ListMessages method - the $message argument indicates the number of a

                   message to be listed.  If you specify an empty string it will list all

                   messages in the mail box.  The $unique_id flag indicates if you want

                   to list the each message unique identifier, otherwise it will

                   return the size of each message listed.  If you list all messages the

                   result will be returned in an array. */

               

                   Function ListMessages($message,$unique_id)

                   {

                        if($this->state!="TRANSACTION")

                             return($this->SetError("connection is not in TRANSACTION state"));

                        if($unique_id)

                             $list_command="UIDL";

                        else

                             $list_command="LIST";

                        if($this->PutLine("$list_command".($message ? " ".$message : ""))==0)

                             return($this->SetError("Could not send the $list_command command"));

                        $response=$this->GetLine();

                        if(GetType($response)!="string")

                             return($this->SetError("Could not get message list command response"));

                        if($this->Tokenize($response," ")!="+OK")

                             return($this->SetError("Could not get the message listing: ".$this->Tokenize("\r\n")));

                        if($message=="")

                        {

                             for($messages=array();;)

                             {

                                  $response=$this->GetLine();

                                  if(GetType($response)!="string")

                                       return($this->SetError("Could not get message list response"));

                                  if($response==".")

                                       break;

                                  $message=intval($this->Tokenize($response," "));

                                  if($unique_id)

                                       $messages[$message]=$this->Tokenize(" ");

                                  else

                                       $messages[$message]=intval($this->Tokenize(" "));

                             }

                             return($messages);

                        }

                        else

                        {

                             $message=intval($this->Tokenize(" "));

                             $value=$this->Tokenize(" ");

                             return($unique_id ? $value : intval($value));

                        }

                   }

               

                   /* RetrieveMessage method - the $message argument indicates the number of

                   a message to be listed.  Pass a reference variables that will hold the

                   arrays of the $header and $body lines.  The $lines argument tells how

                   many lines of the message are to be retrieved.  Pass a negative number

                   if you want to retrieve the whole message. */

               

                   Function RetrieveMessage($message,&$headers,&$body,$lines)

                   {

                        if($this->state!="TRANSACTION")

                             return($this->SetError("connection is not in TRANSACTION state"));

                        if($lines<0)

                        {

                             $command="RETR";

                             $arguments="$message";

                        }

                        else

                        {

                             $command="TOP";

                             $arguments="$message $lines";

                        }

                        if($this->PutLine("$command $arguments")==0)

                             return($this->SetError("Could not send the $command command"));

                        $response=$this->GetLine();

                        if(GetType($response)!="string")

                             return($this->SetError("Could not get message retrieval command response"));

                        if($this->Tokenize($response," ")!="+OK")

                             return($this->SetError("Could not retrieve the message: ".$this->Tokenize("\r\n")));

                        for($headers=$body=array(),$line=0;;)

                        {

                             $response=$this->GetLine();

                             if(GetType($response)!="string")

                                  return($this->SetError("Could not retrieve the message"));

                             switch($response)

                             {

                                  case ".":

                                       return("");

                                  case "":

                                       break 2;

                                  default:

                                       if(substr($response,0,1)==".")

                                            $response=substr($response,1,strlen($response)-1);

                                       break;

                             }

                             if($this->join_continuation_header_lines

                             && $line>0

                             && ($response[0]=="\t"

                             || $response[0]==" "))

                                  $headers[$line-1].=$response;

                             else

                             {

                                  $headers[$line]=$response;

                                  $line++;

                             }

                        }

                        for($line=0;;$line++)

                        {

                             $response=$this->GetLine();

                             if(GetType($response)!="string")

                                  return($this->SetError("Could not retrieve the message"));

                             switch($response)

                             {

                                  case ".":

                                       return("");

                                  default:

                                       if(substr($response,0,1)==".")

                                            $response=substr($response,1,strlen($response)-1);

                                       break;

                             }

                             $body[$line]=$response;

                        }

                        return("");

                   }

               

                   /* DeleteMessage method - the $message argument indicates the number of

                   a message to be marked as deleted.  Messages will only be effectively

                   deleted upon a successful call to the Close method. */

               

                   Function DeleteMessage($message)

                   {

                        if($this->state!="TRANSACTION")

                             return($this->SetError("connection is not in TRANSACTION state"));

                        if($this->PutLine("DELE $message")==0)

                             return($this->SetError("Could not send the DELE command"));

                        $response=$this->GetLine();

                        if(GetType($response)!="string")

                             return($this->SetError("Could not get message delete command response"));

                        if($this->Tokenize($response," ")!="+OK")

                             return($this->SetError("Could not delete the message: ".$this->Tokenize("\r\n")));

                        $this->must_update=1;

                        return("");

                   }

               

                   /* ResetDeletedMessages method - Reset the list of marked to be deleted

                   messages.  No messages will be marked to be deleted upon a successful

                   call to this method.  */

               

                   Function ResetDeletedMessages()

                   {

                        if($this->state!="TRANSACTION")

                             return($this->SetError("connection is not in TRANSACTION state"));

                        if($this->PutLine("RSET")==0)

                             return($this->SetError("Could not send the RSET command"));

                        $response=$this->GetLine();

                        if(GetType($response)!="string")

                             return($this->SetError("Could not get reset deleted messages command response"));

                        if($this->Tokenize($response," ")!="+OK")

                             return($this->SetError("Could not reset deleted messages: ".$this->Tokenize("\r\n")));

                        $this->must_update=0;

                        return("");

                   }

               

                   /* IssueNOOP method - Just pings the server to prevent it auto-close the

                   connection after an idle timeout (tipically 10 minutes).  Not very

                   useful for most likely uses of this class.  It's just here for

                   protocol support completeness.  */

               

                   Function IssueNOOP()

                   {

                        if($this->state!="TRANSACTION")

                             return($this->SetError("connection is not in TRANSACTION state"));

                        if($this->PutLine("NOOP")==0)

                             return($this->SetError("Could not send the NOOP command"));

                        $response=$this->GetLine();

                        if(GetType($response)!="string")

                             return($this->SetError("Could not NOOP command response"));

                        if($this->Tokenize($response," ")!="+OK")

                             return($this->SetError("Could not issue the NOOP command: ".$this->Tokenize("\r\n")));

                        return("");

                   }

              };

               

              ?>

              • Re: calling php functions from sap
                Craig Cmehil
                Currently Being Moderated

                Your R/3 remote enabled function needs to be created in R/3 not in PHP.

                 

                You have to remember that to do what you want to do there are two pieces the PHP side that runs and collects data and mail info and sends that via a WS or RFC to your R/3 system for storage.

                 

                Your R/3 system won't call the PHP application your PHP application needs to call your R/3 system, unless you want to create a ABAP FM (se37 transaction) which will do a HTTP call out and activate the PHP application that way.

                • Re: calling php functions from sap
                  Anton Wenzelhuemer
                  Currently Being Moderated

                  craig,

                   

                  i think you can have your ABAP app call a PHP RFC server. See this server.php Warning: RFC Error Info for details.

                   

                  the tricky thing is to keep the 'server' alive.

                   

                  regards,

                  anton

                  • Re: calling php functions from sap
                    Piers Harding
                    Currently Being Moderated

                    Why not use one of the other scripting languages to write your RFC server in - that way it can be dedicated standalone application without the need of Apache etc.

                     

                    Cheers.

                    • Re: calling php functions from sap
                      Kumar garg
                      Currently Being Moderated

                      Hi Piers ,

                        As , I earlier mention my requirement is that I have to read the internet mail contents in the sap. Can you guide me some other way to do read the contents of the internet mail in sap.

                      regards

                      ashish kumar

                      • Re: calling php functions from sap
                        Piers Harding
                        Currently Being Moderated

                        If I understand your requirement correctly (maybe I'm coming abit late to this), in Perl for example, you can use any of the Net::* mail related packages to access mail services. So you would have ABAP code => Perl RFC Server => Perl Mail tools ?

                        • Re: calling php functions from sap
                          Kumar garg
                          Currently Being Moderated

                          hi piers ,

                                    Can u explain me detail how to do that in perl. how to use perl with the abap . I am not fimiliar with perl.Can you provide me some code of doing this through perl.

                          ashish kumar

                        • Re: calling php functions from sap
                          Anton Wenzelhuemer
                          Currently Being Moderated

                          piers,

                           

                          PHP comes with the same (and complete) mail packages as perl. of course you don't need a webserver to run php scripts either.

                           

                          since this is the PHP development sub-forum of Scripting I regard it as counter- productiv to suggest using other scripting languages for noapparent_reason_.

                           

                          for further reference go <a href="http://www.php.net">here</a> and enter 'imap' into the search box.

                           

                          I think the real problem of ashish is that he doesn't know any scripting language in detail, which makes it really hard to develop an otherwise not so difficult solution.

                           

                          regards,

                          anton

                          • Re: calling php functions from sap
                            Piers Harding
                            Currently Being Moderated

                            Hi Anton,

                            I think your comment is being a bit territorial - I merely showed that there is more than one way to skin a cat - epecially seeing that a comment was allready made about some sort of difficulty in keeping the registered RFC application up and available (see previous posts).  I personally have no problem with people cross posting, and that goes for anything to do with opensource, so long as it is relevent to the topic at hand - in my opinion it only serves to broaden everyones knowledge - for instance - you have just told me that PHP can now run outside the webserver - something that I didn't know before (something to look into) -  the flip side being that other readers of this thread also know that Perl has support for various Mail related protocols, and a Perl based registered RFC application could do the trick if the alternatives dont work for them.

                            Regards,

                            Piers Harding.

                            • Re: calling php functions from sap
                              Anton Wenzelhuemer
                              Currently Being Moderated

                              territorial?

                               

                              I just thought that an answer like

                               

                              import javax.mail.*
                              String host = ...;
                              String username = ...;
                              String password = ...;
                              
                              // Create empty properties
                              Properties props = new Properties();
                              
                              // Get session
                              Session session = Session.getDefaultInstance(props, null);
                              
                              // Get the store
                              Store store = session.getStore("pop3");
                              store.connect(host, username, password);
                              
                              // Get folder
                              Folder folder = store.getFolder("INBOX");
                              folder.open(Folder.READ_ONLY);
                              
                              // Get directory
                              Message message[] = folder.getMessages();
                              
                              for (int i=0, n=message.length; i<n; i++) {
                                 System.out.println(i + ": " + message<i>.getFrom()[0] 
                                   + "t" + message<i>.getSubject());
                              }
                              
                              // Close connection 
                              folder.close(false);
                              store.close();
                              

                               

                              were inappropriate to the question 'how do I solve the problem using PHP' as long as there is no problem to solve it in PHP, which is shown in all the material that has been referenced in this thread so far.

                               

                              anton

                              (very much disliking such animosities)

                              • Re: calling php functions from sap
                                Piers Harding
                                Currently Being Moderated

                                Ha - excellent!

                                 

                                How did we get from PHP -> Perl -> Java!

                                 

                                As I said - there was a reference to there being some problem with the "upness" of registered RFC applications running in PHP, hence the fuel for my original post branching to the possibilities of Perl (for exampe) as an alternative.

                                 

                                "i think you can have your ABAP app call a PHP RFC server. See this thread for details.

                                 

                                the tricky thing is to keep the 'server' alive."

                                 

                                Best of luck,

                                 

                                Piers.

                  • Re: calling php functions from sap
                    Craig Cmehil
                    Currently Being Moderated

                    Yep Anton, but as you said very tricky sometimes.

                    • Re: calling php functions from sap
                      Craig Cmehil
                      Currently Being Moderated

                      Piers, Anton,

                       

                      Let's stay focused here - it's hard for me to split threads and I'm seeing a 4 way split here.

                       

                      Perl, PHP, Python, VBScript - doesn't really matter. Yes they asked about PHP and this is the PHP forum but hey if the Perl or LISP programming langauge can do it and the user is comfortable with it then I say go for it.

                       

                      I'm just happy the two of you are willing to jump in and work inside and outside the box to help the user out.

                       

                      Remember - 1st and formost this is the "Scripting Languages" forums and sooner or later even "Groovy on Rails" is going to pop in here I think. I would like though to try and keep things as clean as possible and when a cross post comes and if it continues I will move it over to another sub forum, in fact the only reason this area has two forums at the moment is because we had enough content for it, once Perl, Ruby or anything else begins to grow they'll get a forum as well.

                       

                      So now back to the problem at hand, and I'll actually give 200 points to each weblog written explaining the process of calling one of the Scripting Languages from your R/3 or NW system and not the Scripting app calling the R/3 system - no Apache or webserver involved...

                       

                      @ashish

                       

                      Does that work for you? A custom tutorial in more than one language to accomplish what you need?

                      • Re: calling php functions from sap
                        Anton Wenzelhuemer
                        Currently Being Moderated

                        FACT:

                         

                        1) how to call a PHP RFC server (without a web server) from within ABAP has been solved by this very community, e.g. in this server.php Warning: RFC Error Info. (Addition: set -dmax_execution_time=0, which means forever)

                         

                        2) our colleague's real problem does not seem to be the one solved in 1), but <b>coding access to a POP3 mailbox using ANY scripting language</b> ... so, if at all, those 200pts should go to a blog explaining how to access a mailbox using ANY scripting language

                         

                        3) he came up with a (nice) custom low-level pop3 implementation(pop3.php) neglecting the nativ mail functions in recent PHP versions. this would be something worth discussing...

                         

                        Summarizing 1) and elaborating on 2) has been going on in this thread and should be helping Ashish the most, be it a blog or just in here.

                         

                        greetz,

                        anton

          • Re: calling php functions from sap
            Kumar garg
            Currently Being Moderated

            hi,

            Thanks for the replies. I am able to call to simple function of php in sap.But my requirement is that I have to read the mails from interner users through php and get its content in the r/3 . Can you help me in this.

            regards

            ashish kumar

            • Re: calling php functions from sap
              Anton Wenzelhuemer
              Currently Being Moderated

              hi ashish,

               

              this is a not so simple task, since it involves a more advanced knowledge of PHP and more important mail and mailbox issues.

               

              Here's a quickly crafted code fragment, which won't work as it is but helps you to get started and shows you what to take care for (MIME types and conversion, attachments, multipart emails, etc):

               

              [code]<?

               

              $ServerName = ...; $UserName = ...; $PassWord = ...;

               

               

              if ( $mbox = imap_open($ServerName, $UserName,$PassWord, CL_EXPUNGE) ){ 

                if ($hdr = imap_check($mbox)) {

                  $msgCount = $hdr->Nmsgs;

                    if ($msgCount > 0) {

                      $nos=$msgCount;

                      $overview=imap_fetch_overview($mbox,"1:$nos",FT_UID);                                    

                      $size=sizeof($overview);

                   for($i=0;$i<=$size-1;$i++){

                     $val=$overview[$i];

                     $msgno=$val->msgno;

                     $from=$val->from;

                     $date=$val->date;

               

                        $subj=$val->subject;

                        $subj1 = imap_mime_header_decode($subj);  //decode 8859 subject

                        $recent = $val->recent;

                        $flagged = $val->flagged;

                        $seen=$val->seen;

               

                        $from = ereg_replace("\"","",$from);

                        $uid = $val->uid;

               

              //        get text body

                        $dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");

              //        get attachments if any

                        $struct = imap_fetchstructure($mbox,$msgno);

                        $contentParts = count($struct->parts);

               

                        if ($contentParts >= 2) {

                          for ($j=1;$j<=$contentParts;$j++) {

                            $att[$j-1] = imap_bodystruct($mbox,$msgno,$j);

                          }

                          for ($k=0;$k<sizeof($att);$k++) {

                            if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value    == "US-ASCII") {

              //              accept only certain image types (Case sensitive!!)------                                          

                              if (ereg($attregexp, $att[$k]->parameters[1]->value)) {

                                $fileContent = imap_fetchbody($mbox,$msgno,$k+1);

                                $fileName = $att[$k]->parameters[1]->value;

                        }

                            }

                            elseif ($att[$k]->parameters[0]->value != "iso-8859-1" &&    $att[$k]->parameters[0]->value != "ISO-8859-1") {

              //              accept only certain image types (Case sensitive!!)------                                          

                              if (ereg($attregexp, $att[$k]->parameters[0]->value)) {

                                $fileContent = imap_fetchbody($mbox,$msgno,$k+1);

                                $fileName = $att[$k]->parameters[0]->value;

                              }

                            }

                          }

                        }

                         

              // output $subject, $from, save the file, do whatever you need to do         

                                   

                      }

                    }

                  }

              }

               

              ?>[/code]

               

              But again, not so easy for the PHP novice I suppose. Check <a href="http://www.php.net">php.net</a> regularly!

               

              regards,

              anton

               

               

              Message was edited by: Anton Wenzelhuemer [corrected fatal error in coding ;-)]

               

            • Re: calling php functions from sap
              John Astill
              Currently Being Moderated

              Why is there a requirement on PHP. Can you not have the ABAP code read from the mailserver? That way you are not requiring exta hardware and server.

               

              JohnA

Actions