‎2008 Aug 19 5:38 AM
HI experts,
I have doubt in Internal Table.
Currently my internal table data in vertical format.
I need to convert that same data into horizontal format.
I have given a example of my problem.
itab1
abc 001 777
abd 002 888
abe 003 999
i need to change that internal table data into this format.
itab2
abc abd abe
001 002 003
777 888 999
Please guide me.
Thank you in advanced.
regards,
mrsara27...,.
‎2008 Aug 19 6:09 AM
Hi,
I hope this psudo code would help your cause.
Say internal table itab1 is the internal table with the contents which you want ot transpose into table itab2.
Here itab1 and itab2 are internal tables with header lines with 3 columns f1,f2 and f3 all of character type and of same length.
data: wa1 type itab1,
wa2 type itab1,
wa3 type itab1.
data: i1 type i.
describe table itab1 to i1.
loop at itab1.
case sy-index.
when 1.
move-corresponding itab1 to wa1.
when 2.
move-corresponding itab1 to wa2.
when 2.
move-corresponding itab1 to wa3.
endcase.
d0 i1 times.
Read table itab2 with index sy-index.
if sy-subrc <> 0.
case sy-index.
when 1.
itab2-f1 = wa1-f1.
itab2-f2 = wa2-f1.
itab2-f3 = wa3-f1.
when 2.
itab2-f1 = wa1-f2.
itab2-f2 = wa2-f2.
itab2-f3 = wa3-f2.
when 3.
itab2-f1 = wa1-f3.
itab2-f2 = wa2-f3.
itab2-f3 = wa3-f3.
Modify itab2 with corresponding index.
-
Regards,
Ram.
‎2008 Aug 19 5:43 AM
hi,
You can display the data in the horizontal format but you cannot fill data inside an internal table in the format you have prescribed.
We should have only one type of data into one column and here each column of yours is having a different type of data.
That is not possible.
Regards
Sumit Agarwal
‎2008 Aug 19 5:48 AM
Hi saravannan .,
The requirement is Tricky ,
To get it done first the internal table Number of fileds should be equal to Number of Records Records .
and All Fields are of same Data type . By using RowID and ColumnID Variables u can Achive .
But in ABAP u dont get such Scinario where swaping of Rows and Columns .
thanks
Sreenivas Reddy
‎2008 Aug 19 5:53 AM
‎2008 Aug 19 6:06 AM
Hi...
You can use OOABAP to solve your problem... But Iam not sure about that mathos names...
I tried in normal ABAP, But it causes performance reduce...
data: begin of itab occurs 0,
f1(3), f2(3), f3(3),
end of itab.
itab-f1 = 'abc'.
itab-f2 = '001'.
itab-f3 = '777'.
append itab.
clear itab.
itab-f1 = 'abd'.
itab-f2 = '002'.
itab-f3 = '888'.
append itab.
clear itab.
itab-f1 = 'abe'.
itab-f2 = '003'.
itab-f3 = '999'.
append itab.
clear itab.
loop at itab.
write: itab-f1.
endloop.
skip 1.
loop at itab.
write: itab-f2.
endloop.
skip 1.
loop at itab.
write: itab-f3.
endloop.At last....Get back with your solution.....
Thanks,
Naveen.I
‎2008 Aug 19 6:09 AM
Hi,
I hope this psudo code would help your cause.
Say internal table itab1 is the internal table with the contents which you want ot transpose into table itab2.
Here itab1 and itab2 are internal tables with header lines with 3 columns f1,f2 and f3 all of character type and of same length.
data: wa1 type itab1,
wa2 type itab1,
wa3 type itab1.
data: i1 type i.
describe table itab1 to i1.
loop at itab1.
case sy-index.
when 1.
move-corresponding itab1 to wa1.
when 2.
move-corresponding itab1 to wa2.
when 2.
move-corresponding itab1 to wa3.
endcase.
d0 i1 times.
Read table itab2 with index sy-index.
if sy-subrc <> 0.
case sy-index.
when 1.
itab2-f1 = wa1-f1.
itab2-f2 = wa2-f1.
itab2-f3 = wa3-f1.
when 2.
itab2-f1 = wa1-f2.
itab2-f2 = wa2-f2.
itab2-f3 = wa3-f2.
when 3.
itab2-f1 = wa1-f3.
itab2-f2 = wa2-f3.
itab2-f3 = wa3-f3.
Modify itab2 with corresponding index.
-
Regards,
Ram.
‎2008 Aug 19 6:17 AM
You can go for CASE ENDCASE.
CASE field.
WHEN 1.
fill field1 of itab2.
WHEN 2.
fill field2 of itab2.
.
.
.
ENDCASE.
you can refer to the code below. I am transferring data from T_COSP to T_REPORT
LOOP AT t_cosp INTO fs_cosp.
IF fs_cosp-objnr CS fs_mat_quan-werks.
fs_report-twaer = fs_cosp-twaer.
CASE fs_cosp-kstar.
WHEN c_kstar0.
w_cost = fs_cosp-wkgtot / w_lfimg.
w_cost = w_cost + fs_report-thru.
fs_report-thru = w_cost.
CLEAR w_cost.
w_index = w_index + 1.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING thru.
WHEN c_kstar1.
w_cost = fs_cosp-wkgtot / w_lfimg.
w_cost = w_cost + fs_report-steam.
fs_report-steam = w_cost.
CLEAR w_cost.
w_index = w_index + 1.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING steam.
WHEN c_kstar3.
w_cost = fs_cosp-wkgtot / w_lfimg.
w_cost = w_cost + fs_report-demur.
fs_report-demur = w_cost.
CLEAR w_cost.
w_index = w_index + 1.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING demur.
WHEN c_kstar4.
w_cost = fs_cosp-wkgtot / w_lfimg.
w_cost = w_cost + fs_report-time.
fs_report-time = w_cost.
CLEAR w_cost.
w_index = w_index + 1.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING time.
WHEN c_kstar5.
w_cost = fs_cosp-wkgtot / w_lfimg.
w_cost = w_cost + fs_report-test.
fs_report-test = w_cost.
CLEAR w_cost.
w_index = w_index + 1.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING test.
WHEN c_kstar6.
w_cost = fs_cosp-wkgtot / w_lfimg.
w_cost = w_cost + fs_report-start.
fs_report-start = w_cost.
CLEAR w_cost.
w_index = w_index + 1.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING start.
ENDCASE. " CASE fs_cosp-kstar
AT END OF objnr.
* To modify the report table with obtained data
PERFORM modify_report_table.
EXIT.
ENDAT.
ENDIF. " IF fs_cosp-objnr CS...
ENDLOOP. " LOOP t_cosp
*---------------------------------------------------------------------*
* FORM MODIFY_REPORT_TABLE *
*---------------------------------------------------------------------*
* This subroutine modifies the report table with necessary data *
*---------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*---------------------------------------------------------------------*
FORM modify_report_table .
fs_report-total = fs_report-steam +
fs_report-demur +
fs_report-start +
fs_report-test +
fs_report-time +
fs_report-thru.
MODIFY t_report FROM fs_report
INDEX w_count
TRANSPORTING total
twaer.
DELETE t_cosp TO w_index.
CLEAR w_index.
ENDFORM. " MODIFY_REPORT_TABLE
Structures of T_COSP and T_REPORT
*"--------------------------------------------------------------------*
* Declaration of the structure for holding Cost Totals *
*"--------------------------------------------------------------------*
DATA:
BEGIN OF fs_cosp,
lednr TYPE cosp-lednr, " Ledger for Controlling
" objects
objnr TYPE cosp-objnr, " Object number
gjahr TYPE cosp-gjahr, " Fiscal year
wrttp TYPE cosp-wrttp, " Value type
versn TYPE cosp-versn, " Version
kstar TYPE cosp-kstar, " Cost element
hrkft TYPE cosp-hrkft, " CO key subnumber
vrgng TYPE cosp-vrgng, " CO Business Transaction
vbund TYPE cosp-vbund, " Company ID: Trading Partner
pargb TYPE cosp-pargb, " Trading Partner's
" Business Area
beknz TYPE cosp-beknz, " Debit/credit indicator
twaer TYPE cosp-twaer, " Transaction Currency
perbl TYPE cosp-perbl, " Period block
wkg001 TYPE cosp-wkg001, " Cost total for period 1
wkg002 TYPE cosp-wkg002, " Cost total for period 2
wkg003 TYPE cosp-wkg003, " Cost total for period 3
wkg004 TYPE cosp-wkg004, " Cost total for period 4
wkg005 TYPE cosp-wkg005, " Cost total for period 5
wkg006 TYPE cosp-wkg006, " Cost total for period 6
wkg007 TYPE cosp-wkg007, " Cost total for period 7
wkg008 TYPE cosp-wkg008, " Cost total for period 8
wkg009 TYPE cosp-wkg009, " Cost total for period 9
wkg010 TYPE cosp-wkg010, " Cost total for period 10
wkg011 TYPE cosp-wkg011, " Cost total for period 11
wkg012 TYPE cosp-wkg012, " Cost total for period 12
wkgtot TYPE cosp-wkg001, " Cost total for all periods
END OF fs_cosp.
*"--------------------------------------------------------------------*
* Declaration of the structure for holding Report output data *
*"--------------------------------------------------------------------*
DATA:
BEGIN OF fs_report,
werks TYPE lips-werks, " Plant number
name1 TYPE t001w-name1, " Plant name
steam TYPE cosp-wkg001, " Steaming expenses
demur TYPE cosp-wkg001, " Demurrage expenses
start TYPE cosp-wkg001, " 1 time startup expenses
test TYPE cosp-wkg001, " Testing expenses
time TYPE cosp-wkg001, " Over time expenses
thru TYPE cosp-wkg001, " Thru-put expenses
total TYPE cosp-wkg001, " Total expenses
twaer TYPE cosp-twaer, " Transaction Currency
lfimg TYPE lips-lfimg, " Actual delivered quantity
END OF fs_report.