2010 Apr 09 8:21 AM
Dear Experts,
I need a logic for my program, My internal table looks like below, I want to do one calucalation using my internal table. I need to check the STLNR and SERNP, if its comes once that suituvation no need todo any calculation, if its comes more then once (stlnr-15646 and 17203 comes more then once here ) then i need to take the particular records and i need to do another type of calculation. Can anyone help this logic. How to seperate the repeated enteries?
MATNR SERNP STLNR
10Z0300 LX01 15637
10Z0305 LX01 15644
20G0279 LX01 15646
21J0484 LX01 15646
001575Y LX01 16054
12L1000 LX01 17203
14N1092 LX01 17203
21Z0336 LX01 17203
Mohana
2010 Apr 09 8:28 AM
create another internal table itab2 with fields in following squence:
SERNP STLNR MATNR FLAG
where flag is of type char1.move all data from your original internal table to itab2.then proceed as follows
sort itab2 by sernp stlnr.
loop at itab2.
at new stlnr.
itab2-flag = 'X'.
modify itab2 transporting flag.
endat.
endloop.
loop at itab2 where flag ne 'X'.
*do your calculation..
endloop.
Dear Experts,
I need a logic for my program, My internal table looks like below, I want to do one calucalation using my internal table. I need to check the STLNR and SERNP, if its comes once that suituvation no need todo any calculation, if its comes more then once (stlnr-15646 and 17203 comes more then once here ) then i need to take the particular records and i need to do another type of calculation. Can anyone help this logic. How to seperate the repeated enteries?
MATNR SERNP STLNR
10Z0300 LX01 15637
10Z0305 LX01 15644
20G0279 LX01 15646
21J0484 LX01 15646
001575Y LX01 16054
12L1000 LX01 17203
14N1092 LX01 17203
21Z0336 LX01 17203
Mohana
2010 Apr 09 8:28 AM
create another internal table itab2 with fields in following squence:
SERNP STLNR MATNR FLAG
where flag is of type char1.move all data from your original internal table to itab2.then proceed as follows
sort itab2 by sernp stlnr.
loop at itab2.
at new stlnr.
itab2-flag = 'X'.
modify itab2 transporting flag.
endat.
endloop.
loop at itab2 where flag ne 'X'.
*do your calculation..
endloop.
2010 Apr 09 8:39 AM
hi mohana,
try as follows hope this helps
data l_stlnr_count type i.
clear l_stlnr_count.
sort itab by sernp stlnr.
loop at sernp into wa_sernp.
l_stlnr_count = l_stlnr_count + 1.
at end of stlnr.
if l_stlnr_count > 1.
do your processing.
clear l_stlnr_count,
endif.
endat..
endloop.
thanks
tanmaya
2010 Apr 09 8:41 AM
Hi, One more alternate solution.
Create new tab with columns stlnr, cnt.
Loop though exitsiting itab.
move-corresponding <wa> into <new wa>
move 1 to <new wa>-cnt.
collect <new wa> to <new itab>.
endloop.
loop through existing itab.
read table <new itab> into <new wa> with key sernp,stlnr.
if <new wa>-cnt gt 1.
do process1.
else.
do process 2.
endif.
endloop.or
cnt = 0.
loop at itab into wa_itab.
ON CHANGE OF stlnr
if cnt > 1
do process 1.
else
do process 2.
endif.
cnt = 0.
ENDON.
endloop.
if cnt > 1
do process 1.
else
do process 2.
endif.Regards
Vinod
Edited by: Vinod Kumar on Apr 9, 2010 1:17 PM
2010 Apr 09 8:50 AM
Hi,
Do not forget to sort the table on the basis of field on which you will use AT END OF or At NEW.
Change oyur internal table to the following format:
SERNP STLNR MATNR
LX01 15637 10Z0300
LX01 15644 10Z0305
LX01 15646 20G0279
LX01 15646 21J0484
LX01 16054 001575Y
LX01 17203 12L1000
LX01 17203 14N1092
LX01 17203 21Z0336
Now do the following:
SORT it_table DESCENDING BY sernp stlnr.
LOOP AT it_table INTO wa_table.
"Do something
AT END OF STLNR.
"count the number records
" Now check if it is greater then one and put whatever logic you want
ENDAT.
ENDLOOP.
Thanks & Regards
Rocky
2010 Apr 09 8:59 AM
Hi Mohana,
You can try with the below steps.
1. Sort the internal table A (main) by SERNR and STLNR.
2. move the value into a local internal table B (type same of A).
3. delete adjacent duplcates from B comparing SERNR, STLNR.
4. loop at B into workarea.
5. read table A with key sernp = wa_B-sernp and stlnr = wa_B-stlnr binary search transporting no fields.
6.if sy-subrc = 0. l_index = sy-tabix.
7. loop at A from l_index.
8. if wa_A-sernp = wa_B-sernp and wa_A-stlnr = wa_B-stlnr.
do the calculation.
endif.
9. endloop A.
10. endif. "endif for sy-subrc
11. endloop B.
2010 Apr 09 11:52 AM
Let your below internal table be it_data with work area wa_data as the same structure as it_data.
Then you create another internal table with the same structure say it_data_copy.
MATNR SERNP STLNR
10Z0300 LX01 15637
10Z0305 LX01 15644
20G0279 LX01 15646
21J0484 LX01 15646
001575Y LX01 16054
12L1000 LX01 17203
14N1092 LX01 17203
21Z0336 LX01 17203
types : begin of ty_stlnr,
stlnr type STLNR,
end of ty_stlnr.
data : it_stlnr type table of ty_stlnr,
wa_stlnr type ty_stlnr.
SORT it_data BY SERNP STLNR.
CLEAR : wa_data , wa_stlnr.
LOOP AT it_data INTO wa_data.
i_count = i_count+1.
AT END OF STLNR.
IF i_count GT 1.
wa_stlnr-stlnr = wa_data-stlnr.
APPEND wa_stlnr TO it_stlnr.
CLEAR wa_stlnr.
ENDIF.
i_count = 0.
ENDAT.
CLEAR wa_data.
ENDLOOP.
now it_stlnr contains the stlnr of the duplicate entries.
CLEAR : wa_data , wa_stlnr.
LOOP AT it_data INTO wa_data.
READ TABLE it_stlnr into wa_stlnr with key stlnr = wa_data-STLNR.
IF SY-SUBRC EQ 0.
APPEND wa_data TO it_data_copy.
ENDIF.
CLEAR : wa_data , wa_stlnr.
ENDLOOP.
it_data_copy now contains only the duplicate entries of it_data.
I think the above piece of code should deliver you the desired result...
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |