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

insert initial line into itab

Former Member
0 Likes
7,617

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.

7 REPLIES 7
Read only

former_member189779
Active Contributor
0 Likes
3,019

Did you tried Debugging and see what happens?

Read only

0 Likes
3,019

Yes you can do debugging you can find the solutions for your question...

Thanks,

Raj

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,019

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.

Read only

vinoth_aruldass
Contributor
0 Likes
3,019

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.

Read only

Former Member
0 Likes
3,019

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
3,019

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


Read only

Former Member
0 Likes
3,019

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