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

counter value problem in internal table

Former Member
0 Likes
1,352

Hi experts,

Can some one help with small problem.

i need to count entries(no) and put into one varibale after deleting first 4 values from the itab.

LOOP AT ITAB.

COUNTER = COUNTER + 1.

IF COUNTER > 4.

EXIT.

ENDIF.

DELETE ITAB INDEX SY-TABIX.

ENDLOOP.

This is working fine up to deleting 4 values from itab.

after that i want to store the no enetries remaining in the itab into one variable.

How can we do it?

say itab having 40 entries after deleting first 4 i have to store 36 entries as a no into "one variable".

I used DESCRIBE TABLE itab LINES N.

but it is giving only "4".

why?

Thanks.

Sailu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,326

LOOP AT ITAB.

COUNTER = COUNTER + 1.

IF COUNTER <= 4.

DELETE ITAB .

ENDIF.

Append itab

ENDLOOP.

Hope this will solve ur problem...

11 REPLIES 11
Read only

Former Member
0 Likes
1,327

LOOP AT ITAB.

COUNTER = COUNTER + 1.

IF COUNTER <= 4.

DELETE ITAB .

ENDIF.

Append itab

ENDLOOP.

Hope this will solve ur problem...

Read only

0 Likes
1,326

Hi Try this.

Delete itab index 1.

Delete itab index 2.

Delete itab index 3.

Delete itab index 4.

Then try describe table itab lines lv_lin.

you will get the no of entries in lv_lin.

Regards,

Sharath

Read only

0 Likes
1,326

IN MY CODE I AM USING LIKE THAT

LOOP AT ITAB.

COUNTER = COUNTER + 1.

IF COUNTER > 4.

EXIT.

ENDIF.

DELETE ITAB INDEX SY-TABIX.

ENDLOOP.

DESCRIBE TABLE itab LINES N.

CONCATENATE text-001 g_text N text-002

INTO g_lang SEPARATED BY space.

But inconcatenate "N" is not alowing because n is DATA:N type I.

I want "N" value in my concatenate statement.

How we going to convert?

Thanks.

Read only

0 Likes
1,326

move it to a character variable.

DATA:
  w_lines   type i,
  w_char(2) type c.


DESCRIBE TABLE itab LINES w_lines.

w_char = w_lines.

Read only

0 Likes
1,326

you can move any type of variable to a character varaible and then use it in concatenate. You can do the same here as well by passing integer variable in a caharacter variable.

Read only

0 Likes
1,326

It is giving "char " value as a "*"(star) not exactly converting.

Read only

0 Likes
1,326

Solved one

Read only

0 Likes
1,326

increase the length of your character variable. means something like char(10) means your char variable should be of enough length to hold the integer value otherwise it will give *.

Read only

0 Likes
1,326

Hi,

It is because of the length in char field.Change the declaration according to the no. of lines.

DATA:

w_lines type i,

w_char(5) type c.

Read only

former_member242255
Active Contributor
0 Likes
1,326

it is working fine..


DATA : counter TYPE i,
     counter1 TYPE i.
DATA itab TYPE but000 OCCURS 0 WITH HEADER LINE.
SELECT * FROM but000 INTO TABLE itab UP TO 10 ROWS.
LOOP AT itab.
  counter = counter + 1.
  IF counter > 4.
    EXIT.
  ENDIF.
  DELETE itab INDEX sy-tabix.
ENDLOOP.


DESCRIBE TABLE itab LINES counter1.
WRITE / counter1.

Read only

Former Member
0 Likes
1,326

Hello,

Instead doing loop and all. Use delete statement using from and to.

DELETE ITAB FROM 1 to 4. See help for delete statements.

Try to debug the logic, you can know what exactly happening and you can fix it yourself.