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: 

how to compare records in singe internal table

Former Member
0 Kudos
290

Hi Folks,

iam having 3 records in my first itab( T_FINAL) with fields

material no, descrip , mat type and group.

and 16 records in second itab(T_MVKE ) with fields

mat no , distri.chanel and division

now I want to fetch the records from T_MVKE by comparing the records in

T_FINAL .my requirement is to check the given mat no. in sales org.2000,2100. if yes then i have to consider 2000 only, if it is in only 2100 then consider 2100 only . is it is in 2000 only then consider 2100 only

my code is

LOOP AT T_FINAL.

READ TABLE T_MVKE WITH KEY MATNR = T_FINAL-MATNR.

IF SY-SUBRC = 0.

ON CHANGE OF T_MVKE-MATNR OR T_MVKE-VKORG.

IF T_MVKE-VKORG = '2000' and SY-TABIX > 1.

CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.

ELSEIF T_MVKE-VKORG = '2000' AND SY-TABIX = 1.

CONCATENATE '2000' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.

ELSE.

CONCATENATE '2100' 'TS' P_WERKS T_FINAL-MATNR INTO KEY.

ENDIF.

this logic fails ,. could tell me how to compare values in single itab?

Thanks

neha

1 ACCEPTED SOLUTION

andreas_mann3
Active Contributor
0 Kudos
135

Hi ,

if i've understand you correctly , try that:

LOOP AT t_final.
  AT NEW matnr.
    CLEAR: v_2000, v_2100.
*1) 2000
    READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                   vkorg = 2000.

    IF sy-subrc = 0.
      v_2000 = 'X'.
    ENDIF.

*2) 2100
    READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                   vkorg = 2100.

    IF sy-subrc = 0.
      v_2100 = 'X'.
    ENDIF.

*compare
    IF v_2000 = 'X' AND  v_2100 = 'X'.
*read 2000 only
    ELSEIF v_2000 = ' '  AND v_2100 = ' '.
*nothing found
    ELSE.
*all other combinations
*read 2100 only
    ENDIF.
  ENDAT.
ENDLOOP.

regards Andreas

6 REPLIES 6

Former Member
0 Kudos
135

Hi,

Sort t_mvke.

loop at t_final.

read table t_mvke with key matnr = t_final-matnr.

check sy-subrc = 0. "Assuming at least one record for mat

CONCATENATE t_mvke-vkorg 'TS' P_WERKS T_FINAL-MATNR INTO KEY.

endloop.

cheers,

andreas_mann3
Active Contributor
0 Kudos
136

Hi ,

if i've understand you correctly , try that:

LOOP AT t_final.
  AT NEW matnr.
    CLEAR: v_2000, v_2100.
*1) 2000
    READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                   vkorg = 2000.

    IF sy-subrc = 0.
      v_2000 = 'X'.
    ENDIF.

*2) 2100
    READ TABLE  t_mvke    WITH KEY matnr = t_final-matnr
                                   vkorg = 2100.

    IF sy-subrc = 0.
      v_2100 = 'X'.
    ENDIF.

*compare
    IF v_2000 = 'X' AND  v_2100 = 'X'.
*read 2000 only
    ELSEIF v_2000 = ' '  AND v_2100 = ' '.
*nothing found
    ELSE.
*all other combinations
*read 2100 only
    ENDIF.
  ENDAT.
ENDLOOP.

regards Andreas

0 Kudos
135

Hi Andreas Mann ,

thanks for ur help, my program working properly with your logic.

regrds

srini

0 Kudos
135

Hi srini,

that's fine that i could help you

So please say

'Thanks the SDN way'. Click on the yellow star, and award suitable points.

Check out this weblog:

/people/mark.finnern/blog/2004/08/10/spread-the-love

thanks

Andreas

0 Kudos
135

Hi Srinivas,

The response that Andreas has given deserves 10 points, because it has solved your problem. I have done it for this time. But from the next time around, please do make a habit of rewarding as many points as the answers deserve.

Regards,

Anand Mandalika.

0 Kudos
135

Thank you Anand,

have you actually received my mail from 03/may/2005 ?

regards Andreas