‎2007 Aug 10 4:45 AM
I have an internal table with two fields FLD1 & FLD2(flag). I have to make sure that for same FLD1, there has to be only one FLD2 flag:
FLD1 FLD2
A X
A
B X
B X
BFor example in the above example, 'B' has two 'X' therefore, I have to give an error message saying " Maintain only one 'X' value for B"
How do I do this?
Thanks
Sg
‎2007 Aug 10 5:02 AM
Hi,
sort itab by fld1.
loop at itab.
at end of fld1.
move 'Y' to v_flg.
endat.
if itab-fld2 eq 'X'.
v_no = v_no + 1.
endif.
if v_flg eq 'Y'.
if v_no gt 1 .
message e999(yyy) "<<<<<<<
endif.
clear: v_flg, V_NO.
endif.
endloop.
aRs
‎2007 Aug 10 5:02 AM
Hi,
sort itab by fld1.
loop at itab.
at end of fld1.
move 'Y' to v_flg.
endat.
if itab-fld2 eq 'X'.
v_no = v_no + 1.
endif.
if v_flg eq 'Y'.
if v_no gt 1 .
message e999(yyy) "<<<<<<<
endif.
clear: v_flg, V_NO.
endif.
endloop.
aRs
‎2007 Aug 10 5:10 AM
‎2007 Aug 10 5:15 AM
HI
wa_itab and wa-previous are two work areas of same internal table.
loop at itab into wa_itab.
if sy-tabix = 1.
exit.
endif.
if wa_itab-FLD1 = wa_previous-FLD1
and wa_itab-FLD2 = wa_previous-FLD2
*display error message
endif.
clear wa_previous
wa_previous = wa_itab.
clear wa_itab.
endloop.
‎2007 Aug 10 5:35 AM
hi,
try like this,
sort itab by fld1 asc.
data: flag type c value 0.
loop at itab.
write:/10 itab-fld1.
if flag <=1.
at new itab.
itab-fld2 = 'X'.
modify itab.
endat.
else
flag = flag + 1.
message e000(zaluri) with 'record' sy-tabix 'has more values'.
endif.
if useful reward some points.
with regards,
Suresh Aluri.
‎2007 Aug 10 5:37 AM
data : count type i.
sort itab by fld1.
loop at itab.
at new fld1.
clear : count.
endat.
if itab-fld2 = 'X'.
count = count + 1.
endif.
if count gt 1.
message 'Maintain only one 'X' value' type 'E'.
endif.
endloop.
regards
shiba dutta
‎2007 Aug 10 7:11 AM
try the code given below. It may help to code occording to ur desired logic.
DATA: BEGIN OF it OCCURS 10,
fld1 TYPE c,
fld2 TYPE c,
END OF it.
PARAMETERS: pfld1 type c .
pfld2 type c.
data temp type i.
start-of-SELECTION.
loop at it.
if it-fld1 = pfld1 and it-fld2 = pfld2.
temp = 1.
STOP.
endif.
ENDLOOP.
end-of-SELECTION.
if temp = 0.
it-fld1 = pfld1. it-fld2 = pfld2.
append it.
write: / 'data append'.
sort it by fld1.
loop at it.
write: / it-fld1, it-fld2.
ENDLOOP.
else.
WRITE / 'Maintain only one',pfld2, 'value for',pfld1.
it-fld1 = pfld1. it-fld2 = ''.
APPEND it.
sort it by fld1.
loop at it.
write: / it-fld1, it-fld2.
ENDLOOP.
endif.
regards
Vijaykumar Reddy. S
‎2007 Aug 10 7:29 AM
Hi sugnani,
All the above methods work really guuud,
but different logic. This code below is one more approach , try this also
delcare one more internal table same as first internal table .(say.) itab2.
data: w_temp(1) type c.
itab2[] = itab1[].
sort itab2 ascending by fld1 fld2.
delete adjacent duplicates from itab2 comparing fld1 fld2.
clear w_temp.
loop at itab2.
if ( itab2-fld1 = w_temp )
*display message.
endif.
w_temp = itab2-fld1.
endloop.
Hope you found it useful... ;)
Regards,
SJ
‎2007 Aug 14 4:53 AM
Thanks everyone for your response. I have assigned the points to everyone.