2008 Jan 28 3:07 PM
hi,
Please help me out with this. My situation is that, there are some records in a notepad,
which has pernr and other details. I have copied the data into a internal table.
I need to split the records based on the pernr.
for example,
PERNR INFTY NAME
00000004 0006 ram
00000004 0006 ramu
00000006 0006 raman
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
if the user enters 2, the above 6 records must be splited into 2 sets(not necessarily equal).
The same pernr should be in one set i.e here, if it is divided into 2 sets,
1st set:
00000004 0006 ram
00000004 0006 ramu
00000006 0006 raman
2nd set:
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
but my need is, the pernr number 00000006 should not be in different sets.
i.e is,
1st set:
00000004 0006 ram
00000004 0006 ramu
2nd set:
00000006 0006 raman
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
The same pernr nos must be in same set. please help me with a logic. please give a example.
Thanks in advance.
2008 Jan 28 4:30 PM
Well, first of all you need to find out the internal table record lines using statement 'DESCRIBE' (Find out help on describe command).
Then use compute result = itablen / 2 (whatever user entered).
You will have the result and remember all of the above parameters should be type i.
for example you have 9 records in your internal table and user entered 2. you will have result 9. Loop at the first internal table and calculate the current loop pass. if result => loop pass.
"Continue your process to store in new internal table.
else exit from the loop.
now you will have 2 sets of internal tables.
At this point, you need to find out the duplicate records in both internal table.s
Again loop at the 1st set of the internal table and read the first records of the last internla table. if the match append the same into snd set of internal table and delete from 1st set of internla table.
Do untill end of the loop.
you will have 2 internal tables with 2 sets.
hi,
Please help me out with this. My situation is that, there are some records in a notepad,
which has pernr and other details. I have copied the data into a internal table.
I need to split the records based on the pernr.
for example,
PERNR INFTY NAME
00000004 0006 ram
00000004 0006 ramu
00000006 0006 raman
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
if the user enters 2, the above 6 records must be splited into 2 sets(not necessarily equal).
The same pernr should be in one set i.e here, if it is divided into 2 sets,
1st set:
00000004 0006 ram
00000004 0006 ramu
00000006 0006 raman
2nd set:
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
but my need is, the pernr number 00000006 should not be in different sets.
i.e is,
1st set:
00000004 0006 ram
00000004 0006 ramu
2nd set:
00000006 0006 raman
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
The same pernr nos must be in same set. please help me with a logic. please give a example.
Thanks in advance.
2008 Jan 28 4:30 PM
Well, first of all you need to find out the internal table record lines using statement 'DESCRIBE' (Find out help on describe command).
Then use compute result = itablen / 2 (whatever user entered).
You will have the result and remember all of the above parameters should be type i.
for example you have 9 records in your internal table and user entered 2. you will have result 9. Loop at the first internal table and calculate the current loop pass. if result => loop pass.
"Continue your process to store in new internal table.
else exit from the loop.
now you will have 2 sets of internal tables.
At this point, you need to find out the duplicate records in both internal table.s
Again loop at the 1st set of the internal table and read the first records of the last internla table. if the match append the same into snd set of internal table and delete from 1st set of internla table.
Do untill end of the loop.
you will have 2 internal tables with 2 sets.
2008 Jan 28 4:44 PM
Hi Arunsri
itab have 6 records.
00000004 0006 ram
00000004 0006 ramu
00000006 0006 raman
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
lv_total = 6.
itab1 :
00000004 0006 ram
00000004 0006 ramu
00000006 0006 raman
itab2 :
00000006 0006 xyz
00000006 0006 aaa
00000018 0006 ttt
loop at itab into wa_itab.
if sy-tabix LE lv_total / 2.
if not itab_buff[] is initial.
append lines of itab_buff to itab1.
clear itab_buff [].
endif.
move-corresponding wa_itab to wa_itab1.
append wa_itab1 to itab1.
else .
read table itab into wa_itab_buff index = sy-tabix - 1.
if wa_itab-pernr = wa_itab_buff.
append wa_itab_buff to itab_buff.
skip.
endif.
move-corresponding wa_itab to wa_itab2.
append wa_itab2 to itab2.
endloop.Hope this helps
2008 Jan 28 5:12 PM
check this code...
TYPES: BEGIN OF ty_data,
pernr(8),
infty(4),
name(15),
END OF ty_data.
DATA: itab TYPE TABLE OF ty_data,
final TYPE TABLE OF ty_data,
wa_itab TYPE ty_data.
DATA: cnt TYPE i.
PARAMETER: p_set TYPE i.
wa_itab-pernr = '00000004'.
wa_itab-infty = '0006'.
wa_itab-name = 'ram'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000004'.
wa_itab-infty = '0006'.
wa_itab-name = 'ramu'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000006'.
wa_itab-infty = '0006'.
wa_itab-name = 'raman'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000006'.
wa_itab-infty = '0006'.
wa_itab-name = 'xyz'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000006'.
wa_itab-infty = '0006'.
wa_itab-name = 'aaa'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000018'.
wa_itab-infty = '0006'.
wa_itab-name = 'ttt'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
SORT itab BY pernr. " sort before loop.
cnt = 1.
LOOP AT itab INTO wa_itab.
APPEND wa_itab TO final.
AT END OF pernr.
IF cnt <= p_set.
cnt = cnt + 1.
ELSE.
EXIT.
ENDIF.
ENDAT.
CLEAR wa_itab.
ENDLOOP.
if it does not meet ur requirements let me know.
2008 Jan 29 2:19 AM
Hi,
Hope below code can give you a lead, have extended code of Sunita.
TYPES: BEGIN OF ty_data,
pernr(8),
infty(4),
name(15),
END OF ty_data.
DATA: itab TYPE TABLE OF ty_data, " Internal table
wa_itab TYPE ty_data, " Work Area1
wa_itab1 type ty_data. " Work Area2
DATA: cnt TYPE i. " Counter for number of Sets
DATA: start TYPE i, " Start Position
end TYPE i, " End Position
split_pos TYPE i, " Split Position
lin TYPE i. " No.. of Records
PARAMETER: p_set TYPE i. " No. Of Sets
wa_itab-pernr = '00000004'.
wa_itab-infty = '0006'.
wa_itab-name = 'ram'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000004'.
wa_itab-infty = '0006'.
wa_itab-name = 'ramu'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000006'.
wa_itab-infty = '0006'.
wa_itab-name = 'raman'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000006'.
wa_itab-infty = '0006'.
wa_itab-name = 'xyz'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000006'.
wa_itab-infty = '0006'.
wa_itab-name = 'aaa'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
wa_itab-pernr = '00000018'.
wa_itab-infty = '0006'.
wa_itab-name = 'ttt'.
APPEND wa_itab TO itab.
CLEAR:wa_itab.
SORT itab BY pernr. " sort before loop.
DESCRIBE TABLE itab LINES lin. " No. Of Records
start = 1. end = lin. " Start and End Positions
WHILE p_set > 1. " Required number of sets
CLEAR: wa_itab, wa_itab1.
cnt = cnt + 1. " Counter for Set number
split_pos = ( start + end ) / p_set. " Split position for Sets
READ TABLE itab INTO wa_itab INDEX split_pos.
" Compare PERNR with next record
WHILE ( wa_itab-pernr EQ wa_itab1-pernr OR
wa_itab1-pernr IS INITIAL ) AND
split_pos < lin.
" IF Pernr is same skip to next record to group PERNR in sets
split_pos = split_pos + 1.
READ TABLE itab INTO wa_itab1 INDEX split_pos.
ENDWHILE.
end = split_pos - 1. " Split Position
WRITE:/ cnt, 'Set:'.
LOOP AT itab INTO wa_itab FROM start TO end.
WRITE:/ wa_itab-pernr.
ENDLOOP.
start = end + 1. end = lin. " Next group for set determination
p_set = p_set - 1.
CLEAR: wa_itab, wa_itab1.
ENDWHILE.
cnt = cnt + 1.
WRITE:/ cnt, 'Set:'.
LOOP AT itab INTO wa_itab FROM start TO end.
WRITE:/ wa_itab-pernr.
ENDLOOP.
Consider above code as a lead and use according to your requirement.
Regards
Eswar