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

Month Year format

Hi all

I've passed the paramaters : year and month i.e. 2005, 06(month).

i want to select one month for example june 2005, in vbak table erdate. how should write query?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:36 AM

    Hi,

    I did some modification to my earlier post

    Now you can eneter any month or year on the selection-screen and you call get the documents for that perios from VBAk.

    REPORT YUP_TEST2 .

    DATA: IT_VBAK TYPE TABLE OF VBAK WITH HEADER LINE.

    DATA:V_DATE_A TYPE SY-DATUM,

    V_DATE_B TYPE SY-DATUM.

    PARAMETERS:P_YEAR(4),

    P_MONTH(2).

    • v_date = sy-datum.

    *write:/ sy-datum.

    CONCATENATE P_YEAR P_MONTH '01' INTO V_DATE_A.

    CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

    EXPORTING

    DAY_IN = V_DATE_A

    IMPORTING

    LAST_DAY_OF_MONTH = V_DATE_B

    EXCEPTIONS

    DAY_IN_NOT_VALID = 1

    OTHERS = 2

    .

    IF SY-SUBRC <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    SELECT * FROM VBAK INTO TABLE IT_VBAK

    WHERE ERDAT >= V_DATE_A AND

    ERDAT <= V_DATE_B.

    LOOP AT IT_VBAK.

    WRITE:/ IT_VBAK-VBELN,IT_VBAK-ERDAT.

    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:12 AM

    data: gv_date like sy-datum.

    data: gv_out(7),

    gv_yy(4),

    gv_mmm(2) .

    select single erdat into gv_date from vbak.

    gv_yy = gv_date+0(4).

    gv_mmm = gv_date+4(2).

    CONCATENATE of gv_yy gv_mmm into gv_out seprated by ','.

    write : gv_out .

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:13 AM

    Using this will give you the month you want.

    m = VBAK-ERDAT+4(2)

    READ TABLE t247 INDEX m.

    IF sy-subrc = 0.

    mname = month_names-ltx.

    ENDIF.

    Rgds,

    Jothi.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:14 AM

    Hi,

    What you can do is to concatenate the 01 / 31 to the month and date and then use the BETWEEN clause

    concatenate year month '01' into w_start_date.

    Using the starting date, get the last day of the month.

    Now use the BETWEEN clause.

    Select * from VBAK where erdat between w_start_date and w_end_date.

    Regards,

    Ravi

    Note : Please mark the helpful answers

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:17 AM

    hi

    just check the way in which date is stored in vbak..

    pass the date to some string..w_string(200506)

    then concatenate w_string '01' to w_first_date.

    use this fm to get the last date of the month SG_PS_GET_LAST_DAY_OF_MONTH...pass it w_last_date

    query at vbak

    select...

    ...

    where erdate ge w_first_date and erdate le w_last_date..

    and manipulate this part accordingly..

    Reward points if it helps

    regards

    Gunjan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:31 AM

    Hi,

    I wrote this sample program . you will get all documents

    for the the entered June month.

    DATA: IT_VBAK TYPE TABLE OF VBAK WITH HEADER LINE.

    DATA:V_DATE_A TYPE SY-DATUM,

    V_DATE_B TYPE SY-DATUM.

    PARAMETERS:P_YEAR(4) DEFAULT '2006',

    P_MONTH(2) DEFAULT '06'.

    • v_date = sy-datum.

    *write:/ sy-datum.

    CONCATENATE P_YEAR P_MONTH '01' INTO V_DATE_A.

    CONCATENATE P_YEAR P_MONTH '30' INTO V_DATE_B.

    SELECT * FROM VBAK INTO TABLE IT_VBAK

    WHERE ERDAT >= V_DATE_A AND

    ERDAT <= V_DATE_B.

    LOOP AT IT_VBAK.

    WRITE:/ IT_VBAK-VBELN,IT_VBAK-ERDAT.

    ENDLOOP.

    Thanks,

    Pramod

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 05:55 AM

    Hi Muthu,

    U can try out this.

    tables: vbak.

    select * from vbak where erdat like '200508%'.

    write: vbak-erdat.

    endselect.

    Rgds,

    Sumana

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 20, 2006 at 06:09 AM

    Hi Muthu,

    Please check this code.

    TABLES : vbak.

    DATA : itab TYPE TABLE OF vbak WITH HEADER LINE.

    DATA : l_start_date TYPE sy-datum,

    l_end_date TYPE sy-datum.

    PARAMETERS : l_month(2),

    l_year(4).

    CONCATENATE l_year l_month '01' INTO l_start_date.

    --- Getting last day of the month --

    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'

    EXPORTING

    day_in = l_start_date

    IMPORTING

    last_day_of_month = l_end_date

    EXCEPTIONS

    day_in_no_date = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    SELECT * FROM vbak

    INTO TABLE itab

    WHERE erdat GE l_start_date

    AND

    erdat LT l_end_date.

    IF sy-subrc = 0.

    LOOP AT itab.

    WRITE : / itab-erdat, itab-vbeln.

    ENDLOOP.

    ENDIF.

    If found helpful, please do reward.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Muthu,

      you are far more flexible if you use a range for the selection; you declare it in the selection screen like

      <pre>

      TABLES:

      vbak.

      DATA:

      gt_vbak TYPE TABLE of vbak.

      SELECT-OPTIONS:

      s_erdat FOR vbak-erdat.

      SELECT vbeln erdat "an the fields you really need

      FROM vbak

      INTO CORRESPONDING FIELDS OF TABLE gt_vbak

      WHERE erdat IN s_erdat.

      • ... further processing

      </pre>

      Note: This database selection will be quite time-cosuming if you do not have an index defined on field erdat.

      The big advantage of ranges is that they can be used for a lot of selection conditions including patterns, exclusions and so on. With a range you could for example specify for example specific months and exclude in the same selection specific dates.

      Regards,

      Clemens

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.