Skip to Content
Author's profile photo Tom Cenens

CBTA using dynamic date parameter input #solman

A common need in a test script recording / playback tool is the need to insert dates throughout business processes. While I was working together with end-users at customer side, we noticed the date was captured in a raw format as let’s say today 22.10.2014 which is fine for today but can be problematic tomorrow since the input field of this date was a “required end date”.

Thus we need to be able to pass a dynamic parameter to the script that takes today’s date and adds days or months or years to that date in order for the process to run through fine when we play back the test script.

Otherwise you see this nice error in your task bar of SAPgui:

/wp-content/uploads/2014/10/enter_568618.jpg

ECATT parameter &DATE?

So what are the options then? CBTA script can leverage ECATT parameters so the &DATE would translate into the date of today. Well, if your configuration is correct and you’ve implemented a couple of recent (at moment of writing) notes to make this work:

2025280 – CBTA – Support of &DATE eCATT variable

2013565 – eCATT – Integration of external test tools – &DATE not resolved


So I tried to use &DATE but it still failed by giving me a date in format DD/MM/YYYY while the system expected DD.MM.YYYY. Darn, that’s too bad, right. So I contacted SAP and the CBTA team actually told me I need to look at my end-user environment date settings because this parameter takes the settings from the local system (Windows XP in my case, so my laptop at customer side which runs the script to do this automated test).

Where to find this configuration, depends on the Windows version but in essence you want to look at regional options / date-time / calendar options in your respective Windows version or at your registry (check out windows support website to locate the registry key for it).

/wp-content/uploads/2014/10/regional_568625.jpg

Just changing the short date format for my own language / environment (Belgium – Dutch) didn’t cut it. I had to go and change English (United States) into this format to make the script execution take the right format but that worked in the end.

To use it in CBTA, you can use &date (comes from ECATT capaibilities)

/wp-content/uploads/2014/10/date_568617.jpg

So putting today’s date in the parameters tab in your CBTA script, can work.

But that doesn’t meet the requirements of getting a date in the future …

VBscript as input?

So I continued to explore the next option which is to use VBscript as input for the CBTA input parameter.

The date() function returns the date of today but in a wrong format, darn again, as it returns the date in MM.DD.YYYY and I need DD.MM.YYYY instead. So using just date() won’t cut it either.

Looking at more date / time functions of VBScript, I noticed day(), month(), year() and now(). Furthermore, using day() +1 is possible in VBScript.

Aha!

To use VBscript in that input parameter value field, you need to use %=% so for example %=date()% will then translate in 10.22.2014.

Next month?

So if I want to have next month as input I can use the following line of VBscript:

%=day(now())&”.”&month(now())+1&”.”&year(now())%


Update 01.12.2014: The above function works fine, except in December!


To overcome this, you can include the DateAdd() VBScript function. Thanks to Mark Goovaerts to figure out the code update for me 😉 .

%=day(DateAdd(“m”,1,now()))&”.”&month(DateAdd(“m”,1,now()))&”.”&year(DateAdd(“m”,1,now()))%


Note that you can use a shorter expression if you don’t have specific format requirements. In this case, I have a prerequisite to have a “.” in between the mm dd yyyy.


Instead of using +1, we use the DateAdd function to get the current date, one month from now without “next year” issues.

/wp-content/uploads/2014/10/vbscript_568626.jpg

Et voila, there it is, now run the script and let’s see if that works.

/wp-content/uploads/2014/10/dynamicdate_568627.jpg

Works like a charm!

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Tom,

      Nice blog, dealing with a topic for which I have already torn my hair out a few times!

      I like to use another solution which, in my opinion, is slightly simpler when you only have to deal with days.

      Here it is:

      %=Day(Date+7)%.%=Month(Date+7)%.%=Year(Date+7)%


      The evaluation of the Day, Month and Year is done individually, so it will be correct every time: either on 03/11/3014, or 29/11/2014, or even 30/12/2014.

      The limitation is that it works only when dealing with days.


      Rémi.



      P.S.: Tobias Kratofil added very interesting suggestions about the possibility to choose what to add (among which were days, weekdays, months, etc.), but somehow its comment has been deleted. I don't know who did it? Is there any way to retrieve the information he had provided?

      Author's profile photo Tom Cenens
      Tom Cenens
      Blog Post Author

      Hi Rémi

      Thanks, great to see you here as well 🙂 .

      Thanks for adding value by giving more options as well.

      There are multiple ways to achieve the same thing and it's possible to use even shorter VBscript lines, as Tobias pointed out but then you need to have your front-end configuration in a specific way to ensure the date format is correct and that's where things can get complicated.

      That's why I have the "." included and I see you have them as well because transaction X need dd.mm.yyyy and another transaction could expect dd/mm/yyyy so I want to avoid having to change settings on the front-end where the test execution is performed on.

      Yes, I see, we wanted to have the due date, one month ahead of time. Therefor that's our current solution. In terms of if it's simple, I think it's simple enough (any of our example) if the person who implements the logic understands the VBscript, once you have it, the next is just copy / paste and adjust.

      Kr,

      Tom

      PS: I'll can send you (mail) his comment if you want but he removed it from the blog which is why it isn't visible anymore

      Author's profile photo Virendra Kumar
      Virendra Kumar

      How to use Regular expression in CBTA URI

       

      I am trying to identify an object in SAP Fiori application using CBTA Object Spy URI. As the Frame Id is always changing, would like to use Regular Expression so that it can be identified all the times.

       

      I tried with Frame Id~=^iFrameId_[0-9]+$ but I am unbale to find unique object identification.

       

      Default used URI :- ls.type=LN; label=Search Material; windowId=1; frameId=iFrameId_1613557579968; tag=SPAN; innerText=Search Material; parentTag=A

       

      Could you please help on this issue.

       

      Regards,

      Virendra Kumar

      Author's profile photo Prasanth Nalam
      Prasanth Nalam

      In case of unstable ID's you can use Object Spy and spy those elements with unstable IDs and use URI alternatives within the Object Spy. Within the Operator you can choose different operator like Starts, Contains, Ends for some of the Attributes.