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

compare 2 value

Former Member
0 Likes
2,435

Hi All,

I want to compare 2 values in same internal table.

like.

belnr qty qty1

1234 12 1

1234 12 2

I want to compare belnr value and put qty = 0 if belnr is duplicate.

like

belnr qty qty1

1234 12 1

1234 00 2

please help me.

thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,384

Hi Ankita,

Try this code:

Create one more field at the end of the record of internal table as flag type c.

I have consider matnr for belnr.

data: temp_matnr like mara-matnr.

clear temp_matnr.

sort itab by matnr.

loop at itab.

if itab-matnr = temp_matnr and itab-flag = ''.

itab-qty = '0.00'.

itab-flag = 'X'.

modify itab TRANSPORTING qty flag.

endif.

temp_matnr = itab-matnr.

endloop.

Hope fully it will work for your requirement.

Thanks..

Regards,

Mukul Bopche

Edited by: Mukul TATA on Dec 7, 2009 6:43 AM

25 REPLIES 25
Read only

Former Member
0 Likes
2,383

Hi,

You can sort the internal table by belnr, then loop the internal table, and compare the belnr, if identical, modify the internal table.

Read only

Former Member
0 Likes
2,383

Hi,

Please try this:-

sort t_belnr by belnr.

loop at t_belnr into wa_belnr.

v_temp = wa_belnr-qty.

at new belnr.

continue.

endat.

clear wa_belnr-qty.

modify t_belnr from wa_belnr index sy-tabix.

endloop.

Regards,

Subhashini

Read only

0 Likes
2,383

Hi shubhasini

It also gives same output...

please help me.

Read only

0 Likes
2,383

HI all,

My actual problem is like :

40559178 110.000 40559178 138.000

40559178 004.000 40559178 138.000

40559178 024.000 40559178 138.000

here i want to put 0 on place of 138 in 2nd and 3rd row...

please help me...

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,383

sort itab by <field1>.


loop at itab into wa.
l_tabix = sy-tabix.
at new wa-<field1>.
continue.
endat.
clear wa-qty.
modify itab index l_tabix from wa transporting <field4>
clear wa.
endloop.

Read only

0 Likes
2,383

Hi Ksd

Can u give me some hint by code...

Read only

0 Likes
2,383

What hint do you require ?

Read only

0 Likes
2,383

hI KDS,

IT GIVE SAME OUTPUT...

PLEASE HELP ME.

Read only

0 Likes
2,383

HI,

the code is written assuming that your itab sturcture is like

field1 field2 field3 field4

40559178 110.000 40559178 138.000

40559178 004.000 40559178 138.000

40559178 024.000 40559178 138.000

if there is any change in the structure the control break statement may not work.

Read only

0 Likes
2,383

HI

i AM USING FOLLOWING CODE..

ITAB , AND ITAB1 BOTH R INTERNAL TABLES

AND I AM APPENDING THEM IN ONE..

i AM GATING OUT PUT LIKE THIS:

40559178 110.000 138.000 701002 202630

40559178 4.000 138.000 701002 202630

40559178 24.000 138.000 701002 202630

I WANT OUTPUT LIKE :

40559178 110.000 138.000 701002 202630

40559178 4.000 000.000 701002 202630

40559178 24.000 000.000 701002 202630

FOR THIS OUTPUT I AM USING FOLLOWING CODE.

DATA : CHECK TYPE C.

LOOP AT ITAB.

LOOP AT ITAB1 WHERE MBLNR_REG = ITAB-MBLNR_SRP .

MOVE : ITAB-MBLNR_SRP TO ITAB3-MBLNR_SRP,

ITAB-MATNR_SRP TO ITAB3-MATNR_SRP,

ITAB-MENGE_SRP TO ITAB3-MENGE_SRP,

ITAB1-MENGE_REG TO ITAB3-MENGE_REG,

ITAB1-MATNR_REG TO ITAB3-MATNR_REG.

APPEND ITAB3.

CHECK = 'X'.

ENDLOOP.

IF CHECK = ' '.

ITAB3-MATNR_REG = SPACE.

ITAB3-MENGE_REG = SPACE.

APPEND ITAB3.

CLEAR CHECK.

ENDIF.

ENDLOOP.

IS IT RIGHT?

Read only

0 Likes
2,383

Try this :

Sort your table based on your field1 .

After this use below code :


loop at itab.
lv_tabix = sy-tabix. " Required to modify field
at new field1.
continue.
endat.
clear  field. " This will make the field blank
modify itab index lv_tabix  transporting  field
endloop.

Read only

0 Likes
2,383

YES U R RIGHT.

BUT I WANT 0 ONPLACE OF 138 IN 2ND & 3RD ROW.

40559178 110.000 138.000

40559178 4.000 138.000

40559178 24.000 138.000

Read only

0 Likes
2,383

You code is a bit confusing

Consider this data

40559178 110.000 138.000 701002 202630

40559178 4.000 138.000 701002 202630

40559178 24.000 138.000 701002 202630

My previos code will work.

sort the itab based on field1.

loop at itab into wa.

at new wa-field1. "Gets triggered when a new belnr is found

continue.

endat.

wa-field4 = 0. "For other records make it 0

modify itab from wa.

endloop.

Please debug and find the solution.

Read only

0 Likes
2,383

hI KSD

I AM USING SAME CODE

BUT OUTPUT IS SAME NO CHANGE..

MY CODE IS :

SORT ITAB BY MBLNR_SRP.

loop at itab3.

at new MBLNR_SRP.

continue.

endat.

ITAB3-MENGE_REG = 0 .

modify itab3 .

endloop.

Read only

0 Likes
2,383

is the field MBLNR_SRP the first field in your internal table ?

Read only

0 Likes
2,383

YES.

Read only

0 Likes
2,383

my first field is mblnr_srp ,

2nd is menge_srp

3rd is menge_reg

4th is matnr_srp

5th is matnr_reg

Read only

0 Likes
2,383

Now debugging is the only solution.

Check whether its changing the value to zero or not.

Read only

0 Likes
2,383

no changing value is not 0

it is same as before.

Read only

0 Likes
2,383

NO idea how to help you,

Try moving the data to another table.

loop at itab.

at new field1.

read table itab index sy-tabix.

move itab-field1 to itab1-field1.

-

-

move itab-field4 to itab1-field4.

append itab1.

clear itab1.

continue.

endat.

move itab-field1 to itab1-field1.

"Donot move the field Quantity

move itab-field4 to itab1-field4.

append itab1.

clear itab1.

endloop.

Read only

0 Likes
2,383

any ways

thanks Kds

for your valuable time and suggestions.

Read only

0 Likes
2,383

Hi ankita,

you wrote this

"MY CODE IS :

SORT ITAB BY MBLNR_SRP.

loop at itab3.

at new MBLNR_SRP.

continue.

endat.

ITAB3-MENGE_REG = 0 .

modify itab3 .

endloop.

"

in your internal table (ITAB3) MBLNR_SRP must be first field. So please check it and then write the following.

Data : tabix like sy-tabix.

SORT ITAB3 BY MBLNR_SRP.

loop at itab3.

tabix = sy-tabix.

at new MBLNR_SRP.

continue.

endat.

ITAB3-MENGE_REG = 0 .

modify itab3 index tabix transporting MENGE_REG.

endloop.

with regards

MADAN NAMDEO

Read only

Former Member
0 Likes
2,383

Please do not use all caps.

And what is the problem? it looks pretty basic to me.

Rob

Read only

Former Member
0 Likes
2,383

Hi,

Assume your table is itab.

declare one variable name z_belnr.

loop at itab.

if z_belnr is not initial.

if z_belnr = itab-belnr.

itab-qty = 0.

modify itab.

endif.

endif.

z_belnr = itab-belnr.

endloop.

Regards,

Simon

Read only

Former Member
0 Likes
2,385

Hi Ankita,

Try this code:

Create one more field at the end of the record of internal table as flag type c.

I have consider matnr for belnr.

data: temp_matnr like mara-matnr.

clear temp_matnr.

sort itab by matnr.

loop at itab.

if itab-matnr = temp_matnr and itab-flag = ''.

itab-qty = '0.00'.

itab-flag = 'X'.

modify itab TRANSPORTING qty flag.

endif.

temp_matnr = itab-matnr.

endloop.

Hope fully it will work for your requirement.

Thanks..

Regards,

Mukul Bopche

Edited by: Mukul TATA on Dec 7, 2009 6:43 AM