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

Function "Lines(IT)" can pass value to internal table?

Former Member
0 Likes
42,032

Hi,

i wonder is it possible to pass value back to its internal table after using function lines?

All i know is that after using using lines, you have to pass value to integer variable.

The codes below is the example that my senior use to pass value back to its own:

g_kfgr_cnt     = LINES( g_kfgr_cnt ).

g_kfgr_act_cnt = g_kfgr_cnt.
g_kfgr_cnt     = g_kfgr_cnt + 1.


I do not know which exact table my senior used, but its purpose is to count the number of key figure.


1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
21,895

The only possible way this would be syntactically valid is if g_kfgr_cnt is defined:

DATA; g_kfgr_cnt TYPE i OCCURS 0.

I.e. an internal table of integers (or some other numeric type), with a header line. In this day and age, to use such a construct would imply that your senior is in fact a dinosaur, using ABAP techniques of over 15 years ago. And with terrible variable naming habits...

The equivalent in modern coding would be something like:

DATA bunch_of_integers TYPE STANDARD TABLE OF i WITH NON-UNIQUE KEY table_line.

DATA an_integer TYPE i.

an_integer = LINES( bunch_of_integers ).

DATA another_integer TYPE i.

another_integer = an_integer.

ADD 1 TO an_integer.

At no point is the table in the above example (or in your original) modified in any way.

So your questions doesn't really make any sense. Why not ask your senior?

Hi,

i wonder is it possible to pass value back to its internal table after using function lines?

All i know is that after using using lines, you have to pass value to integer variable.

The codes below is the example that my senior use to pass value back to its own:

g_kfgr_cnt     = LINES( g_kfgr_cnt ).

g_kfgr_act_cnt = g_kfgr_cnt.
g_kfgr_cnt     = g_kfgr_cnt + 1.


I do not know which exact table my senior used, but its purpose is to count the number of key figure.


14 REPLIES 14
Read only

0 Likes
21,895

Hi,

g_kfgr_cnt     = LINES( g_kfgr_cnt ).


g_kfgr_cnt  must be an internal table,  lines( arg ) returns the row count .

Read only

0 Likes
21,895

yes i know, but how can it return value to its own internal table. I understand if it returns to integer variable.

Read only

pavanm592
Contributor
0 Likes
21,895

Hi Vong,

LINES is used for getting the ROW count of any internal table as per your code g_kfgr_cnt is an internal table.

can you please post the types declarations of g_kfgr_cnt and g_kfgr_act_cnt .

Regards,

Pavan

Read only

Former Member
0 Likes
21,895

Hi,

The declaration is what is want to know because it's my senior code and i don have a complete code.
The statement is very strange for passing back to its own internal table. i ask because may be some of you experts understand and tell me how to declare it.

Read only

0 Likes
21,895

The only possible explanation that I can think of is that, g_kfgr_cnt is a Table of type integer with header line.


But it doesn't make much sense on how it is being used. We can deduce more is we could see more parts of the code.

Read only

matt
Active Contributor
0 Likes
21,896

The only possible way this would be syntactically valid is if g_kfgr_cnt is defined:

DATA; g_kfgr_cnt TYPE i OCCURS 0.

I.e. an internal table of integers (or some other numeric type), with a header line. In this day and age, to use such a construct would imply that your senior is in fact a dinosaur, using ABAP techniques of over 15 years ago. And with terrible variable naming habits...

The equivalent in modern coding would be something like:

DATA bunch_of_integers TYPE STANDARD TABLE OF i WITH NON-UNIQUE KEY table_line.

DATA an_integer TYPE i.

an_integer = LINES( bunch_of_integers ).

DATA another_integer TYPE i.

another_integer = an_integer.

ADD 1 TO an_integer.

At no point is the table in the above example (or in your original) modified in any way.

So your questions doesn't really make any sense. Why not ask your senior?

Read only

Former Member
0 Likes
21,895

He just wants me to understand the codes. It's just like an exercise for me to solve.

This statement is really confusing that's y m asking.

Thanks for all the answers, everyone.

Read only

Former Member
0 Likes
21,895

Hi,

It still gives error although i declare it DATA: g_kfgr_cnt TYPE I OCCURS 0.

Read only

Former Member
0 Likes
21,895

I guess the exercise was meant to teach you how to read keyword documentation.

Using forum to reach the answer kind of defeats the purpose.

How about this snippet?

DATA lt TYPE TABLE OF i WITH HEADER LINE.
APPEND 11 TO lt.
APPEND 22 TO lt.
lt = lines( lt ).
WRITE: / 'Total ', lt.
LOOP AT lt.
   WRITE: / 'Line' , sy-tabix, ': ',  lt.
ENDLOOP.

Read only

Former Member
0 Likes
21,895

To understand more i have to use the forum. Asking Qs and giving answer is one of the forum purposes.

The purpose of my senior is that i can find the answer and able to seek help for answers.

Read only

matt
Active Contributor
0 Likes
21,894

Yes, but this is quite basic stuff, so it's reasonable to expect you to be able to work it out. If he truly wants you to figure out how code works, why has he given you a sample of what is effectively very bad code?

Read only

Former Member
0 Likes
21,894

I am a newbie in sap that's why i need to try every thing to get answer. Anyhow, still thanks for answers and advice. I am really confused right now. What exactly he, my senior, want me to do.

Read only

Former Member
0 Likes
21,894

Actually, i have checked the document and i knew it would return integer, but The confusing part is that it returns value to it's own internal table.

Read only

matt
Active Contributor
0 Likes
21,894

The internal table is not updated in any way.