Application Development and Automation 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 only

fetch data based on year and period

Former Member
0 Likes
727

Hi,

I want to fetch all entries for year and period less than entered in parameters as below.

SELECT rprctr racct matnr hsl

FROM glpca

INTO TABLE git_glpca_2

WHERE rbukrs = p_bukrs

AND ( ryear LE p_gjahr )

AND poper <= p_perio

AND racct = p_hkont2

AND rprctr IN s_prctr2.

Suppose user entered period as 6 and year 2010 then if there are entries with 2009 it will take from period 6 but it should take all periods of 2009 and less than or equal to 6 for 2009.

Kindly advice.

Rgds

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
658

Hi Sanjay,

If I understand correctly, if user enters period = 6 and year = 2010, you must fetch Jan 2009, Feb 2009, also July 2009, Aug 2009, but not July 2010, Aug 2010.

For this write the code as follows:


SELECT  rprctr 
	racct 
	matnr 
	hsl
  FROM  glpca
  INTO  TABLE git_glpca_2
 WHERE  rbukrs = p_bukrs
   AND  ( ryear < p_gjahr OR  ( ryear = p_gjahr AND
				poper <= p_perio ) )
   AND  racct = p_hkont2
   AND  rprctr IN s_prctr2[].

Let me know if this works! If you have any further queries, please do reply back.

On a separate note, I would advise you to avoid such a confusing query. If you are not very very stringent on performance issues, you can also code as follows:


SELECT  rprctr 
	racct 
	matnr 
	hsl
	ryear
	poper
  FROM  glpca
  INTO  TABLE git_glpca_2
 WHERE  rbukrs = p_bukrs
   AND  ryear < p_gjahr 
   AND  racct = p_hkont2
   AND  rprctr IN s_prctr2[].

LOOP AT git_glpca_2 INTO gwa_glpca.
  IF gwa_glpca-ryear = p_gjahr and gwa_glpca-poper > p_perio.
    delete git_glpca.
  ENDIF.
ENDLOOP.

Cheers,

Shailesh.

Hi,

I want to fetch all entries for year and period less than entered in parameters as below.

SELECT rprctr racct matnr hsl

FROM glpca

INTO TABLE git_glpca_2

WHERE rbukrs = p_bukrs

AND ( ryear LE p_gjahr )

AND poper <= p_perio

AND racct = p_hkont2

AND rprctr IN s_prctr2.

Suppose user entered period as 6 and year 2010 then if there are entries with 2009 it will take from period 6 but it should take all periods of 2009 and less than or equal to 6 for 2009.

Kindly advice.

Rgds

2 REPLIES 2
Read only

Former Member
0 Likes
658

>

> Suppose user entered period as 6 and year 2010 then if there are entries with 2009 it will take from period 6 but it should take all periods of 2009 and less than or equal to 6 for 2009.

Is that correct??

Rob

Read only

Former Member
0 Likes
659

Hi Sanjay,

If I understand correctly, if user enters period = 6 and year = 2010, you must fetch Jan 2009, Feb 2009, also July 2009, Aug 2009, but not July 2010, Aug 2010.

For this write the code as follows:


SELECT  rprctr 
	racct 
	matnr 
	hsl
  FROM  glpca
  INTO  TABLE git_glpca_2
 WHERE  rbukrs = p_bukrs
   AND  ( ryear < p_gjahr OR  ( ryear = p_gjahr AND
				poper <= p_perio ) )
   AND  racct = p_hkont2
   AND  rprctr IN s_prctr2[].

Let me know if this works! If you have any further queries, please do reply back.

On a separate note, I would advise you to avoid such a confusing query. If you are not very very stringent on performance issues, you can also code as follows:


SELECT  rprctr 
	racct 
	matnr 
	hsl
	ryear
	poper
  FROM  glpca
  INTO  TABLE git_glpca_2
 WHERE  rbukrs = p_bukrs
   AND  ryear < p_gjahr 
   AND  racct = p_hkont2
   AND  rprctr IN s_prctr2[].

LOOP AT git_glpca_2 INTO gwa_glpca.
  IF gwa_glpca-ryear = p_gjahr and gwa_glpca-poper > p_perio.
    delete git_glpca.
  ENDIF.
ENDLOOP.

Cheers,

Shailesh.