Calling RFC funtions from VBA

Hi all,
I would like to call RFC funtions from VBA, could you please advise on what library should I set reference to?
A piece of sample code would also be highly appreciated.
Thanks in advance.
Tomas

here is a small code sample using vbscript
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>RFC Example - THUSRINFO</title>
<script language="VBScript">
sub get_cust_data()
dim fns
set fns = createobject("SAP.Functions")
fns.logfilename = "my_log.txt"
fns.loglevel = 6
dim conn
set conn = fns.connection
conn.ApplicationServer = "application server name or ip address"
conn.System = "DEV"
conn.user = document.myf.t1.value
conn.password = document.myf.t2.value
conn.Client = "025"
conn.Language = "E"
conn.tracelevel = 6
if conn.logon(0, true) <> true then
exit sub
end if
dim myfunct
set myfunc = fns.add("THUSRINFO")
result = myfunc.Call
the_exception = myfunc.exception
dim users
if result = true then
set users = myfunc.tables.item("USR_TABL")
document.write "Table USR_TABL, " & users.rowcount & " rows"
document.write "<table border=1>"
document.write "<tr>"
document.write "<td>BNAME</td>"
document.write "<td>MANDT</td>"
document.write "<td>TCODE</td>"
document.write "<td>TERM</td>"
document.write "<td>ZEIT</td>"
document.write "<td>HOSTADR</td>"
document.write "<td>RFC TYPE</td>"
document.write "</tr>"
for each user in users.Rows
document.write "<tr>"
document.write "<tr>"
document.write "<td>"
document.write trim(user("BNAME"))
document.write "</td>"
document.write "<td>"
document.write trim(user("MANDT"))
document.write "</td>"
document.write "<td> "
document.write trim(user("TCODE"))
document.write "</td>"
document.write "<td> "
document.write trim(user("TERM"))
document.write "</td>"
document.write "<td>"
document.write trim(user("ZEIT"))
document.write "</td>"
document.write "<td>"
document.write trim(user("HOSTADR"))
document.write "</td>"
document.write "<td> "
document.write trim(user("RFC_TYPE"))
document.write "</td>"
next
document.write "</table>"
set users = nothing
end if
fns.connection.logoff
Set fns = nothing
Set conn = nothing
end sub
</script>
</head>
<body>
<form method="POST" name="myf">
  User Id <input type="text" name="T1" size="20"></p>
  <p>Password<input type="password" name="T2" size="20"></p>
  <p> </p>
  <p><input type="button" value="Submit" onclick="get_cust_data()" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
Regards
Raja

Similar Messages

  • Call BEX-Query from VBA with BEX-automatic login?

    Hi,
    I'm trying to call a query from VBA. I have two problems/questions:
    1. Automatic login?
    I want to do an automatic login. I found this peace of code here, but I get an error:
    Public Function  LogonToYourBW()
    ' create Logon & RFC-Handle
    logonToBW = False ‘ clear connect Flag the flag can be used to find out if connected or not
        'load SAP functionality by opening BEX file ( use your installation path)
            Workbooks.Open (“c:\sappc\bw\sapbex.xla”)
        With Run("sapbex.xla!sapbexGetConnection") ‘ call the connection
           ' Set the params for Auto logon
           .client = “YOUR CLIENT NO”
           .user = “YOUR BW USER”
           .Password = “YOUR BW PWD” ‘ I recommend to create a dummy reporting user for this task
           .Language = “YOUR LANGUAGE YOU LIKE TO USE FOR QUERY DISPLAY ( i.E.  “EN”)”
           .SystemNumber = “YOUR SYSTEM NO” ‘
           .ApplicationServer = “YOUR SERVER Name OR IP-ADDRESS”
           .UseSAPLOgonIni = FALSE 'important for automatic connection
           .logon 0, True ‘ This will provide a dialog to appear
            If .IsConnected <> 1 Then
                .logon 0, False
                If .IsConnected <> 1 Then Exit Function
            Else
                Set g_oFunction = CreateObject("SAP.Functions")
                Set g_oFunction.Connection = g_oConnection
            End If
        End With
        Run "sapbex.xla!sapbexinitConnection" ‘ this will enable the connection you just created
        logonToBW = True
    End Function
    The error is by this row:
    Set g_oFunction.Connection = g_oConnection
    Object is needed! How is the g_oConnection-object defined?
    2. How can I pass values for the parameters from VBA?
    If I open the query usually from SAP-BEX-Toolbar, after selecting the query, I get a parameter mask, where I must put in a value. How can I this automatize from VBA? Has anybody a short samplecode for that?
    Thank you for your help
    Stefan
    [email protected]

    Peter and others:
    What I really want to do … is write a stand-alone application that I can run from windows scheduler … that queries our BW for sales data for certain items (in a tabular form) … and pulls that data into a VB recordset, or a .NET dataset … so that I can insert the rows into another database (SQL Server, or Access) … I already know how to do all the data movement to/from datasets and databases … I just cannot figure out how to programmatically grab this sales data from BW … our company has “workbooks” already set up that aggregate WW sales information by region (IE, there is a separate workbook for each region of the world) … I can manually go into the Excel interface, tell it which items to pull the sales info for, and it dumps the data into the worksheet (organized by customer, and then by cat #) …
    So, what I’d like to do is write an app that will pull data every week or so from the BW (from each region’s sales invoice detail “workbook”), and insert it into another database that we use for reporting other, non-sales, data.
    Thoughts on this ?  Is there another, non-BEx method that is better ?
    thanks !!

  • How can I call RFC FM from webdynpro application for ABAP? Please help!

    Hi Experts,
              I have a requirement where I have to make a call to RFC enabled function module passing some data from webdynpro for ABAP application. How can I achieve this? Any tutorial or links or docs will be very helpfull.
    I have seen some tutorial on Adaptive RFC but it talks about webdynpro for Java.
    Can I use "Call function XYZ destination A10" statement in webdynpro for ABAP application?
    Thanks
    Gopal

    am doing same thing for my current SRM implementation.I am taking data to SRM server from another R/3 server .
    This is solution I have used
    1) First of all I have made ABAP connection in SM59 .
    Go to SM59 .In ABAP Connection creat ABAP connection with system with which u want communicate .
    Eg I am connection with Systems PB1.
    So i developed Connection call PB1CLNT800.
    2) In my requirement I have taken data in my context from another r/3,
    I have give called RFC in my supply function of node.
    Call to RFC is as usual.
    In my case,
    CALL FUNCTION 'RFC_MATNR'
    DESTINATION 'PB1CLNT800'
    TABLES
    IT_MATNR = IT_MATNR.
    Onwards I have read my itab IT_MATNR and populated data to context.
    Hope solution will serve your purpose.
    Give point if it works .If any problem i have other ways.
    Cheers
    Parag Bhise

  • CALL RFC DATA FROM TWO LINKED TABLES IN EXCEL VBA

    Hi,
    I am using Excel VBA to call information from tables in SAP.
    This is working correctly, however I now need to be able to call information from another table where the two tables are linked by a common data field.
    Example.
    The first table I have lists all items in stock and contains an article number. The second table contains all article numbers and their descriptions.
    I want to be able to call the first table but to have the article codes description on there aswell.
    Here is the code I am currently using.
    Sub GetTable()
    'Connect to SAP
    Dim sapConn As Object 'Declare variant
    Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object
    sapConn.Connection.System = "QA2"
    sapConn.Connection.client = "900"
    sapConn.Connection.user = "mbrough"
    sapConn.Connection.Password = "st34lh"
    sapConn.Connection.Language = "EN"
    If sapConn.Connection.Logon(1, False) <> True Then 'Try Logon
       MsgBox "Cannot Log on to SAP"
    End If
    'Define the table specifics
    Dim objRfcFunc As Object
    Set objRfcFunc = sapConn.Add("RFC_READ_TABLE")
    Dim objQueryTab, objRowCount As Object
    Set objQueryTab = objRfcFunc.Exports("QUERY_TABLE")
    objQueryTab.Value = "LQUA"
    Set objRowCount = objRfcFunc.Exports("ROWCOUNT")
    objRowCount.Value = "15000"
    Dim objOptTab, objFldTab, objDatTab As Object
    Set objOptTab = objRfcFunc.Tables("OPTIONS")
    Set objFldTab = objRfcFunc.Tables("FIELDS")
    Set objDatTab = objRfcFunc.Tables("DATA")
    'Set the condition and refresh the table
    objOptTab.FreeTable
    objOptTab.Rows.Add
    objOptTab(objOptTab.RowCount, "TEXT") = "LGTYP BETWEEN 'K01' AND 'K06'"
    'Set fields to obtain and refresh table
    objFldTab.FreeTable
    'Then set values to call
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGNUM"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "MATNR"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "WERKS"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGTYP"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "LGPLA"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "GESME"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "VERME"
    objFldTab.Rows.Add
    objFldTab(objFldTab.RowCount, "FIELDNAME") = "MEINS"
    If objRfcFunc.Call = False Then
       MsgBox objRfcFunc.Exception
    End If
    Dim objDatRec As Object
    Dim objFldRec As Object
    For Each objDatRec In objDatTab.Rows
       For Each objFldRec In objFldTab.Rows
          Cells(objDatRec.Index, objFldRec.Index) = _
                Mid(objDatRec("WA"), objFldRec("OFFSET") + 1, objFldRec("LENGTH"))
       Next
    Next
    End Sub
    The table which contains the article descriptions is called 'MAKT' and this table also contains the column 'MATNR' which is the article field.
    Many thanks,
    Mike

    Is there no way of connecting the tables within the code.
    IT won't give me access to SE11
    Thanks,
    Mike

  • Call RFC directly from PI

    Hi. Is there a way to call an RFC from PI? I want the scenario to be triggered by PI, not an external system.
    Thank you.
    Nicole

    Hi Nicole,
    You have to create a RFC Receiver Adapter. In this case, PI sends the data in the RFC format to the target system where the RFC is executed. Configuring the receiver adapter is even simpler. Look at:
    http://help.sap.com/saphelp_nw70/helpdata/en/33/c6e63b60c25767e10000000a11402f/frameset.htm
    Depend on your scenario and ERP version, consider using ABAP Proxy instead of RFC module.
    Regards,
    Rogério

  • Setting Characteristics after calling RFC Fucntion from IPC

    From the java Class with the name as the Function Module, I connected to R/3 and called an RFC enabled Function Module.  Now I get more parameters from the output table. How do I set these output Parameters back to the Configuration page characteristics. I tried args.set_value() but it throwed error saying that the characteristics is not in the args.
    So how do i set the characteristics from the output of the FRC function call?

    Answer is:
    scelib.set_value(inst, output_parameter_name,output_parameter_value);
    Just thought of sharing..

  • How can I call a variable from VBA in Diadem report?

    Hello,
    I have a script in Diadem, script that I can control from a VBA application ( from Excell), and I want to send from Excell some details to the report.
    I want in the report, the  Local Test Order field to by the LocalTO from the VBA (Excell), the DVM Test Order fiel to be the DVMTO from Excell, and ..... al the fields from the excell to be in the report.
    And in the Diadem script the filename of the export .pdf file to be the filename from the Excell.
    Attached I put the script from Diadem and the VBA application.
    Thank you for your time.
    Attachments:
    Diadem.zip ‏28 KB

    Hello Marse!
    Sorry that I was not clear enough and add the hwo-to via OLE
    For way 1. you have to add this lines to your Excel VBA code:
    loadscript = IDIACommand.TextVarSet("T1","Value of T1")
    For way 2. it is:
    loadscript = IDIACommand.CmdExecuteSync("GlobalDim('MyGlobalVar'")
    loadscript = IDIACommand.VariantVarSet("MyGlobalVar","Value of MyGlobalVar")
    Inserted before your line
    loadscript = IDIACommand.CmdExecuteSync("scriptstart('C:\BForce\LIBR\BForce2.VBS')")
    Hope it is clear now! Otherwise feel free to ask
    Matthias
    Message Edited by Twigeater on 10-10-2008 09:43 AM
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • RFC_ERROR while calling RFC FM from XI

    Hi Guys,
                  I am getting following error in the XI Monitor
    <rfc:ZFIBAPI_ACC_DOCUMENT_POST.Exception xmlns:rfc="urn:sap-com:document:sap:rfc:functions"><Name>RFC_ERROR_SYSTEM_FAILURE</Name><Text>Type conflict when calling a function module.</Text><Message><ID>RFC_ERROR_SYSTEM_FAILURE</ID><Number>341</Number></Message><Attributes><V1>CALL_FUNCTION_CONFLICT_TYPE</V1></Attributes></rfc:ZFIBAPI_ACC_DOCUMENT_POST.Exception>
    Have you come across this type of error.
    Is it an issue with mapping.
    Cheers
    Senthil

    Hi Sentil,
    Have you created a message type for your RFC ? You dont need a message type for your RFC, you can use RFC request and response directly in your message mapping.
    For re-importing an RFC, I would prefer deleting the RFC and then importing it again. Most of your field mapping ( in case of graphical mapping) will be taken care by XI, except for the new fields, if any, will be there in your RFC.
    Thanks,
    Pooja pandey

  • How to call the RFC's from the third party applications or Non SAP applicat

    Hi,
    For calling RFC's from the wedynpro , SAP has provided the modeling concept.
    In the same way, if i want to access or call the RFC 's from the third applications or Non SAP applications what is the procedure and what is the methodoligy.
    As per my knowledge, we need to expose those RFC's as webservices . Then we must be able to acces in hetrogeous environment from any third party applications..
    Please revert back soon, It is very urgent.
    Regards
    Vijay

    Ayyappa Raj,
    Thanks for the reply.
    Please let me the detailed information for implementing.
    AS you said . I need expose the RFC's as webservice. This point is clear to me.
    2) Use tthe JCo to connect and create client proxy.
    Can u please elabrate the above point?
    If u have any steps created in the document or url to refer. Please forward it to me.
    Please forwar the document to this id "vijay00" in yahoo.
    AS the sdn is not allowing to give  the maill id i have given only the id details in yahoo.
    I am new to this procedure.
    Regards
    Vijay

  • How to call a BAPI from Visual Composer

    hi,
       I am new to Visual composer. can some body give me step by step information of calling a bapi or RFC from VC.
    Thanks in advance,
    Gopi

    Hi Gopi,
    Steps involed for calling RFC/BAPI from VC
    1. Choose Model->Select Data Services.
    (Alternatively, click the Data button in the task panel toolbar.)
    2. In the Portal field at the right end of the main toolbar, enter the URL of the portal from
    which you can access the back-end system used by the iView.
    For example, you could enter: http://<yourportal>:50000/..
    3. Click the traffic light icon to the right of the Portal field. The portal Welcome screen
    appears.
    4. Log on to the portal as a user that exists in the connected back-end system, or which is
    mapped to a user of that system. Click OK.
    Once a connection to the portal is established, a list of system aliases defined in the
    portal system landscape appears in the System drop-down
    list.
    From the System drop-down list, choose the SAP system that contains the function module.
    6. Under Search SAP System, click the Search tab and in the Name field, enter the search string: <RFC/BAPI name>. Then click Search (at the bottom).
    5. A list of function modules matching the search string is displayed.
    7. Drag the function module/bapi from the Data task panel into the
    workspace: The data service is added to your model.
    8. Periodically save your work. To do so, choose File->Save Model.
    Finally test the iview in VC.
    In the workspace, drag your mouse from the Input port of the data service, <inputform> and dragn your mouse from the outut port from the data service <tabelview and etc..>
    or
    Go through the this documentation...
    http://help.sap.com/download/netweaver/nw04/visualcomposer/VC_60_UserGuide_v1_1.pdf
    Thanks,
    Suriya.

  • Help for Calling RFC in B2C application.

    hi,
    We had written one RFC and all java classes related to that.
    we are able to call RFC in b2c application.we are calling RFC on loading of JSP.
    now my requirement is to call same RFC in other JSP but muliple times(in a for loop).But how can i do that?
    one thing is sure we cannot calll this RFC on loading of new jsp page.we have to call inside jsp page(in a loop).
    there is any way?
    please help me out.
    thanks in advance.
    jayesh talreja

    Two things I would like to say here:
    1) Calling RFCs directly from JSP is not supported so we need to use interfaces and backend classes.
    2) Calling an rfc is java code and in jsp we write java code along with html to make it dynamic...so dynamic
    call is also possible.
    ie. suppose we want to call our rfc for fetching some data from the backend based on the data entered at item level once the user clicks on update button on order creation page.So we can write the code like below
                                  <%--   messages --%>
                                       <%@ include file="/b2b/itemErrMsg.inc.jsp"%>
                                       <% } %>
                                       <%-- ui.showItemDetailButton() --%>
                                       <% } %>
                                       <%-- ui.isBOMSubItemToBeSuppressed() --%>
                                       <%--Start of addition by Arshid --%>
                        <!-- From here our custom rfc call is starting-->
                        <%
                             String arg1[]= {"crm~isa~isacore~resources_en"};
                             if((JspUtil.removeNull(item.getProduct()).length()) !=0 && !(JspUtil.removeNull(item.getNetValue()).equals(WebUtil.translate(pageContext,"yourcompany.order.minimumValue",arg1))) )
                                  String baseUOM = "";
                                  int enteredQuan= 0;
                                  double minOrderQuan = 0.00;
                                  double roundingValue = 0.00;
                                  BusinessObjectManager isaBOM = (BusinessObjectManager)userSessionData.getBOM(BusinessObjectManager.ISACORE_BOM);
                                  User user = (User)isaBOM.getUser();
                                  Shop shop = (Shop)isaBOM.getShop();
                                  String distrChannel = shop.getDistributionChannel();
                                  String sod = shop.getSalesOrganisation();
                                  Z_CustomBusinessObjectManager customBOM = (Z_CustomBusinessObjectManager)userSessionData.getBOM(Z_CustomBusinessObjectManager.CUSTOM_BOM);
    //Z_prodInfoValue is a bo that will hold the data returned from rfc call
                                  Z_prodInfoValue z_prodinfo = customBOM.getZ_prodInfobo().getProdInfo(Zeropadding.productInfoNoPadding(item.getProduct()), sod, distrChannel);
    <!-- Call ends here and this piece of code is called for every item on clicking on update buton -->
    Although this is not a good code design as instead of making multiple calls to the backend we can get the above thing done in a single call also.I wrote this code just to give an example .
    This clearky proves we can have dynamic calls to the backend through jsps also.
    But Jayesh, your question is not very clear to me.
    If its about for loop, where you want to call the backend for multiple times with different set of values than i would rather suggest you to create lists of these different datasets and send these in a single call to the backend and fetch the data similarily in tables in a single call.
    Regards,
    Arshi

  • What is best option to Create an Annotation in PDF from VBA?

    It appears thwere are 2 ways to create an annotation (Like a sticky note) via scritping into a PDF File from VBA
    1. In VBA use the Acrobat Interapplication Communication via OLE to use AcroExch.PDAnnot
    2. Use AcroJS from a VBA call
    My question is:
    What are the pros and cons of each - is one better than anohter/
    How do I call Acro JS from VBA?
    thanks

    ayman hamdan01 wrote:
    hi all
    i read and learn about (( tablespaces and datafiles)) and all option and types like (local , dictionary , autoextend , reuse,segment manual and auto , autoallocate,logging , storage ..etc) , if you are real dba in software company . what is your plan to create best tablespace and datafile ?
    thanks alot
    Edited by: ayman hamdan01 on May 17, 2013 7:58 AMwhich metric measures "best"?
    Is it fewest characters in SQL statement?

  • Call RFC enabled function from within VBA in BI 7.0

    Hello Experts,
    the problem that we have should be general, i have found some postings on this forum concerning it, but unfortunately no proper solutiont.
    I just want to have the possibility to call the rfc enabled function module from within the callback function in VBA after executing of some query.
    I have seen the suggestion to build a new RFC connection in VBA, but therefore you should hard-code all connection parameters (including user + password)
    in the VBA code, this solution is for us not acceptable due to the security reasons.
    Is there some way to use the existing connection of BEx Analyser in order to execute the function calls?
    This functionality was possible in 3.5 but not in 7.0 since many functions that were available in 3.5 are not supported now.
    Do you have experience/suggestions for this problem?
    Any help would be great.
    Thanks a lot,
    Kirill

    I've got the same problem. Did you find the solution?
    Thank you,

  • Call RFC from Excel

    I have created rfc function, and it works fine in SAP, but when I try to call this function from Excel I get '0.00000', data type is correct.
    VBA code:
        Set F2 = functionCtrl.Add("ZFUNC")
        F2.exports("PARAM1") = "123"
        F2.exports("PARAM2") = "321"
        F2.Call
        MsgBox F2.Imports("EXP1").Value
    Any suggestions?

    it's is ok now

  • Call  RFC from ECC and display the values in  AET

    Hi ALL,
    I had an RFC in ECC ( Z_CRM_SPEC_DATA) this should be called into my AET Fields in getter method.
    In getter method of tat AET field what code should i write?
    Plz help me on this.

    HI,
    1) Call the  RFC(Z_CRM_SPEC_DATA) from ECC and display the values as mentioned in below AET fields.
    AET FIELDS :    zzfld00000M    zzfld00000N
    Description  :    Budget Quan    Forecast Quan
    values         :    (--5.0)(6.0--
    2) (Fetch Budget and Forecast data from ECC ),you would need to pass Material Number(MATNR) as well as Ship to party info to fetch the budget and forecast data as one material may be assigned to 2 or more SH with specific budget and forecast data for each.
    Edited by: venkatabharathv on May 23, 2011 2:44 PM
    Edited by: venkatabharathv on May 23, 2011 2:49 PM

Maybe you are looking for

  • JMS Resource Adapter and JDeveloper 10g

    Hello, I an trying to use the OC4J JMS Resource Adapter for WebSphere MQ with Jdeveloper 10g (OC4J 9.0.4). The program is just a servlet that sends a message to a JMS Queue. My orion-web.xml looks like: <?xml version = '1.0' encoding = 'windows-1252'

  • Early days but disappointing

    The engineer turned up as arranged a week ago to connect infinity.  I wanted the main box upstairs rather than in my dining room but that was not an issue as there are 2 cables at the incoming point so easy to use the right one. Engineer did as asked

  • Where is the lock symbol that tells me I am on a secure page in Firefox 5.0

    I just recently upgraded to Firefox 5.0. The old version had a little lock in the bottom right hand corner that signified that I was on a secure page (for banking, shopping checkout, etc). I do not know where to check on the page of this new version

  • CS6 and CC compatability

    I've been working on a project on my laptop that runs Premiere Pro CC, but i want to also work on the project on my work computer that has CS6 installed. the Premiere Pro CS6 will not open the project that is stored on an external hard drive. Is it p

  • How do you individually strikeout text in a menu ring?

    I have a menu ring with a list of options for the user. Once the option has been ran, I want the text in the menu ring to reflect this by being "strikedout"... I don't want it disabled, just incase the user wants to rerun the option but I want the me