How to Iterate SAP Table in Ascending Order and select it?

Hi Everyone,

In SAP i Have table i want iterate that in ascending order and click that row only how can do that in uipath?

please help

Thanks in Advance


Could you explain a bit more by clicking that? Do you mean that you have a specific row that you need to click or that you want to iterate through from bottom to top and click on each row?

Hi @strqsr
Numbering is like random (1,3,6,7,8,2,3 ).here i want to put them in ascending order and i want click each row one by one.

Hi @krishnareddy

Check this

DataView view = new DataView(table)
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...)
DataTable =DataTable.DefaultView.ToTable(true)


in SAP itself, is sorting not possible? Like you click the order tab for it to sort into ascend/descend?

Is scripting enabled at both end? Can you use data scraping?

If not. what you could do is you could create a do a loop where you extract the number from order and sort it in an excel/csv file for example, and then use an assign function to go through the rows and use text exists and click text


it possible when i was use mouse right click it is showing both ascending and decending.but how to handle them i was not able to do that can u please suggest how to do that.

Do you mean you can’t click on the button using UiPath? I’m not too sure what you mean by it’s possible but you aren’t able to handle it.

If that’s the case you can use getVisibletext (native) to make the mouse click on the text for it to be sorted. You can also use an If activity to check the first and last row to see if the first row is smaller than the last row to check if it is sorted correctly. I can’t show you as I don’t have SAP installed on my computer.

Perhaps these two links may be able to help you

Hi @krishnareddy ,

You can use below vbs script for iterating the Table
Use invoke vbs to call the Script

On Error Resume Next
If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.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 application, "on"
End If

Set Arg = WScript.Arguments


''Check Vendor Number
totalRows = session.findById("wnd[0]/usr/cntlCONTAINER_0111/shellcont/shell").rowCount
visibleRows = session.findById("wnd[0]/usr/cntlCONTAINER_0111/shellcont/shell").visiblerowCount

'maxVerPos = session.findById("wnd[0]/usr/cntlCONTAINER_0111/shellcont/shell").firstVisibleRow
'Msgbox(totalRows&" "&visibleRows)
rowCount = visibleRows-1
counter = 0
ccPos = 0
verPos = 1
flagSearch = "No"
If counter > totalRows Then
	WScript.Echo("Error, could not found any vendor number("&Arg(1)&") while blocking payment in SAP")
	Exit Do
End If
If counter > (visibleRows-1) Then
	session.findById("wnd[0]/usr/cntlCONTAINER_0111/shellcont/shell").firstVisibleRow = verPos
	verPos = verPos + 1
End If

textVendor = session.findById("wnd[0]/usr/cntlCONTAINER_0111/shellcont/shell").GetCellValue(counter,"LIFNR")
If InStr(textvendor, Arg(0)) > 0 Then  ''Vendor number
	session.findById("wnd[0]/usr/cntlCONTAINER_0111/shellcont/shell").setCurrentCell counter,"LIFNR"

	'''''######Search Document######''''''
	textVendor1 = ""
	'''''Check Document Number'''''
	totalRows1 = session.findById("wnd[0]/usr/cntlCONTAINER_0112/shellcont/shell").rowCount
	visibleRows1 = session.findById("wnd[0]/usr/cntlCONTAINER_0112/shellcont/shell").visiblerowCount
	'Msgbox(totalRows&" "&visibleRows)
	rowCount1 = visibleRows1-1
	counter1 = 0
	ccPos1 = 0
	verPos1 = 1
	If counter1 > totalRows1 Then
		'MsgBox("Error, could not found any document("&Arg(1)&") number while blocking payment in SAP")
		'WScript.Echo("Error, could not found any document("&Arg(1)&") number while blocking payment in SAP")
		flagSearch = "No"
		Exit Do
	End If
	If counter1 > (visibleRows1-1) Then
		session.findById("wnd[0]/usr/cntlCONTAINER_0112/shellcont/shell").firstVisibleRow = verPos1
		verPos = verPos + 1
	End If

	textVendor1 = session.findById("wnd[0]/usr/cntlCONTAINER_0112/shellcont/shell").GetCellValue(counter1,"BELNR")
	If InStr(textvendor1, Arg(1)) > 0 Then  ''Document number
		session.findById("wnd[0]/usr/cntlCONTAINER_0112/shellcont/shell").setCurrentCell counter1,"BELNR"
		if InStr(1,information_tab,"items")then
		End if

		flagSearch = "Yes"
		Exit Do
		counter1 = counter1+1
	End IF
	'''''######End Search Document####
	If flagSearch <> "No" Then
		Exit Do
		counter = counter+1
	End If
	counter = counter+1
End IF

sBarText = session.findById("wnd[0]/sbar").Text
If Err.Number <> 0 Then
  	WScript.Echo("Error occured while blocking payment for vendor("&Arg(0)&") and document("&Arg(1)&"). Error: " & Err.Description &" "& sBarText)
End If

On Error Goto 0


HI All,

There is no single need to use any SAP VBS scripts. All action in SAP WinGUI can be performed just with help of UiPath Studio.

For Table operation, check the latest docu

We have invested a lot of effort to make it easy of use for users.

Check it out! And just to let you know, our SAP WinGUI Automation capabilities are certified by SAP

Best regards, Lev

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.