cancel
Showing results for 
Search instead for 
Did you mean: 

Date variable format in Design Studio scripting

moritz_kelm
Participant
0 Kudos

Hi all,

Is there any way to get a date variable into a standardized format in Design Studio scripting?

I have a BW User Exit Variable for 0CALDAY that is filled with a default key date. It is possible to change this variable during application runtime via scripting. This works fine.

I'd like to link the date variable to a DATEFIELD-object and I am struggling, because I cannot retrieve the variable in a standardized format.

Look:


// Preferred viewing locale: German (Germany)

t = DS_1.getVariableValueExt("USO_CD_GSA"); // Returns date in external format - German: dd.mm.yyyy - 21.03.2016

t = DS_1.getVariableValueText("USO_CD_GSA"); // Returns date 21.03.2016


// Preferred viewing locale: English (United States)

t = DS_1.getVariableValueExt("USO_CD_GSA"); // Returns date 3/21/2016

t = DS_1.getVariableValueText("USO_CD_GSA"); // Returns date 3/21/2016


// Date field:

t = DATEFIELD_1.getDate(); // Returns string yyyymmdd

I could substring the date and build a yyyymmdd-version of it, but this solution is very error-prone as it is not really possible to determine the user's locale.


var d = "3/21/2016";

var sep = d.substring(d.length-5,d.length-4);

var yyyymmdd = "";

if(sep == "/") {

  // m/dd/yyyy

var split = d.split("/");

  var day_int = Convert.stringToInt(split[1]);

  var month_int = Convert.stringToInt(split[0]);

  var month_string = "" + month_int;

  var day_string = "" + day_int;

  if(month_int < 10) {

  month_string = "0" + month_int;

  }

  if(day_int < 10) {

  day_string = "0" + day_int;

  }

  yyyymmdd = split[2] + month_string + day_string; // Finally yyyymmdd 🙂

  // What if the date format is 21/03/2016 like in Brazil?

DS 1.6 SP0 and BI 4.1 SP7

Appreciate any help,

Moritz

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Moritz

I am dealing with same issue.

I d appreciate if you can share if you had any solution.

Thanks

Former Member
0 Kudos

Hi,

Of course you can. Basically, you shouldn't deal with date formating when calculating in DS. Not as well DS is poorly fitted to do that alone.

Exchange your call to getVariableValueExt() with getVariableValue() to avoid dealing with external format.

Dates format needs to be handled with the standard SAP (and logical) format: YYYYMMDD, and the last method gives you that.

SCN component SimpleDate gives you everything you could need to create those formulas (addDays, addMonth, InitializeWithInternalDate from APPLICATION.getInfo().dateInternalFormat).

moritz_kelm
Participant
0 Kudos

Franck, I appreciate your response and agree that working with internal date formats is the right way, but getVariableValue() is not available for me (see Screenshot). Variable USO_CD_GSA is a  BEx Query variable on Infoobject 0CALDAY.

Karol-K
Advisor
Advisor
0 Kudos

Hi Moritz,

the method DS.getVariableValue() is not existing in my installation (1.6 SP1, on BW data source), but it is documented - really strange.

to help you in short term,

1/

the external date format is dependent on your language, so you can use it as well, but the problem is, your script for the conversion must be language dependent. If you only working in one format you can risk it to have only one conversion routine. as far I know there are 2 major formats - the German one (DD.MM.YYYY) and the English (M/D/YYYY) one.

when converted, use the method

APPLICATION.setVariableValueExt(variable, value)

2/

you should be also able to use the method

APPLICATION.setVariableValue(variable, value)

and place the internal format which is coming from the datefield 1:1 into the value parameter.

//

for conversion you can use also the simple date component

which is included in scn community package

Karol

moritz_kelm
Participant
0 Kudos

Karol,

setting the variable is less of an issue than retrieving the date from the variable and filling the date field with its value.

In the meantime I helped myself with a blunt workaround, I created a text variable that is filled from the key date via Customer Exit. Reading the variable in Design Studio gets me a string in yyyymmdd format, no conversion needed.

A fix would be very much appreciated, though.

Could you take a look into the missing getVariableValue()-method, or should I open an Incident?


Cheers,

Moritz

Former Member
0 Kudos

That's ... unfortunate ! I dealt with dates using App internal format, stuff like that, and had no issues. I was sure the getVariableValue method would have been available !

You should create an incident with SAP to get this fixed for everyone. That's definitely a mandatory method.

moritz_kelm
Participant
0 Kudos

Incident has been opened. Will keep you updated.