Quantcast
Channel: SCN : Discussion List - Scripting Languages
Viewing all 325 articles
Browse latest View live

VBA and RFC - How to deal with tables in export/import parameters

$
0
0

Hi,

 

maybe one of you can support me...

 

I have a couple of vba modules reading and writing data to SAP by means of function modules. As usual, they use export and import parameters as well as tables (in the table section). They work very well.

.

Now, I want to execute some newer function modules and they don't use tables in the table section (because they're obsolete nowadays), instead they expect the tables as export resp. import parameters. I tried it in a couple of ways, without any success.

Has anybody tried this before? And if so, do you mind share some snippets?

 

Best regards, Thomas


Alternative function for FCI_GET_COMMA_LIST (SAP eSourcing)

$
0
0

Hi all,

 

The function FCI_GET_COMMA_LIST sorts the result set after fetching the list. I am looking for a function which can give me the list (comma separeted ) without sorting.

 

Is there any list function which exists in SAP eSourcing ?

 

Kind Regards!

M A Siddiqui


saprfc_export values not displaying

$
0
0

Hello,

 

I cannot get the export values to display from the saprfc_export.  When I print the array, the fields show blank values, however when I output saprfc_function_debug_info, the fields and their values are all shown. So can anyone show me why the values in the export array are not displaying?

$cust_params['PMNTTRMS'] not showing value in php

 

thanks!

// Create saprfc-instance

$login = array(

"ASHOST"=>"xxx.xxx.xxx.xxx" // application server
,"SYSNR"=>"00" // system number
,"CLIENT"=>"400" // client
,"USER"=>"xxx" // user

,"PASSWD"=>"xxx"

,"CODEPAGE"=>"1100" // password

); // detailed debugging information

 

 

$rfc = saprfc_open ($login );

         //We must know if the function really exists

          $fce = saprfc_function_discover($rfc, "ZZBAPI_SALESORDER_SIMULATE");

          if(!$fce){

               echo "<br>The function module has failed.<br><br>";

            echo "<br> rfc: " . $rfc;

            exit;

          } else {

echo "<br>The function module connection successful!.<br>"; 
  }

 

 

$cust_params = '';

 

 

          //Pass import parameters

  
       $ORDER_HEADER_IN = array("DOC_TYPE"=>"ZOR",

                              "ORD_REASON" => "WWW",

"PURCH_NO_C" => "WEB ORDER",

                              "SALES_ORG"=>"0010");

 
 

          saprfc_import ($fce,"ORDER_HEADER_IN",$ORDER_HEADER_IN);

          //Pass table parameters

          saprfc_table_init ($fce,"ORDER_ITEMS_IN");

        

$ORDER_ITEMS_IN = array("ITM_NUMBER"=>"10",
       "MATERIAL" => "000000000000029901",
                              "REQ_QTY"=>"3");
 
 

          saprfc_table_append ($fce,"ORDER_ITEMS_IN", $ORDER_ITEMS_IN);

         // $ORDER_ITEMS_IN = array (

                   // "MATERIAL"=>"P-101",

                  //  "REQ_QTY"=>"0000000001000"

             //  );

          // saprfc_table_append ($fce,"ORDER_ITEMS_IN", $ORDER_ITEMS_IN);

        

  $ORDER_PARTNERS = array (

                    "PARTN_ROLE"=>"AG",

                    "PARTN_NUMB"=>"0000099996"

               );

          saprfc_table_append ($fce,"ORDER_PARTNERS", $ORDER_PARTNERS);

          saprfc_table_init ($fce,"ORDER_ITEMS_OUT");

 
 
//saprfc_export ($fce,"ZBAPICUSTOMER",$cust_params);
    $cust_params = saprfc_export ($fce,"ZBAPICUSTOMER");

   echo ($cust_params);

   //$FULLNAME = saprfc_export ($fce,"FULLNAME");

   //echo ($FULLNAME[FIRST]." ".$FULLNAME[LAST]);

 

 

  

          //Call and execute the function

          $rc = saprfc_call_and_receive ($fce);

 

 

echo "<br>HERE ZBAPICUSTOMER[PMNTTRMS]: " . $cust_params["PMNTTRMS"] . "<br>";
echo "<br>HERE ZBAPICUSTOMER1: " . $cust_params . "<br>";
echo "<br>HERE ZBAPICUSTOMER2: " . $cust_params[1] . "<br>";

 

 

echo "<br>HERE ZBAPICUSTOMER3: " . $cust_params[PMNTTRMS] . "<br><br><br>";
echo "<br>HERE ZBAPICUSTOMER4: " . $cust_params['PMNTTRMS'] . "<br>";
print_r ($cust_params);
echo "<br>----<br>";

 

 

saprfc_function_debug_info($fce);

 

 

foreach ($cust_params as $cust) {

        echo "<br>2HERE cust_params PMNTTRMS2:  " . $cust['PMNTTRMS'] . " - PMNTTRMS: " . $cust["PMNTTRMS"] . "<br>";

       }

PHP + SAP: Objetivo (Extração e interação via web)

$
0
0
Tema

Olá, ontem iniciei um estudo no qual visa levar resultado, tabelas e registros de pedidos entre outros temas via página WEB com desenvolvimento interno PHP. (sem SAP Fiori) (e sem .net)


Sei que o assunto é extenso e complexo, porém dividi em algumas fases como por exemplo ESTA INICIAL e conforme for evoluindo criarei um POST no BlogSap no qual viso criar esse material.


Equipe atual em evolução no tema:

-Funcional MM

-Developer PHP

-Basis

 

captura.png

 

Depois de diversas tentativas obtivemos sucesso no início desse desafio:

-Instalação do ambiente Windows (no meu caso Windows 2003 server R2)

-Instalação do ambiente PHP neste ambiente (Apache + MySql)

-Registro das DLLS de SAP+PHP (SAPRFC)

-Instalação do SapGui

-via php + html puro logar com um usuário e senha em um ambiente de teste SAP

-trazer um resultado de uma rfc para uma tabela web

-testamos trazer uma tabela que não possuía acesso a RFC e claro, mensagem de "acesso negado"

-e por fim trazer um resultado de uma rfc para uma tabela web de usuários e ok, exibidos com sucesso

 

Até ai acredito que tenha passado o obstáculo de conectar o SAP a uma página WEB. Já conseguiremos internamente baseando-nos nas Rfcs que temos trazer diversos resultados e gráficos de forma fácil para nossa intranet por exemplo. (um dos motivos de não utilizarmos uma solução extremamente completa).

 

Perguntas:

-Poderíamos trazer requisições / pedidos de um determinado code, diferentes de liberados e interagir com aprovações e reprovações? (conhecemos as tabelas envolvidas nesses processos)

-Existem exemplos que possa não só trazer as tabelas mas também uma via dupla que eu possa levar dados ao SAP via Rfc?

-Existem mais pessoas que estão buscando essas soluções mais simples?

-Existem documentações ou algum tipo de horizonte que poderíamos dar continuidade nisso?

-É recomendado esse tipo de ação?

-No tema segurança já estamos avaliando diversos pontos, mas existem recomendações nessa frente?

-É permitido esse tipo de interação por um determinado usuário? (temos já funcional a tela de logon)

-Posso trazer este tema para ser debatido aqui levando em consideração que o Sap Fiori possui aprovações e muito mais do que isso?

 

Posteriormente nosso objetivo é maior do que isso claro (outras interações), pode ser que nos deparemos com outras questões mas espero que possa receber ajuda e ajudar neste tema inicial.

 

 

Atenciosamente Bruno Rizzo

Script for the SAP report - download to excel - problem

$
0
0

Hi all

I know that similar problem had already been discussed but going through the solution presented in
any of that topic I was not able to be successful  (I am beginner in terms of VBA and SAP scripting)

What I would like to do is simply create the SAP script which based on the parameters filled
in in the excel sheet (user form created) will connect to SAP and make the report which I would like to have saved on my local drive as an excel file.
Everything is ok till the moment I would like to save it.  As you know SAP records the macro only till the moment some window pops up (where and under what name you would like to have your report  saved)

 

Could you please advise  ?

 

As a screen I attached also point where macro stops (maybe this makes difference)

 

Thank you in advance for any suggestions.

 

Below my code.

 

 

Private Sub CommandButton1_Click()

 

Dim MojaData

MojaData = ComboBox2.Value

 

Dim Companycode

Companycode = ComboBox1.Value

 

Dim Depreciation_area

Depreciation_area = ComboBox3.Value

 

If Not IsObject(Application1) Then

Set SapGuiAuto = GetObject("SAPGUI")

Set Application1 = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

Set Connection = Application1.Children(0)

End If

  If Not IsObject(session) Then

     Set session = Connection.Children(0)

  End If

 

If IsObject(WScript) Then


WScript.ConnectObject session, "on"

   
WScript.ConnectObject Application1, "on"

 

End If

Dim sbar As String

sbar = session.findById("wnd[0]/sbar").Text

  

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").Text = "/n s_alr_87011990"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtBUKRS-LOW").Text = Companycode

session.findById("wnd[0]/usr/ctxtSO_ANLKL-LOW").Text = ""

session.findById("wnd[0]/usr/ctxtBERDATUM").Text = MojaData

session.findById("wnd[0]/usr/ctxtBEREICH1").Text = Depreciation_area

session.findById("wnd[0]/usr/ctxtSRTVR").Text = "0003"

             

session.findById("wnd[0]/usr/radSUMMB").SetFocus

session.findById("wnd[0]/tbar[1]/btn[8]").press

session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[1]").Select

 

??

 

sap.macro.png

 

How to Create Script Mass User Login & Doing Transaction

$
0
0

Hi SAP Experts,

 

I have a activity to do performance test with 100 concurrent users.

But unfortunately i have no supplement PT software for this activity (Like Rational PT or Loadrunner).

So i think i will do it with sapgui script.

Is it possible to create vb script (SAP GUI Scripting) to fulfill my requirement to do this activity. If yes how to create this script.

 

Thanks & Best Regards,

Husin

Pass the SAP User Credentials retrieved through rfcConnection function as input parameters to another Java Program

$
0
0

All,

I have a VBA Excel program that call Java program to update config objects in SAP PI. Now when the user first opens the excel he has to go through SAP authentication using rfc.logon and connection functions. This is just to get access to the excel.
the second step is running the Java program through call shell command. The java program internally needs uswer id and password again to actually connect and update the config in SAP PI.

What I am trying to do was when the user first enters the user id and password (rfcConnection.Password), I can pass the same credentials as the input paramerets to the java program. However though I am able to pass userID (rfcConnection.User) in call shell which runs Java cmd. I am unable to pass rfcConnection.Password as the value is hashed.

Please let me know if anyone is aware of passing the SAP User Credentials retrieved through rfcConnection function as input parameters to another Java Program.

Thanks

Wants some understanding on SAP code using VBA Urgent

$
0
0

I am not good in SAP coding .... so cant figure out the below line. Could you find out why I am getting an error on second last line ... And Also I am not getting any details about pressbutton method.

 

And How can we identify the button name or id in SAP coding

 

 

  .findById("wnd[0]/usr/cntlCLFRM_CONTAINER/shellcont/shell/shellcont[1]/shell/shellcont[0]/shell/shellcont[0]/shell/shellcont/shell").modifyCell 0, "VALUE1", sCaseId.Item(y)

 

.findById("wnd[0]/usr/cntlCLFRM_CONTAINER/shellcont/shell/shellcont[1]/shell/shellcont[0]/shell/shellcont[1]/shell").pressButton "DO_QUERY"

 

Set dgrid = .findById("wnd[0]/usr/cntlCLFRM_CONTAINER/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell")
dgrid.currentcellrow = 0
dgrid.doubleclickcurrentcell

 

'to copy the check number and paste it to the customer.
.findById("wnd[0]/usr/cntlCLFRM_CONTAINER/shellcont/shell/shellcont[1]/shell/shellcont/shell/shellcont[0]/shell").pressButton "TOGGLE_DISPLAY_CHANGE"      ' Here getting an error

.findById("wnd[0]/usr/cntlCLFRM_CONTAINER/shellcont/shell/shellcont[1]/shell/shellcont/shell/shellcont[1]/shell/shellcont/shell").setCurrentCell 23, "VALUE2"


BASIC is fifty

$
0
0

Hello community,

 

BASIC is the favorite language style of different scripting languages, like VBScript resp. SAP GUI Scripting, AutoIt or FBSL. BASIC celebrates now its 50th birthday, look here, also look here for a comment.

 

Happy birthday BASIC.

 

Cheers

Stefan

Object is not created in VBA

$
0
0

Hello All,

 

I encountered a problem with my VBA code. Basically what I am trying to do is to change the posting date of parked documents in SAP by VBA code run from Excel. I created the original code about one and a half years ago. It works fine assuming that the user does not switch on the legend for the FBL1N T-code. Now I trying to develop the code further and tackle this issue. The basic problem is that the code navigates in the SAP user area by absolute addresses (explicit column and row numbers, with other words, 22 characters from left and 5 from top). The procedure requires to sort the report first and then click in each document. That's why the legend makes the trouble because it adds two rows to the top and then the sort does not work (instead of selecting a column header field for sorting it selects a blank screen field).

 

Now, I see two options to handle the matter: a, enhance the code to loop through all screen fields and determine where are the header fields or b, acquire user setting and swith off legend temporarily. Currently I am trying work out the first approach as I have no clue is it possible to get user settings.

 

I have inserted the macro itself and printscreens to understand the problem. The SAP FBL1N picture shows the report on screen. I would like to find the red marked field (the Doc.no) in my VBA collection. See VBA editor pic. The object named "Userarea" are created properly. This is the collection of all fields displayed on the SAP screen of user area. However I cannot access any member of this collection. This command: Set Screenfield = UserArea.Item(i) should work (as it does create the object from a member of a collection in other non-SAP related cases where I use this command in VBA).

 

I hope somebody can help me.

 

Thank you very much

Sandor

 

Ps:

 

the VBA code:

 

Sub Main()

    Dim PtDate As Date, cocode As String, docno As Long, doc As Variant, Msg As Integer, endtext As String
   
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
   
again2:
    On Error Resume Next
    PtDate = Application.InputBox("Pls Enter", "Posting date?", Left(Now(), 10))
    If PtDate < Now() - 1 Then
        Msg = MsgBox("You cannot give an earlier date than today. Please try again. Thank you.", vbOKCancel, "Error encountered"):
        If Msg = vbCancel Then Exit Sub Else GoTo again2:
    End If
   
again:
    On Error Resume Next
    cocode = InputBox("Please enter company code", "Which Company code to run on?")
   
    On Error Resume Next
    Msg = CInt(cocode)
    If Err.Number <> 0 Then Msg = MsgBox("Not valid number. Try again?", vbOKCancel, "Error encountered"):  If Msg = vbCancel Then Exit Sub Else GoTo again:
   
    If Err.Number <> 0 Or Len(cocode) > 4 Or Len(cocode) < 3 Then
        Msg = MsgBox("Not valid number. Try again?", vbOKCancel, "Error encountered")
        If Msg = vbCancel Then Exit Sub Else GoTo again:
    End If

Dim SapGuiAuto As Object, SapApp As Object, SapConn As Object, SapSession As Object, wnd As Object, wnd2 As Object, Sbar As Object
Dim UserArea As Object, Screenfield As Object, term As String
   
    Set SapGuiAuto = GetObject("SAPGUI")
    Set SapApp = SapGuiAuto.GetScriptingEngine
    Set SapConn = SapApp.Children(0)
            If SapConn Is Nothing Then
            Msg = MsgBox("Please login to  SAP, then press Ok", vbOKCancel, "SAP not started")
            If Msg = vbCancel Then Exit Sub
            Set SapConn = SapApp.Children(0)
            End If
    Set SapSession = SapConn.Children(0)
    Set wnd = SapSession.findById("wnd[0]")
    Set Sbar = SapSession.findById("wnd[0]/sbar")
   
    Txt = "wnd[0]/usr/subHEADER_AND_ITEMS:SAPLMR1M:6005/tabsHEADER/tabpHEADER_TOTAL/ssubHEADER_SCREEN:SAPLFDCB:0010/ctxtINVFO-BUDAT"
   
    SapSession.findById("wnd[0]").maximize
   
SapSession.findById("wnd[0]/tbar[0]/okcd").Text = "/nfbl1n"
wnd.sendVKey 0
   
SapSession.findById("wnd[0]/usr/chkX_NORM").Selected = False
SapSession.findById("wnd[0]/usr/chkX_SHBV").Selected = False
SapSession.findById("wnd[0]/usr/chkX_MERK").Selected = False
SapSession.findById("wnd[0]/usr/chkX_APAR").Selected = False
SapSession.findById("wnd[0]/usr/chkX_PARK").Selected = True
SapSession.findById("wnd[0]/usr/radX_AISEL").Select
   
SapSession.findById("wnd[0]/usr/ctxtKD_LIFNR-LOW").Text = "1000000"
SapSession.findById("wnd[0]/usr/ctxtKD_LIFNR-HIGH").Text = "9999999"
SapSession.findById("wnd[0]/usr/ctxtKD_BUKRS-LOW").Text = cocode
SapSession.findById("wnd[0]/usr/ctxtSO_BUDAT-LOW").Text = "010112"
SapSession.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").Text = Convdate(Day(Now())) & Convdate(Month(Now() - 1)) & Right(Year(Now() - 1), 2)  ' Convdate(Day(Now())) & Convdate(Month(Now())) & Right(Year(Now()) + 1, 2)
SapSession.findById("wnd[0]/usr/ctxtPA_VARI").Text = "/WMC."

wnd.sendVKey 8
st = Sbar.Text
If Right(Sbar.Text, 15) = "items displayed" Then endtext = "All selected docs changed": noofit = CInt(Left(Sbar.Text, Len(Sbar.Text) - 15))
If Left(Sbar.Text, 17) = "No items selected" Then endtext = "No items selected": GoTo finished

Set UserArea = Nothing
Set UserArea = SapSession.findById("wnd[0]/usr").Children

' THIS IS THE CODE USED EARLIER. IT SELECTS ONE OF THE HEADER FIELDS (I.E. THE DOC.NO AS THE MACRO SETS A SPECIFIC LAYOUT AS WELL)
'SapSession.findById("wnd[0]/usr/lbl[22,5]").SetFocus
'wnd.sendVKey 2
' AND THEN SORTS THE REPORT
'SapSession.findById("wnd[0]/tbar[1]/btn[41]").press

    j = 0
    For i = 0 To UserArea.Count

    'Line = "wnd[0]/usr/lbl[22," & j & "]"
    st = CStr(UserArea.Item(i).Text)
   
    Set Screenfield = UserArea.Item(i)
   
    If UserArea.Item(i).displayText = "DocumentNo" Then j = UserArea.Item(i).CharLeft
    If j > 0 Then
        On Error Resume Next
       
        SapSession.findById("wnd[0]/usr/lbl[" & j & "," & j & "]").SetFocus
        SapSession.findById("wnd[0]").sendVKey 2
        SapSession.findById("wnd[0]/mbar/menu[5]/menu[1]").Select
        SapSession.findById("wnd[0]/mbar/menu[1]/menu[0]").Select
       
        'Set doc = SapSession.findById("wnd[0]/usr/tabsTS/tabpMAIN/ssubPAGE:SAPLFDCB:0010/txtINVFO-BELNR")
        SapSession.findById("wnd[1]/tbar[0]/btn[0]").press
        docno = 0
        docno = CLng(SapSession.findById("wnd[0]/usr/tabsTS/tabpMAIN/ssubPAGE:SAPLFDCB:0010/txtINVFO-BELNR").displayedText)
       
        If Left(docno, 2) = 19 Or Left(docno, 2) = 17 Then
       
            ' KRdoc
            'SapSession.findById("wnd[0]").sendVKey 2
            SapSession.findById("wnd[0]/mbar/menu[0]/menu[0]").Select
            SapSession.findById("wnd[0]/usr/tabsTS/tabpMAIN/ssubPAGE:SAPLFDCB:0010/ctxtINVFO-BUDAT").Text = Convdate(Day(PtDate)) & Convdate(Month(PtDate)) & Right(Year(PtDate), 2)
            SapSession.findById("wnd[0]/mbar/menu[0]/menu[5]").Select
            If Sbar.messagetype = "W" Then wnd.sendVKey 0 ' posting period adjusted
            SapSession.findById("wnd[1]/tbar[0]/btn[0]").press ' translation date adjusted
            wnd.sendVKey 0 ' translation date adjusted
            If Sbar.messagetype = "W" Then wnd.sendVKey 0 ' if invoice with doc exists
            If Sbar.messagetype = "W" Then wnd.sendVKey 0 ' net due date in the past
            ' end KR
        End If
       
        If Left(docno, 2) = 0 Then
            ' RE doc
            SapSession.findById(Txt).Text = Convdate(Day(PtDate)) & Convdate(Month(PtDate)) & Right(Year(PtDate), 2)
            SapSession.findById("wnd[0]").sendVKey 0
            st = Sbar.Text
            If Sbar.messagetype = "W" Then wnd.sendVKey 0 ' posting period adjusted
           
            st = Sbar.Text
            SapSession.findById("wnd[0]").sendVKey 0 ' translation date adjusted
            SapSession.findById("wnd[0]").sendVKey 0
            If Sbar.messagetype = "W" Then wnd.sendVKey 0 ' net due date in the past
            If Sbar.messagetype = "E" Then Msg = MsgBox("Please resolve in SAP, then press Ok to continue with the next item", vbOKOnly, "Error message came up in SAP")
           
            SapSession.findById("wnd[0]/tbar[0]/btn[11]").press
           
            If Sbar.Text = "Invoice document still contains messages" Then
            Msg = MsgBox("Please resolve in SAP, then press Ok to continue with the next item", vbOKOnly, "Error message came up in SAP")
            Else: SapSession.findById("wnd[0]/tbar[0]/btn[3]").press
            End If
           
            On Error Resume Next
            Set wnd2 = SapSession.findById("wnd[1]")
            ' end RE
        End If

    End If
   
    'j = j + 1
   
    Next i
   
finished:

    Set SapGuiAuto = Nothing: Set SapApp = Nothing: Set SapConn = Nothing: Set SapSession = Nothing: Set wnd = Nothing: Set wnd2 = Nothing: Set Sbar = Nothing:
    Set UserArea = Nothing: Set Screenfield = Nothing:
   
    MsgBox endtext, vbOKOnly
   
End Sub

Sub Pagedown(SapSession)

    SapSession.findById("wnd[0]").sendVKey 82

End Sub

Private Function Convdate(dval As Integer) As String

    If Len(CStr(dval)) = 2 Then Convdate = dval Else Convdate = "0" & dval

End Function

 

The SAP screen:

FBL1N.png

the VBA editor

VBA editor.png

How to handle multiple sessions in Script recorder

$
0
0

Hi,

 

I have a requirement to update certain records from a program. For that I have to put a breakpoint the program (which I did manually).

 

Now when I use the scripting tool to record the events, only events related to the original session gets recorded. Any events on the newly opened debugger mode is not recorded !

 

However, I can record the events in the debugger separately.

 

So I have 2 scripts which are session dependent. In Session 1 my program runs and in session 2 (which opens the debugger in runtime) my edits need to be done.

 

How to create a VB script which can handle this session issue?

 

Went through this blog by Scriptman and since i am new couldnt get it working !!

 

Please help me with a framework to handle this issue.

 

Activate a session via Gui scripting

 

Thanks,

Jaywant

Find from SAP and Copy and Paste in Excel

$
0
0

Hello,

 

I am trying to find a specific value from my output data and copy and paste into a specific excel spreadsheet (C:\Users\raw_geek\Desktop\ACR-TSO_Macro/SAP.xlsm)

 

I can find the specific value

but I can not copy and paste the find item into the excel spreadsheet.  (C:\Users\raw_geek\Desktop\ACR-TSO_Macro/SAP.xlsm)

Is it possible to copy the find item and paste in excel spreadsheet?

Here is what I have ...I’m doing through VBA script through excel 2010.

 

I know it's hard.... I mean Hard for me but like you , it's easy !!! I know there is some smart people can help me on this .. Any help will be appreciate!!!!!

 

I'm not sure this is the correct forum so if it needs to be moved please let me know. Thanks all...

 

 

Private Sub CommandButton1_Click()

 

 

Dim SapGuiApp As Object

Dim oConnection As Object

Dim session As Object

Dim SAPCon As Object, SAPSesi As Object

Dim SAPGUIAuto As Object, SAPApp As Object

'Dim sapConnection As Object

 

 

If SapGuiApp Is Nothing Then

    Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")

End If

If oConnection Is Nothing Then

    Set oConnection = SapGuiApp.OpenConnection("L&R General Ledger – PRD", True)

End If

If SAPSesi Is Nothing Then

   Set SAPSesi = oConnection.Children(0)

End If

   

    'sapConnection.Client = "100"

    'sapConnection.User = "USER"

    'sapConnection.Password = "PASSW"

    'sapConnection.Language = "EN"

    'If nsapConnection.Logon(1, True) = True Then

    'MsgBox "No connection to R/3!"

    'End If

    

     'Set SAPCon = SAPApp.Children(0)

     'Set SAPSesi = SAPCon.Children(0)

    

    'Application.DisplayAlerts = False

   

With SAPSesi

       

    .findById("wnd[0]/usr/txtRSYST-MANDT").text = "100"

    .findById("wnd[0]/usr/txtRSYST-BNAME").text = "ABCD"

    .findById("wnd[0]/usr/pwdRSYST-BCODE").text = "XXXXXX"

    .findById("wnd[0]/usr/txtRSYST-LANGU").text = "EN"

    .findById("wnd[0]").sendVKey 0

 

    'start extraction

   

    .findById("wnd[0]").maximize

    .findById("wnd[0]/tbar[1]/btn[5]").press

    .findById("wnd[0]").sendVKey 0

    .findById("wnd[0]").maximize

    .findById("wnd[0]/tbar[1]/btn[5]").press

    .findById("wnd[0]/usr/lbl[5,8]").setFocus

    .findById("wnd[0]/usr/lbl[5,8]").caretPosition = 0

    .findById("wnd[0]").sendVKey 2

    .findById("wnd[0]/usr/lbl[9,10]").setFocus

    .findById("wnd[0]/usr/lbl[9,10]").caretPosition = 0

    .findById("wnd[0]").sendVKey 2

    .findById("wnd[0]/usr/lbl[16,13]").setFocus

    .findById("wnd[0]/usr/lbl[16,13]").caretPosition = 0

    .findById("wnd[0]").sendVKey 2

    .findById("wnd[0]/usr/ctxt$ALLCOMP").text = ""

    .findById("wnd[0]/usr/ctxt$ALLCOMP").setFocus

    .findById("wnd[0]/usr/ctxt$ALLCOMP").caretPosition = 0

    .findById("wnd[0]/usr/btn%__ALLCOMP_%_APP_%-VALU_PUSH").press

    .findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,0]").text = "205"

    .findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,1]").text = "243"

    .findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,1]").setFocus

    .findById("wnd[1]/usr/tabsTAB_STRIP/tabpSIVA/ssubSCREEN_HEADER:SAPLALDB:3010/tblSAPLALDBSINGLE/ctxtRSCSEL-SLOW_I[1,1]").caretPosition = 3

    .findById("wnd[1]/tbar[0]/btn[8]").press

    .findById("wnd[0]/tbar[1]/btn[8]").press

    .findById("wnd[0]/shellcont/shell/shellcont[2]/shell").hierarchyHeaderWidth = 300

    .findById("wnd[0]/shellcont/shell/shellcont[2]/shell").selectedNode = "000002"

 

.findById("wnd[0]").maximize

.findById("wnd[0]").sendVKey 71

.findById("wnd[1]/usr/txtRSYSF-STRING").text = "220702"

.findById("wnd[1]/usr/txtRSYSF-STRING").caretPosition = 6

.findById("wnd[1]").sendVKey 0

.findById("wnd[2]").sendVKey 0

.findById("wnd[2]/usr/lbl[5,2]").setFocus

.findById("wnd[2]/usr/lbl[5,2]").caretPosition = 2

.findById("wnd[2]").sendVKey 2

.findById("wnd[0]/shellcont/shell/shellcont[2]/shell").unselectAll

 

 

End With

 

 

End Sub

Loading Non-English Characters using VBA and BAPI

$
0
0

Hi Experts,

 

I am trying to load Non-English characters (Chinese, Korean, Japanese, etc.) into a SAP Table using BAPI and VBA. I have set the connection language and codepage values but when I run the tool, the non-English characters display as ????? or #####. Do you know how to fix this issue?

 

Thanks!

Variable declaration in sap logon

$
0
0

Dear Experts,

 

Please note that I’m new in VBA and SAP GUI SCRITPING. I just read few discussion about with SAP LOGON, most of users use early binding to establish connection with SAP.

 

As far I'm concerned I use late binding. Please find below:

 

Set Connection = GetObject("SAPGUI").GetScriptingEngine.Children(0)

 

If Not IsObject(SAPGUIApp) Then

   Set SapGuiAuto = GetObject("SAPGUI")

   Set SAPGUIApp = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(Connection) Then

   Set Connection = SAPGUIApp.Children(0)

End If

If Not IsObject(SAP_Session) Then

   Set session = Connection.Children(0)

End If

If IsObject(WScript) Then

   WScript.ConnectObject session, "on"

   WScript.ConnectObject SAPGUIApp, "on"

End If

 

I would like to use OPTION EXPLICIT in my codes, but that requires also Variable declaration for that part. I already add SAP GUI SCRIPTING API library in references, bo still i don't know objects there.

 

Can anyone help me out with that variable declaration?

Check all open sessions

$
0
0

Dear Experts,

 

I’m trying to build a procedure which will be checking all open session with SAP.

Some time ago I found that great procedure made by Sayuti Azmi. I made small changes I now I able to check what session/and t-codes are open.

 

But if I will login to SAP with two different users, (me + someone else) second user is not visible for that script.

General idea is to build procedure to validate who is login in to SAP on a specific computer.

 

Sub CheckAllOpenSessions()

 

Dim SapGuiAuto As Object

Dim i As Integer

Dim iSession As Integer

Dim sapapplication

Dim Connection As SAPFEWSELib.GuiConnection

Dim Session As SAPFEWSELib.GuiSession

Dim strSessions As String

 

   i = 1

    iSession = 0

    ' There may be bad entries in the ROT from previous crashes

    While i < 10 And SapGuiAuto Is Nothing

      i = i + 1

       On Error Resume Next

       Set SapGuiAuto = GetObject("SAPGUI")

      On Error GoTo 0

    Wend

   

   

    If SapGuiAuto Is Nothing Then

        MsgBox "Could not connect to SAPlogon process. Did you start it?"

        Exit Sub

    End If

   

    On Error Resume Next

    Set sapapplication = SapGuiAuto.GetScriptingEngine

    Set SapGuiAuto = Nothing

    On Error GoTo 0

    If sapapplication Is Nothing Then

        MsgBox "Could not access GuiApplication. Maybe Scripting is disabled?"

        Exit Sub

    End If

    Set SapGuiAuto = Nothing

 

    For Each Connection In sapapplication.Children

        If Not Connection.DisabledByServer Then

            For Each Session In Connection.Children

           

               If Session.Busy = False Then

                   iSession = iSession + 1

                        For x = 1 To iSession

Sheets(1).Cells(iSession, 1) = Session.Info.SessionNumber

Sheets(1).Cells(iSession, 2) = Session.Info.SystemName

Sheets(1).Cells(iSession, 3) = Session.Info.User

Sheets(1).Cells(iSession, 4) = Session.Info.Transaction

                        Next

                End If

            Next

       End If

    Next

end sub

 

Result:

Session.Info.SessionNumberSession.Info.SystemNameSession.Info.UserSession.Info.TransactionComment
1MAIN SYSTEMUSER1SESSION_MANAGER
2MAIN SYSTEMUSER1SU53
3MAIN SYSTEMUSER1MM50
4MAIN SYSTEMUSER1ZQM1_001
1TEST SYSTEMS000Just open window of SAP not logged in

 

How to check if there is more than one user login to SAP?


SAP Connection R/3 using a SSO in Visual Basic

$
0
0

Hello,  I have been trying to get an R/3 connection to SAP using VB.

 

I log into SAP by getting a SSO ticket and running SAPGUI with the ticket.

 

Is there a way to use R/3 and the SSO ticket to log in using VIsual Basic?

 

Set R3 = CreateObject("SAP.Functions")

R3.Connection.Client = "000"
R3.Connection.User = "123456789"
R3.Connection.Language = "EN"
R3.Connection.System = "0"

If R3.Connection.logon(0, True) <> True Then
    MsgBox "No connection to R/3 System"
    Exit Sub                                    
End If

 

 

I have a string from the .SAP file each time it is downloaded, I assume it is the single use password..

 

[User]

Name=123456789+

at="MYSAPSSO2=thisIsAReallyLongStringOfCharectersEndingWIthA="

Language=EN

 

Thanks.

Scripting-Need Loop Help

$
0
0

Hi everyone!

I am trying to create a script to create a sales order (t-code VA01) with multiple line items.

 

My script code is using counter i to go down each row in excel to pull in the data (for each sales order),

but to create each line item within each sales order, i need it to read across a few columns so that i can make multiple line items.

 

Any ideas?

 

 


IF & Else Statement for VBA script

$
0
0

Hi every Experts!

 

I am looking some VBA script for my search results.

 

 

I am searching a value ;

 

 

     .findById("wnd[0]").maximize

     .findById("wnd[0]").sendVKey 71

     .findById("wnd[1]/usr/txtRSYSF-STRING").Text = "6306"

     .findById("wnd[1]/usr/txtRSYSF-STRING").caretPosition = 6

     .findById("wnd[1]").sendVKey 0

 

 

If the search results that I found then this code will copy and paste into my excel ;

 

 

    .findById("wnd[2]/usr/lbl[5,2]").SetFocus

    .findById("wnd[2]/usr/lbl[5,2]").caretPosition = 2

    .findById("wnd[2]/usr/lbl[48,2]").SetFocus

    .findById("wnd[2]/usr/lbl[48,2]").caretPosition = 6

     Sheet2.Cells(22, 4) = .findById("wnd[2]/usr/lbl[5,2]").Text

     Sheet2.Cells(22, 5) = .findById("wnd[2]/usr/lbl[48,2]").Text

    .findById("wnd[1]").sendVKey 0

    .findById("wnd[2]/tbar[0]/btn[17]").press

    .findById("wnd[1]/tbar[0]/btn[12]").press

 

 

But If I don’t have any search results then it’s says "Search unsuccessful - no hits found for: 6306" ;

 

 

     .findById("wnd[2]/usr/txtMESSTXT1").caretPosition = 4

     .findById("wnd[2]/tbar[0]/btn[0]").press

     .findById("wnd[1]/tbar[0]/btn[12]").press

 

 

Is there any way I can do If and else function? Or I can do another statement? (IF or Else) or argument ? something like that , I want combine this all together.

 

 

Thanks all,

SAP Proxy Class using .net connector 3.0

$
0
0

Hi,

 

We had been using .net connector 1.2.0.0 with .net 1.1 framework since 2005 and recently our servers were upgraded to a newer version of SAP.

 

I am wondering if any one knew if the old .net connector and the Proxy class we generated works.

 

If not, how can i use my code to access .net connector 3.0. I am nor sure on how to generate proxy classes for the table access i was using before. I am a .net developer and have no idea on how to go about it. BTW, web services is not an option.

 

Any help would be appreciated.

 

thanks,

ephraim

Method 'Text' of object 'ISapCTextField' failed

$
0
0

I have an SAP GUI script embedded in Excel 2010

The automation is emulating a user deleting User statuses in EEDM01, which is standard functionality. The script is very simple (based on my experience with similar automations), however at random intervals between 90 - 120 records into the automation the script terminates with error:

Unexpected error - script terminated -2147417856 : it_WC_95.xls : Method 'Text' of object 'ISapCTextField' failed


Reattempting the automation from the failed record onwards invariably succeeds without exception. It will run for 90 - 120 more records, & do the same thing.


Googled my heart out & only really found  -2147417856 0x80010100  System call failed.on autoitscript.com.


This isn't super helpful, as rerunning the script works on resubmit of identical data.


Any thoughts?

Viewing all 325 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>