Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Read Year from System Date & Compare - Assistance required

Former Member
0 Kudos

Hi All,

I am trying to read only the year part from the system date & then checking if any entry exists in EKKO table (EKKO-BEDAT) for the year. I think i am making an error in my data declaration for V_YEAR & in my select statement (EKKO~BEDAT LIKE V_YEAR), not sure how to compare only the year part, can someone help.

DATA:

V_EBELN TYPE EKPO-EBELN,

V_YEAR TYPE SY-DATUM.

CLEAR: V_EBELN, V_YEAR.

*Read year from system date

V_YEAR = SY-DATUM+0(4).

CONCATENATE '%' '%' '%' '%' V_YEAR INTO V_YEAR.

*Select section

SELECT SINGLE EKPO~EBELN INTO V_EBELN

FROM EKPO

INNER JOIN EKKO

ON EKPOEBELN = EKKOEBELN

INNER JOIN LFM1

ON EKKOLIFNR = LFM1LIFNR

WHERE EKKO~LIFNR = LFM1-LIFNR

AND EKKO~BEDAT LIKE V_YEAR

AND EKPO~LOEKZ = SPACE.

1 ACCEPTED SOLUTION

Sougata
Active Contributor
0 Kudos

Your approach is incorrect. Try this instead:


Data:  v_ebeln  type ebeln,
       v_begda type datum,
       v_endda type datum.

Move: sy-datum(4) to v_begda,
       '0101'     to v_begda,
       sy-datum(4) to v_endda,
       '1231'     to v_endda.

SELECT SINGLE EKPO~EBELN 
INTO V_EBELN
FROM EKPO as ekpo 
INNER JOIN EKKO as ekko 
ON EKPO~EBELN = EKKO~EBELN
INNER JOIN LFM1 as lfm1    
ON EKKO~LIFNR = LFM1~LIFNR
WHERE EKKO~LIFNR = LFM1~LIFNR 
AND EKKO~BEDAT between v_begda and v_endda  "<-------
AND EKPO~LOEKZ = SPACE.

Cheers,

Sougata.

7 REPLIES 7

Sougata
Active Contributor
0 Kudos

Your approach is incorrect. Try this instead:


Data:  v_ebeln  type ebeln,
       v_begda type datum,
       v_endda type datum.

Move: sy-datum(4) to v_begda,
       '0101'     to v_begda,
       sy-datum(4) to v_endda,
       '1231'     to v_endda.

SELECT SINGLE EKPO~EBELN 
INTO V_EBELN
FROM EKPO as ekpo 
INNER JOIN EKKO as ekko 
ON EKPO~EBELN = EKKO~EBELN
INNER JOIN LFM1 as lfm1    
ON EKKO~LIFNR = LFM1~LIFNR
WHERE EKKO~LIFNR = LFM1~LIFNR 
AND EKKO~BEDAT between v_begda and v_endda  "<-------
AND EKPO~LOEKZ = SPACE.

Cheers,

Sougata.

Former Member
0 Kudos

Hi Sougata,

Thanks for the inputs, but it is not working:

Move: sy-datum(4) to v_begda, -> This reads the system year 2008

'0101' to v_begda, -> This changes 2008 to 0101

sy-datum(4) to v_endda, -> This reads system year i.e. 2008

'1231' to v_endda. -> This changes 2008 to 1231

Also in the select statement

AND EKKO~BEDAT between v_begda and v_endda

This would not work, as EKKO-BEDAT is in year month date format.

So can you please clarify why we are assigining 0101 & 1231 & also how we can compare only the year in EKKO-BEDAT with System Year

Update

I tried to

concatenate '0101 into v_begda.

concatenate '1231' into v_endda.

but system prompts "charlike-field" expected after "'0101'"

Can you please advice?

Edited by: Vivek on Jan 5, 2008 7:59 PM

Sougata
Active Contributor
0 Kudos

Why wouldn't it work? Have you tried running it with the correct data?

I understand EKKO-BEDAT is in YYYYMMDD format (SAP standard date format) but so is V_BEGDA and V_ENDDA. So it should select the data BETWEEN the begin and end dates. Identify a PO where it should meet your select condition and run the program to see if the select is successful.

Cheers,

Sougata.

Ok, change the MOVE statement above to:


Move: sy-datum(4) to v_begda(4),
       '0101'     to v_begda+4(4),
       sy-datum(4) to v_endda(4),
       '1231'     to v_endda+4(4).

Edited by: Sougata Chatterjee on Jan 5, 2008 11:01 PM

Code bug fixed...I'm not in front of a system

Former Member
0 Kudos

Thank you very much for your guidance. It has solved my problem

Regards,

Vivek

Edited by: Vivek on Jan 5, 2008 8:07 PM

Sougata
Active Contributor
0 Kudos

You are welcome.

Regards,

Sougata.

kesavadas_thekkillath
Active Contributor
0 Kudos

DATA:WK_YEAR(10).

CONSTANTS:CO_SEP VALUE '%'.

CONCATENATE CO_SEP CO_SEP CO_SEP CO_SEP CO_SEP CO_SEP SY-DATUM+0(4) INTO WK_YEAR.

PASS WK_YEAR IN THE QUERY...

JUST CHECK IN WHAT FORMAT THE DATE IS SORED IN THE TABLE AND PASS THE PARAMETER AS THAT

0 Kudos

aLSO CONCATENATE DOT(.) IN THE VALUIE