Skip to Content
author's profile photo Former Member
Former Member

Date Ranges Problem in report

Hi All,

Iam developing report in which I enter Proj# from_month, from_year, To_month and To_year.

The output data for the project must be within this year range.

suppose I enter proj no. 13381 and

from_month - 05

from_year - 2004

To_month - 04

from_year - 2005

This is the Desired Output:

yearmonth

200405 -


13381 -


0

200406 -


13381 -


100

200407 -


13381 -


100

200408 -


13381 -


0

200409 -


13381 -


678

...............................

.................................

200504 -


13381 -


2222

Right Now the Output what Iam getting is:

200401 -


13381 -


0

200402 -


13381 -


300

200403 -


13381 -


400

200404 -


13381 -


0

200405 -


13381 -


0

200406 -


13381 -


100

200407 -


13381 -


100

200408 -


13381 -


0

200409 -


13381 -


100

200410 -


13381 -


100

200411 -


13381 -


0

200501 -


13381 -


234

200502 -


13381 -


344

200503 -


13381 -


0

200504 -


13381 -


2222

.............................

..........................

200511 -


13381 -


234

I need to Limit the data within the date range 200405 to 200504. as shown in the desired output.

Rightnow the Abstract code is :

DATA: MNT_INDX(20) TYPE C,

HLD_INDX(3) TYPE N,

W_MTH(2) TYPE N,

W_DATE LIKE PROJ-ERDAT.

RANGES: R_YEAR FOR COSP-GJAHR,

R_DATE FOR PROJ-ERDAT.

FIELD-SYMBOLS <FS>.

PARAMETERS FR_MONTH(2) TYPE N OBLIGATORY.

PARAMETERS FR_YEAR(4) TYPE N OBLIGATORY.

PARAMETERS TO_MONTH(2) TYPE N .

PARAMETERS TO_YEAR(4) TYPE N .

data: l_counter type i. "number of month

l_counter = ( to_year - fr_year ) * 12 + ( to_month - fr_month ).

DATA: W_TXT(20) TYPE C.

R_YEAR-LOW = FR_YEAR.

R_YEAR-HIGH = TO_YEAR .

R_YEAR-OPTION = 'BT'.

R_YEAR-SIGN = 'I'.

APPEND R_YEAR.

concatenate FR_YEAR FR_MONTH INTO R_DATE-LOW .

concatenate TO_YEAR TO_MONTH INTO R_DATE-HIGH.

SELECT * FROM COSP

WHERE OBJNR = PRPS-OBJNR AND

GJAHR IN R_YEAR AND

KSTAR BETWEEN '0000400996' AND '0000400999' AND

VERSN = '014' AND

WRTTP = '01' .

do l_counter times.

W_MTH = SY-INDEX.

CONCATENATE COSP-GJAHR W_MTH INTO W_DATE.

HLD_INDX = SY-INDEX. " (similar to your defn)

CONCATENATE 'COSP-WKG' HLD_INDX INTO W_TXT.

ASSIGN (W_TXT) TO <FS>.

CLEAR ITAB_OUT-PLAN14."where Plan14 is the field wit value

ITAB_OUT-PLAN14 = ITAB_OUT-PLAN14 + <FS>.

APPEND ITAB_OUT.

enddo.

ENDSELECT.

I just want to know what changes must i make to get the desired output.

Thanks in advance

Dan

Add comment
10|10000 characters needed characters exceeded

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 12:41 PM

    Daniel,

    The solution is indicated below check on the *change

    DATA: MNT_INDX(20) TYPE C,

    HLD_INDX(3) TYPE N,

    W_MTH(2) TYPE N,

    W_DATE LIKE PROJ-ERDAT.

    RANGES: R_YEAR FOR COSP-GJAHR,

    R_DATE FOR PROJ-ERDAT.

    FIELD-SYMBOLS <FS>.

    PARAMETERS FR_MONTH(2) TYPE N OBLIGATORY.

    PARAMETERS FR_YEAR(4) TYPE N OBLIGATORY.

    PARAMETERS TO_MONTH(2) TYPE N .

    PARAMETERS TO_YEAR(4) TYPE N .

    data: l_counter type i. "number of month

    l_counter = ( to_year - fr_year ) * 12 + ( to_month - fr_month ).

    DATA: W_TXT(20) TYPE C.

    R_YEAR-LOW = FR_YEAR.

    R_YEAR-HIGH = TO_YEAR .

    R_YEAR-OPTION = 'BT'.

    R_YEAR-SIGN = 'I'.

    APPEND R_YEAR.

    *change

    concatenate FR_YEAR FR_MONTH '01' INTO R_DATE-LOW .

    concatenate TO_YEAR TO_MONTH '01'INTO R_DATE-HIGH.

    R_DATE-option = 'BT'.

    R_DATE-SIGN = 'I'.

    APPEND R_DATE.

    SELECT * FROM COSP

    WHERE OBJNR = PRPS-OBJNR AND

    GJAHR IN R_YEAR AND

    KSTAR BETWEEN '0000400996' AND '0000400999' AND

    VERSN = '014' AND

    WRTTP = '01' .

    do l_counter times.

    W_MTH = SY-INDEX.

    *change

    CONCATENATE COSP-GJAHR W_MTH '01' INTO W_DATE.

    CHECK W_DATE IN R_DATE.

    HLD_INDX = SY-INDEX. " (similar to your defn)

    CONCATENATE 'COSP-WKG' HLD_INDX INTO W_TXT.

    ASSIGN (W_TXT) TO <FS>.

    CLEAR ITAB_OUT-PLAN14."where Plan14 is the field wit value

    ITAB_OUT-PLAN14 = ITAB_OUT-PLAN14 + <FS>.

    APPEND ITAB_OUT.

    enddo.

    ENDSELECT.

    Regards

    Anurag

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 12:07 PM

    Hi,

    Concatenate From_year and From_Month , To_year and To_Month.

    While selecting date check whether period field is in between these values.

      concatenate from_year from_month into from_period.
      concatenate to_year to_month into to_period.
      
      r_period-low = from_period.
      r_period-high = to_period.
      r_period-sign = 'I'.
      r_period-option = 'BT'. append r_period. clear r_period.
      select .... where period in r_period.
    

    Then, you will get correct results as you expected.

    Regards,

    Sailaja.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 10:43 AM

    Hi,

    Try this Fm-

    CONVERT_DATE_TO_EXTERNAL

    Regards,

    Seema.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 11:11 AM

    Hello Daniel,

    as some data types are not known to me, I can not give you a full solution. From point of easiest way to code the issue can be solved by deleting unwanted entries just before you do the output.

    
    delete {result] where {year <= {start_year} and {month} < {start_month}.
    
    delete {result] where {year >= {end_year} and {month} > {end_month}.
    
    

    An even better solution is to have these conditions earlier (:=

    Regards

    Klaus

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 11:51 AM

    hi ,

    try to make use of this fm <b>MM_ARRANG_SPMON_RANGE</b>.

    Regards

    Prabhu

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 12:18 PM

    Hello,

    I see the problem in the value of range field only,

    try concatenating even the day. I tried this example below and it worked perfect for me.

    Data: Begin of ivbak occurs 0,

    vbeln like vbak-vbeln,

    erdat like vbak-erdat,

    end of ivbak.

    Ranges : r_erdate for vbak-erdat.

    INITIALIZATION.

    r_erdate-low = '20010118'.

    r_erdate-high = '20010309'.

    r_erdate-OPTION = 'BT'.

    r_erdate-sign = 'I'.

    append r_erdate.

    select vbeln erdat from vbak into table ivbak

    where erdat in r_erdate.

    If that did not work, try for different date formats.

    Thanks,

    Thirumal

    Add comment
    10|10000 characters needed characters exceeded