Number of enrties in an Internal Table
Hi All,
We use describe table ITAB to find the number of lines in the internal table. Is there any other alternative?
Thanks,
Manjula.S
Hi,
loop at itab.
count = count + 1.
endloop.
write:/ count.
I think sy-tabix will also give you the value...
Regards,
deepthi.
Similar Messages
-
How to find the number of columns in an internal table DYNAMICALLY ?
Hi,
How to find the number of columns in an internal table DYNAMICALLY ?
Thanks and Regards,
saleem.Hi,
you can find the number of columns and their order using
the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif
now describe your fieldcat . and find no of columns.
and their order also..
regards
vijay -
How to find number of lines in an internal table
Dear all,
how to find number of records present in an internal table.DESCRIBE TABLE
Syntax
DESCRIBE TABLE itab [KIND knd] [LINES lin] [OCCURS n].
Extras:
1. ... KIND knd
2. ... LINES lin
3. ... OCCURS n
Effect
This statement determines some properties of the internal table itab and assigns them to the specified variables. The various additions enable you to determine the table type, the number of currently filled rows and the initial memory requirement.
In addition, the system fields sy-tfill and sy-tleng are filled with the current number of table rows and the length of a table row in bytes.
Notes
For detailed information about an internal table, you should use the methods of RTTS of the DESCRIBE TABLE statement.
Without the specification of an addition, the statement DESCRIBE TABLE only sets the system fields sy-tfill and sy-tleng.
Addition 1
... KIND knd
Effect
The table type of the internal table itab is determined and a corresponding one-digit identification is assigned to the data object knd. A character-type data type is expected for the data object. The identifications are "T" for standard tables, "S" for sorted tables and "H" for hashed tables. These values are also defined as constants sydes_kind-standard, sydes_kind-sorted, and sydes_kind-hashed in the type group SYDES.
Addition 2
... LINES lin
Effect
The current number of table rows of the internal table itab is determined and is assigned to the data object lin.The data type i is expected for the data object.
Note
As of release 6.10, the current number of rows of an internal table can also be determined using the in-built function lines.
Addition 3
... OCCURS n
Effect
The initial memory requirement defined during the creation of the internal table with the addition INITIAL SIZE or the obsolete addition OCCURS is determined and assigned to the data object n. The data type i is expected for the data object.
Example
Descending sorting of a generically typed internal table in a subprogram. Since sorted tables cannot be sorted in a descending order, the table type is checked to avoid an exception that cannot be handled.
TYPE-POOLS sydes.
FORM sort_descending CHANGING itab TYPE ANY TABLE.
DATA tabkind(1) TYPE c.
DESCRIBE TABLE itab KIND tabkind.
IF tabkind = sydes_kind-standard OR
tabkind = sydes_kind-hashed.
SORT itab DESCENDING.
ELSEIF tabkind = sydes_kind-sorted.
MESSAGE '...' TYPE 'E'.
ELSE.
MESSAGE '...' TYPE 'E'.
ENDIF.
ENDFORM.
DESCRIBE FIELD INTO
Note
This statement is for internal use only.
It cannot be used in application programs.
Syntax
DESCRIBE FIELD dobj INTO td.
Effect
All characteristics of the field f, its components , sub-components etc. are displayed in the field td (type description). td has to be of the type SYDES_DESC, defined in Type Group SYDES. Because of this, the type group SYDES must be integrated into the ABAP-program with a TYPE-POOLS statement .
The structure SYDES_DESC has two table-type components TYPES and NAMES:
In TYPES, the tree structure of the type belonging to f is displayed. The components of a node are stored in the table TYPES in a continuous manner. Beginning and end of the line area that represents the components are stored in TYPES-FROM and TYPES-TO. The reference to the superior node can be found in TYPES-BACK. If no superior resp. subordinate node exists, then this is marked by the value 0 (For the relevance of further components, refer to the following sections).
The names of components, types etc. are not stored directly in TYPES. Instead, the components TYPES-IDX_... hold an index in the name table NAMES. The value 0 indicates that there is no reference to the name table.
NAMES contains the possibly fragmented names in the component NAMES-NAME. If a name continues in the following line, this is indicated by an asterisk ('*') in the component NAMES-CONTINUE.
The type description table (TYPES) not only stores information about the tree structure but also further information about the type of f resp. its components. This includes especially all information that can be determined using the usual additions to DESCRIBE FIELD. In detail, TYPES contains the following columns:
IDX_NAME
Component Name
IDX_USER_TYPE
Name of a user-defined type, i.e., a type that was defined through its TYPES-statement. Derived types (... TYPE A-B) and structures from the ABAP-Dictionary are not considered to be user-defined types.
CONTEXT
For user-defined types only: The context, in which the type is defined. Possible values are defined in the constant SYDES_CONTEXT of the type group SYDES. Please only use these constants to carry out a comparison. In detail, we distinguish between the following type contexts:
SYDES_CONTEXT-PROGRAM: Program-global type
SYDES_CONTEXT-FORM : FORM-local type
SYDES_CONTEXT-FUNCTION: FUNCTION-local type
SYDES_CONTEXT-METHOD : METHOD-local type
IDX_CONTEXT_NAME
For user-defined types only:
With a local context: The name of the FORM or FUNCTION, whose type was defined. The name of the associated program is then the first entry in the name table.
With a global context: The name of the program in which the type was defined.
IDX_EDIT_MASK
Conversion routine from the ABAP-Dictionary, is in accordance with the addition EDIT MASK at simple DESCRIBE.
IDX_HELP_ID
Help-Id when referencing to fields from the ABAP-Dictionary
LENGTH
Internal length, corresponds to the addition LENGTH at simple DESCRIBE
OUTPUT_LENGTH
Output length, corresponds to the addition OUTPUT-LENGTH at simple DESCRIBE
DECIMALS
Number of decimal digits, corresponds to the addition DECIMALS at simple DESCRIBE
TYPE
ABAP-Type, corresponds to the addition TYPE at simple DESCRIBE
TABLE_KIND
A table type is stored here for the components which represent an internal table. The same values are returned as with the variant DESCRIBE TABLE itab KIND k. Components which do not represent a table get the return value set to SYDES_KIND-UNDEFINED (see type group SYDES).
Example
Example definition of the complex data type EMPLOYEE_STRUC:
PROGRAM DESCTEST.
TYPES: BEGIN OF name_struc,
first TYPE c LENGTH 20,
last TYPE c LENGTH 20,
END OF name_struc,
BEGIN OF absence_time_struc,
day TYPE d,
from TYPE t,
to TYPE t,
END OF absence_time_struc,
phone_number TYPE n LENGTH 20,
BEGIN OF employee_struc,
id LIKE sbook-customid,
name TYPE name_struc,
BEGIN OF address,
street TYPE c LENGTH 30,
zipcode TYPE n LENGTH 4,
place TYPE c LENGTH 30,
END OF address,
salary_per_month TYPE p LENGTH 10 DECIMALS 3,
absent TYPE STANDARD TABLE OF absence_time_struc
WITH NON-UNIQUE DEFAULT KEY,
phone TYPE STANDARD TABLE OF phone_number
WITH NON-UNIQUE DEFAULT KEY,
END OF employee_struc.
You can determine the structure of the type EMPLOYEE_STRUC by collecting the type group SYDES as follows:
TYPE-POOLS: sydes.
DATA: employee TYPE employee_struc,
td TYPE sydes_desc.
DESCRIBE FIELD employee INTO td.
The following table shows a few selected columns of the type description table TD-TYPES. For a better overview, the names of the columns IDX_NAME, IDX_UERR_TYPE and IDX_EDIT_MASK have been shortened:
|FROM| TO |BACK|NAME|UTYP|EMSK|TYPE
|--||||||--
1 | 2 | 7 | 0 | 0 | 2 | 0 | v
2 | 0 | 0 | 1 | 6 | 0 | 4 | N
3 | 8 | 9 | 1 | 7 | 5 | 0 | u
4 | 10 | 12 | 1 | 8 | 0 | 0 | u
5 | 0 | 0 | 1 | 9 | 0 | 0 | P
6 | 13 | 13 | 1 | 11 | 0 | 0 | h
7 | 17 | 17 | 1 | 12 | 0 | 0 | h
8 | 0 | 0 | 3 | 13 | 0 | 0 | C
9 | 0 | 0 | 3 | 14 | 0 | 0 | C
10 | 0 | 0 | 4 | 15 | 0 | 0 | C
11 | 0 | 0 | 4 | 16 | 0 | 0 | N
12 | 0 | 0 | 4 | 17 | 0 | 0 | C
13 | 14 | 16 | 6 | 0 | 18 | 0 | u
14 | 0 | 0 | 13 | 20 | 0 | 0 | D
15 | 0 | 0 | 13 | 21 | 0 | 0 | T
16 | 0 | 0 | 13 | 22 | 0 | 0 | T
17 | 0 | 0 | 7 | 0 | 0 | 0 | N
Please note that the entries in rows 6 and 7 represent internal tables (ABAP-Type h). There is always an entry for the corresponding row type (rows 13 and 17) to an internal table.
The indices in the rows 5 to 7 refer to entries in the name table TD-NAMES. If you look, e.g., at row 3, you find the corresponding component name in TD-NAMES from row 7 (NAME) onward and the corresponding user type from row 5 (NAME_STRUC) onward.
In the name table TD-NAMES you find the following entries. Note that the names SALARY_PER_MONTH and ABSENCE_TIME_STRUC are stored in two parts:
|CONTINUE|NAME |CONTINUE|NAME
|--| -||--
1 | |DESCTEST 12 | |PHONE
2 | |EMPLOYEE_STRUC 13 | |FIRST
3 | |SBOOK-CUSTOMID 14 | |LAST
4 | |==ALPHA 15 | |STREET
5 | |NAME_STRUC 16 | |ZIPCODE
6 | |ID 17 | |PLACE
7 | |NAME 18 | * |ABSENCE_TIME_ST
8 | |ADDRESS 19 | |RUC
9 | * |SALARY_PER_MONT 20 | |DAY
10 | |H 21 | |FROM
11 | |ABSENT 22 | |TO -
Spilt the number of records in a internal table
Hi all,
I have a requirement where i must spilt the number of records in my internal table itab .Say if i have 2000 records , i must spilt it taking the first 990 records and doing some posting using Bapi and again take the next 990 records and do the posting .Can some one help me out.
Good answers will be rewarded with points.Hi,
You can use these instructions using two internal tables, but please be aware to not forget any line.
REFRESH my_table2.
APPEND LINES OF my_table FROM 1 TO 990 TO my_table2.
CALL FUNCTION 'BAPI'....
(with my_table2)
REFRESH my_table2.
APPEND LINES OF my_table FROM 991 TO my_table2.
CALL FUNCTION 'BAPI'....
(with my_table2)
Regards,
Mathieu -
Count number of records in a internal table
hi
i want to count number of records in internal table
pls let me know how to count the number of records in a internal table.
regards
Arorahi
one way is
data field type i.
Decribe table itab lines field.
write: / field.
displays the no of records in tha internal table
or if u want to write logic.
data:
w_count type i.
loop at itab.
w_count = w_count + 1.
endloop.
write: / w_count.
displays the no of records.
reward points if useful. -
To count number of records in an internal table for a condition
Hello All,
I want to count number of records in an internal table for a condition.
For e.g. -- I have one internal table IT which having fields F1, F2, F3, F4, F5.
Now, I want number of records in itnternal table IT where F1 = 'ABC'.
Is it possible to do..?? If yes, then how.??
Thanks in advance...!!
Regards,
Poonam.Hi,
If you mean an internal table, there are a few ways to do this.
1 One would be to loop over the table with a WHERE clause and increment a counter.
data: lv_counter type i.
clear lv_counter.
loop at itab where fld1 = 'ABC'.
lv_counter = lv_counter + 1.
endloop.
lv_counter now has the number of rows per the condiction.
2 Well, you may want to try this as well, and compare to the LOOP way. Not sure what kind of overhead you may get doing this way. Here ITAB is our main internal table, and ITAB_TMP is a copy of it. Again I think there may be some overhead in doing the copy. Next, delete out all records which are the reverse of your condition. Then whatever is left is the rows that you want to count. Then simply do a LINES operator on the internal table, passing the number of lines to LV_COUNT.
data: itab type table of ttab.
data: itab_tmp type table of ttab.
itab_tmp[] = itab[].
delete table itab_tmp where fld1 'ABC'.
lv_count = lines( itab_tmp ).
Thanks & Regards,
ShreeMohan -
Max number of records in an internal table
Hi,
Can any one tell me what is the Max Number of records we can get into an internal table.
if you have any link of sap help on this please FWD.
thanks in Adv.
Regards,
Lakshmikanth.T.VHi lakshmikanth,
Internal Tables as Dynamic Data Objects
Internal tables are always completely specified regarding row type, key and access type. However, the number of lines is not fixed. Thus internal tables are dynamic data objects, since they can contain any number of lines of a particular type. The only restriction on the number of lines an internal table may contain are the limits of your system installation. The maximum memory that can be occupied by an internal table (including its internal administration) is 2 gigabytes. A more realistic figure is up to 500 megabytes. An additional restriction for hashed tables is that they may not contain more than 2 million entries. The line types of internal tables can be any ABAP data types - elementary, structured, or internal tables. The individual lines of an internal table are called table lines or table entries. Each component of a structured line is called a column in the internal table.
regards,
keerthi. -
How to extract cost centers and their number of appendant assets to internal table?
Hello,
my aim is to get an internal table with all my selected cost centers and the number of their appendant assets to pass this to a SmartForm.
The result would be something like:
cost center
number of assets
100000
65
100001
13
100002
105
100007
3
100008
57
What I did so far: I made up an SQL statement, which I tested in the transaction DBACOCKPIT (Performance -> Additional Functions -> SQL Command Editor), which works fine and gives me exactly what I need.
The SQL statement is (slightly simplified, and exemplarily only for costcenters 100000 and 100001):
select costcenter, count( assetnr ) as numberofassets from
( select anlz.kostlv as costcenter, anla.anln1 as assetnr, anla.deakt, anla.aktiv from anla
join anlz on anla.mandt = anlz.mandt and anla.bukrs = anlz.bukrs and anla.anln1 = anlz.anln1
where anlz.kostlv = '0000100000' or anlz.kostlv = '00000100001' )
group by costcenter
Now, I want this SQL statement to work in my ABAP code. To match the requirements of the ABAP Editor (SE80), I
- replaced all the point delimiters (.) by a tilde (~),
- removed all commas,
- added "into costcenter_assetcount" to store my result in an internal table.
So in my ABAP code the SQL looks like this (alias assetnr inb the first line is printed in red):
select costcenter count( assetnr ) as numberofassets from
( select anlz~kostlv as costcenter anla~anln1 as assetnr anla~deakt anla~aktiv from anla
join anlz
on anla~mandt = anlz~mandt
and anla~bukrs = anlz~bukrs
and anla~anln1 = anlz~anln1
where anlz~kostlv = '0000100000' or anlz~kostlv = '00000100001' )
into costcenter_assetcount
group by costcenter
Checking my code, ABAP Editor gives me a syntax error pointing to the SELECT of the subquery (it's in German, because this is my default language setting). After my first FROM, ABAP seems to expect a table name instead of a subquery.
Programm Z_FIAA_ASSETCOUNT @0A\QFehler@
"SELECT" ist im ABAP-Dictionary nicht als Tabelle, Projektions- oder
Datenbank-View deklariert.
Isn't it possible to use a SELECT subquery after my FROM in the ABAP Editor?
What would be the best practice to put the data in an internal table?
Looking forward to your comments!Hi,
I think, You make it to complicated, try this:
select anlz~kostlv as costcenter count( distinct anla~anln1 ) as numberofassets
from anla
join anlz
on anla~mandt = anlz~mandt
and anla~bukrs = anlz~bukrs
and anla~anln1 = anlz~anln1
where anlz~kostlv = '0000100000' or anlz~kostlv = '00000100001'
group by anlz~kostlv.
Jarek -
Number of entries in the internal table for perticular field value
hi All,
Is this possible to get the count of records from the internal table for a perticular field value.
currently my requirement is to get the entries from the internal table which does not have two records for perticular field value (say a = 123) whose status is active (say b = 'X').
also suggets should use LOOP or DELETE or DESCRIBE for a internal table to ful fill this requirement.
Thanks in advance.
PradeepTry like this..
Create another table itab2 with same structure as itab1 & move the contents of itab1 to itab2
ITAB2[] = ITAB1[].
Then delete entries from itab2
Delete itab2 whete a = '123' and b = 'X'
Then use Describe statement to get the no of entries
Describe table itab2 lines v_lines.
Hope this helps... -
Current row number in internal table
HI,
How to find current number of record in internal table which is being processed.
Srini.Hi Srinu,
Welcome to SDN...
The system field <b>SY-TABIX</b> will give the current number of record in an internal table.
If the internal table is iterated through LOOP...ENDLOOP then for each iteration the SY-TABIX will be incremented by one.
If the internal table is iterated through LOOP...ENDLOOP WHERE <COND> then for each iteration the SY-TABIX will hold the condition met record number.
READ TABLE ITAB WITH KEY F1=<VAL> . The SY-TABIX will hold the record number of success record.
Thanks,
Vinay -
Determine Number of rows in Internal Table
Hi,
I have defined my internal table as follows:
TYPES : BEGIN OF ABC_KEY,
FIELD1(2) TYPE C,
FIELD2(1) TYPE C,
FIELD3(8) TYPE N,
END OF ABC_KEY.
DATA: itab1 TYPE TABLE OF ABC_KEY
WITH KEY FIELD1,
wa_lines_1 LIKE LINE OF itab1.
How can I retrieve the number of rows in Internal Table?
Thanks.
Regards,
bw_newbieYou can define the number of rows of the internal table using the DESCRIBE itab command .
As the rest have already stated a sample code snippet .
For more info type in DESCRIBE in your prgram and click on (F1) by placing the cursor on DESCRIBE .
You will find more options as to how you can use the DESCRIBE command according to your requirement .
Thanks ,
Hari -
Display data to edit based on fields and its value defined in internal tabl
I need to display data in a internal table for editing in a screen.
you have a internal table with field name , data types and its value. I need to display data in a screen ( sceen painter not in a report) row by row in vrtical format.
The internal table's structure not fix. you can have any number of fields in the internal table.
Can you please send me code if it is available with you or send me any senario in SAP if any ...so that i can debug to extract the code..
have to display data vertically as below in editable format,
for example,
Airline
Flight Number
Flight date
Flight price
Airline Currency
Plane Type
Maximum capacity
Occupied econ.
Total
No of fields will change.
also F4 help needs to be attached with each field.
I think it can be done through step loop. can anybody give sample code or tell me where to find in SAP or somewhere else?
it will be great help to me..
SanjeevHi
just check out this program DEMO_DYNPRO_STEP_LOOP. -
Hi,
How to get number of fields in an internal table?
Please send a solution.
Thanks & Regards,
Vani.Hi,
you can find the number of columns and their order using
the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = sy-repid
I_INTERNAL_TABNAME = 'ITAB'
I_INCLNAME = sy-repid
changing
ct_fieldcat = IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif
now describe your fieldcat . and find no of columns.
and their order also..
Regards
vijay -
How to find number of fields in an internal table ?
my requirement is i have 20 internal tables and the data is being uploaded into an application server. so how to find no of fields in a particular internal tableconcatenate all the fields and move them to final internal table , call the function module "GET_COMPONENT_LIST" and pass the work area of the final internal table in the parameter fieldname
***For getting no of FIELDS in an internal table ********
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = syrepid
FIELDNAME = 't_payr'
TABLES
COMPONENTS = fieldlist.
describe table fieldlist lines pyr_no_fields.
********end of getting no of fields**********
TRANSFER wa_mat_out_head TO P_FNAME.
LOOP AT GT_PAYR.
MOVE: GT_payr-LIFNR TO T_payr-lifnr,
GT_payr-ZBUKR TO T_payr-zbukr,
GT_payr-LAUFD TO T_payr-LAUFD,
GT_payr-CHECT TO T_payr-CHECT,
GT_payr-RWBTR TO T_payr-RWBTR.
Concatenate T_payr-lifnr t_payr-zbukr T_payr-laufd T_payr-chect
T_payr-rwbtr into wa_mat_out-rec SEPARATED by ',' . -
Count the Records in an internal table without a loop.
How do i count the number of records in an internal table without using the loop statement.
The Describe statement give the total no. of records in the internal table.But i want the count of the key fields in the internal table
For eg
Row Field
1 A
2 A
3 A
4 B
5 B
6 C
Count of A = 3
Count of B = 2
Count of C = 1Dilip,
I think isn't posible. Only 3 ideas:
1ª, make other table "table2", similar to your actual table.
table2[] = yourtable[].
delete table2 where key <> 'A'.
describe table table2 lines contA.
But depending the amount of data, you may have problems in performance or memory consumption...
2ª, make other table, only with the keys fields and a count field,
data begin table2
key_field1,
cont type i.
end data.
when you append lines to yourdata, make a collect to this table:
table2-keys = yourtable-keys.
table2-cont = 1.
collect table2.
But only works if you can modify the program where data is appended, and you may be carefull when data is deleted :-(...
3ª if your data if filled in a select, you may fill the table2 of point 2ª, making a similar select but:
select keyfields count( * ) into table table2
from ...
where (the same you have to fill your original table...)
group by keys.
But you have the same problem is data is deleted later...
I hope that any of the three is useful for you...
Edited by: Diego Alvarez on Jan 5, 2010 5:09 PM
Maybe you are looking for
-
Changed Internal HD - Now Photoshop won't load: "Could not initialize.."
Hi All, I apologise for posting here.. I've been trawling the Adobe forums and none of the suggestions for this seem to work. I recently used Carbon Copy Cloner to take a copy of my 80gig HD and transfer it to my new 320gig HD (internal) that I have
-
So I was cleaning out my Computer, and deleted one of The 200mb lightroom catalog files, since it looked like i had a bunch of them there(not smart, i know). Now when I start up LR, it cant find the right one, I oped up a backup but that one doesnt h
-
RE: Forté 3.0.M Communication under HP11 &TCP_NODELAY
Hi Olivier, Good news for you. In Release 3.0.N Forte will allow users to configure TCP_NODELAY option for Forte sockets. Please see defect report 52766. Regards, Zenon Adamek Purolator -----Original Message----- From: Olivier Brousseau [SMTP:Olivier
-
IllegalMonitorStateException on some queries
Hi, Some SELECT statements in my java code consistently cause exceptions and Oracle core dumps. Here is one example: SELECT COUNT(H.harvest_id) FROM nm_harvest H , nm_messages M WHERE H.msg_uid=M.msg_uid AND M.user_id=1 AND H.harvest_type='foo' AND M
-
I have two iBook G4s both with OS 10.4.1. I'm having trouble getting one unit to auto link to my home network. What's strange is that networking preference selections under this unit are different than my other iBook that has the same OS. Under Netwo