cancel
Showing results for 
Search instead for 
Did you mean: 

Variable in DTP to get current and previous period

Former Member
0 Kudos


I have a DTP to open hub where I am trying to get current period and current period - 1 data into the open hub.  I am using value in table TVARV as a starting point.

The value in TVARV field LOW is 12/31/2014 which controls how we report.  For us 12/31/2014 translates to Period 09 and we are actually in period 10 now. So my code thinks the current period is 09 because of the 12/31/2014 date.

How can I make the code that thinks currend period is 09 make it so current period is 10?  Thanks

   REPORT  ZBWV_ZVR_FISCPER_LAST2MONS.

TYPE-POOLS: RS, RSR, RSDS, RSSM, RSARI, RSD, SBIWM, RSA, RSODS, RSDU,
            RSARR, RSDM, RSS2, RRS0.

DATAWA_RANGESID    TYPE RRRANGESID,
       WA_VAR_RANGE   TYPE RRRANGEEXIT.

*&---------------------------------------------------------------------*
*&      Form  DOZBWV_ZVR_FISCPER_LAST2MONS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_VNAM         text
*      -->I_VARTYP       text
*      -->I_IOBJNM       text
*      -->I_S_COB_PRO    text
*      -->I_S_RKB1D      text
*      -->I_PERIV        text
*      -->I_STEP         text
*      -->I_T_VAR_RANGE  text
*      -->E_T_RANGE      text
*      -->E_MEEHT        text
*      -->E_MEFAC        text
*      -->E_WAERS        text
*      -->E_WHFAC        text
*      -->E_S_CUSTOMER   text
*----------------------------------------------------------------------*
FORM DOZBWV_ZVR_FISCPER_LAST2MONS
             USING    I_VNAM        LIKE  RSZGLOBV-VNAM
                      I_VARTYP      LIKE  RSZGLOBV-VARTYP
                      I_IOBJNM      LIKE  RSZGLOBV-IOBJNM
                      I_S_COB_PRO   TYPE  RSD_S_COB_PRO
                      I_S_RKB1D     TYPE  RSR_S_RKB1D
                      I_PERIV       TYPE  RRKB1F-PERIV
                      I_STEP        TYPE  I
                      I_T_VAR_RANGE TYPE  RRS0_T_VAR_RANGE
             CHANGING E_T_RANGE     TYPE  RSR_T_RANGESID
                      E_MEEHT       LIKE  RSZGLOBV-MEEHT
                      E_MEFAC       LIKE  RSZGLOBV-MEFAC
                      E_WAERS       LIKE  RSZGLOBV-WAERS
                      E_WHFAC       LIKE  RSZGLOBV-WHFAC
                      E_S_CUSTOMER  TYPE  RRO04_S_CUSTOMER.


  DATA: WA_LOW(45),
        WA_PERIV(2) TYPE C,
        WA_DATE TYPE D,
        WA_PER(3) TYPE N,
        WA_PREV_PER(3) TYPE N,
        WA_YR(4) TYPE N,
        WA_PYR(4) TYPE N,
        WA_FISCPER(7) TYPE N,
        WA_PFISCPER(7) TYPE N.

  SELECT SINGLE LOW
    INTO WA_LOW
    FROM TVARVC
    WHERE NAME = 'BWREPORTDATE'.     "this date in TVARVC is 12/31/2014. I want it to think the date is 1/31/2015
  IF SY-SUBRC <> 0 .
    WA_DATE = SY-DATUM.
  ELSEIF WA_LOW IS INITIAL.
    WA_DATE = SY-DATUM.
  ELSE.
    WA_DATE = WA_LOW+0(8).
  ENDIF.

  SELECT SINGLE LOW
    INTO WA_PERIV
    FROM TVARVC
    WHERE NAME = 'VOUGHT_FISCVARNT'.
  IF SY-SUBRC <> 0.
    WA_PERIV = 'K9'.
  ELSEIF WA_PERIV IS INITIAL.
    WA_PERIV = 'K9'.
  ENDIF.


  CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
    EXPORTING
      I_DATE  = WA_DATE
      I_PERIV = WA_PERIV
    IMPORTING
      E_BUPER = WA_PER
      E_GJAHR = WA_YR.

*  CONCATENATE WA_PYR WA_PER INTO WA_FISCPER. (prior year low range)
  WA_PREV_PER = WA_PER - 1.
  WA_PYR = WA_YR.
  if WA_PREV_PER = 0.
    WA_PREV_PER = 12.
    WA_PYR = WA_YR - 1.
    IF WA_PYR = '2011'.
      WA_PYR = '2000'.
    ENDIF.
  endif.
* If the previous year is 2011, set the previous year to 2000 so that the
* periods 4 through 12 will not through a period error since FY 2011
* is a short year due Triumph.



  CONCATENATE WA_PYR WA_PREV_PER INTO WA_PFISCPER.
*  CONCATENATE WA_YR WA_PER INTO WA_FISCPER. (current year high range)
  CONCATENATE WA_YR WA_PER INTO WA_FISCPER.

  WA_RANGESID-LOW = WA_PFISCPER.
  WA_RANGESID-HIGH = WA_FISCPER.
  WA_RANGESID-SIGN = 'I'.
  WA_RANGESID-OPT = 'BT'.

  APPEND WA_RANGESID TO E_T_RANGE.

  CLEAR WA_RANGESID.

ENDFORM.

Accepted Solutions (1)

Accepted Solutions (1)

ccc_ccc
Active Contributor
0 Kudos

Hi Keith ,

SELECT SINGLE LOW

    INTO WA_LOW

    FROM TVARVC

    WHERE NAME = 'BWREPORTDATE'.     "this date in TVARVC is 12/31/2014. I want it to think the date is 1/31/2015

  IF SY-SUBRC <> 0 .

    WA_DATE = SY-DATUM.

  ELSEIF WA_LOW IS INITIAL.

    WA_DATE = SY-DATUM.

  ELSE.

    WA_DATE = WA_LOW+0(8).

  ENDIF.


As per your requirement if WA_LOW LE '12/31/2014' then we can assign wa_date = '1/31/2015' this temporary how about feature for example 12/31/2015 then again we need to change '1/31/2016' which is not correct as per my knowledge.


There is something different requirement, if 12/31/2014 comes as per logic it giving 09, its correct, either you need to change date from 12/31/2014 to 1/31/2015 in TVARVC table or ask business people what exactly requirement.


Thank you,

Nanda


Answers (1)

Answers (1)

RafkeMagic
Active Contributor
0 Kudos

have a (good) look at function module RSARCH_DATE_SHIFT...

the following values

I_DATE                           <your value from TVARVC in the correct format - should be type D>

I_SHIFT                          1

I_SHIFT_UNIT                MON

I_OPTION                       GT

should get you a long way