Skip to Content
0

t-code REAJSH

Sep 21, 2017 at 05:40 AM

160

avatar image
Former Member

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. :)

10 |10000 characters needed characters left characters exceeded

In your previous question, I have pointed to a mistake in your example. Did not it help?

EXCEL_Path = Range("J29").value & "\" instead of EXCEL_Path = Range("J29").value & "/"

0
Former Member

Hello ScriptMan! :)

it still give me the same error even if it's changed.

0

Can you save it manually without a script under the desired path?

0
Former Member

Yes Script Man

0

Then take the script recorder and record the relevant script passage. Also replace the appropriate lines in your original script.

You could also show us the new script. If it does not work, please tell us the exact error description and the corresponding error line. ;-)

0
Former Member

the recorder always stop in SAVING part. :(

0

Please show us what the script recorder has recorded at all.

What is the name of the Excel file, which is on the screen at the moment, when the script recorder can not record anymore?

"Worksheet in Basis(1)" or maybe "Worksheet in ALVXXL01 (1)"

0
Former Member
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
  
    Dim current As Workbook
    Set current = ActiveWorkbook
    Dim ARlayout As String
    Dim objExcel
    Dim objSheet, intRow, i
    Set objExcel = GetObject(, "Excel.Application")
    Set objBook = objExcel.ActiveWorkbook
    
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


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]/usr/ctxtP_PEXTID").caretPosition = 34
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
session.findById("wnd[1]/tbar[0]/btn[0]").press

SAP_Workbook = "Worksheet in Basis(1)"
EXCEL_Path = Sheets("FreeAdjPost").Range("J29").value & "\"
myWorkbook = CoCode & "_FREEADJ SIM_" & Contract & "_" & Year(Now) & monthtoday & daytoday & ".xls"

session.findById("wnd[1]/usr/ctxtDY_PATH").Text = EXCEL_Path
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = myWorkbook
session.findById("wnd[1]/tbar[0]/btn[11]").press

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


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


On Error Resume Next
Do
Err.Clear
Set xclapp = GetObject(, "Excel.Application")
If Err.Number = 0 Then Exit Do
session.findById("wnd[0]").iconify
'msgbox "Wait for Excel session"
wscript.sleep 2000
session.findById("wnd[0]").maximize
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 EXCEL_Path & myWorkbook
xclapp.ActiveWorkbook.Close


Set xclwbk = Nothing
Set xclSheet = Nothing
xclapp.Quit
Set xclapp = Nothing


End Sub



0
Former Member

HI ScriptMan, that's the code I used and always flagged as an error in

EXCEL_Path = Sheets("FreeAdjPost").Range("J29").value & "\"

0
Former Member

Hi ScriptMan,

I attached here the generated file that did not push though saving in specific path.

error.jpg

Thank you.

error.jpg (73.2 kB)
0

Hi Bomb Sheels,

if the error appears, please press the button called "Debug" and make a screenshot. Then you can see exactly where the error occurred. And then it would be interesting to see what is hidden behind Sheets ("FreeAdjPost"). Range ("J29"). value. Best Show with:

msgbox Sheets ("FreeAdjPost"). Range ("J29").value

0

If the error in Excel_Path is removed, your current script would look like this:

. . .

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]/usr/ctxtP_PEXTID").caretPosition = 34
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
'session.findById("wnd[1]/tbar[0]/btn[0]").press

SAP_Workbook = "Worksheet in Basis(1)"
EXCEL_Path = Sheets("FreeAdjPost").Range("J29").value & "\"
myWorkbook = CoCode & "_FREEADJ SIM_" & Contract & "_" & Year(Now) & monthtoday & daytoday & ".xls"

'session.findById("wnd[1]/usr/ctxtDY_PATH").Text = EXCEL_Path
'session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = myWorkbook
'session.findById("wnd[1]/tbar[0]/btn[11]").press

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


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

On Error Resume Next
Do
Err.Clear
Set xclapp = GetObject(, "Excel.Application")
If Err.Number = 0 Then Exit Do
'session.findById("wnd[0]").iconify
'msgbox "Wait for Excel session"
wscript.sleep 2000
'session.findById("wnd[0]").maximize
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

0
Former Member

Hi Script Man,

Below is the highlighted in debug

debug.png (147.0 kB)
0

Please check if there is actually a sheet named "FreeAdjPost". I see only the following:

EXCEL_Path = Sheets("Sheet1").Range("J29").value & "\"

0
Former Member

Hi Scriptman,

I've changed the sheetname based on the sheets indicated. but still got the same error.

error2.jpg (147.1 kB)
sheets.jpg (30.2 kB)
0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Script Man Sep 22, 2017 at 08:46 AM
0

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

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hello Scriptman,

Copying the script you have provided, I got the error which pointed to the same path and no report generated as well.

error4.jpg (143.3 kB)
error5.png (114.4 kB)
0

If you copied it correctly, the error would no longer exist!

EXCEL_Path = Sheets("Sheet4").Range("J29").value & "\" is not equal to

EXCEL_Path = Sheets("Free Adj").Range("J29").value & "\"

0
Former Member

hello Script Man! Thank you BTW for helping me solve the issue. :) Just want to ask if what could be the possible reason why my excel file froze and "not responding" while running the code. It generates the report however, it just hanged and froze. Thank you.

0

Hi Bomb Sheels,

open the Excel macro and execute it in the increment (eg with F8). Please let me know where the macro freezes.

0