Interchanging rows and colums of internal table
Hi all,
I have one requirement to interchange the rows and colums of 3X3 internal table.(internal table contains 3 rows and 3 columns ). In the new internal table, I have to display the rows as column values and column values as rows..
It's urgently. Kindly send me the sample code for the same.
Thanks in advance.
Ramesh.
Hi ramesh,
it is not possible to create a 'transponed' internal table if the (2) fields in your table arte or different type. Thus each row of the new table would be of different type.
The quick solution for display is
field-symbols:
<any> type any.
do.
loop at itab.
assign component sy-index of structure itab to <any>.
if sy-subrc <> 0.
* not assigned means no more components
exit.
endif.
write <any>.
endloop.
if sy-subrc = 0.
* start a new line for the next field
write /.
else.
* all done
exit.
endif.
enddo.
If you really want to store the values in transposes table, you could do so by storing their references in fields of type REF TO DATA because this is good for any data.
possible usage:
types:
ty_t_reftab type standard table of ref to data with default key,
ty_t_transposed type standard table of ty_t_reftab with default key.
data:
lt_transposed type ty_t_transposed,
lv_ref type ref to data.
field-symbols:
<any> type any,
<transposed> type line of ty_t_transposed
do.
loop at itab.
at first.
append initial line to lt_transposed assigning <transposed>.
endat.
assign component sy-index of structure itab to <any>.
if sy-subrc <> 0.
* not assigned means no more components
exit.
endif.
get refernce of <any> into lv_ref.
append lv_ref to <transposed>.
endloop.
if sy-subrc <> 0.
* all done
exit.
endif.
enddo.
read table
Sorry, don't know what it's good for. If you need the values, access them like
loop at lt_transposed assigning <transposed>.
loop at <transposed> assigning <any>.
write <any>->*. "Hope that works with WRITE
endloop.
endloop.
Regards,
Clemens
Similar Messages
-
Copy a certain row of data into the next row in a same internal table ??
HI, guys.
May i know how to copy a certain row of data into the next row in a same internal table ?? Bcz I plan to update a certain colum of data in the row just now into another value..
For example:-
*at first...
ebeln1 ebelp1 xblnr1
ebeln2 ebelp2 xblnr2
ebeln3 ebelp3 xblnr3
*after that, become...
ebeln1 ebelp1 xblnr1
ebeln2 ebelp2 xblnr2
ebeln2 ebelp2 xblnr4
ebeln2 ebelp2 xblnr5
ebeln3 ebelp3 xblnr3
Thanks in advance.hi,
If you have this kind of requirement then you must be having 2 internal tables ,one existing data and 2nd from which you have to insert the records into 1st table.
so in this case,
loop at itab1.
v_index = sy-tabix.
loop at itab2 into wa where pri_key = itab1-pri_key.
v_index = v_index + 1.
insert wa into itab index v_index.
endloop.
endloop.
Using this code ,your data records similar to your 1st tables primary key records will get inserted into table. -
How to send multiple row data into an internal table??
I have a view with table control.i want to select multiple row and send all the row data into an internal table.i am able to select multiple row but all the selected row data is not going to the internal table.....only a particular row data which is lead selected is going.
Do anyone can help me regarding this issue?
Thanks in advance,
Subhasis.Hey,
Some code example:
declaring an internal table and work area to get all the elements from the node.
data : lt_Elements type WDR_CONTEXT_ELEMENT_SET,
ls_Element type WDR_CONTEXT_ELEMENT_SET,
considering flights is my node.
lt_data type sflight.
Node_Flights is the ref of the node to which ur table is binded.
Use Code Inspector to read the node.
lt_Element = Node_Flights->GET_ELEMENTS
loop at lt_elements into ls_Element.
l_bollean = ls_elements->is_selected ( returns abap true/false ).
if l_bollean IS INITIAL.
append ls_Element to lt_data.
endif.
Hope this would help.
Cheers,
Ashish -
Diference between DATA: and TYPES: on internal tables
Hi people,
Can somebody help me. I wanna know whats the diference between DATA: and TYPES: on internal tables
and whitch has the best performance, here is a eg:
DATA: BEGIN OF ti_sbook occurs 0,
carrid LIKE sbook-carrid,
fldate LIKE sbook-fldate,
customid LIKE sbook-customid,
loccuram LIKE sbook-loccuram,
END OF ti_sbook.
AND
TYPES: BEGIN OF ti_sbook ,
carrid LIKE sbook-carrid,
fldate LIKE sbook-fldate,
customid LIKE sbook-customid,
loccuram LIKE sbook-loccuram,
END OF ti_sbook.
DATA: gw_sbook TYPE TABLE OF ti_sbook,
gs_sbook TYPE ti_sbook.
witch of both types is better?
thanks.Hi Marcelo,
For compatibility matters is better to create internal tables with a work area separately. So yes it's better to use types. When you work with Object Oriented coding you will need to use internal tables defined with types. Also when defining tables with types is the new way of coding, the another coding is getting obsolete defined by SAP. That's why when working in ABAP with OO (Object Oriented) code you'll have to define tables with types and not the other way.
Hope it helps.
Regards,
Gilberto Li -
CONVERT ROWS INTO COLUMNS IN INTERNAL TABLE
Hi Experts,
I want to convert rows into coloumns in final internal table.
How to do that one. Can any one help me its very urgent.
Regards,
PBS.hi,
Find the below code for changing rows into colums.
data: begin of itab1 occurs 0,
fld,
end of itab1.
data: begin of itab2 occurs 0,
fld1,
fld2,
fld3,
end of itab2.
itab1-fld = 1.
append itab1.
itab1-fld = 2.
append itab1.
itab1-fld = 3.
append itab1.
read table itab1 index 1.
if sy-subrc eq 0.
itab2-fld1 = itab1-fld.
endif.
read table itab1 index 2.
if sy-subrc eq 0.
itab2-fld2 = itab1-fld.
endif.
read table itab1 index 3.
if sy-subrc eq 0.
itab2-fld3 = itab1-fld.
endif.
append itab2.
loop at itab1.
write:/ itab1.
endloop.
loop at itab2.
write:/ itab2.
endloop.
refer the below link for further information
internal table rows to columns
in the final display list how can i change rows to columns and vice versa -
Adding Rows and Columns to a table depending requirements
Hi all,
I have created a table with one row and 2 columns of a table. My client requested adding form one to 3 columns of the right table and rows as well, depending business requirements.
I can add coding add columns on the right, but I cannot add rows because the columns dynamic.
I tried to write the coding for adding rows but it is not successful. Please help.
event : click - add colum button
for (var i = 0; i < form1.page1.Table1._Row1.count; i++){
var newrow = form1.page1.Table1.resolveNode("Row1[" + i + "]");
var newrow2 = form1.page1.Table1.resolveNode("HeaderRow[" + i + "]");
newrow._Col3D.addInstance(0);
newrow2._Col3D.addInstance(0);
i also published my file for your reviewing.
https://workspaces.acrobat.com/?d=xcgcfby89J-IHenn-8xeaQ
Thank you very much,
CindyWhen you are adding instances it uses the default properties of the object...
If its hidden as a default value in the form and you add an instance, the new instance will be hidden..
So if you have 3 columns in your default row and trying to add an instance withthe 5 columns it will only add a row with 3 columns..
If you want to add the columns to the table, you must add the column to each new row instance.
E.g.:
var intCount = xfa.resolveNode("page1.table1.Row1").instanceManager.count;
form1.page1.table1._Row1.addInstance(1);
xfa.resolveNode("page1.table1.Row1[" + intCount.toString() + "].Col3D").addInstance(1); -
How to convert rows to lines in internal table?
Hi Folks,
i have an internal table with some rows and would like to convert that table into another internal table with columns.
Let me give you an example:
it1:
a
b
c
d
it1 should be converted into table it2 and should look like this:
it2:
a b c d
The problem is that the entries in table it1 are not fixed, so that means that the number of lines is different depending on the query...
Has anyone an idea?
Thanks in advance,
Ralf
Edited by: Ralf Vath on Oct 17, 2008 11:01 AMhi i have an example in the alv ....that the rows are transported into columns...
REPORT Z_TRANSPOSEALV .* Type pools declaration for ALV
TYPE-POOLS: slis.*Declarations for ALV, dynamic table and col no for transpose
DATA: l_col TYPE sy-tabix,
l_structure TYPE REF TO data,
l_dyntable TYPE REF TO data,
wa_lvc_cat TYPE lvc_s_fcat,
lt_lvc_cat TYPE lvc_t_fcat,
lt_fieldcatalogue TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_layout TYPE slis_layout_alv.*Field symbols declarations
FIELD-SYMBOLS :
<header> TYPE ANY,
<dynheader> TYPE ANY,
<dyndata> TYPE ANY,
<ls_table> TYPE ANY,
<dynamictable> TYPE STANDARD TABLE,
<it_table> TYPE STANDARD TABLE.*Input the name of the table
PARAMETERS p_table TYPE dd02l-tabname OBLIGATORY.*Initialization event
INITIALIZATION.*Start of selection event
START-OF-SELECTION.* Create internal table of dynamic type
CREATE DATA l_dyntable TYPE STANDARD TABLE OF (p_table)
WITH NON-UNIQUE DEFAULT KEY.
ASSIGN l_dyntable->* TO <it_table>.*select statement to select data from the table as input into
*our dynamic internal table.
*Here i have restricted only till 5 rows.
*You can set a variable and give no of rows to be fetched
*The variable can be set in your select statement SELECT * INTO CORRESPONDING FIELDS OF TABLE <it_table>
FROM (p_table) up to 5 rows.*Fieldcatalogue definitions
wa_lvc_cat-fieldname = 'COLUMNTEXT'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND wa_lvc_cat TO lt_lvc_cat. wa_fieldcat-fieldname = 'COLUMNTEXT'.
wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
wa_fieldcat-key = 'X'..
APPEND wa_fieldcat TO lt_fieldcat. DESCRIBE TABLE <it_table>. DO sy-tfill TIMES.
For each line, a column 'VALUEx' is created in the fieldcatalog
Build Fieldcatalog
WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.
CONCATENATE 'VALUE' wa_lvc_cat-fieldname
INTO wa_lvc_cat-fieldname.
wa_lvc_cat-ref_field = 'VALUE'.
wa_lvc_cat-ref_table = 'LVC_S_DETA'.
APPEND wa_lvc_cat TO lt_lvc_cat.
Build Fieldcatalog
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = wa_lvc_cat-fieldname.
wa_fieldcat-ref_fieldname = 'VALUE'.
wa_fieldcat-ref_tabname = 'LVC_S_DETA'.
APPEND wa_fieldcat TO lt_fieldcat.
ENDDO.* Create dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_lvc_cat
IMPORTING
ep_table = l_dyntable. ASSIGN l_dyntable->* TO <dynamictable>.* Create structure as structure of the internal table
CREATE DATA l_structure LIKE LINE OF <dynamictable>.
ASSIGN l_structure->* TO <header>.* Create structure = structure of the internal table
CREATE DATA l_structure LIKE LINE OF <it_table>.
ASSIGN l_structure->* TO <ls_table>.* Create field catalog from our table structure
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = p_table
CHANGING
ct_fieldcat = lt_fieldcatalogue
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. DESCRIBE TABLE lt_fieldcatalogue.* Fill the internal to display <dynamictable>
DO sy-tfill TIMES.
IF sy-index = 1.
READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.
ENDIF.
For each field of it_table
ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.
IF sy-subrc NE 0. EXIT .ENDIF.
READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.
Fill 1st column
<dynheader> = wa_fieldcat-seltext_m.
IF <dynheader> IS INITIAL.
<dynheader> = wa_fieldcat-fieldname.
ENDIF.*Filling the other columns
LOOP AT <it_table> INTO <ls_table>.
l_col = sy-tabix + 1.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.
IF sy-subrc NE 0. EXIT .ENDIF.
ASSIGN COMPONENT l_col OF STRUCTURE <header> TO
<dynheader>.
IF sy-subrc NE 0. EXIT .ENDIF.
WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.
ENDLOOP.
APPEND <header> TO <dynamictable>.
ENDDO.*Layout for ALV output
lt_layout-zebra = 'X'.
lt_layout-no_colhead = 'X'..
lt_layout-colwidth_optimize ='X'.
lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.*ALV Grid output for display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = lt_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = <dynamictable>. -
How to ADD rows to a dynamic internal table??
My question is simple.
I have a dynamic internal table and I need to ADD rows to if.
I read this thread How to modify a dynamic internal table from dynamic work area but they are modifying existing data.
My internal table is EMPTY and I need to ADD new rows, so I can't use LOOP ASSIGNING.
How can I do that?
Any help is welcome!
Thanks!
BettinaHi,
try something similar.
FIELD-SYMBOLS: <fs> type any.
FIELD-SYMBOLS: <f1> type any.
ASSIGN INITIAL LINE TO lo_data ASSIGNING <fs>. " or <f_tab> - not sure w/o editor :-)
assigning component 1 of structure <fs> to <f1>.
<f1> = 'aaa'.
I write it from memory so there can be some syntax errors but focus to command APPEND INITIAL LINE ...
Regards,
Karol -
How to code header and items in internal table
Hi all,
Iam new to abap.
I have to write a report in internal table , for 1 header item related child items must exist,suppose if header is org then the child like branches in diff cities must be printed under that org and other org ther related branches etc.
can u tell me how i have to approach this with code.
Thanx.Hi MJN,
U can either declare one internal table to hold the header & item data or u can declare two separate interal tables for each one of it.
Suppose i take only one internal table.
First declare a structure with all the relevant fields of the ORG & Branches then create an internal table for it.
Code:
TYPES:
Begin of t_struct,
org_field1 type <datatype> or <dataobj>,
org_field2 type <datatype> or <dataobj>,
branch_field1 type <datatype> or <dataobj>,
branch_field2 type <datatype> or <dataobj>,
END of t_struct.
Data:
t_data like table of t_struct with header line.
select <fields declared in struct> from ORG Inner Join Branch ON <org_field> = <branch_field>
where <some condition> into table t_data.
if sy-subrc <> 0.
message 'No Records Found:" type 'E'.
endif.
endselect.
Loop at t_data into t_data.
at new <org_field1>
write: org_field.
endat.
write: branch_field1, branch_field2.
endloop.
This shall solve the issue.
Thanks
Ravi -
Regarding read and compare of internal table.
HI,
i want to read internal table based on key pernr.
suppose if we load the dec month data we want the last record of that month.
if we load march 2008 data we want todays record.
for this there are two fields datefrom and dateto.
how to compare thesse two fields in read statement.
regards,
swami.Hi,
Check this code
loop at itab.
endloop.
if month = december
read table itab with key sy-tabix = sy-dbcnt.
"above stmt will fetch the last record
elseif month = march
read table itab with key sy-tabix = 1.
"above stmt will fetch the first record.
endif.
Reward if helpful.
Regards. -
Performance Problems with "For all Entries" and a big internal table
We have big Performance Problems with following Statement:
SELECT * FROM zeedmt_zmon INTO TABLE gt_zmon_help
FOR ALL ENTRIES IN gt_zmon_help
WHERE
status = 'IAI200' AND
logdat IN gs_dat AND
ztrack = gt_zmon_help-ztrack.
In the internal table gt_zmon_help are over 1000000 entries.
Anyone an Idea how to improve the Performance?
Thank you!>
Matthias Weisensel wrote:
> We have big Performance Problems with following Statement:
>
>
SELECT * FROM zeedmt_zmon INTO TABLE gt_zmon_help
> FOR ALL ENTRIES IN gt_zmon_help
> WHERE
> status = 'IAI200' AND
> logdat IN gs_dat AND
> ztrack = gt_zmon_help-ztrack.
>
> In the internal table gt_zmon_help are over 1000000 entries.
> Anyone an Idea how to improve the Performance?
>
> Thank you!
You can't expect miracles. With over a million entries in your itab any select is going to take a bit of time. Do you really need all these records in the itab? How many records is the select bringing back? I'm assuming that you have got and are using indexes on your ZEEDMT_ZMON table.
In this situation, I'd first of all try to think of another way of running the query and restricting the amount of data, but if this were not possible I'd just run it in the background and accept that it is going to take a long time. -
How to export internal table and pass the internal table to another screen?
Hi,
I have a sql SELECT statement that select data from table into internal table. I would like to export out the internal table and pass to another screen and display the data in ALV list. How to export it out? I try but the error given was " The type of "OUT_SELECT_ITAB" cannot be converted to the type of "itab_result".
Another question is, how to pass the internal table that i export out from the function module to another screen?
Here is the code
==============================================================
FUNCTION ZNEW_SELECT_ZSTUD00.
""Local Interface:
*" IMPORTING
*" REFERENCE(IN_SELECT_YEAR) TYPE ZSTUD00-EYEAR
*" EXPORTING
*" REFERENCE(OUT_RESULT) TYPE CHAR9
*" REFERENCE(OUT_SELECT_ITAB) TYPE ZSTUD00
*& Global Declarations
DATA: itab TYPE ZSTUD00,
itab_result TYPE TABLE OF ZSTUD00.
*& Processing Blocks called by the Runtime Environment
itab-eyear = IN_SELECT_YEAR.
SELECT *
FROM ZSTUD00
INTO TABLE itab_result
WHERE eyear = IN_SELECT_YEAR.
IF sy-subrc = 0.
out_result = 'Success'.
OUT_SELECT_ITAB = itab_result.
ELSE.
out_result = 'Fail'.
ENDIF.
ENDFUNCTION.
===============================================================
Please advise. Thanks
Regards,
RaydenHi Nagaraj,
I try to change it in Tables tab page but it state that TABLES parameters are obsolete. when i "Enter". I try to "Enter" again. it seem to be ok but it stil give me the same error.
================================================================
FUNCTION ZNEW_SELECT_ZSTUD00.
""Local Interface:
*" IMPORTING
*" REFERENCE(IN_SELECT_YEAR) TYPE ZSTUD00-EYEAR
*" EXPORTING
*" REFERENCE(OUT_RESULT) TYPE CHAR9
*" TABLES
*" OUT_SELECT_ITAB STRUCTURE ZSTUD00
*& Global Declarations
DATA: itab TYPE ZSTUD00,
itab_result TYPE TABLE OF ZSTUD00.
*& Processing Blocks called by the Runtime Environment
itab-eyear = IN_SELECT_YEAR.
SELECT *
FROM ZSTUD00
INTO TABLE itab_result
WHERE eyear = IN_SELECT_YEAR.
IF sy-subrc = 0.
out_result = 'Success'.
OUT_SELECT_ITAB = itab_result.
ELSE.
out_result = 'Fail'.
ENDIF.
ENDFUNCTION.
===============================================================
regards,
Rayden -
Read Application server file and upload into internal table
Another help needed guys,
My file in the application server is of format
Name Marks 1 Marks 2 Marks 3............
A 10 15 20
The only thing separating the columns is space.
Actually this file was downloaded from an internal table into the app server.
Now I want to load it back into the internal table.
How do I load this into internal table so that each column goes in separate internal table field.
Currently am using cl_abap_char_utilities=>HORIZONTAL_TAB but I can get only the first column name in my field1 of the internal table.
How should I applroach this?
Points will be awarded for useful answers.
Regards
AnkitHi ankit,
i think u have uploaded the tab delimited file in the application sever.
then suppose see if u r file is in the format of name#marks1#marks2#marks3.
then in the program u do like this..
first declare one internal table with one filed.
data:
c_hextab(1) TYPE x VALUE '09'.
data:
begin of t_data occurs 0,
line(256) type c,
endof t_data.
and declare one more intternal table
data:
begin of t_itab occurs 0,
name(15) type c,
marks1(4) type c,
marks2(4) type c,
marks3(4) type c,
endof t_itab.
then
open the file with
OPEN DATASET p_file FOR INPUT IN TEXT MODE.
then between do and endo do like this..
DO.
clear t_data.
READ DATASET p_file INTO t_data.
if sy-subrc ne 0.
exit.
else.
split t_data at c_hextab
into t_itab-name
t_itab-marks1
t_itab-marks2
t_itab-marks3.
append t_itab.
endif.
enddo.
i think it will be helpful to u
Please let me know wht type of file has been uploaded into application server.(tab deleimted, comma separated or something else).
Regards,
Sunil Kumar Mutyala. -
Export and import the internal table
Hi,
Could you explain the total internal table data how we export and import please give me example.
Thanks,
HariHi,
Check this thread..
exporting internal table to memory variable -
A query with row and colum numbers?
Hello,
i have my java code divided into if conditions and in each if clause i need to select a certain field from a table. Is it somehow possible to select a table field which for example is in the third row and fifth column? So basically, how to select a certain matrix element?
Thank you:)
Edited by: user10956166 on Apr 5, 2009 6:09 AMHi,
Assuming you have a table called Distance:
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> DESCRIBE DISTANCE;
Name Type Nullable Default Comments
LINN VARCHAR2(30) Y
TALLINN NUMBER Y
TARTU NUMBER Y
P2RNU NUMBER Y
SQL> select * from distance;
LINN TALLINN TARTU P2RNU
TALLINN 0 186 128
TARTU 186 0 174
P2RNU 128 174 0
SQL>
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
2 v_sql VARCHAR2(4000);
3 v_column_name VARCHAR2(30):= 'TARTU';
4 v_to VARCHAR2(30):= 'P2RNU';
5 v_distance NUMBER;
6 BEGIN
7 v_sql := 'SELECT ' || v_column_name || ' FROM DISTANCE d WHERE d.LINN = ''' || v_to || '''';
8 EXECUTE IMMEDIATE v_sql
9 INTO v_distance;
10
11 dbms_output.put_line(v_distance);
12
13 EXCEPTION
14 WHEN OTHERS THEN
15 dbms_output.put_line(SQLERRM);
16 END;
17 /
174
PL/SQL procedure successfully completed
SQL> Regards,
Maybe you are looking for
-
Web service not working when called remotely
Hi there! I built a simple web service to generate a sequence number to be cosumed by PDF forms. It works perfecly when I run PDFs on my machine, using localhost, etc. Whem deployed on the client's servers it does not work. The only difference is the
-
Wiping the BB, few questions
when i back up all my files and then whipe the bb do i get to pick and choose what of the old stuff i want to restore? i am worried that by restoring will put the bad bug back in it, i want to completely whipe it then start over and redownload what i
-
My 8 month old son corroded my USB cable by chewing on the ipod connector. Not realizing this, I come in, plug in my ipod, and get an error that the USB cable is corrupted. I unplug ipod and look at the cable. The part that goes into the ipod is gree
-
Not able to join group calls on IOS
Whenever I join any group calls it either has no sound for a few seconds before hanging up, or continuously rings. My skype is updated to the latest version and so is my tablet, I've also tried reinstalling skype. Is there any way to fix this?
-
No Export Track as Audio File option
I have created a track in a project file that I want to place on my iPod. I select the track and choose File>Export> but the only option available is All Tracks as Audio Files. The Track as Audio File option is greyed out. When I choose All Tracks, I