Skip to Content

Tasting the mix of PHP and SAP – Volume 12

I wanted to start this blog with a little anecdote -:)

   body

   #login

 

image

We need a page to call the functions from the SE78 class…So we first create

Show_Graphics.php

   body

   #login

 

$SE78 = new SE78();
$Login = new Login();
$Log_Me = $Login->Log_In($_SESSION[“Server”],$_SESSION[“Sysnum”],$_SESSION[“Client”],
$_SESSION[“User”],$_SESSION[“Pass”]);
$RFC_Me = $Login->RFC_Connection($Log_Me);

if(isset($_POST[‘BUTTON’]))
{
SWITCH($_POST[‘BUTTON’])
{
CASE ‘VIEW’:
$SE78->View_Graphic($RFC_Me,$_POST[“GRAPH_NAME”],$_POST[“TYPE”]);
BREAK;
CASE ‘UPLOAD’:
$SE78->Upload_Graphic($RFC_Me,$_POST[“GRAPH_NAME”],$_POST[“FILE_NAME”],
$_POST[“TYPE”]);
BREAK;
CASE ‘DELETE’:
$SE78->Delete_Graphic($RFC_Me,$_POST[“GRAPH_NAME”],$_POST[“TYPE”]);
BREAK;
}
}

?>

And now, we create the

SE78.php

class…

fce )

   {

       ECHO “The function module has failed.”;

       EXIT;

   }

  

   $pos = strrpos(__FILE__,”
“);

   $new_file = substr(__FILE__,0,$pos);

   if($TYPE == “BCOL”)

   {

   $Graphic = $new_file . “
BCOL
” . $GRAPH_NAME . “.bmp”;

   }

   else

   {

   $Graphic = $new_file . “
BMON
” . $GRAPH_NAME . “.bmp”;

   }

       

   saprfc_import ($this->fce,”OBJECT”,”GRAPHICS”);

   saprfc_import ($this->fce,”NAME”,$GRAPH_NAME);

   saprfc_import ($this->fce,”BTYPE”,$TYPE);

   saprfc_import ($this->fce,”ID”,”BMAP”);

   saprfc_table_init ($this->fce,”GRAPHIC_TABLE”);

  

   $rfc_rc = “”;  

  

   $rfc_rc = saprfc_call_and_receive ($this->fce);

   if ($rfc_rc != SAPRFC_OK)

   {

       if ($rfc == SAPRFC_EXCEPTION )

           echo (“Exception raised: “.saprfc_exception($this->fce));

       else

           echo (“Call error: “.saprfc_error($this->fce));

       exit;

   }

  

   $graphics_row = saprfc_table_rows ($this->fce,”GRAPHIC_TABLE”);

  

   $fh = fopen($Graphic, “w”);

  

   for ($i=1; $i<=$graphics_row; $i++)
{
$GRAPHS = saprfc_table_read ($this->fce,”GRAPHIC_TABLE”,$i);
@fwrite($fh, $GRAPHS[‘CONTENT’]);
}

fclose($fh);

if($TYPE == “BCOL”)
{
$Img_name = “bcol/” . $GRAPH_NAME . “.bmp”;
PRINT(““);
}
else
{
$Img_name = “bmon/” . $GRAPH_NAME . “.bmp”;
PRINT(““);
}

PRINT(“

“);
PRINT(“
“);
PRINT(”   “);
PRINT(“

“);

}

function Upload_Graphic($RFC_Me,$GRAPH_NAME,$FILE_NAME,$TYPE)
{
$this->fce = saprfc_function_discover($RFC_Me, “ZUPLOAD_GRAPHICS_TABLE”);
IF (! $this->fce )
{
ECHO “The function module has failed.”;
EXIT;
}

saprfc_import ($this->fce,”OBJECT”,”GRAPHICS”);
saprfc_import ($this->fce,”NAME”,$GRAPH_NAME);
saprfc_import ($this->fce,”BTYPE”,$TYPE);
saprfc_import ($this->fce,”ID”,”BMAP”);

$fp = file_get_contents($FILE_NAME);

$fh_array = str_split($fp,255);

$size = count($fh_array);

for($i=0;$i<$size;$i++)
{
$T_BITMAP = array(“CONTENT”=>$fh_array[$i]);
saprfc_table_append ($this->fce,”T_BITMAP”,$T_BITMAP);
}

$rfc_rc = “”;

$rfc_rc = saprfc_call_and_receive ($this->fce);
if ($rfc_rc != SAPRFC_OK)
{
if ($rfc == SAPRFC_EXCEPTION )
echo (“Exception raised: “.saprfc_exception($this->fce));
else
echo (“Call error: “.saprfc_error($this->fce));
exit;
}

PRINT(“Succesfully uploaded!”);

PRINT(“

“);
PRINT(“
“);
PRINT(”   “);
PRINT(“

“);

}

function Delete_Graphic($RFC_Me,$GRAPH_NAME,$TYPE)
{
$this->fce = saprfc_function_discover($RFC_Me, “ZDELETE_GRAPHICS”);
IF (! $this->fce )
{
ECHO “The function module has failed.”;
EXIT;
}

saprfc_import ($this->fce,”OBJECT”,”GRAPHICS”);
saprfc_import ($this->fce,”NAME”,$GRAPH_NAME);
saprfc_import ($this->fce,”BTYPE”,$TYPE);
saprfc_import ($this->fce,”ID”,”BMAP”);

$rfc_rc = “”;

$rfc_rc = saprfc_call_and_receive ($this->fce);
if ($rfc_rc != SAPRFC_OK)
{
if ($rfc == SAPRFC_EXCEPTION )
echo (“Exception raised: “.saprfc_exception($this->fce));
else
echo (“Call error: “.saprfc_error($this->fce));

       exit;

   }  

   $pos = strrpos(__FILE__,”
“);

   $new_file = substr(__FILE__,0,$pos);

   if($TYPE == “BCOL”)

   {

   $Graphic = $new_file . “
BCOL
” . $GRAPH_NAME . “.bmp”;

   }

   else

   {

   $Graphic = $new_file . “
BMON
” . $GRAPH_NAME . “.bmp”;

   }

   delete($Graphic);

   PRINT(“

“);
PRINT(“
“);
PRINT(”   “);
PRINT(“

“);

PRINT(“Succesfully deleted!”);

}

}
?>

But, of course…Without the SAP FM we can do anything, so here they are…

ZUPLOAD_GRAPHICS_TABLE


FUNCTION ZUPLOAD_GRAPHICS_TABLE.

*”—-


“Local interface:

*”  IMPORTING

*”     VALUE(OBJECT) TYPE  TDOBJECT DEFAULT ‘GRAPHICS’

*”     VALUE(NAME) TYPE  TDOBNAME

*”     VALUE(BTYPE) TYPE  TDBTYPE

*”     VALUE(ID) TYPE  TDID DEFAULT ‘BMAP’

*”     VALUE(RESOLUTION) TYPE  TDRESOLUT OPTIONAL

*”     VALUE(RESIDENT) TYPE  TDRESIDENT OPTIONAL

*”     VALUE(AUTOHEIGHT) TYPE  TDAUTOHGHT OPTIONAL

*”  TABLES

*”      T_BITMAP STRUCTURE  BLOB

*”—-


  TYPES: TY_BOOLEAN(1) TYPE C.

  TYPES: BEGIN OF TY_SBDST_CONTENT.

          INCLUDE STRUCTURE BAPICONTEN.

  TYPES: END OF TY_SBDST_CONTENT.

  TYPES: SBDST_COMPONENTS LIKE BAPICOMPON OCCURS 1,

         SBDST_PROPERTIES LIKE BAPIPROPER OCCURS 1,

         SBDST_SIGNATURE LIKE BAPISIGNAT OCCURS 1,

         SBDST_CONTENT LIKE BAPICONTEN OCCURS 1.

  DATA: T_BDS_CONTENT TYPE STANDARD TABLE OF

        TY_SBDST_CONTENT,

        WA_BDS_COMPONENTS TYPE LINE OF SBDST_COMPONENTS,

        L_BDS_PROPERTIES  TYPE SBDST_PROPERTIES,

        L_BDS_COMPONENTS  TYPE SBDST_COMPONENTS,

        T_STXBITMAPS TYPE STANDARD TABLE OF STXBITMAPS

        WITH HEADER LINE,

        WA_BDS_SIGNATURE TYPE LINE OF SBDST_SIGNATURE,

        L_BDS_SIGNATURE TYPE SBDST_SIGNATURE,

        L_BDS_CONTENT TYPE SBDST_CONTENT,

        WA_STXBITMAPS TYPE STXBITMAPS,

        WA_BDS_PROPERTIES TYPE LINE OF SBDST_PROPERTIES.

  DATA: W_BYTECOUNT TYPE I,

        W_COLOR(1) TYPE C,

        W_WIDTH_TW TYPE STXBITMAPS-WIDTHTW,

        W_HEIGHT_TW TYPE STXBITMAPS-HEIGHTTW,

        W_WIDTH_PIX TYPE STXBITMAPS-WIDTHPIX,

        W_HEIGHT_PIX TYPE STXBITMAPS-HEIGHTPIX,

        W_RESOLUTION TYPE STXBITMAPS-RESOLUTION,

        W_BDS_BYTECOUNT TYPE I,

        W_TYPE TYPE STXBITMAPS-TDBTYPE,

        W_DOCID TYPE STXBITMAPS-DOCID.

  DATA: L_BDS_OBJECT TYPE REF TO CL_BDS_DOCUMENT_SET.

  CONSTANTS:

    C_TRUE  TYPE TY_BOOLEAN VALUE ‘X’,

    C_FALSE TYPE TY_BOOLEAN VALUE SPACE,

    C_BDS_MIMETYPE  TYPE BDS_MIMETP VALUE ‘application/octet-stream’,

    C_BDS_CLASSNAME TYPE SBDST_CLASSNAME VALUE ‘DEVC_STXD_BITMAP’,

    C_BDS_CLASSTYPE TYPE SBDST_CLASSTYPE VALUE ‘OT’.

  IF BTYPE = ‘BMON’.

    W_COLOR = C_FALSE.

  ELSE.

    W_COLOR = C_TRUE.

  ENDIF.

  CALL FUNCTION ‘SAPSCRIPT_CONVERT_BITMAP_BDS’

       EXPORTING

            COLOR                    = W_COLOR

            FORMAT                   = ‘BMP’

            BITMAP_BYTECOUNT         = W_BYTECOUNT

       IMPORTING

            WIDTH_TW                 = W_WIDTH_TW

            HEIGHT_TW                = W_HEIGHT_TW

            WIDTH_PIX                = W_WIDTH_PIX

            HEIGHT_PIX               = W_HEIGHT_PIX

            DPI                      = W_RESOLUTION

            BDS_BYTECOUNT            = W_BDS_BYTECOUNT

       TABLES

            BITMAP_FILE              = T_BITMAP

            BITMAP_FILE_BDS          = T_BDS_CONTENT

       EXCEPTIONS

            FORMAT_NOT_SUPPORTED     = 1

            NO_BMP_FILE              = 2

            BMPERR_INVALID_FORMAT    = 3

            BMPERR_NO_COLORTABLE     = 4

            BMPERR_UNSUP_COMPRESSION = 5

            BMPERR_CORRUPT_RLE_DATA  = 6

            OTHERS                   = 7.

  CREATE OBJECT L_BDS_OBJECT.

  WA_BDS_COMPONENTS-DOC_COUNT  = ‘1’.

  WA_BDS_COMPONENTS-COMP_COUNT = ‘1’.

  WA_BDS_COMPONENTS-MIMETYPE   = C_BDS_MIMETYPE.

  WA_BDS_COMPONENTS-COMP_SIZE  = W_BYTECOUNT.

  APPEND WA_BDS_COMPONENTS TO L_BDS_COMPONENTS.

  W_TYPE = ‘BSD’.

  SELECT SINGLE *

  INTO T_STXBITMAPS

  FROM STXBITMAPS WHERE TDOBJECT = OBJECT

                                  AND   TDNAME   = NAME

                                  AND   TDID     = ID

                                  AND   TDBTYPE  = BTYPE.

  IF SY-SUBRC = 0.

    READ TABLE T_STXBITMAPS INDEX 1.

    W_DOCID = T_STXBITMAPS-DOCID.

  ELSE.

    CLEAR W_DOCID.

  ENDIF.

  IF W_DOCID IS INITIAL.

    WA_BDS_SIGNATURE-DOC_COUNT = ‘1’.

    APPEND WA_BDS_SIGNATURE TO L_BDS_SIGNATURE.

    CALL METHOD L_BDS_OBJECT->CREATE_WITH_TABLE

         EXPORTING

              CLASSNAME  = C_BDS_CLASSNAME

              CLASSTYPE  = C_BDS_CLASSTYPE

              COMPONENTS = L_BDS_COMPONENTS

              CONTENT    = T_BDS_CONTENT

         CHANGING

              SIGNATURE  = L_BDS_SIGNATURE

         EXCEPTIONS

              OTHERS     = 1.

    READ TABLE L_BDS_SIGNATURE INDEX 1 INTO WA_BDS_SIGNATURE

    TRANSPORTING DOC_ID.

    IF SY-SUBRC = 0.

      W_DOCID = WA_BDS_SIGNATURE-DOC_ID.

    ENDIF.

  ELSE.

    CALL METHOD L_BDS_OBJECT->UPDATE_WITH_TABLE

         EXPORTING

              CLASSNAME  = C_BDS_CLASSNAME

              CLASSTYPE  = C_BDS_CLASSTYPE

              DOC_ID     = W_DOCID

              DOC_VER_NO = ‘1’

              DOC_VAR_ID = ‘1’

         CHANGING

              COMPONENTS = L_BDS_COMPONENTS

              CONTENT    = T_BDS_CONTENT

         EXCEPTIONS

              NOTHING_FOUND = 1

              OTHERS        = 2.

  ENDIF.

  WA_STXBITMAPS-TDNAME     = NAME.

  WA_STXBITMAPS-TDOBJECT   = OBJECT.

  WA_STXBITMAPS-TDID       = ID.

  WA_STXBITMAPS-TDBTYPE    = BTYPE.

  WA_STXBITMAPS-DOCID      = W_DOCID.

  WA_STXBITMAPS-WIDTHPIX   = W_WIDTH_PIX.

  WA_STXBITMAPS-HEIGHTPIX  = W_HEIGHT_PIX.

  WA_STXBITMAPS-WIDTHTW    = W_WIDTH_TW.

  WA_STXBITMAPS-HEIGHTTW   = W_HEIGHT_TW.

  WA_STXBITMAPS-RESOLUTION = RESOLUTION.

  WA_STXBITMAPS-RESIDENT   = RESIDENT.

  WA_STXBITMAPS-AUTOHEIGHT = AUTOHEIGHT.

  WA_STXBITMAPS-BMCOMP     = SPACE.

  INSERT INTO STXBITMAPS VALUES WA_STXBITMAPS.

ENDFUNCTION.

ZDOWNLOAD_GRAPHICS_TABLE


FUNCTION ZDOWNLOAD_GRAPHICS_TABLE.

*”—-


“Local interface:

*”  IMPORTING

*”     VALUE(OBJECT) TYPE  TDOBJECT DEFAULT ‘GRAPHICS’

*”     VALUE(NAME) TYPE  TDOBNAME

*”     VALUE(BTYPE) TYPE  TDBTYPE

*”     VALUE(ID) TYPE  TDID DEFAULT ‘BMAP’

*”  TABLES

*”      GRAPHIC_TABLE STRUCTURE  BLOB

*”  EXCEPTIONS

*”      DOWNLOAD_ERROR

*”—-


  DATA : L_BYTECOUNT TYPE I,

         L_TDBTYPE   LIKE STXBITMAPS-TDBTYPE,

         L_CONTENT   TYPE STANDARD TABLE OF BAPICONTEN INITIAL SIZE 0.

  DATA: GRAPHIC_SIZE TYPE I.

  CALL FUNCTION ‘SAPSCRIPT_GET_GRAPHIC_BDS’

       EXPORTING

            I_OBJECT       = OBJECT

            I_NAME         = NAME

            I_ID           = ID

            I_BTYPE        = BTYPE

       IMPORTING

            E_BYTECOUNT    = L_BYTECOUNT

       TABLES

            CONTENT        = L_CONTENT

       EXCEPTIONS

            NOT_FOUND      = 1

            BDS_GET_FAILED = 2

            BDS_NO_CONTENT = 3

            OTHERS         = 4.

  CALL FUNCTION ‘SAPSCRIPT_CONVERT_BITMAP’

       EXPORTING

            OLD_FORMAT               = ‘BDS’

            NEW_FORMAT               = ‘BMP’

            BITMAP_FILE_BYTECOUNT_IN = L_BYTECOUNT

       IMPORTING

            BITMAP_FILE_BYTECOUNT    = GRAPHIC_SIZE

       TABLES

            BDS_BITMAP_FILE          = L_CONTENT

            BITMAP_FILE              = GRAPHIC_TABLE

       EXCEPTIONS

            OTHERS                   = 1.

  IF SY-SUBRC NE 0.

    RAISE DOWNLOAD_ERROR.

  ENDIF.

ENDFUNCTION.

ZDELETE_GRAPHICS


FUNCTION ZDELETE_GRAPHICS.

*”—-


“Local interface:

*”  IMPORTING

*”     VALUE(OBJECT) TYPE TDOBJECTGR DEFAULT ‘GRAPHICS’

*”     VALUE(NAME) TYPE  TDOBNAME

*”     VALUE(ID) TYPE  TDIDGR DEFAULT ‘BMAP’

*”     VALUE(BTYPE) TYPE  TDBTYPE

*”  EXCEPTIONS

*”      NOT_FOUND

*”      ENQUEUE_FAILED

*”      DELETE_FAILED

*”—-


  TYPES: SBDST_SIGNATURE LIKE BAPISIGNAT OCCURS 1.

  DATA  WA_STXBITMAPS TYPE STXBITMAPS.

  DATA: L_BDS_OBJECT TYPE REF TO CL_BDS_DOCUMENT_SET,

        L_BDS_SIGNATURE  TYPE SBDST_SIGNATURE,

        WA_BDS_SIGNATURE TYPE LINE OF SBDST_SIGNATURE.

  CONSTANTS: C_BDS_ORIGINAL TYPE SBDST_DOC_VAR_TG VALUE ‘OR’,

             C_BDS_CLASSNAME TYPE SBDST_CLASSNAME

             VALUE ‘DEVC_STXD_BITMAP’,

             C_BDS_CLASSTYPE TYPE SBDST_CLASSTYPE VALUE ‘OT’.

  SELECT SINGLE * INTO WA_STXBITMAPS

                  FROM STXBITMAPS WHERE TDOBJECT = OBJECT

                                  AND   TDNAME   = NAME

                                  AND   TDID     = ID

                                  AND   TDBTYPE  = BTYPE.

  IF SY-SUBRC NE 0.

    RAISE NOT_FOUND.

  ENDIF.

  CALL FUNCTION ‘ENQUEUE_ESSGRABDS’

       EXPORTING

            TDOBJECT     = OBJECT

            TDNAME       = NAME

            TDID         = ID

            TDBTYPE      = BTYPE

       EXCEPTIONS

            FOREIGN_LOCK = 1

            OTHERS       = 2.

  IF SY-SUBRC NE 0.

    RAISE ENQUEUE_FAILED.

  ENDIF.

  CREATE OBJECT L_BDS_OBJECT.

  CLEAR WA_BDS_SIGNATURE.

  REFRESH L_BDS_SIGNATURE.

  WA_BDS_SIGNATURE-DOC_COUNT  = ‘1’.

  WA_BDS_SIGNATURE-DOC_ID     = WA_STXBITMAPS-DOCID.

  WA_BDS_SIGNATURE-DOC_VER_NO = ‘1’.

  WA_BDS_SIGNATURE-DOC_VAR_ID = ‘1’.

  WA_BDS_SIGNATURE-DOC_VAR_TG = C_BDS_ORIGINAL.

  APPEND WA_BDS_SIGNATURE TO L_BDS_SIGNATURE.

  CALL METHOD L_BDS_OBJECT->DELETE

       EXPORTING

            CLASSNAME  = C_BDS_CLASSNAME

            CLASSTYPE  = C_BDS_CLASSTYPE

       CHANGING

            SIGNATURE  = L_BDS_SIGNATURE

       EXCEPTIONS

            NOTHING_FOUND  = 1

            OTHERS         = 2.

  IF SY-SUBRC NE 0.

    CALL FUNCTION ‘DEQUEUE_ESSGRABDS’

         EXPORTING

              TDOBJECT = OBJECT

              TDNAME   = NAME

              TDID     = ID

              TDBTYPE  = BTYPE.

  ELSE.

    DELETE STXBITMAPS FROM WA_STXBITMAPS.

    CALL FUNCTION ‘DEQUEUE_ESSGRABDS’

         EXPORTING

              TDOBJECT = OBJECT

              TDNAME   = NAME

              TDID     = ID

              TDBTYPE  = BTYPE.

  ENDIF.

ENDFUNCTION.

Now, I can show you some pictures -:)

!https://weblogs.sdn.sap.com/weblogs/images/48024/Main_SE78.png|height=190|alt=image|width=304|src=https://weblogs.sdn.sap.com/weblogs/images/48024/Main_SE78.png|border=0!

!https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_Upload.png|height=190|alt=image|width=297|src=https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_Upload.png|border=0!

!https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_SAP.png|height=286|alt=image|width=391|src=https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_SAP.png|border=0!

!https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_View.png|height=184|alt=image|width=279|src=https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_View.png|border=0!

!https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_PHP.png|height=323|alt=image|width=216|src=https://weblogs.sdn.sap.com/weblogs/images/48024/SE78_PHP.png|border=0!

8 Comments
You must be Logged on to comment or reply to a post.