cancel
Showing results for 
Search instead for 
Did you mean: 

Selection Variable for 1st Saturday prior to Current Calendar Day (sys-date)

john_hawk
Active Contributor
0 Kudos

Hi Gang,

I need some help. I need to create a variable on a DATS based InfoObject  in a Bex query which selects the first Saturday prior to current calendar day as defined by sys-date. Day of Week is NOT available in the Time Dimension and client is reluctant to remodel at this time.

The perfect solution would be to create a variable which could read the sys-date and determine the calendar day of the previous Saturday as an output parameter for use a a single value selection.

My ABAP skills could be generously be described as "advanced novice". Please be a specific as possible, and hyperlinks to useful materials are greatly appreciated.

Thank you in advance for your help,

John Hawk

Accepted Solutions (1)

Accepted Solutions (1)

john_hawk
Active Contributor
0 Kudos

Hi Gang,

I like my code better

WHEN 'ZPRIORSAT'.

  DATA: day_p TYPE p,

      w_saturday TYPE SYDATUM.

CLEAR: L_S_RANGE.

CLEAR: day_p.

CLEAR: w_saturday.

I_STEP = 0. "No data entry

day_p = SY-DATUM MOD 7.

* DAY_P equals 0 for Saturday, 1 for Sunday, etc..

CASE day_p.

    WHEN 0.

      w_saturday = SY-DATUM.

    WHEN 1.

      w_saturday = SY-DATUM - 1.

    WHEN 2.

      w_saturday = SY-DATUM - 2.

    WHEN 3.

      w_saturday = SY-DATUM - 3.

    WHEN 4.

      w_saturday = SY-DATUM - 4.

    WHEN 5.

      w_saturday = SY-DATUM - 5.

    WHEN 6.

      w_saturday = SY-DATUM - 6.

  ENDCASE.

L_S_RANGE-LOW = w_saturday.

      L_S_RANGE-SIGN = 'I'.

      L_S_RANGE-OPT = 'EQ'.

      APPEND L_S_RANGE TO E_T_RANGE.

Former Member
0 Kudos

Mr John Hawk, Simple and sweet code. Easy to understand.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

I agree to Dhrubojyoti Saha. Other method can be as below.

FM DATE_COMPUTE_DAY returns the day number (l_day) of the given date (l_date).

You can subtract this value from the date to get the Saturday of previous week.

i.e. l_date - l_day

Regards,

Sucheta

john_hawk
Active Contributor
0 Kudos

Function Module DATE_TO_DAY is not found in my BW 7.4 system.

dhrubojyoit_saha
Explorer
0 Kudos

Hi,

You can use the below two FMs

DATE_GET_WEEK

This function module returns the week for the date passed.

WEEK_GET_FIRST_DAY

This function module returns the first day of the week passed. (This is always a Monday, regardless of whether it is a working day or a holiday.)

Then you can subtract 2 from this day to get the saturday of the week before.

Regards

miguel_varela
Explorer
0 Kudos

Hi,

I would definitively do this requirement  with an user-exit type variable, although some "advanced novice ABAP" is needed.

You can search in the community for examples with "SAP Enhancement RSR00001".

Some preliminary links:

Customer Exit Variables in SAP BI - SAP NetWeaver Business Warehouse - SCN Wiki

Five Ways to Enhance BI Functionality Using ABAP--Part III--BEx Variables - SAP NetWeaver Business W...

Regards,

Miguel Varela