Skip to Content
avatar image
Former Member

t-code REAJSH

Hello team,

Anybody here familiar with t-code REAJSH? I was trying to automate extracted report to be saved in a specified file, but in any try I did, i was unsuccessful. Any help please. Thank you. :)

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Sep 22, 2017 at 08:46 AM

    The error in Excel_Path does not occur when you move the declaration of the variables forward.

    For example:

    Public Sub GSAPpost()
    
    
    AdjID = Sheet4.Cells(4, 11)
    Contract = Sheet4.Cells(10, 4)
    CoCode = Sheet4.Cells(8, 4)
    
    
    If Month(Now) < 9 Then
        monthtoday = "0" & Month(Now)
    Else
        monthtoday = Month(Now)
    End If
    
    
    If Day(Now) < 9 Then
        daytoday = "0" & Day(Now)
    Else
        daytoday = Day(Now)
    End If
      
     
    Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
    Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
    Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
    Set session = SAPCon.Children(0) 'Get the first session (window) on that connection
    
    SAP_Workbook = "Worksheet in Basis(1)"
    EXCEL_Path = Sheets("Free Adj").Range("J29").value & "\"
    myWorkbook = CoCode & "_FREEADJ SIM_" & Contract & "_" & Year(Now) & monthtoday & daytoday & ".xls"
    
    session.findById("wnd[0]/tbar[0]/okcd").Text = "/NREAJSH"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/ctxtP_PEXTID").Text = AdjID
    session.findById("wnd[0]/tbar[1]/btn[8]").press
    session.findById("wnd[0]/usr/cntlCC_ADJM_ADJMREC_GRID/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
    session.findById("wnd[0]/usr/cntlCC_ADJM_ADJMREC_GRID/shellcont/shell").selectContextMenuItem "&XXL"
    session.findById("wnd[1]/usr/cmbG_LISTBOX").SetFocus
    session.findById("wnd[1]/usr/cmbG_LISTBOX").Key = "08"
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").Select
    session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[0,0]").SetFocus
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    
    On Error Resume Next
    Do
    Err.Clear
    Set xclapp = GetObject(, "Excel.Application")
    If Err.Number = 0 Then Exit Do
    'msgbox "Wait for Excel session"
    wscript.sleep 2000
    Loop
    
    
    Do
    Err.Clear
    Set xclwbk = xclapp.Workbooks.Item(SAP_Workbook)
    If Err.Number = 0 Then Exit Do
    'msgbox "Wait for SAP workbook"
    wscript.sleep 2000
    Loop
    
    
    On Error GoTo 0
    Set xclSheet = xclwbk.Worksheets(1)
    xclapp.Visible = True
    xclapp.DisplayAlerts = False
    xclapp.ActiveWorkbook.SaveAs chr(34) & EXCEL_Path & myWorkbook & chr(34)
    xclapp.ActiveWorkbook.Close
    
    
    Set xclwbk = Nothing
    Set xclSheet = Nothing
    xclapp.Quit
    Set xclapp = Nothing
    
    
    End Sub
    
    
    

    Regards,

    ScriptMan

    Add comment
    10|10000 characters needed characters exceeded