TIPS & TRICKS



Using the Copytext Command | Finding the Weekday from a Date | Writing Long Text to PM Notifications with WebUI | Using Long Text in Sales and Distribution with SAPGUI | Building Launch Pads | 

Finding the Weekday from a Date

It is often useful to know what day of the week matches a particular date. Many SAP transactions are based around dates, especially in the HR and Financials modules and so users have a need to be able to match a particular date to a particular calendar day. Fortunately, Synactive provides a handy function that will do precisely that. In the following example, we are using this script on a user-created field in the default VA01 Create Order screen, as shown below:

GuiXT Solution Suite

We have added a new readonly field entitled 'Day of Week' , that will display the actual day of the week, based on the following codes:

  • Friday: -3
  • Saturday: -2
  • Sunday: -1
  • Monday: 0
  • Tuesday: 1
  • Wednesday: 2
  • Thursday: 3

This new field displays the actual calendar day of the week according to the list above. The actual day of the week is then Thursday, as shown below:

GuiXT Solution Suite

We place the code to accomplish this in the file listed below:

• date.txt

This input script contains the following code:

Set V[date1] "&V[today_m/d/y]"
Set V[absdate] "&V[date1]" * "1"
Set V[day_of_week] "&V[absdate]" / "7" decimals=0
Set V[day_of_week] "&V[day_of_week]" * "7"
Set V[day_of_week] "&V[absdate]" - "&V[day_of_week]"
// day_of_week:
// -3 = Friday -2=Saturday -1=Sunday 0=Monday 1=Tuesday 2=Wednesday 3=Thursday
message "&V[day_of_week]" "-statusline"

The script file for the example screen in the VA01 transaction, is the SAPMV45A.E4001TXT file. Within this file is the code that creates the new inputfield, as follows:

inputfield (4,0) "Day of Week" (4,17) name="day_of_week" size="10" -readonly

The main VA01 script file SAPMV45A.E0100.TXT and SAPMV45A.E0101.TXT script files must call the FindDayForDate script in order to accomplish the conversion. The code a user needs to enter will be as follows:

on enter process="date.txt"

This instructs the main script to transfer control to the input script when the user presses enter. The input script then accomplishes the date-to-day process and returns control to the main script.