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

Select Latest entry in each material based on input

Former Member
0 Likes
519

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

bbb 2008 01 4545 878

bbb 2008 03 5255 900

bbb 2008 07 4545 1212

bbb 2009 02 4551 1555

like that internel table stored in PSA in BI Side in around 10000 materialsi fetch all 10000 materials based on sam einput logic.

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

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

bbb 2008 01 4545 878

bbb 2008 03 5255 900

bbb 2008 07 4545 1212

bbb 2009 02 4551 1555

like that internel table stored in PSA in BI Side in around 10000 materialsi fetch all 10000 materials based on sam einput logic.

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

2 REPLIES 2
Read only

Former Member
0 Likes
486

Hi,

Did you want this?



TYPES: BEGIN OF ty_data,
      f1 TYPE char10,
      f2 TYPE char10,
      f3 TYPE char10,
      f4 TYPE char10,
      END OF ty_data.
TYPES: BEGIN OF ty_data1,
      f1 TYPE char10,
      f2 TYPE char10,
      f3 TYPE char10,
      f4 TYPE char10,
      sub TYPE char10,
      END OF ty_data1.

DATA: it_data TYPE STANDARD TABLE OF ty_data,
      wa_data TYPE ty_data,
      it_data1 TYPE STANDARD TABLE OF ty_data1,
      wa_data1 TYPE ty_data1.

wa_data-f1 = 'abc'.
wa_data-f2 = '2009'.
wa_data-f3 = '01'.
wa_data-f4 = '4545'.
APPEND wa_data TO it_data.

wa_data-f1 = 'abc'.
wa_data-f2 = '2008'.
wa_data-f3 = '01'.
wa_data-f4 = '768'.
APPEND wa_data TO it_data.

wa_data-f1 = 'abc'.
wa_data-f2 = '2008'.
wa_data-f3 = '07'.
wa_data-f4 = '435'.
APPEND wa_data TO it_data.

wa_data-f1 = 'abc'.
wa_data-f2 = '2009'.
wa_data-f3 = '08'.
wa_data-f4 = '34'.
APPEND wa_data TO it_data.

it_data1 = it_data.
PARAMETERS: p_year TYPE char10,
            p_period TYPE char10.

SORT it_data BY f2 f3.
SORT it_data1 BY f2 f3.

READ TABLE it_data INTO wa_data WITH KEY f2 = p_year BINARY SEARCH.
IF sy-subrc = 0.
  LOOP AT it_data INTO wa_data FROM sy-tabix.
    IF ( wa_data-f3 EQ p_period ) AND
       ( wa_data-f2 EQ p_year ).
      WRITE: wa_data-f1,
       wa_data-f2,
       wa_data-f3,
       wa_data-f4.
      EXIT.
    ELSEIF ( wa_data-f2 EQ p_year ) AND
         ( wa_data-f3 NE p_period ).
      READ TABLE it_data1 INTO wa_data1 INDEX sy-tabix.
      IF sy-subrc = 0.
        wa_data1-sub = wa_data-f3 - p_period.
        MODIFY it_data1 FROM wa_data1 INDEX sy-tabix.
      ENDIF.
    ENDIF.

  ENDLOOP.
ENDIF.

SORT it_data1 ASCENDING BY sub.
READ TABLE it_data1 INTO wa_data1 WITH KEY f2 = p_year.

WRITE: wa_data1-f1,
      wa_data1-f2,
      wa_data1-f3,
      wa_data1-f4,
      wa_data1-sub.

Read only

Former Member
0 Likes
486

Hi,

I think your question is already answered. Hmmm...stumbled on this.....

[]