Sort the internal table based on the vendor field
hello experts,
I am stuck with a small problem...
I am uploading the data for partner association for vendors through lsmw BI program.
I am collecting all the records in the end of trasaction and downloading all those records on to the apps server.
I declared one internal table as
TYPES: BEGIN OF type_erecord,
mesg(1000) TYPE c,
END OF type_erecord.
DATA: t_precord type standard table of type_erecord initial size 0,
w_precord type type_erecord.
I am concatenating all the fields and moving to the internal table..
concatenate zvendor_master-source zvendor_master-lifnr blf00-lifnr
zvendor_master-lname zvendor_master-parvw
zvendor_master-psource zvendor_master-pname
zvendor_master-lifn2 bwyt3-lifn2
zvendor_master-ekorg zvendor_master-werks
w_PLANT-muplant zvendor_master-defpa
v_message
into w_precord-mesg separated by c_pipe.
append w_precord to t_precord.
now at the end I have to sort this internal table t_precord based on blf00-lifnr
can any one guide me how to do it
Thanks for your anticipation
Nitesha
OK...
Than you can create one more table and do the process of sorting and than put data into the final table.
TYPES: BEGIN OF type_erecord,
mesg(1000) TYPE c,
END OF type_erecord.
DATA: t_precord type standard table of type_erecord initial size 0,
w_precord type type_erecord.
TYPES: BEGIN OF type_erecord_1,
mesg(1000) TYPE c,
lifnr type blf00-lifnr , "<<<
END OF type_erecord_1.
DATA: t_precord_1 type standard table of type_erecord initial size 0,
w_precord_1 type type_erecord.
I am concatenating all the fields and moving to the internal table..
concatenate zvendor_master-source zvendor_master-lifnr blf00-lifnr
zvendor_master-lname zvendor_master-parvw
zvendor_master-psource zvendor_master-pname
zvendor_master-lifn2 bwyt3-lifn2
zvendor_master-ekorg zvendor_master-werks
w_PLANT-muplant zvendor_master-defpa
v_message
into w_precord_1-mesg separated by c_pipe.
w_precord_1-lifnr = blf00-lifnr . " <<<
append w_precord_1 to t_precord_1. " <<<
SORT T_PRECORD_1 by LIFNR. " <<
LOOP AT T_PRECORD_1 into w_precord_1.
move-corresponing w_precord_1 to w_precord.
append w_precord to T_PRECORD.
clear w_precord .
endloop.
Regards,
Naimesh Patel
Similar Messages
-
Generating a internal table based on the fieldcatalog
hi,
i want to generate an internal table based on field catalog which will be generated after the user has selected a particular layout.
For eg. Suppose there are at present 25 fields at the ALV output and out of which user selects 10 fields using layout option and i save the layout.
Now i want an internal table with these 10 fields in my internal table not all the 25 fields.
any ideas?
regards
jignesh.Hi,
Look at the sample code below.
FIELD-SYMBOLS: <outtab> TYPE ANY TABLE,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
DATA: new_table TYPE REF TO data.
DATA: new_line TYPE REF TO data.
DATA: it_fieldcat TYPE lvc_t_fcat.
DATA: wa_fieldcat TYPE lvc_s_fcat.
DATA: BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
aenam TYPE aenam,
END OF itab.
"Fill the fieldcat here
"For example say it contains two fields MATNR AENAM
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <outtab>. "This is the required table
CREATE DATA new_line LIKE LINE OF <outtab>.
ASSIGN new_line->* TO <l_line> . "Work area forthe same
SELECT matnr aenam UP TO 5 ROWS
FROM mara
INTO TABLE itab.
LOOP AT itab.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = itab-matnr.
ASSIGN COMPONENT 'AENAM' OF STRUCTURE <l_line> TO <l_field>.
<l_field> = itab-aenam.
INSERT <l_line> INTO TABLE <outtab>.
ENDLOOP.
LOOP AT <outtab> ASSIGNING <l_line>.
WRITE: / <l_line>.
ENDLOOP.
Regards,
Manoj Kumar P -
Adding the field in the internal table based on another field
Hi all,
I am Creating a Function module with three fields (HKONT,EBELN,DMBTR) in the output internal table(ITAB)
My Requirement is that as soon as the value of the HKONT in the internal table changes, i need to sum the DMBTR field values and should pass into a variable(v_sum).
ON CHANGE OF seems to me Obsolete.
Please help me in doing this.
Thanks
AjayHI,
Use control break event . AT END OF.
loop at ITAB.
V_DMBTR = V_DMBTR + ITAB-DMBTR.
at end of HKONT.
v_sum = V_DMBTR.
clear : V_DMBTR.
endat.
endloop.
Regards,
Srini. -
How to sort an Internal table Based on a One Char Trans type in the rec?
Meaning, ascending descending will not work, lets say itab_A has the order O-H-W-G-I-A, and I want it to write it to itab_B to the correct order, G-H-O-I-A-W.
I know I can do loop at itab_A where for each one and write it, but is their a better way?
Thank-Youif you know the correct order play with index in the itab_A and append to itab_B
loop at itab_A index X.
blah.. blah..
endloop.
or
itab_temp [] = itab_A[].
delete itab_temp where index <> 'X'.
append itab_temp to itab_B.
refresh itab_temp[].
itab_temp [] = itab_A[].
delete itab_temp where index <> 'Y'.
append lines of itab_temp to itab_B.
refresh itab_temp[]. -
Summing the internal table values
Hi Experts,
I have requirement in report to add the values in the internal table based on document no.
for example
Document no date Amount Exchange Rate
190000012 05.04.2009 100 1
190000012 05.04.2009 200 1
190000012 05.04.2009 300 1
190000013 05.04.2009 100 1
190000013 05.04.2009 200 1
190000014 05.04.2009 100 1
If i use Collect or On change statements , the exchange rate is also adding
Document no date Amount Exchange Rate
190000012 05.04.2009 600 3
190000013 05.04.2009 300 2
190000014 05.04.2009 100 1
But i want to add only the amount field not the exchange rate .Please suggest me the best solutions.
I want to display as
Document no date Amount Exchange Rate
190000012 05.04.2009 600 1
190000013 05.04.2009 300 1
190000014 05.04.2009 100 1
Thanks in advance
satishhi,
check this
Sort itab by documentno.
Loop at itab1.
on change of itab1-dcno.
clear total.
move itab1-docno to itab2-docno.
itab2-total = itab-amont.
move itab1-total to itab2-total.
move itab1-date to itab2-date.
move itab1-rate to itab2-rate.
flag = ' '.
append itab2.
clear itab2.
else.
itab2-total = itab2-total + itab-amont.
endon
Endloop.
it will work for adjest append statement according to the out put .
~linganna -
Summarizing entries of the Internal table
Hi All Experts!!
I have problem regarding summarizing of the entries of the internal table.I want the amount field of the entries be summed based on 3 fields of table rkst skst rkstar.It means that summation be carried out if the set of these 3 fields are same.If there is different set new entry will be created.
Here I want to summarize itab gt_yrepost2.
LOOP AT gt_yrepost2 INTO gwa_yrepost2.
sum_amount = sum_amount + gwa_yrepost2-amount
be summed for repeating sets of 3 fields*****
lwa_sum_yrepost2-amount = sum_amount.
lwa_sum_yrepost2-kokrs = gwa_yrepost2-kokrs.
lwa_sum_yrepost2-belnr = gwa_yrepost2-belnr.
lwa_sum_yrepost2-buzei = gwa_yrepost2-buzei.
lwa_sum_yrepost2-kstar = gwa_yrepost2-kstar.
lwa_sum_yrepost2-bukrs = gwa_yrepost2-bukrs.
lwa_sum_yrepost2-pbukrs = gwa_yrepost2-pbukrs.
lwa_sum_yrepost2-tcurr = gwa_yrepost2-tcurr.
lwa_sum_yrepost2-skst = gwa_yrepost2-skst."field1
lwa_sum_yrepost2-rkst = gwa_yrepost2-rkst."field2
lwa_sum_yrepost2-rkstar = gwa_yrepost2-rkstar."field3
lwa_sum_yrepost2-txt = gwa_yrepost2-txt.
APPEND lwa_sum_yrepost2 TO gt_sum_yrepost2.
It means that if there is change in set of key fields new entry will be created. Else the entries will be summed to a single entry.In this example gt_sum_yrepost2 contained the summed(summarized) entries.
The positive thing here is that if for one set of these fields the other values will be same.Hence other fields will take value of any of the repeating entries(with repeated set).
Please help in this regards..
Thanks in Advance....
Prabhas.
Edited by: PRABHAS jha on Jan 25, 2008 4:34 PMHi Prabhas ,
You could use Collect statement instead of Append.
Thanks
Rekha -
Divide the internal table for months
How to divide the internal table itab for the months?
I have a field data in internal table itab and now i have need to divide itab in n table for months.
The data interval is max 4 months.
Sorry for my english.
ex. itab.
data: begin of itab occurs 0,
data LIKE vbak-erdat,
num_ord LIKE vbap-vbeln,
gruppo LIKE mara-labor,
end of itab.I have solved in this method:
SORT tab_gia DESCENDING BY data.
tmp_mese = tab_gia-data+4(2).
LOOP AT tab_gia.
IF tmp_mese EQ tab_gia-data+4(2).
IF flag1 = 'TRUE'.
MOVE tab_gia-data TO mese1-data.
MOVE tab_gia-gruppo TO mese1-gruppo.
MOVE tab_gia-tipo TO mese1-tipo.
MOVE tab_gia-matnr TO mese1-matnr.
MOVE tab_gia-giacenza TO mese1-giacenza.
APPEND mese1.
ENDIF.
IF flag2 EQ 'TRUE'.
MOVE tab_gia-data TO mese2-data.
MOVE tab_gia-gruppo TO mese2-gruppo.
MOVE tab_gia-tipo TO mese2-tipo.
MOVE tab_gia-matnr TO mese2-matnr.
MOVE tab_gia-giacenza TO mese2-giacenza.
APPEND mese2.
ENDIF.
IF flag3 EQ 'TRUE'.
MOVE tab_gia-data TO mese3-data.
MOVE tab_gia-gruppo TO mese3-gruppo.
MOVE tab_gia-tipo TO mese3-tipo.
MOVE tab_gia-matnr TO mese3-matnr.
MOVE tab_gia-giacenza TO mese3-giacenza.
APPEND mese3.
ENDIF.
IF flag4 EQ 'TRUE'.
MOVE tab_gia-data TO mese4-data.
MOVE tab_gia-gruppo TO mese4-gruppo.
MOVE tab_gia-tipo TO mese4-tipo.
MOVE tab_gia-matnr TO mese4-matnr.
MOVE tab_gia-giacenza TO mese4-giacenza.
APPEND mese4.
ENDIF.
ELSE.
* trovato un altro mese.
cnt = cnt + 1.
tmp_mese = tab_gia-data+4(2).
CASE cnt.
WHEN 2.
flag1 = 'FALSE'.
flag2 = 'TRUE'.
WHEN 3.
flag2 = 'FALSE'.
flag3 = 'TRUE'.
WHEN 4.
flag3 = 'FALSE'.
flag4 = 'TRUE'.
ENDCASE.
ENDIF.
ENDLOOP.
thanks!!!
Edited by: Alfonso Manzo on May 28, 2008 1:51 PM
Edited by: Alfonso Manzo on May 28, 2008 1:52 PM -
Difference betwen the internal tables
Hai friends,
Pls give me the types of internal tables and their differences .and its usage by example.
regrds,
Prashanth.Internal tables
Definition
Data structure that exists only at program runtime.
An internal table is one of two structured data types in ABAP. It can contain any number of identically structured rows, with or without a header line.
The header line is similar to a structure and serves as the work area of the internal table. The data type of individual rows can be either elementary or structured.
Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for storing and formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program.
Like all elements in the ABAP type concept, internal tables can exist both as data types and as data objects . A data type is the abstract description of an internal table, either in a program or centrally in the ABAP Dictionary, that you use to create a concrete data object. The data type is also an attribute of an existing data object.
Internal Tables as Data Types
Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type, key, and table type.
Line type
The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the structure is a column in the internal table. However, the line type may also be elementary or another internal table.
Key
The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.
If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves internal tables. If a table has an elementary line type, the default key is the entire line . The default key of an internal table whose line type is an internal table, the default key is empty.
The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.
Table type
The table type determines how ABAP will access individual table entries. Internal tables can be divided into three types:
Standard tables have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries.
Sorted tables are always saved sorted by the key. They also have an internal index. The system can access records either by using the table index or the key. The response time for key access is logarithmically proportional to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique or non-unique. When you define the table, you must specify whether the key is to be unique or not. Standard tables and sorted tables are known generically as index tables.
Hashed tables have no linear index. You can only access a hashed table using its key. The response time is independent of the number of table entries, and is constant, since the system access the table entries using a hash algorithm. The key of a hashed table must be unique. When you define the table, you must specify the key as UNIQUE.
Generic Internal Tables
Unlike other local data types in programs, you do not have to specify the data type of an internal table fully. Instead, you can specify a generic construction, that is, the key or key and line type of an internal table data type may remain unspecified. You can use generic internal tables to specify the types of field symbols and the interface parameters of procedures. You cannot use them to declare data objects.
Internal Tables as Dynamic Data Objects
Data objects that are defined either with the data type of an internal table, or directly as an internal table, are always fully defined in respect of their line type, key and access method. 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.
Choosing a Table Type
The table type (and particularly the access method) that you will use depends on how the typical internal table operations will be most frequently executed.
Standard tables
This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.
Sorted tables
This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.
Hashed tables
This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.
Special Features of Standard Tables
Unlike sorted tables, hashed tables, and key access to internal tables, which were only introduced in Release 4.0, standard tables already existed several releases previously. Defining a line type, table type, and tables without a header line have only been possible since Release 3.0. For this reason, there are certain features of standard tables that still exist for compatibility reasons.
Standard Tables Before Release 3.0
Before Release 3.0, internal tables all had header lines and a flat-structured line type. There were no independent table types. You could only create a table object using the OCCURS addition in the DATA statement, followed by a declaration of a flat structure:
DATA: BEGIN OF .
The effect of the OCCURS addition is to construct a standard table with the data type
They can also be replaced by the following statements:
Standard Tables From Release 4.0
When you create a standard table, you can use the following forms of the TYPES and DATA statements. The addition INITIAL SIZE is also possible in all of the statements. The addition WITH HEADER LINE is possible in the DATA statement.
Standard Table Types
Generic Standard Table Type:
TYPES TYPE|LIKE TABLE OF TYPE|LIKE TABLE OF
WITH TYPE|LIKE TABLE OF TYPE|LIKE TABLE OF TYPE|LIKE TABLE OF
WITH .
Here, the LIKE addition refers to an existing table object in the same program. The TYPE addition can refer to an internal type in the program declared using the TYPES statement, or a table type in the ABAP Dictionary.
You must ensure that you only refer to tables that are fully typed. Referring to generic table types (ANY TABLE, INDEX TABLE) or not specifying the key fully is not allowed (for exceptions, refer to Special Features of Standard Tables).
The optional addition WITH HEADER line declares an extra data object with the same name and line type as the internal table. This data object is known as the header line of the internal table. You use it as a work area when working with the internal table (see Using the Header Line as a Work Area). When you use internal tables with header lines, you must remember that the header line and the body of the table have the same name. If you have an internal table with header line and you want to address the body of the table, you must indicate this by placing brackets after the table name ([]). Otherwise, ABAP interprets the name as the name of the header line and not of the body of the table. You can avoid this potential confusion by using internal tables without header lines. In particular, internal tables nested in structures or other internal tables must not have a header line, since this can lead to ambiguous expressions.
TYPES VECTOR TYPE SORTED TABLE OF I WITH UNIQUE KEY TABLE LINE.
DATA: ITAB TYPE VECTOR,
JTAB LIKE ITAB WITH HEADER LINE.
MOVE ITAB TO JTAB. <- Syntax error!
MOVE ITAB TO JTAB[].
The table object ITAB is created with reference to the table type VECTOR. The table object JTAB has the same data type as ITAB. JTAB also has a header line. In the first MOVE statement, JTAB addresses the header line. Since this has the data type I, and the table type of ITAB cannot be converted into an elementary type, the MOVE statement causes a syntax error. The second MOVE statement is correct, since both operands are table objects.
Declaring New Internal Tables
You can use the DATA statement to construct new internal tables as well as using the LIKE or TYPE addition to refer to existing types or objects. The table type that you construct does not exist in its own right; instead, it is only an attribute of the table object. You can refer to it using the LIKE addition, but not using TYPE. The syntax for constructing a table object in the DATA statement is similar to that for defining a table type in the TYPES statement.
DATA ]
As when you define a table type, the type constructor
of an internal table as follows:
UNIQUE KEY belong to the key as long as they are not internal tables or references, and do not contain internal tables or references. Key fields can be nested structures. The substructures are expanded component by component when you access the table using the key. The system follows the sequence of the key fields.
UNIQUE KEY TABLE LINE
If a table has an elementary line type (C, D, F, I, N, P, T, X), you can define the entire line as the key. If you try this for a table whose line type is itself a table, a syntax error occurs. If a table has a structured line type, it is possible to specify the entire line as the key. However, you should remember that this is often not suitable.
UNIQUE DEFAULT KEY
This declares the fields of the default key as the key fields. If the table has a structured line type, the default key contains all non-numeric columns of the internal table that are not and do not contain references or internal tables. If the table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
Specifying a key is optional. If you do not specify a key, the system defines a table type with an arbitrary key. You can only use this to define the types of field symbols and the interface parameters of procedures. For exceptions, refer to Special Features of Standard Tables.
The optional additions UNIQUE or NON-UNIQUE determine whether the key is to be unique or non-unique, that is, whether the table can accept duplicate entries. If you do not specify UNIQUE or NON-UNIQUE for the key, the table type is generic in this respect. As such, it can only be used for specifying types. When you specify the table type simultaneously, you must note the following restrictions:
· You cannot use the UNIQUE addition for standard tables. The system always generates the NON-UNIQUE addition automatically.
· You must always specify the UNIQUE option when you create a hashed table.
Initial Memory Requirement
You can specify the initial amount of main memory assigned to an internal table object when you define the data type using the following addition:
INITIAL SIZE , the system calculates a new value so that n times the line width is around 12KB.
Examples
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
1. TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
The program defines a table type ITAB. It is a sorted table, with line type of the structure LINE and a unique key of the component COLUMN1.
2. TYPES VECTOR TYPE HASHED TABLE OF I WITH UNIQUE KEY TABLE LINE.
TYPES: BEGIN OF LINE,
COLUMN1 TYPE I,
COLUMN2 TYPE I,
COLUMN3 TYPE I,
END OF LINE.
TYPES ITAB TYPE SORTED TABLE OF LINE WITH UNIQUE KEY COLUMN1.
TYPES: BEGIN OF DEEPLINE,
FIELD TYPE C,
TABLE1 TYPE VECTOR,
TABLE2 TYPE ITAB,
END OF DEEPLINE.
TYPES DEEPTABLE TYPE STANDARD TABLE OF DEEPLINE
WITH DEFAULT KEY.
The program defines a table type VECTOR with type hashed table, the elementary line type I and a unique key of the entire table line. The second table type is the same as in the previous example. The structure DEEPLINE contains the internal table as a component. The table type DEEPTABLE has the line type DEEPLINE. Therefore, the elements of this internal table are themselves internal tables. The key is the default key - in this case the column FIELD. The key is non-unique, since the table is a standard table.
Specifying the Type of Formal Parameters
Formal parameters can have any valid ABAP data type. You can specify the type of a formal parameter, either generically or fully, using the TYPE or LIKE addition. If you specify a generic type, the type of the formal parameter is either partially specified or not specified at all. Any attributes that are not specified are inherited from the corresponding actual parameter when the subroutine is called. If you specify the type fully, all of the technical attributes of the formal parameter are defined with the subroutine definition.
The following remarks about specifying the types of parameters also apply to the parameters of other procedures (function modules and methods).
If you have specified the type of the formal parameters, the system checks that the corresponding actual parameters are compatible when the subroutine is called. For internal subroutines, the system checks this in the syntax check. For external subroutines, the check cannot occur until runtime.
By specifying the type, you ensure that a subroutine always works with the correct data type. Generic formal parameters allow a large degree of freedom when you call subroutines, since you can pass data of any type. This restricts accordingly the options for processing data in the subroutine, since the operations must be valid for all data types. For example, assigning one data object to another may not even be possible for all data types. If you specify the types of subroutine parameters, you can perform a much wider range of operations, since only the data appropriate to those operations can be passed in the call. If you want to process structured data objects component by component in a subroutine, you must specify the type of the parameter.
Specifying Generic Types
The following types allow you more freedom when using actual parameters. The actual parameter need only have the selection of attributes possessed by the formal parameter. The formal parameter adopts its remaining unnamed attributes from the actual parameter.
Check for actual parameters
No type specificationTYPE ANY The subroutine accepts actual parameters of any type. The formal parameter inherits all of the technical attributes of the actual parameter.
TYPE C, N, P, or X The subroutine only accepts actual parameters with the type C, N, P, or X. The formal parameter inherits the field length and DECIMALS specification (for type P) from the actual parameter.
TYPE TABLE The system checks whether the actual parameter is a standard internal table. This is a shortened form of TYPE STANDARD TABLE (see below).
TYPE ANY TABLE The system checks whether the actual parameter is an internal table. The formal parameter inherits all of the attributes (line type, table type, key) from the actual parameter.
TYPE INDEX TABLE The system checks whether the actual parameter is an index table (standard or sorted table). The formal parameter inherits all of the attributes (line type, table type, key) from the actual parameter.
TYPE STANDARD TABLE The system checks whether the actual parameter is a standard internal table. The formal parameter inherits all of the attributes (line type, key) from the actual parameter.
TYPE SORTED TABLE The system checks whether the actual parameter is a sorted table. The formal parameter inherits all of the attributes (line type, key) from the actual parameter.
TYPE HASHED TABLE The system checks whether the actual parameter is a hashed table. The formal parameter inherits all of the attributes (line type, key) from the actual parameter.
Note that formal parameters inherit the attributes of their corresponding actual parameters dynamically at runtime, and so they cannot be identified in the program code. For example, you cannot address an inherited table key statically in a subroutine, but you probably can dynamically.
TYPES: BEGIN OF LINE,
COL1,
COL2,
END OF LINE.
DATA: WA TYPE LINE,
ITAB TYPE HASHED TABLE OF LINE WITH UNIQUE KEY COL1,
KEY(4) VALUE 'COL1'.
WA-COL1 = 'X'. INSERT WA INTO TABLE ITAB.
WA-COL1 = 'Y'. INSERT WA INTO TABLE ITAB.
PERFORM DEMO USING ITAB.
FORM DEMO USING P TYPE ANY TABLE.
READ TABLE P WITH TABLE KEY (KEY) = 'X' INTO WA.
ENDFORM.
The table key is addressed dynamically in the subroutine. However, the static address
READ TABLE P WITH TABLE KEY COL1 = 'X' INTO WA.
is syntactically incorrect, since the formal parameter P does not adopt the key of table ITAB until runtime.
Assigning Internal Tables :
Like other data objects, you can use internal tables as operands in a MOVE statement
MOVE , including the data in any nested internal tables. The original contents of the target table are overwritten.
If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in an assignment, you must place two brackets () after the table name.
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c,
END OF line.
DATA: etab LIKE TABLE OF line WITH HEADER LINE,
ftab LIKE TABLE OF line.
line-col1 = 'A'. line-col2 = 'B'.
APPEND line TO etab.
MOVE etab[] TO ftab.
LOOP AT ftab INTO line.
WRITE: / line-col1, line-col2.
ENDLOOP.
The output is:
A B
The example creates two standard tables ETAB and FTAB with the line type of the structure LINE. ETAB has a header line. After filling ETAB line by line using the APPEND statement, its entire contents are assigned to FTAB. Note the brackets in the statement.
DATA: ftab TYPE SORTED TABLE OF f
WITH NON-UNIQUE KEY table_line,
itab TYPE HASHED TABLE OF i
WITH UNIQUE KEY table_line,
fl TYPE f.
DO 3 TIMES.
INSERT sy-index INTO TABLE itab.
ENDDO.
ftab = itab.
LOOP AT ftab INTO fl.
WRITE: / fl.
ENDLOOP.
The output is:
1.000000000000000E+00
2.000000000000000E+00
3.000000000000000E+00
FTAB is a sorted table with line type F and a non-unique key. ITAB is a hashed table with line type I and a unique key. The line types, and therefore the entire tables, are convertible. It is therefore possible to assign the contents of ITAB to FTAB. When you assign the unsorted table ITAB to the sorted table FTAB, the contents are automatically sorted by the key of FTAB.
In Unicode systems, the following conversion is not allowed:
DATA: BEGIN OF iline,
num TYPE i,
END OF iline,
BEGIN OF fline,
num TYPE f,
END OF fline,
itab LIKE TABLE OF iline,
ftab LIKE TABLE OF fline.
DO 3 TIMES.
iline-num = sy-index.
APPEND iline-num TO itab.
ENDDO.
ftab = itab.
loop AT ftab INTO fline.
WRITE: / fline-num.
ENDLOOP.
In a non-Unicode system, the output may look something like this:
6.03823403895813E-154
6.03969074613219E-154
6.04114745330626E-154
Here, the line types of the internal tables ITAB and FTAB are structures each with one component of type I or F. The line types are convertible, but not compatible. Therefore, when assigning ITAB to FTAB, the contents of Table ITAB are converted to type C fields and then written to FTAB. The system interprets the transferred data as type F fields, so that the results are meaningless. In Unicode systems, you are not allowed to convert numeric fields to fields of type C.
Initializing Internal Tables
Like all data objects, you can initialize internal tables with the
CLEAR .
statement. This statement restores an internal table to the state it was in immediately after you declared it. This means that the table contains no lines. However, the memory already occupied by the memory up until you cleared it remains allocated to the table.
If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets () after the table name.
CLEAR , LT, <).
If you are using internal tables with header lines, remember that the header line and the body of the table have the same name. If you want to address the body of the table in a comparison, you must place two brackets () after the table name.
The first criterion for comparing internal tables is the number of lines they contain. The more lines an internal table contains, the larger it is. If two internal tables contain the same number of lines, they are compared line by line, component by component. If components of the table lines are themselves internal tables, they are compared recursively. If you are testing internal tables for anything other than equality, the comparison stops when it reaches the first pair of components that are unequal, and returns the corresponding result.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA: ITAB LIKE TABLE OF LINE,
JTAB LIKE TABLE OF LINE.
DO 3 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.
MOVE ITAB TO JTAB.
LINE-COL1 = 10. LINE-COL2 = 20.
APPEND LINE TO ITAB.
IF ITAB GT JTAB.
WRITE / 'ITAB GT JTAB'.
ENDIF.
APPEND LINE TO JTAB.
IF ITAB EQ JTAB.
WRITE / 'ITAB EQ JTAB'.
ENDIF.
LINE-COL1 = 30. LINE-COL2 = 80.
APPEND LINE TO ITAB.
IF JTAB LE ITAB.
WRITE / 'JTAB LE ITAB'.
ENDIF.
LINE-COL1 = 50. LINE-COL2 = 60.
APPEND LINE TO JTAB.
IF ITAB NE JTAB.
WRITE / 'ITAB NE JTAB'.
ENDIF.
IF ITAB LT JTAB.
WRITE / 'ITAB LT JTAB'.
ENDIF.
The output is:
ITAB GT JTAB
ITAB EQ JTAB
JTAB LE ITAB
ITAB NE JTAB
ITAB LT JTAB
This example creates two standard tables, ITAB and JTAB. ITAB is filled with 3 lines and copied to JTAB. Then, another line is appended to ITAB and the first logical expression tests whether ITAB is greater than JTAB. After appending the same line to JTAB, the second logical expression tests whether both tables are equal. Then, another line is appended to ITAB and the third logical expressions tests whether JTAB is less than or equal to ITAB. Next, another line is appended to JTAB. Its contents are unequal to the contents of the last line of ITAB. The next logical expressions test whether ITAB is not equal to JTAB. The first table field whose contents are different in ITAB and JTAB is COL1 in the last line of the table: 30 in ITAB and 50 in JTAB. Therefore, in the last logical expression, ITAB is less than JTAB.
Sorting Internal Tables
You can sort a standard or hashed table in a program. To sort a table by its key, use the statement
SORT ASCENDING .
The statement sorts the internal table ASCENDING
BY ASCENDING
ASCENDING .
The table is now sorted by the specified components : T for standard table, S for sorted table, and H for hashed table.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1
INITIAL SIZE 10.
DATA: LIN TYPE I,
INI TYPE I,
KND TYPE C.
DESCRIBE TABLE ITAB LINES LIN OCCURS INI KIND KND.
WRITE: / LIN, INI, KND.
DO 1000 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
INSERT LINE INTO TABLE ITAB.
ENDDO.
DESCRIBE TABLE ITAB LINES LIN OCCURS INI KIND KND.
WRITE: / LIN, INI, KND.
The output is:
0 10 H
1,000 10 H
Here, a hashed table ITAB is created and filled. The DESCRIBE TABLE statement is processed before and after the table is filled. The current number of lines changes, but the number of initial lines cannot change.
INSERT LINE INTO TABLE ITAB.
LINE-TEXT = 'Moller'.
CONVERT TEXT LINE-TEXT INTO SORTABLE CODE LINE-XTEXT.
INSERT LINE INTO TABLE ITAB.
LINE-TEXT = 'Miller'.
CONVERT TEXT LINE-TEXT INTO SORTABLE CODE LINE-XTEXT.
INSERT LINE INTO TABLE ITAB.
SORT ITAB.
PERFORM LOOP_AT_ITAB.
SORT ITAB BY XTEXT.
PERFORM LOOP_AT_ITAB.
SORT ITAB AS TEXT.
PERFORM LOOP_AT_ITAB.
FORM LOOP_AT_ITAB.
LOOP AT ITAB INTO LINE.
WRITE / LINE-TEXT.
ENDLOOP.
SKIP.
ENDFORM.
This example demonstrates alphabetical sorting of character fields. The internal table ITAB contains a column with character fields and a column with corresponding binary codes that are alphabetically sortable. The binary codes are created with the CONVERT statement (see Converting to a Sortable Format). The table is sorted three times. First, it is sorted binarily by the TEXT field. Second, it is sorted binarily by the XTEXT field. Third, it is sorted alphabetically by the TEXT field. Since there is no directly corresponding case in English, we have taken the results from a German text environment:
Miller
Moller
Muller
Möller
Miller
Moller
Möller
Muller
Miller
Moller
Möller
Muller
After the first sorting, 'Möller' follows behind 'Muller' since the internal code for the letter 'ö' comes after the code for 'u'. The other two sorts are alphabetical
The binary sort by XTEXT has the same result as the alphabetical sorting by the field TEXT.
Regards,
Amit
Reward all helpful replies. -
Getting dynamically the internal table type
Hello all,
is there a standard function to get the internal table type name.like if a internal table is based on sflight,by using the function i pass the internal table and get the type sflight.
regards
kaushikfor this we have the CL_ABAP_TYPEDESCR class, subclasses and all of their methods.
Coding should look something like this:
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
<line> TYPE ANY.
DATA: lr_reference TYPE REF TO cl_abap_typedescr.
DATA: lr_tab TYPE REF TO cl_abap_tabledescr.
DATA: lr_data TYPE REF TO cl_abap_datadescr.
PARAMETERS: pa_tab TYPE tabname DEFAULT 'BUT000'.
CREATE DATA dref TYPE STANDARD TABLE OF (pa_tab).
ASSIGN dref->* TO <table>.
SELECT * FROM but000 INTO TABLE <table>
UP TO 10 ROWS.
CALL METHOD cl_abap_typedescr=>describe_by_data
EXPORTING
p_data = <table>
RECEIVING
p_descr_ref = lr_reference.
lr_tab ?= lr_reference.
lr_data = lr_tab->get_table_line_type( ).
WRITE lr_data->absolute_name.
Edited by: Micky Oestreich on Jan 19, 2009 8:09 AM
Edited by: Micky Oestreich on Jan 19, 2009 8:44 AM -
How to pass the internal table defined in program to ALV
Hi Friends,
I have a doubt regaring the ALV's,
How can we pass the internal table defined in the program to ALV by not filling the attribute (I_STRUCTURE_NAME) in the REUSE_ALV_LIST_DISPLAY.
I have tried many ways but unable to pass the structure of the internal table. I am getting the error message "Field Catalog Not Specified......" and its terminating and when i am giving the I_STRUCTURE_NAME = 'INTERNAL-TABLE-NAME' then its displaying a blank screen with all the tool-bars and icons...(No output of internal table data is seen on the screen) .
and when i am passing the DDIC table or structure ( for eg. LFA1) to I_STRUCTURE_NAME then its displaying with any error.
Plaese help in resolving this problem....
Regards
Pradeep GoliHi,
Check this thread which gives example of ALV. This will give you an idea.
Interactive ALV
ashish -
How to pass the internal table data to smartforms
Hi Gurus,
I have a problem in passing the internal table data to the smartforms. In the print program
I get the data into one internal table "LT_PRDLBL1". I am passing this internal table to the other in print program by calling the FM_NAME.
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = T_SSFCTRLOP
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
OUTPUT_OPTIONS = T_SSFCOMPOP
USER_SETTINGS = ' '
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO =
JOB_OUTPUT_OPTIONS =
TABLES
LT_PRDLBL = LT_PRDLBL1
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
In the print program I had defined the internal tables like
Data: lt_prdlbl type standard table of zprdlbl.
Data: Begin of lt_prdlbl1 occurs 0.
include structure zprdlbl.
Data: End of lt_prdlbl1.
How do I define the internal table in the smartform to get the values printed in the smartform?.
<REMOVED BY MODERATOR>
Thanks,
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 1:01 PMNehal,
Thanks for quick response.
In the smartform under the Form Interface->Tables tab
I had defined
LT_PRDLBL LIKE ZPRDLBL. If I define TYPE instead of LIKE I get the error message saying "FLAT TYPES may only be referenced using LIKE for table parameters".
In the main window I have created LOOP, in which I have ticked the internal table and
LT_PRDLBL INTO LT_PRDLBL. In the text node I am passing the values of this internal table
<_PRDLBL-XXXX&.
I am able to get the print but the data is not printing.
Please help me with this.
Thanks, -
Downloading the internal table with header to FTP folder
Hi All,
I have one requirement in downloading the internal table details with the fixed header line to FTP folder. The header line having the fixed text of 425 characters length.
Note: We are not suppose to use WS_DOWNLOAD and GUI_DOWNLOAD function modules.
Thanks in advance for your reply.
Regards
Kamini.Hi,
I can download the internal table details successfully to FTP folder using the FTP function modules like(FTP_CONNECT, FTP_COMMAND , FTP_R/3_TO_SERVER and FTP_DISCONNECT). Here my problem is I am unable to download the internation table with some header text.
You can see the format (example) of file to be download.
Here I can successfully download the below details without the header. But I am unable to download with header line. Could you please suggest me.
seq_no|record_action|trans_date|sku|description|
1|N|2008-01-03 07:52:31|TTASA5025CBO
2|N|2008-01-03 10:28:33|411014
3|N|2008-01-03 10:01:03|TTASA6030CBO
4|N|2008-01-03 10:01:15|TTASA6630CBO
5|N|2008-01-03 10:01:25|TTASA7035CBO
6|N|2008-01-08 16:57:39|TT6G
Regards
Kamini. -
To Find the type of field in the internal table.
I have internal table i_tab.
TYPES : BEGIN OF t_makt,
matnr TYPE matnr,
maktx TYPE maktx,
qty type mseg-menge,
show type char01,
END OF t_makt.
DATA : i_tab TYPE t_makt OCCURS 0 WITH HEADER LINE.
I want to know the type of the field of the i_tab at some stage in the program.
is there any piece of code or FM available to find the TYPE of the field of the internal table.Check out the following code
TYPES:
BEGIN OF my_struct,
comp_a type i,
comp_b type f,
END OF my_struct.
DATA:
my_data TYPE my_struct,
descr_ref TYPE ref to cl_abap_structdescr.
FIELD-SYMBOLS:
<comp_wa> TYPE abap_compdescr.
START-OF-SELECTION.
descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).
WRITE: / 'Typename :', descr_ref->absolute_name.
WRITE: / 'Kind :', descr_ref->type_kind.
WRITE: / 'Length :', descr_ref->length.
WRITE: / 'Decimals :', descr_ref->decimals.
WRITE: / 'Struct Kind :', descr_ref->struct_kind.
WRITE: / 'Components'.
WRITE: / 'Name Kind Length Decimals'.
LOOP AT descr_ref->components ASSIGNING <comp_wa>.
WRITE: / <comp_wa>-name, <comp_wa>-type_kind,
<comp_wa>-length, <comp_wa>-decimals.
ENDLOOP. -
Dynamic internal table ( make one internal table parts of the record )
hello i am doing a program that look for document billing put it in a internal table then loop the internal table and use the FM SD_DOCUMENT_FLOW_GET for get the document flow that fm return a table and i need make every record of that table part of the currect register , i already do this in a ugly static way but i am looking a dynamic way of do this , i know that the ABAP OO is the way but i am no able to get this approarch ( i am noob in abap and any experience with OO programing )
i will show the code for better understanding of it
pd: is a crappy code i know sorry
[CLick Here for the see the Code ( pastebin )|http://linuxlatino.pastebin.com/m39120e69]thanks all for the answer , but i will try explain better my problem :
i have a it_data interntal table with document bill record i do a loop to that table and used the vbeln field in the FM for get the docment flow of that document billing number now the output of the FM is a table and i need take each record of that table am make it part of the current record of it_Data.
Example:
it_Data without the it_docflow data
*Sales ORg* *Distri.Channel* *Billing Type* *Payer* *Sold-to-party* vbeln*
TP01 C1 ZT17 1000524 1000524 85003435 ..........
it_docflow table ( FM Output ):
*DOCNUM ITEMNU DOCNUV ITEMNU Description*
53107842 000000 000000 Standard Order
65004606 000000 53107842 000000 Outbound Delivery
75179356 000000 65004606 000000 Invoice
57000118 000000 75179356 000000 Returns
85003435 000000 57000118 000000 Credit for Returns
5200003681 000000 85003435 000000 Accounting Doc.
now the it_docflow data add in the it_data record:
53107842 Standard Order 65004606 Outbound Delivery 75179356 Invoice 57000118 Returns 85003435 Credit for Returns 5200003681 Accounting Doc TP01 C1 ZT17 1000524 1000524 85003435 .........
i hope this explain better my problem here , thanks again -
Function Module in VL10G containing the Internal Table with All SO & PO
Hi,
I have a situation where I need to get all the Sales Orders and POs for the given Shipping Point and Planned GI Date from my custom Report without writing SELECT queries. Now, can somebody give me a Function Module and the Internal Table Name where the actual data with Sales Orders and POs is stored?
Thanks,
Venkat.Hi,
I have a situation where I need to get all the Sales Orders and POs for the given Shipping Point and Planned GI Date from my custom Report without writing SELECT queries. Now, can somebody give me a Function Module and the Internal Table Name where the actual data with Sales Orders and POs is stored?
Thanks,
Venkat.
Maybe you are looking for
-
What the difference and use between of TABLES and SY-REPID?
Hi, Experts, I have came accross 2 cases that i can't able understand EX1: TABLES: VBAP - >( Here also Appplication Server(AS) creates Wrokarea of Structure VBAP but, by data: v_vbeln like vbap-vbeln. double clicking on variable v_vbeln AS taki
-
Populating the PO_REQUISITIONS_INTERFACE_ALL table
Hi all I am new to the technical side of Oracle. Which product would you advise as the best way to populate the PO_REQUISITIONS_INTERFACE_ALL table , so that we can import requistions from an external system into oracle. Thanks
-
Ease-in ease-out weirdness in motion tab FCP
I've been doing a lot of animating stills in FCP by keyframing SCALE and CENTRE in the MOTION TAB of the VIEWER. I discovered the EASE-IN and EASE-OUT options by control-clicking the end key frames, but when I play back the animated clip, it does the
-
Extracting long text of a message
Hi, I have a message in a message class with a long text.I want to extract this longtext in my program. Is there any method to access/extract lontext of a message of a mesasge class? i.e if i can give the message class and message id as input?
-
My iCal doesn't communicate with iCloud
I have a new MacBook Air with Lion (purchased last week). iCal does not synch with my iCloud calendar. Does anybody know how to fix this? Thanks, M.