Created a nice software using SpiderBasic ? Post you link here !
Stefan Schnell
 
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am

Read Table Data from SAP with SpiderBasic

by Stefan Schnell Tue Feb 02, 2016 6:49 am

Hello community,

I presented here the possibility to use SpiderBasic in the context of SAP.

I presented here the possibility to use the SAP remote enabled function module RFC_READ_TABLE via JavaScript.

Here now the combination, SpiderBasic gets data from SAP.

At first the SpiderBasic source which calls the web service and shows the XML response as tree.

Code: Select all
; Begin-----------------------------------------------------------------

  ; Directives----------------------------------------------------------
    EnableExplicit

  ; Constants-----------------------------------------------------------
    Enumeration
      #MainWin
      #tUser
      #User
      #tPassword
      #Password
      #tTableName
      #TableName
      #btnReadTable
      #XMLTree
      #XML
    EndEnumeration

  ; Variables-----------------------------------------------------------
    Global wsurl.s = "http://ABAP:8080/sap/bc/srt/rfc/sap/ztest/001/" +
      "ztest/rfc_read_table"

  ; Sub FillTree--------------------------------------------------------
    Procedure FillTree(CurrentNode.i, CurrentSublevel.i)

      ; Variables-------------------------------------------------------
        Protected NodeName.s, ChildNode.i

      If XMLNodeType(CurrentNode) = #PB_XML_Normal
        ChildNode = ChildXMLNode(CurrentNode)
        NodeName = GetXMLNodeName(CurrentNode)
        If ChildNode <> 0
          AddGadgetItem(#XMLTree, -1, NodeName, 0, CurrentSublevel)
        Else
          If Trim(GetXMLNodeText(CurrentNode)) <> ""
            AddGadgetItem(#XMLTree, -1, NodeName + " = " +
              GetXMLNodeText(CurrentNode), 0, CurrentSublevel)
          Else
            AddGadgetItem(#XMLTree, -1, NodeName, 0, CurrentSublevel)
          EndIf
        EndIf
        While ChildNode <> 0
          FillTree(ChildNode, CurrentSublevel + 1)     
          ChildNode = NextXMLNode(ChildNode)
        Wend       
      EndIf
 
    EndProcedure

  ; Sub btnReadTableHandler---------------------------------------------
    Procedure btnReadTableHandler()
   
      ; Variables-------------------------------------------------------
        Protected User.s, Password.s, id.s, basicauth.s
        Protected soaprequest.s
        Protected answer.s, MainNode.i
   
      User = GetGadgetText(#User)
      Password = GetGadgetText(#Password)
      id = User + ":" + Password
      !v_basicauth = "Basic " + btoa(v_id)

      soaprequest = "<?xml version='1.0' encoding='UTF-8'?>" +
        "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' " +
        "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
        "xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
        "<env:Body>" +
        "<ns1:RFC_READ_TABLE xmlns:ns1='urn:sap-com:document:sap:rfc:functions'>" +
        "<DATA />" +
        "<FIELDS />" +
        "<OPTIONS />" +
        "<QUERY_TABLE>" + GetGadgetText(#TableName) + "</QUERY_TABLE>" +
        "<DELIMITER>~</DELIMITER>" +
        "</ns1:RFC_READ_TABLE>" +
        "</env:Body>" +
        "</env:Envelope>"

      !$.ajax({
      !  type: "POST",
      !  url: v_wsurl,
      !  contentType: 'text/xml',
      !  dataType: 'xml',
      !  headers: {
      !    'Authorization': v_basicauth,
      !    'Accept': '*/*'
      !  },
      !  data: v_soaprequest,
      !  success: processSuccess,
      !  error: processError
      !});

      !function processSuccess(data, textStatus, jqXHR) {
      !  if (textStatus == "success") {
      !    spider.debug.Print(textStatus);
      !    v_answer = jqXHR.responseText;
           If ParseXML(#XML, answer)
             If XMLStatus(#XML) = #PB_XML_Success
               MainNode = MainXMLNode(#XML)     
               If MainNode
                 ClearGadgetItems(#XMLTree)
                 FillTree(MainNode, 0)
               EndIf             
             EndIf
           EndIf
      !  }
      !}

      !function processError(jqXHR, textStatus, errorThrown) {
      !  spider.debug.Print(textStatus);
      !}   

    EndProcedure

  ; Main----------------------------------------------------------------
    If OpenWindow(#MainWin, 10, 10, 480, 640, "RfcReadTable")

      TextGadget(#tUser, 10, 10, 100, 24, "User:")
      StringGadget(#User, 110, 10, 150, 24, "BCUSER")
      TextGadget(#tPassword, 10, 44, 100, 24, "Password:")
      StringGadget(#Password, 110, 44, 150, 24, "minisap", #PB_String_Password)
      TextGadget(#tTableName, 10, 78, 100, 24, "Tablename:")
      StringGadget(#TableName, 110, 78, 150, 24, "USR01")
      ButtonGadget(#btnReadTable, 10, 112, 250, 24, "ReadTable")
      TreeGadget(#XMLTree, 10, 146, 460, 484)

      BindGadgetEvent(#btnReadTable, @btnReadTableHandler())

    EndIf

; End-------------------------------------------------------------------

; IDE Options = SpiderBasic 1.20 beta 2 (Windows - x86)
; CursorPosition = 101
; FirstLine = 81
; Folding = -
; WindowTheme = blue
; EnableAsm
; EnableUnicode
; EnableXP
; EnableOnError
; CompileSourceDirectory


Here the html code which is used in SAP as Business Server Page (BSP) with flow logic.

Code: Select all
<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8"/>
<title>SpiderBasic</title>
<script type="text/javascript">var spider = {}; spider.nbModules = 0; spider.nbLoadedModules = 0;</script>

<script type="text/javascript">
var Path = "/SAP/BC/BSP/SAP/PUBLIC/spiderbasic/libraries/javascript";
document.write("<script type='text/javascript' data-main='" + Path + "/main.js' src='" + Path + "/require.js'><\/script>");
document.write("<script type='text/javascript' src='" + Path + "/library.js'><\/script>");
document.write("<script type='text/javascript' src='" + Path + "/debug.js'><\/script>");
</script>
<script type="text/javascript">var dojoConfig = { async: 1 }; </script>
<script type="text/javascript">
document.write("<link rel='stylesheet' href='" + Path + "/dijit/themes/flat/flat.css' type='text/css' />");
document.write("<link rel='stylesheet' href='" + Path + "/dgrid/css/dgrid.css' />");
document.write("<link rel='stylesheet' href='" + Path + "/cbtree/icons/cbtreeIcons.css' type='text/css' />");
document.write("<link rel='stylesheet' href='" + Path + "/cbtree/icons/fileIconsMS.css' type='text/css' />");
document.write("<script type='text/javascript' src='" + Path + "/xdate.dev.js'><\/script>");
document.write("<script type='text/javascript' src='" + Path + "/canvas-toBlob.js'><\/script>");
document.write("<script type='text/javascript' src='" + Path + "/FileSaver.js'><\/script>");
document.write("<script type='text/javascript' src='" + Path + "'/wgxpath.install.js'><\/script>");
document.write("<link rel='stylesheet' href='" + Path + "/themes/blue/window.css' type='text/css' />");
</script>

<script type="text/javascript" src="spiderbasic.js"></script>

<link rel="icon" type="image/png" href=""/>

</head>

<body class="flat" id="spiderbody">

</body>
</html>


Here now the result in Google Chrome, as example with the table USR01.

Image

On this way you can get the content of all SAP tables you like. I don't check any field type, but with RFC_READ_TABLE you have the possibility to exclude fields which types are problematic. Also don't request tables with too much entries. ;) I tried it with table TFDIR with over 90.000 entries - it works but it needs to much time. It seems to be better in this case to define a meaningful where clause via OPTIONS parameter.

Enjoy it.
:D

Cheers
Stefan
Fred
Site Admin
 
Posts: 1018
Joined: Mon Feb 24, 2014 10:51 am

Re: Read Table Data from SAP with SpiderBasic

by Fred Tue Feb 02, 2016 8:34 am

Great code as usual !
Stefan Schnell
 
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am

Re: Read Table Data from SAP with SpiderBasic

by Stefan Schnell Wed Feb 17, 2016 7:06 am

Hello community, hello Fred,

I have checked the actual SpiderBasic release 1.20 in the actual SAP releases 7.40 SP 12 (SAP_BASIS - SAPKB74012) and SP 13 (SAP_BASIS - SAPKB74013) and it works perfect.
:D

In the MIME-Repository I changed the name strategy, I added the version of SpiderBasic as part of the path. So it is possible to use different versions of SpiderBasic parallel. With the path variable in the code above is it possible to set it very flexible.

Image


Cheers
Stefan
Last edited by Stefan Schnell on Thu Feb 18, 2016 5:33 am, edited 3 times in total.
Fred
Site Admin
 
Posts: 1018
Joined: Mon Feb 24, 2014 10:51 am

Re: Read Table Data from SAP with SpiderBasic

by Fred Wed Feb 17, 2016 7:30 am

Good to know ! So it works out of the box without need of patching anyhing ?
Stefan Schnell
 
Posts: 46
Joined: Tue Dec 01, 2015 8:17 am

Re: Read Table Data from SAP with SpiderBasic

by Stefan Schnell Thu Feb 18, 2016 5:38 am

Hello Fred,

all I do is to compress the SpiderBasic framework, therewith I can answer your question with yes.
;)

Cheers
Stefan
Return to Showcase

Who is online

Users browsing this forum: No registered users and 2 guests