‎2012 Nov 22 10:46 AM
Hi,
Can someone explain the processing of this code? I am not getting the procedure.
TYPES:
BEGIN OF ty_test,
f1 TYPE c,
END OF ty_test.
DATA:
t_test TYPE STANDARD TABLE OF ty_test,
d_test TYPE ty_test.
INSERT INITIAL LINE INTO t_test INDEX 1.
APPEND 'X' TO t_test.
APPEND INITIAL LINE TO t_test.
APPEND 'X' TO t_test.
INSERT INITIAL LINE INTO t_test INDEX 1.
APPEND 'X' TO t_test.
APPEND INITIAL LINE TO t_test.
APPEND 'X' TO t_test.
DELETE ADJACENT DUPLICATES FROM t_test.
DESCRIBE TABLE t_test.
WRITE sy-tfill.
‎2012 Nov 22 11:01 AM
‎2012 Nov 22 11:05 AM
Yes you can do debugging you can find the solutions for your question...
Thanks,
Raj
‎2012 Nov 22 11:09 AM
Debug it u will get it
when u do delete adjacent , only 1,2 and 5,6 are same with adjacent records so one among them gets deleted
so output will be total 6 outof 8.
‎2012 Nov 22 11:12 AM
hi,
When the records are getting populated in the internal table .
the internal table t_test will be as follows
from
(INSERT INITIAL LINE INTO t_test INDEX 1.
APPEND 'X' TO t_test.
APPEND INITIAL LINE TO t_test.
APPEND 'X' TO t_test.
INSERT INITIAL LINE INTO t_test INDEX 1.
APPEND 'X' TO t_test.
APPEND INITIAL LINE TO t_test.
APPEND 'X' TO t_test.)
1
2
3 X
4
5 X
6 X
7
8 X
when
DELETE ADJACENT DUPLICATES FROM t_test.
t_test will be
1
2 X
3
4 X
5
6 X
then sy-tfill will be 6.
Hope it helps.
‎2012 Nov 22 11:19 AM
Hello Rajwinder,
Please debug so that you can get actual flow.
However for your understanding check below :
T_TEST has following values before delete adjacent duplictes.
1
2
3 X
4
5 X
6 X
7
8 X
After delete adjacent duplicated of t_test, You will get 6 entries
1
2 X
3
4 X
5
6 X
So output will be 6 records.
Regards,
Deepti
‎2012 Nov 22 11:53 AM
What you do not understand exactly in this exercise?
As already written, you could try debug statement by statement, or read the documentation of the ABAP statements
Regards,
Raymond
‎2012 Nov 22 12:01 PM
Hi Rajwinder,
First of all, this code in the current form will not work and will give the error on activating. The procedure here is to insert and append the records into the internal table. This question may be used as interview question. To decode this piece of code, just understand the difference between INSERT and APPEND.
INSERT will insert the record at the particular index or line, while APPEND will append or insert the record at the end of table. If the index already exists, then the current record is inserted into that index and the data of that index is moved down to current index + 1. All other records are moved subsequently. Now coming to your code, ignoring the errors: The table values are shown below each statements.
1. INSERT INITIAL LINE INTO t_test INDEX 1.
T_TEST ==> 1 ' ' (Space or blank), sy-tabix = 1
2. APPEND 'X' TO t_test.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 'X'
3. APPEND INITIAL LINE TO t_test.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 'X'
T_TEST ==> 3 ' ' (Space or blank)
4. APPEND 'X' TO t_test.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 'X'
T_TEST ==> 3 ' ' (Space or blank)
T_TEST ==> 4 'X'
5. INSERT INITIAL LINE INTO t_test INDEX 1.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 ' ' (Space or blank)
T_TEST ==> 3 'X'
T_TEST ==> 4 ' ' (Space or blank)
T_TEST ==> 5 'X'
6. APPEND 'X' TO t_test.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 ' ' (Space or blank)
T_TEST ==> 3 'X'
T_TEST ==> 4 ' ' (Space or blank)
T_TEST ==> 5 'X'
T_TEST ==> 6 'X'
7. APPEND INITIAL LINE TO t_test.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 ' ' (Space or blank)
T_TEST ==> 3 'X'
T_TEST ==> 4 ' ' (Space or blank)
T_TEST ==> 5 'X'
T_TEST ==> 6 'X'
T_TEST ==> 7 ' ' (Space or blank)
8. APPEND 'X' TO t_test.
T_TEST ==> 1 ' ' (Space or blank)
T_TEST ==> 2 ' ' (Space or blank)
T_TEST ==> 3 'X'
T_TEST ==> 4 ' ' (Space or blank)
T_TEST ==> 5 'X'
T_TEST ==> 6 'X'
T_TEST ==> 7 ' ' (Space or blank)
T_TEST ==> 8 'X'
After Delete Adjacent duplicates, index with 2 & 6 will be removed
Regards,
Hardik Mehta