Sorting internal table with variable no of fields
Hi ,
I want to sort the internal table with variable no of fields . Every time the report is run the number of fields as well as the sequence by which the table has to be sorted changes . How to do this .
regards
Hi,
Please try this.
DATA: BEGIN OF ITAB OCCURS 0,
F1(4),
END OF ITAB.
DATA: BEGIN OF ITAB2 OCCURS 0,
F1(1),
F2(1),
F3(4),
END OF ITAB2.
ITAB-F1 = '01AC'.
APPEND ITAB.
ITAB-F1 = '02AB'.
APPEND ITAB.
ITAB-F1 = '01CD'.
APPEND ITAB.
ITAB-F1 = '02CA'.
APPEND ITAB.
LOOP AT ITAB.
ITAB2-F1 = ITAB-F1+2(1).
ITAB2-F2 = ITAB-F1+3(1).
ITAB2-F3 = ITAB-F1.
APPEND ITAB2.
ENDLOOP.
SORT ITAB2 BY F1 ASCENDING
F2 DESCENDING.
LOOP AT ITAB2.
WRITE: / ITAB2-F3.
ENDLOOP.
REWARD POINTS IF HELPFUL
Similar Messages
-
Internal table with variable no of columns
Hi All,
I have to create an internal table with some fixed columns and rest of the table should be dynamic. The total no of columns depends on a field of some other table. hence, the number of columns of the table are unknown. How to create such a table.
Thanks,
NehaExecute this program .. we will get a fair idea about how the dyanmic column are populated in the table. Based on that u can write ur sceond table with 92 columns
*& Report ZTEST009
REPORT ztest009 NO STANDARD PAGE HEADING LINE-SIZE 60 LINE-COUNT 2(1).
TYPE-POOLS : slis.
TYPES : BEGIN OF internal,
matnr(18),
werks(4),
qtyn(20),
desc(20) TYPE c,
qty TYPE i,
END OF internal.
DATA : it TYPE TABLE OF internal,
wa TYPE internal.
DATA : fieldcat TYPE lvc_t_fcat,
lcat TYPE lvc_s_fcat,
final_cat TYPE slis_t_fieldcat_alv,
fcat TYPE slis_fieldcat_alv,
top TYPE slis_t_listheader,
events TYPE slis_t_event,
layout TYPE slis_layout_alv.
DATA : newfield TYPE REF TO data,
newdata TYPE REF TO data.
FIELD-SYMBOLS : <fs1>,
<dynamic_value>,
<dynamic_cat> TYPE STANDARD TABLE.
START-OF-SELECTION.
PERFORM popudate.
PERFORM buildcat.
PERFORM loadata.
PERFORM events USING events.
PERFORM header USING top.
PERFORM layout.
END-OF-SELECTION.
PERFORM display.
*& Form popudate
text
--> p1 text
<-- p2 text
FORM popudate .
DEFINE popu.
wa-matnr = &1.
wa-werks = &2.
wa-qtyn = &3.
wa-desc = &4.
wa-qty = &5.
append wa to it.
clear wa.
END-OF-DEFINITION.
popu 'material1' 'pla1' 'QTY1' 'quantity1' 100.
popu 'material1' 'pla1' 'QTY2' 'quantity2' 200.
popu 'material1' 'pla1' 'QTY3' 'quantity3' 300.
popu 'material2' 'pla2' 'QTY1' 'quantity1' 400.
popu 'material2' 'pla2' 'QTY2' 'quantity2' 500.
popu 'material2' 'pla2' 'QTY3' 'quantity3' 600.
popu 'material3' 'pla3' 'QTY1' 'quantity1' 700.
popu 'material3' 'pla3' 'QTY2' 'quantity2' 400.
SORT it BY matnr.
ENDFORM. " popudate
*& Form buildcat
text
--> p1 text
<-- p2 text
FORM buildcat .
lcat-fieldname = 'MATNR'.
lcat-datatype = 'CHAR'.
lcat-seltext = 'Material'.
lcat-intlen = 18.
APPEND lcat TO fieldcat.
CLEAR lcat.
lcat-fieldname = 'WERKS'.
lcat-datatype = 'CHAR'.
lcat-seltext = 'Plant'.
lcat-intlen = 4.
APPEND lcat TO fieldcat.
CLEAR lcat.
LOOP AT it INTO wa.
READ TABLE fieldcat INTO lcat WITH KEY fieldname = wa-qtyn.
IF sy-subrc <> 0.
lcat-fieldname = wa-qtyn.
lcat-datatype = 'CHAR'.
lcat-seltext = wa-desc.
lcat-intlen = 10.
APPEND lcat TO fieldcat.
CLEAR lcat.
ENDIF.
ENDLOOP.
CLEAR lcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
i_style_table =
it_fieldcatalog = fieldcat
i_length_in_byte =
IMPORTING
ep_table = newfield
e_style_fname =
EXCEPTIONS
generate_subpool_dir_full = 1
others = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ASSIGN newfield->* TO <dynamic_cat>.
CREATE DATA newdata LIKE LINE OF <dynamic_cat>.
ASSIGN newdata->* TO <dynamic_value>.
ENDFORM. " buildcat
*& Form loadata
text
--> p1 text
<-- p2 text
FORM loadata .
DATA flag TYPE i.
LOOP AT it INTO wa.
flag = 0.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <dynamic_value> TO <fs1>.
<fs1> = wa-matnr.
ASSIGN COMPONENT 'WERKS' OF STRUCTURE <dynamic_value> TO <fs1>.
<fs1> = wa-werks.
CALL FUNCTION 'AIPC_CONVERT_TO_UPPERCASE'
EXPORTING
i_input = wa-qtyn
i_langu = sy-langu
IMPORTING
e_output = wa-qtyn.
ASSIGN COMPONENT wa-qtyn OF STRUCTURE <dynamic_value> TO <fs1>.
<fs1> = wa-qty.
AT END OF matnr.
APPEND <dynamic_value> TO <dynamic_cat>.
CLEAR : <dynamic_value>.
ENDAT.
CLEAR : wa.
ENDLOOP.
ENDFORM. " loadata
**& Form display
text
--> p1 text
<-- p2 text
FORM display .
LOOP AT fieldcat INTO lcat.
fcat-fieldname = lcat-fieldname.
fcat-outputlen = lcat-intlen.
fcat-seltext_l = lcat-seltext.
APPEND fcat TO final_cat.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
is_layout = layout
it_fieldcat = final_cat
IT_SORT =
I_SAVE = ' '
IS_VARIANT =
it_events = events
TABLES
t_outtab = <dynamic_cat>
ENDFORM. " display
Regards,
Aswin. -
Sorting internal table with line types
Hi,
I have internal table juts for an example with four entries as below:
A[]
Line.....Line Types
444001.....P
New York...C
Evershine..B
Mary.......N
I want to sort the internal table with line types in order of lin types NBCP.
How can i do this ?
Please help.
Note: Above example is just with four entries, there might be internal table with ten entries and ten defined sorting order for line types.Hi Tushar,
Please note that we can't changes the mandatory sequence of the address format as defined in the country specif address format. We can change the sequence of others fields by line_priority.
Try to change the address type :
ADDRESS_TYPE - Address type (from 3.0C)
There are three types of address:
Address type '1': addresses of firms or organizations; the address structure which is used in most SAP applications as 'Address'.
Address type '2': address of a person
Address type '3': work address, usually the address of a contact person in a company
Please use T/code "OY01"> Select Country> Example :AU"--> Display --> Select address key and press F1. You will find SAP 's Address format configuration .
sap help:
Formatting Routine Key for Printing Addresses
For printing addresses, there are country-specific routines which in each case copy the correct postal formatting of the address.
The three-character "Address Layout Key" for the recipient country controls which of the routines available for formatting addresses in the relevant country is used.
These routines are programmed into the ADDRESS_INTO_PRINTFORM function module.
They are based on different national and international guidelines and norms, including:
ISO 11180,
contracts of the World Postal Union (Seoul 1994),
international address samples from the World Postal Union
as well as the available rules of the individual countries.
Below you will find an overview of the country-specific formats currently implemented.
Customers can program their own formatting routines using a customer exit. The SZAD0001 SAP enhancement has been defined in the package SZAD for this (-> transaction CMOD).
General formatting rules
The following parameters are used depending on the transaction:
whether the company address (street/house number) or the P.O. Box address is printed if both exist,
how many lines are available for printing,
which is the sender country.
If there are not enough lines, then lines are left out according to a standard sequence.
The address format depends on whether the sender country is the same as, or different from, the recipient country. The country is always specified from abroad, either as a text name, or as an identification code of up to three characters (license plate code or country key).
Where the country name is written out in full, it is written in the language of the sender country. If a language is not specified for the sender country, or the sender country itself is not specified, the logon language is used instead.
Exception: the language for the country code can be explicitly overwritten by a parameter in the print program (e.g. when the country code for customs transit papers is always to be specified in a particular language, such as English). if the "Print country name in recipient language" flag is set in the print program, the recipient language is used.
Other language-dependent components such as the title and the word 'PO Box' are printed in the recipient language or the recipient country language. If this cannot be determined, the logon language is again used.
For all formats except Great Britain (006), Japan (013), and South Korea (017), the core of the address is formatted as follows (without empty lines, except for the compulsory empty line:)
title line (if applicable)
name block (differs depending on the address type, see below)
street address or PO Box
(compulsory empty line, if applicable)
city line with postal code
country code (if applicable)
The city line and the country name are always printed in upper case for foreign addresses (only for the complete address, not for short forms).
The name block generally consists of the following:
"Normal" addresses (address type SPACE and address type 1):
NAME1
NAME2
NAME3
NAME4
Personal addresses (address type 2):
Title of person and name of person
Business address with department and contact person (address type 3):
NAME1
NAME2
NAME3
NAME4
department
title of person and name of person
In addresses entered using Business Address Services (central address management) (see Release notes Central Address Management for Release 4.0 and Central Address Management for Release 4.5 ), the street address can comprise several lines (see Print street address), otherwise street and house number are maintained in the Street field.
Some countries do not have a compulsory empty line (see notes below). The city and district are printed in the city line, connected by a hyphen (exceptions: 004 USA, 006 Great Britain/Ireland, 013 Japan, 015 Germany, 017 South Korea, 019 Denmark), provided that the total length does not exceed 35 characters. If a different city is specified for the PO Box (PFORT), this is used in the PO Box address.
In all formats which use a country code (currently 001 European standard format 002 Italy, 011 Switzerland and 014 Austria ), the license plate code for that country is used. If this is not maintained, the country key in table T005 is used.
If the "Print country name in foreign addresses" flag is set for the sender country in table 005, the country code is not used; the country name is printed in the last line of the address.
Formats 004 (USA), 005 (Canada) and 008 (Singapore) contain a line ('F') for the function of the contact person in the company (if address type = '3'). This line comes immediately after the line 'N' (Name (and title) of the natural person).
In formats 002 (Italy), 004 (USA), 005 (Canada), 006 (Great Britain), 007 (Brazil) and Australia (009), the REGIO field (Region, State, Province, County) is formatted. For the USA, Canada, Brazil and Australia, the key from table T005S is used; for Great Britain the text name from table T005U.
In all countries for which no "Address structure key" is maintained, a standard format is used which corresponds to format "010".
Hope this may help you.
Lanka -
Differences between Internal table with Occurs 0 and Field-Groups?
Is there really any difference between just using an internal table with an OCCURS 0 statement-- which would write the entire table to paging space-- and using field-groups? How is Field-Groups is more effective than Internal tables with occurs 0 when it comes to performance?
Could anybody please give some information regarding above question?
Thanks,
Surya.hi,
occurs 0 means it wont create any extra memory. based on the records only the memory is allocated to internal tables at run time. but when an internal table is created it can hold data of type to which it is declared.
i.e data: itab like mara occurs 0 with header line.
can take data only from mara table
we can also do in another way as using types keyword we can declare a standard structure and create a internal table of that type. its also not that useful as we have to change the structure depending on changes for storing data.
for this purpose field symbols are used. field symbols can hold any data means that they can point to tables, fields, any standard or user-defined types. field symbols actually points to respective types by which we can directly access to that types using field symbols.
filed symbols works more faster than internal tables.
if helpful reward some points.
with regards,
Suresh.A -
Internal Table with variable field lengths
Hi Guys,
I have a requirement to populate an internal table whose structure is as follows.
Internal Table will have 5 lines.
Line1: 050 char
Line2: 100 char
Line3: 100 char
Line4: 100 char
Line5: 050 char.
I have all the required data with me. I just need to populate the table.
Reward points up for grabs
Regards,
SuhasHi,
Wher do you have the data?
You can define a work area and internal table of two rows..
wa-row1 = 'yourdata'
wa-row2 = 'your data'
append wa to itab.
wa-row1 = 'yourdata'
wa-row2 = 'your data'
append wa to itab.
wa-row1 = 'yourdata'
wa-row2 = 'your data'
append wa to itab.
wa-row1 = 'yourdata'
wa-row2 = 'your data'
append wa to itab.
wa-row1 = 'yourdata'
wa-row2 = 'your data'
append wa to itab.
If you have your data in Db table then you need to write a select query..
select <fields,,,> from DBtable into tableITAb.
Be clear with your question we can help you...
rewads if useful,
regards,
nazeer -
Delete and internal table with not eqaul to fields
Hi I have an internal table I want delete few records with fields not equal to the variable v_lifnr, v_name1 and v_city,
structure of internal table has fields LIFNR, NAME1, CITY, TEXT1 and TEXT2.
I dont want to go by deletin in loop.Hi ,
i want to delete a internal table record based on the values which are NOT in the ranges ..
I am facing a syntax error with not operation in some system s
code looks like below !
i am not facing this problem when there in no not in ranges.
Thanks .
RANGES: RA_FFIDS FOR /VIRSA/ZFFUSERS-ZVIRFFID.
data : BEGIN OF IZVIRFFTRANSLOG OCCURS 0.
INCLUDE STRUCTURE /VIRSA/ZFFTNSLOG.
DATA: DESC LIKE RS38M-REPTI,
END OF IZVIRFFTRANSLOG.
data : IT_ZFlight_T LIKE IZVIRFFTRANSLOG OCCURS 0 WITH HEADER LINE.
IF NOT IT_ZFlight_T_TCODE[] IS INITIAL.
DELETE IT_ZFlight_T_TCODE WHERE ZVIRFFID NOT IN RA_FFIDS.
DELETE IT_ZFlight_T WHERE ZVIRFFID NOT IN RA_FFIDS.
ENDIF. -
Runtime error in Dynamic internal table with AMOUNT and Quantity Fields..
Dear friends,
I am attempting write a dymanic Select Statement (with joins).
And the sleect query looks like this..
SELECT (LT_SEL_LIST)
INTO CORRESPONDING FIELDS OF
TABLE <DYN_TABLE>
FROM (LT_FROM_LIST)
WHERE (LT_WHERE3).
Here the into table is a dynamically created internal table..
which is created by ...this
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_OUTPUT2[]
IMPORTING
EP_TABLE = DY_TABLE.
the it_output2 contains the the fieldcatlog information of dynamically given fields :-
like:-
TABNAME
FIELDNAME
DATATYPE
LENG
INTTYPE
ROLLNAME
DECIMALS
REFTABLE
REFFIELD
i mean the internal table is constructed with reference to all the bove metadata.
Problem:- This query run fine with all the fields Except AMOUNT AND QUANTITY fields....
When the selection list contain VBAK-NETWR or MSEG-MENGE..It throws a runtime error.
"The data read during a SLECT access couldnt be inserted into the target field,either conversion is not supported for
the target field's type or the target field is too short."
after this I even tried to construct the dynamic table with CFILEDNAME and QFIELDNAME in the Fieldcatalog.
so now my fieldcatlog looks like this:---
LOOP AT IT_DD03L..
IF IT_DD03L-DATATYPE = 'CURR'.
TABLEFIELD-CFIELDNAME = IT_DD03L-FIELDNAME .
ENDIF.
IF IT_FIELDCAT3-DATATYPE = 'QUAN'.
TABLEFIELD-QFIELDNAME = IT_DD03L-FIELDNAME .
ENDIF.
TABLEFIELD-TABNAME = IT_DD03L-TABNAME.
TABLEFIELD-FIELDNAME = IT_DD03L-FIELDNAME.
TABLEFIELD-DATATYPE = IT_DD03L-DATATYPE.
TABLEFIELD-INTLEN = IT_DD03L-LENG.
TABLEFIELD-INTTYPE = IT_DD03L-INTTYPE .
TABLEFIELD-ROLLNAME = IT_DD03L-ROLLNAME.
TABLEFIELD-DECIMALS = IT_DD03L-DECIMALS.
TABLEFIELD-REF_TABLE = IT_DD03L-REFTABLE.
TABLEFIELD-REF_FIELD = IT_DD03L-REFFIELD.
APPEND TABLEFIELD.
CLEAR TABLEFIELD.
ENDLOOP.
Note:- this is a test code so ignore performance issues...
Please help me with some code ...to avoid the Runtime erorr.
Thanks,
jeevan.Hi Jeevan,
Why are moving only few fields from DD03L table to your field catalog? Why don't you use move-corresponding? The following code works for me in ECC6.0.
data: it_dd03l type table of dd03l initial size 0,
ls_dd03l type dd03l,
lt_fldcat TYPE lvc_t_fcat,
ls_fldcat TYPE lvc_s_fcat,
ls_where(72) TYPE c,
lt_where LIKE TABLE OF ls_where,
lt_fld LIKE TABLE OF ls_where,
lt_data_dy TYPE REF TO data.
field-symbols: <ft_data> TYPE STANDARD TABLE.
select * into table it_dd03l from dd03l
where tabname = 'VBAK'
and ( fieldname = 'VBELN' or fieldname = 'NETWR' ).
check sy-subrc eq 0.
loop at it_dd03l into ls_dd03l.
move-corresponding ls_dd03l to ls_fldcat.
append ls_fldcat to lt_fldcat.
move ls_dd03l-fieldname to ls_where.
append ls_where to lt_fld.
if ls_dd03l-fieldname = 'VBELN'.
clear ls_where.
concatenate ls_dd03l-fieldname ' <> ''''' into ls_where.
append ls_where to lt_where.
endif.
endloop.
check not lt_fldcat is initial.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fldcat
IMPORTING
ep_table = lt_data_dy
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE no_configuration_data.
ENDIF.
ASSIGN lt_data_dy->* TO <ft_data>.
check sy-subrc eq 0.
select (lt_fld) from VBAK into corresponding fields of table
<ft_data>
where (lt_where).
Thanks
Bala -
Creating Dynamic Internal table with a dynamic name
Hi,
I want to create dynamic internal tables with dynamic names.
For example:
Suppose I have a table with three fields.
1. Structure name
2.Fields
3.file
And the structure of the internal table is as follows:
TYPES:BEGIN OF table_type,
struct TYPE char70,
fields TYPE tt_type OCCURS 0,
File TYPE ttab_type OCCURS 0,
END OF table_type.
Suppose I have one record inside my internal table with struct as "STRUCTURE", fields have an internal table content of set of fields and File has some set of records.
Now I want to create dynamic internal table whose name will be "STRUCTURE" , the fields of the dynamic internal table structure[] will be as in fields, and the records will be as in File.
Like this if i have 100 records in my internal table then I have to create 100 dynamic internal table dynamically.
Can anyone suggest how to do this?
Edited by: Jjammy on Jul 22, 2009 7:52 AMHi,
Check the sample program and develop your program accordingly.
<font color=blue><pre>
REPORT ztest_notepad.
*& Declarations
*Type-pools
TYPE-POOLS:
slis.
*Types
TYPES:
ty_fcat TYPE lvc_s_fcat,
ty_fcatalog TYPE slis_fieldcat_alv.
*Work areas
DATA:
wa_fcat TYPE ty_fcat,
wa_fcatalog TYPE ty_fcatalog.
*Internal tables
DATA:
it_fcat TYPE STANDARD TABLE OF ty_fcat,
it_fcatalog TYPE STANDARD TABLE OF ty_fcatalog.
*Type reference
DATA:
it_dyn_tab TYPE REF TO data,
wa_newline TYPE REF TO data.
*Filed symbols
FIELD-SYMBOLS:
<gt_table> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<l_field> TYPE ANY.
*Variables
DATA:
l_fieldname TYPE lvc_s_fcat-fieldname,
l_tabname TYPE lvc_s_fcat-tabname,
l_fieldtext TYPE lvc_s_fcat-seltext,
l_index TYPE char2.
"Selection-screen
PARAMETERS:
p_colms TYPE i.
*& start-of-selection.
START-OF-SELECTION.
PERFORM build_fieldcat.
PERFORM create_dynamic_table.
DO 20 TIMES.
DO p_colms TIMES.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
<l_field> = sy-index.
ENDDO.
INSERT <fs_dyntable> INTO TABLE <gt_table>.
ENDDO.
LOOP AT it_fcat INTO wa_fcat.
PERFORM fieldcatalog1 USING: wa_fcat-fieldname
wa_fcat-tabname
wa_fcat-seltext.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = 'ZTEST_NOTEPAD'
it_fieldcat = it_fcatalog
TABLES
t_outtab = <gt_table>.
*& Form BUILD_FIELDCAT
FORM build_fieldcat .
CLEAR: l_fieldname,
l_tabname,
l_fieldtext,
l_index.
DO p_colms TIMES.
CLEAR l_index.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
CONCATENATE 'Field' l_index INTO l_fieldtext.
l_tabname = '<GT_TABLE>'.
PERFORM fieldcatalog USING: l_fieldname
l_tabname
l_fieldtext.
ENDDO.
ENDFORM. " BUILD_FIELDCAT
*& Form CREATE_DYNAMIC_TABLE
FORM create_dynamic_table .
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_dyn_tab.
ASSIGN it_dyn_tab->* TO <gt_table>.
Create dynamic work area and assign to FS
CREATE DATA wa_newline LIKE LINE OF <gt_table>.
ASSIGN wa_newline->* TO <fs_dyntable>.
ENDFORM. " CREATE_DYNAMIC_TABLE
*& Form FIELDCATALOG
FORM fieldcatalog USING field table f_txt.
wa_fcat-fieldname = field.
wa_fcat-tabname = table.
wa_fcat-seltext = f_txt.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM. " FIELDCATALOG
*& Form FIELDCATALOG1
FORM fieldcatalog1 USING field table f_txt.
wa_fcatalog-fieldname = field.
wa_fcatalog-tabname = table.
wa_fcatalog-seltext_m = f_txt.
APPEND wa_fcatalog TO it_fcatalog.
CLEAR wa_fcatalog.
ENDFORM. " FIELDCATALOG1 </pre>
</font>
Thanks
Venkat.O -
Dynamic creation of table with variable field-names
HI
I am looking for a way in order to create a table during runtime. The problem is that the field names of the table are provided in another table.
TO illustrate the case at hand, an example:
The initial table contains the fields
UserID - attribut_name - attribute_value
Example Data
d00587 - first_name - Jon
d00587 - last_name - Smith
d00587 - age - 48
d00127 - first_name - Jack
d00127 - last_name - Daniels
d00127 - position - Manager
Now I need to create a table per User that looks as follows:
for user d00587
first_name - last_name - age
**Values
Jon - Smith - 48
for user d00127
first_name - last_name - positioin
Jack - Daniels - Manager
I split the initial table by sorting it according to userID and then looping into an itab with an AT END OF userid, thus I receive the table per user:
Example iTab
UserID - attribut_name - attribute_value
Example Data
d00587 - first_name - Jon
d00587 - last_name - Smith
d00587 - age - 48
However I have no clue on how to create a new internal table with field-names = attribute_name.
Does anybody have an idea or example code for this?
Thanks a lot for your help,
Kind regards,
MingoloHello Minima
Here is some sample coding:
DATA:
gt_fcat type lvc_t_fcat,
gdo_data TYPE REF TO data.
FIELD-SYMBOLS:
<gt_itab> TYPE table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'MARA'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
CHANGING
ct_fieldcat = gt_fcat
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.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
* I_STYLE_TABLE =
it_fieldcatalog = gt_fcat
IMPORTING
ep_table = gdo_data
* E_STYLE_FNAME =
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ASSIGN gdo_data->* TO <gt_itab>.
In your case, you would call the function module with your tables (D00587, D00127). Remove all fields from the fieldcatalog that you do not need before calling the static method.
Regards
Uwe -
How to read an internal table with more than one (2 or 3) key field(s).
how to read an internal table with more than one (2 or 3) key field(s). in ecc 6.0 version
hi ,
check this..
report.
tables: marc,mard.
data: begin of itab occurs 0,
matnr like marc-matnr,
werks like marc-werks,
pstat like marc-pstat,
end of itab.
data: begin of itab1 occurs 0,
matnr like mard-matnr,
werks like mard-werks,
lgort like mard-lgort,
end of itab1.
parameters:p_matnr like marc-matnr.
select matnr
werks
pstat
from marc
into table itab
where matnr = p_matnr.
sort itab by matnr werks.
select matnr
werks
lgort
from mard
into table itab1
for all entries in itab
where matnr = itab-matnr
and werks = itab-werks.
sort itab1 by matnr werks.
loop at itab.
read table itab1 with key matnr = itab-matnr
werks = itab-werks.
endloop.
regards,
venkat. -
How to find min and max of a field from sorted internal table
Hi,
I have sorted Internal Table by field f1.
How do I find max and min value of f1.
For min value of f1 I am using,
READ TABLE IT1 INDEX 1.
IT1-F1 = MIN.
Is this correct? And how do I find the max value of f1 from this table.
Thanks,
CDYes, that is right, and you can get the max like this.
data: lv_lines type i.
* get min
READ TABLE IT1 INDEX 1.
MIN = IT1-F1.
* get max
lv_lines = lines( it1 ).
read table it1 index lv_lines.
MAX = IT1-F1.
Regards,
Rich Heilman -
How to convert internal table with dynamic fields to XML
Dear all,
I met a problem like the following:
The aim is to transform the following parameter to XML
IT_FIELD stores the dynamic filed name of the internal table,with these fields, the dynamic internal can be created by cl_abap_tabledescr=>create(it_field)
IT_VALUE stores the value of the internal table dynamically created with dynamic fields.
For example
IT_FIELD =>
line1: FIELD1
line2: FIELD2
line3: FIELD3,
three lines in this internal table.
dynamically created internal table structure FIELD1 FIELD2 FIELD3
And IT_VALUE=>
1 2 3 (First line)
11 22 33
two lines of data.
Do you have any idea about how to transform the IT_VALUE to XML here? And also the transformed XML to the IT_VALUE.( we may need remember IT_FIELD here for later XML to IT_VALUE.)
Hope I describe the problem clearly.
Any inputs will be appreciated.
Edited by: Max Tang on Jan 12, 2009 3:46 PM
Edited by: Max Tang on Jan 12, 2009 4:14 PMHi,
you need to implement a bit of coding for that.
With the 'do varying' statement abap provides a loop over those fields. Within this loop you can build up a new internal table with one entry for each period and amount.
kind regards
Siggi
PS: I am not very familiar with CO, but I guess there will be a standard extractor for that. -
How to create an internal table with fields from different sources
Hi.
I need to create an internal table where some of the fields are from a database table, and the other fields are user specified. How do i do that?
Example:
DB table ZTAB with fields ZTAB-FIELD1, ZTAB-FIELD2.
I want to create an internal table ITAB with the fields ZTAB-FIELD1, ZTAB-FIELD2 from ZTAB. In addition, I also want to have one more field RECORD_NO, which is not from ZTAB. How do I do it? Could I do something like below?
DATA BEGIN OF ITAB.
INCLUDE STRUCTURE ZTAB.
DATA RECORD_NO TYPE I.
DATA END OF UPLINE.
Or, are there more efficient way of doing it? Thanks.hi KIan,
go:
general type
TYPE : BEGIN OF ty_itab,
field1 TYPE ztab-field1,
field2 TYPE ztab-field2,
*your own fields here:
field TYPE i,
field(30) TYPE c,
END OF ty_itab.
work area
DATA : gw_itab TYPE ty_itab.
internal table
DATA : gt_itab TYPE TABLE OF ty_itab.
hope this helps
ec -
Reg - Reading internal table with multiple record in a single field
Dear Guru's,
i want to read a internal table with field having mutilple entries like
read table READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
But it says comma without preceding colon (after READ?).
please guide me.....
thanks & Regards,
Balaji.Sya this is inside the loop.
plz check....
loop at lt_t2 into lt_t2_wa.
READ TABLE LT_T2 INTO LT_T2_WA WITH KEY HKONT IN ( '0001152430', '0001152930', '0001152410' ).
endloop.
thanks & Regards,
Balaji.S -
Diff Between Internal Table with Occurs 0 & Field Groups
Hi,
Is there really any difference between just using an internal table with an OCCURS 0 statement-- which would write the entire table to paging space-- and using field-groups? How is Field-Groups is more effective than Internal tables with occurs 0 when it comes to performance?
Could anybody please give some information regarding above question?
Thanks,
Mohan.hi,
occurs 0 means it wont create any extra memory. based on the records only the memory is allocated to internal tables at run time. but when an internal table is created it can hold data of type to which it is declared.
i.e data: itab like mara occurs 0 with header line.
can take data only from mara table
we can also do in another way as using types keyword we can declare a standard structure and create a internal table of that type. its also not that useful as we have to change the structure depending on changes for storing data.
for this purpose field symbols are used. field symbols can hold any data means that they can point to tables, fields, any standard or user-defined types. field symbols actually points to respective types by which we can directly access to that types using field symbols.
filed symbols works more faster than internal tables.
if helpful reward some points.
with regards,
Suresh.A
Maybe you are looking for
-
How to reduce the number of crossjoin in my webi query
All, I am running some publication base of a webi report notes that i have a profile for each of the recipient for example in the profile i have a detail objects with: recipient 1 can only see 901 recipient 2 can only see 902 In my publication I do t
-
XML Elements Handling in Incopy
Hi Experts, I'm trying to capture particular type of xml elements and process with that element's content. It's easy in Indesign. But In Incopy, If i use glue code functions, it's throwing error due to unavailability of 'xmlRuleProcessor' property in
-
Generating Envelopes in Report Builder
I am wanting to know if there is a wizard or someway to generate a Mailing Envelope report for Number 10 envelopes. I end up creating a landscape report on 8 1/2 x 11 paper with a top margin of 2.5 inches and a left margin of 1.625 inches. I have to
-
can any1 provide me the link to download SAP net weaver application server ABAP trial version which is compatible with Windows 8& 8.1,Plz ..
-
Why is my itunes shutting the song off after a few seconds?
iTunes will not play certain songs all the way through!!! Im about to push my computer off the desk!!! HELP!!!