Results 1 to 4 of 4

Thread: VB and SAP Integration

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    2

    VB and SAP Integration

    Hi All,

    Can anyone please brief me about that how is integration between Visual Basic and SAP is done.I need to read data from SAP tables and also write some data back to the SAP tables...

    Can anyone give me some solution...

    Thanks

    Javed

  2. #2
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    280

    Re: VB and SAP Integration

    hi,

    I only know about some of the older technologies for this... (i'm aware that new processes/function exist within sap these days)

    you could look at sap business connector but I think that this is being replaced by a new technology soon and requires an install on sap.

    you could also look at the dcom connector (found usually on the gui cd!) - i believe that the .net version is quite good although I have only used the older version.

    or similar to the dcom connector you could use the sap gui functions if U need something quick & dirty.

    eg- heres an old piece of code - copy into a .vbs and dclick (having got up the logon information within the script)

    what this is doing is calling a sap function (BAPI_COSTCENTER_GETLIST) via the gui function and returning data into a string

    eg
    VB Code:
    1. '
    2. '  some more stuff
    3. '
    4.    Option Explicit
    5.  
    6.    Const ForReading = 1, ForWriting = 2
    7.  
    8. '--main r3 object
    9.    Dim ObjR3    
    10.  
    11. '--parameter to abap object
    12.    Dim ObjPrm1
    13.    Dim ObjPrm2
    14.    Dim ObjPrm3
    15.    Dim ObjPrm4
    16.    Dim ObjPrm5
    17.    Dim ObjPrm6
    18.    Dim ObjPrm7
    19.    Dim ObjPrm8
    20.    Dim ObjPrm9
    21.    Dim ObjPrm10
    22.    Dim ObjPrm11
    23.    Dim ObjPrm12
    24.  
    25. '--parameter from abap (return) object
    26.    Dim ObjParmin
    27.    
    28. '--abap function to use object
    29.    Dim ObjR3Func
    30.    
    31. '--return code for abap call
    32.    Dim result
    33.    
    34. '--abap table returned object
    35.    Dim Objudextab
    36.  
    37.    Dim Strout, intidx
    38.  
    39.    logon_to_sap
    40.    read_data
    41.  
    42.    strout = ""
    43.  
    44.    Do
    45.  
    46.       intidx = intidx + 1
    47.  
    48.       on error resume next
    49.  
    50.       if ObjUdextab(intidx, 1) = "" then
    51.          exit do
    52.       end if
    53.  
    54. '-----gav whatever U want goes ere
    55.  
    56.       strout = strout & ObjUdextab(intidx, 1) & _
    57.                         " - "                 & _
    58.                         ObjUdextab(intidx, 2) & _
    59.                         " - "                 & _
    60.                         ObjUdextab(intidx, 3) & _
    61.                vbcrlf
    62.      
    63.    Loop
    64.  
    65.    on error goto 0
    66.  
    67.    set Objudextab = nothing
    68.    Wscript.Echo strout
    69.  
    70.  
    71.  
    72. sub read_data
    73.  
    74.  
    75. '--address the set abap function
    76.    Set ObjR3Func = ObjR3.Add("BAPI_COSTCENTER_GETLIST")
    77.    
    78. '--and the paramters we will send
    79.    Set ObjPrm1 = ObjR3Func.exports("CONTROLLINGAREA")
    80.    Set ObjPrm2 = ObjR3Func.exports("CONTROLLINGAREA_TO")
    81.    Set ObjPrm3 = ObjR3Func.exports("COMPANYCODE")
    82.    Set ObjPrm4 = ObjR3Func.exports("COMPANYCODE_TO")
    83.    Set ObjPrm5 = ObjR3Func.exports("COSTCENTER")
    84.    Set ObjPrm6 = ObjR3Func.exports("COSTCENTER_TO")
    85.    Set ObjPrm7 = ObjR3Func.exports("PERSON_IN_CHARGE")
    86.    Set ObjPrm8 = ObjR3Func.exports("PERSON_IN_CHARGE_TO")
    87.    Set ObjPrm9 = ObjR3Func.exports("DATE")
    88.    Set ObjPrm10 = ObjR3Func.exports("DATE_TO")
    89.    Set ObjPrm11 = ObjR3Func.exports("COSTCENTERGROUP")
    90.  
    91. '--and values
    92.    ObjPrm1.Value = "GB01"
    93.  
    94. '--do it
    95.    result = ObjR3Func.call
    96.    
    97. '--if ok then process - else exit
    98.    If result = False Then
    99.  
    100. '-----if it was stuffed the exit
    101.       Wscript.Echo  "Error reading sap - " & ObjR3.connection.User & " - " & ObjR3.connection.System
    102.       ObjR3.connection.LOGOFF
    103.       WScript.Quit
    104.    else
    105.       Set ObjUdextab = ObjR3Func.Tables("COSTCENTER_LIST")
    106.    End If
    107.  
    108. '--drop objects
    109.    Set ObjR3Func = Nothing
    110.    Set ObjPrm1 = Nothing
    111.    Set ObjPrm2 = Nothing
    112.    Set ObjPrm3 = Nothing
    113.    Set ObjPrm4 = Nothing
    114.    Set ObjPrm5 = Nothing
    115.    Set ObjPrm6 = Nothing
    116.    Set ObjPrm7 = Nothing
    117.    Set ObjPrm8 = Nothing
    118.    Set ObjPrm9 = Nothing
    119.    Set ObjPrm10 = Nothing
    120.    Set ObjPrm11 = Nothing
    121.  
    122. end sub
    123.  
    124. sub logon_to_sap
    125.  
    126.    Set ObjR3 = CreateObject("SAP.Functions")
    127.  
    128.  
    129. '--get this info from your logon pad..
    130.    ObjR3.connection.System            = "Kxx"
    131.    ObjR3.connection.Client            = "172"
    132.    ObjR3.connection.User              = "myid"
    133.    ObjR3.connection.Password          = "mypassword*"
    134.    ObjR3.connection.Language          = "EN"
    135.    ObjR3.connection.ApplicationServer = "appservernamehere"
    136.    ObjR3.connection.SystemNumber      = "61"
    137.  
    138. '--if no logon then exit
    139.    If ObjR3.connection.logon(0, True) <> True Then
    140.       Wscript.Echo  "Sap connection error - " & ObjR3.connection.User & " - " & ObjR3.connection.System
    141.       WScript.Quit
    142.    End If
    143.  
    144. end sub

    pre-req = need a machibne with the sap gui working...


    the code called is a sap written bapi - just returns costcenter given a company code but I could have picked any function to demo..

    what you could do is write functions that take input and read sap tables and other functions similar & update - I write standard functions via sap tran se37 and just set the "rfc"-able checkbox - at this point the function should be callable to both the dcom & gui functions.

    rather than the gui fuction calling above the dcom connecter is really a better solution - when the dcom dll author tool it connects to sap and when u select a bapi function the app will author a dll for U.

    this dll is just like any other activexdll with the function becoming methods for the dll and the parameters the properties to and from...

    the actual dll is a "proxy stub" and just takes the information and sends this over to the sap function..

    I can give u a proper dcom example but its a little indepth lte me know if U want..

    have a play around.. - I have a little vb app that lets me view any table and file all from withing vb but the data is in sap - work well and all is done via the gui functions..

    cheers AJP
    Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor

    Real programmers use less....

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    2

    Re: VB and SAP Integration

    Hi,

    Thanks for the Quick Reply...

    Can you please suggest me any way in which we can pass an entire ADODB Recordset to SAP without Looping through row by row.

    I came to know that there is a option called "TABLES" like IMPORTS AND EXPORTS options...can you please tell us how can we use this TABLES.

    Is there some way in which we can attach the ADODB Recorset directly with the TABLES option.

    Thanks

    Javed

  4. #4
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    280

    Re: VB and SAP Integration

    hi,

    im not sure it works like that I am doing all the work with 1 call and then the loop is later extracting data from the record sets.

    the tables/imports/exports methods statements all directly relate to the similarly named tabs inside sap tran se37.

    the fields that are sent to the function are the "exports"

    eg

    Set ObjPrm1 = ObjR3Func.exports("parametername")
    ObjPrm1.value = "parametervalue"

    this for a normal field - the imports (data returned to us) are similar - so you can send data back and forth as usual.

    when a field is not just a straight standard field or structure but something like a set of data, this is where tables are used. Tables are usually used when sending back a variable set of records (i.e. say we want to send a company code to sap and get all the vendor names back (all in 1 call) - the multiple names would all be returned at one within a record set).

    (tables are not like imports or exports - the are both in & out..)

    so to recap

    - set the sap objects
    - set up the input values (exports here in sap terms)
    - call sap (i.e the "result = ObjR3Func.call" statement)

    at this point ALL data is returned.

    then loop thru the record sets to extract the data - or do whatever U want with the record set...) looping thru the tables isnt doing a communication to sap here..

    does that make sense,
    cheers, AJP
    Intel 486dx3 - VB4 - DR-Dos - 2mb EdoRam - 2x CDrom drive - Window for Workgroups - CGA monitor

    Real programmers use less....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width