‎2010 Dec 26 7:16 AM
Dear All,
Need to get advice on the logic.
I have an internal table.
when there is a start of id 1, it is considered as new group.
in each group i must check that the register value only show 1 time. repeated in the group or no entry in register at all in the group, will print message.
correct
id register
1 y
2
1
2 y
3
incorrect if repeated
id register
1 y
2 y
incorrect if no entry at all
id register
1
2
3
4
Thanks
‎2010 Dec 26 10:54 AM
Hi gengis,
if your iinternal table structure has the first field ID and a second field register, it may me like this:
data:
lv_register type string,
lv_multiple type flag.
field-symbols:
<record> like line of itab.
sort itab by id.
loop at itab assigning <record>.
if lv_register is not initial and <record>-register is not initial.
lv_multiple = 'X'.
endif.
lv_register = <record>-register.
at end of id.
if lv_register is initial.
write: / 'error no regsiter in group'
elseif lv_multiple is not initial.
write: / 'error more than one register in group'.
endif.
clear: lv_register, lv_multiple.
endat.
endloop.Adapt according to your needs.
Note: To make sure the AT events are triggered correctly, ID must be first field in itab.
Regards,
Clemens
‎2010 Dec 27 1:10 PM
Hi.
Please check whether the below code helps:
LOOP AT ITAB INTO WA1.
IF WA1-ID EQ 1.
FLAG = 1.
PERFORM CHECK_GROUP.
IF FLAG EQ 1.
WRITE : / 'GROUP NO :', INDEX.
INDEX = INDEX + 1.
APPEND WA1 TO ITAB1.
ELSE.
ENDIF.
ELSE.
APPEND WA1 TO ITAB1.
ENDIF.
CLEAR WA1.
ENDLOOP.
PERFORM CHECK_GROUP.
&----
*& Form check_group
&----
text
----
FORM CHECK_GROUP.
CLEAR : flag1,num.
IF ITAB1 IS NOT INITIAL.
LOOP AT ITAB1 INTO WA2.
IF WA2-REG EQ 'Y'.
num = num + 1.
FLAG1 = 0.
CONTINUE.
ELSE.
FLAG1 = 1.
CONTINUE.
ENDIF.
ENDLOOP.
IF FLAG1 = 1.
WRITE 'NO REGISTER FOUND'.
ELSEIF NUM GT 1.
WRITE 'INCORRECT ENTRIES'.
ELSE.
WRITE 'ENTRIES ARE CORRECT'.
ENDIF.
ENDIF.
REFRESH ITAB1.
CLEAR WA2.
ENDFORM. "check_group