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

Variable exit or logic (previous month data)

Former Member
0 Likes
551

Dear Experts,

in my itab.

material year period amt qty

abc 2008 01 4545 878

abc 2008 03 5255 900

abc 2008 07 4545 1212

abc 2009 02 4551 1555

like that i stored in PSA in BI Side.

But user give the input period 03-2009 i show the result for only 02-2009 records.

But user give the input period 10-2008 i show the result for only 07-2008 records.

But user give the input period 05-2008 i show the result for only 03-2008 records.

Thanks and regards,

raj

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
519

previously your itab is like this

 *material            year                period              amt         qty*             
 abc                   2008                  01                4545         878
 abc                   2008                  03                5255         900
 abc                   2008                  07                4545         1212
 abc                   2009                  02                4551          1555   

use this code

sort itab by year descending period descending. 

now it becomes like

 *material            year                period              amt         qty*             
 abc                   2009                  02                4551          1555   
 abc                   2008                  07                4545         1212
 abc                   2008                  03                5255         900 
 abc                   2008                  01                4545         878

now use this code to read the value

 loop at itab into is where year = p_year period LT p_per.
write : / is-material , is-year, is-period, is-amt, is-qty.
exit. " to loop only once
endloop.

Edited by: Soumyaprakash Mishra on Oct 27, 2009 11:17 PM

4 REPLIES 4
Read only

Former Member
0 Likes
519

It is because the calendar period and fiscal year periods are different.

For calendar year JANUARY - 01 whereas from

financial point of view .

APRIL - 01

Edited by: vijetasap on Oct 27, 2009 3:16 PM

Read only

Former Member
0 Likes
519

Hello

Try this logic:


do.
  read table itab with key year = p_year
                           period = p_period.
  if sy-subrc = 0.
    write: itab-material, itab-year, itab-period, itab-amt, itab-qty.
    exit.
  else.
    p_period = p_period - 1.
    if p_period = 0.
      p_period = 12.
      p_year = p_year - 1.
    endif.
  endif.
enddo.

p_period and p_year - user input.

Read only

Clemenss
Active Contributor
0 Likes
519

Hi raj a,

so what do you want? If you want an exit, what for? Do you want the previous month data?

I could try to explain but I have no idea what.

Regards,

Clemens

Read only

Former Member
0 Likes
520

previously your itab is like this

 *material            year                period              amt         qty*             
 abc                   2008                  01                4545         878
 abc                   2008                  03                5255         900
 abc                   2008                  07                4545         1212
 abc                   2009                  02                4551          1555   

use this code

sort itab by year descending period descending. 

now it becomes like

 *material            year                period              amt         qty*             
 abc                   2009                  02                4551          1555   
 abc                   2008                  07                4545         1212
 abc                   2008                  03                5255         900 
 abc                   2008                  01                4545         878

now use this code to read the value

 loop at itab into is where year = p_year period LT p_per.
write : / is-material , is-year, is-period, is-amt, is-qty.
exit. " to loop only once
endloop.

Edited by: Soumyaprakash Mishra on Oct 27, 2009 11:17 PM