cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in comparing two dates in SAP textfields

Former Member
0 Kudos

Hello experts, i have a huge problem and i would like to know if im doing something wrong.

i need to compare two dates from two sap fields and then take an action. but im having problem in comparing these two dates. below is the code.

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
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtSO_ORDER-LOW").text = "xxxxxxx"
session.findById("wnd[0]/usr/txtSO_ORDER-LOW").caretPosition = 8
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/lbl[12,10]").setFocus
session.findById("wnd[0]/usr/lbl[12,10]").caretPosition = 6
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4411/subSUBSCREEN_TC:SAPMV45A:4912/subSUBSCREEN_BUTTONS:SAPMV45A:4050/btnBT_POPO").press
session.findById("wnd[1]/usr/txtRV45A-POSNR").text = "xxxx"	
session.findById("wnd[1]/usr/txtRV45A-POSNR").caretPosition = 4
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4411/subSUBSCREEN_TC:SAPMV45A:4912/tblSAPMV45ATCTRL_U_ERF_ANGEBOT/ctxtRV45A-MABNR[1,0]").caretPosition = 5
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\03").select
dim var1,var2
Set var1 = session.findById("/app/con[0]/ses[0]/wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\03/ssubSUBSCREEN_BODY:SAPLV45W:4201/ctxtVEDA-VBEGDAT").text
Set var2 = "4/01/2010"
If var1 == var2 Then
	session.findById("wnd[0]").sendVKey 3
End If	

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi scriptman, thank you so much, i actually solved my problem and got it to work perfectly, i certainly would not be able to do this without your help, thank you.

Former Member
0 Kudos

Hi scriptman, thanks for your effort and time again, but still not working, it seems i cant read the value from the field, i think i would need to access this information directly on the SAP database,

when i put var 1 on the msgbox the output is "var1", and not the date from the field, ill post the code once again for you to follow the progress.

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
session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtSO_ORDER-LOW").text = "xxxxxxxx"
session.findById("wnd[0]/usr/txtSO_ORDER-LOW").caretPosition = 8
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[0]/usr/lbl[12,10]").setFocus
session.findById("wnd[0]/usr/lbl[12,10]").caretPosition = 6
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4411/subSUBSCREEN_TC:SAPMV45A:4912/subSUBSCREEN_BUTTONS:SAPMV45A:4050/btnBT_POPO").press
session.findById("wnd[1]/usr/txtRV45A-POSNR").text = "xxxx"	
session.findById("wnd[1]/usr/txtRV45A-POSNR").caretPosition = 4
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\02/ssubSUBSCREEN_BODY:SAPMV45A:4411/subSUBSCREEN_TC:SAPMV45A:4912/tblSAPMV45ATCTRL_U_ERF_ANGEBOT/ctxtRV45A-MABNR[1,0]").caretPosition = 5
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_ITEM/tabpT\03").select
dim var1,var2
var1 = session.findById("/app/con[0]/ses[0]/wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\03/ssubSUBSCREEN_BODY:SAPLV45W:4201/ctxtVEDA-VBEGDAT").text
msgbox ("var1")
var2 = "4/01/2010"
If var1 = var2 Then
   session.findById("wnd[0]").sendVKey 3
End If

maybe i can create and object dynpro to try to extract the data from the field, i cant figure out what i am doing wrong so far, if anyone has an opinion and want to sugest something please feel free to post on this thread.

script_man
Active Contributor
0 Kudos

Hi alfa85,

1. The correct code is:


...
msgbox var1
...

2. What is the name used for the transaction?

Regards,

ScriptMan

Former Member
0 Kudos

Hi scriptman, thank you so much for replying to my question, but as i said the problem is too complex, i have tried your code but still cant get it to work, it seems SAP cant compare these two fields.

just for your information, if the condition is true, then the script must go to the previous screen, but when it comes to the end of the script, nothing happens it doesn´t go back to the previous screen.

what i think is that SAP can´t retrieve the values from the fields, if i could read those values it could work. oh and sorry for the bad english.

script_man
Active Contributor
0 Kudos

Hi alfa85,

the MSGBOX command shows the format of the read variable var1. It may be that is has a different format. Then the variable var2 should read as follows:

For example:

var2 = "01.04.2010"

or

var2 = "01042010"

or

var2 = "2010.04.01"

or

var2 = "2010.04.01"

etc.

Select the command with MSGBOX and get the value display. Then adjust your var2 the displayed date format.

By the way, my English is no better.

Regards,

ScriptMan

script_man
Active Contributor
0 Kudos

Hi alfa85,

I would try the following:


. . .
dim var1,var2
var1 = session.findById("/app/con[0]/ses[0]/wnd[0]/usr/tabsTAXI_TABSTRIP/tabpT\03/ssubSUBSCREEN_BODY:SAPLV45W:4201/ctxtVEDA-VBEGDAT").text
'msgbox var1
var2 = "4/01/2010"
If var1 = var2 Then
   session.findById("wnd[0]").sendVKey 3
End If	

Regards,

ScriptMan

Edited by: ScriptMan on Apr 9, 2010 12:23 PM