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

Logic required for a Internal table issue

Former Member
0 Likes
906

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

1 ACCEPTED SOLUTION
Read only

former_member188827
Active Contributor
0 Likes
869

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

6 REPLIES 6
Read only

former_member188827
Active Contributor
0 Likes
870

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.

Read only

Former Member
0 Likes
869

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

Read only

Former Member
0 Likes
869

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

Read only

Rocky1
Product and Topic Expert
Product and Topic Expert
0 Likes
869

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

Read only

dibakar_balida
Discoverer
0 Likes
869

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.

Read only

Former Member
0 Likes
869

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...