2007 Nov 02 9:13 AM
Hello All,
I have data in an internal table of the structure row, coloumn, value. i extracted it from an excel sheet. i have to move that data into another internal table of the structure itemcode, item description. the data in the excel sheet is as follows.
itemcode itemdescription
-
ABC itemABCdesc
DEF itemDEFdesc
GHI itemGHIdesc
JKL itemJKLdesc
MNO itemMNOdesc
can someone help me out??
regards,
Seenu
Hello All,
I have data in an internal table of the structure row, coloumn, value. i extracted it from an excel sheet. i have to move that data into another internal table of the structure itemcode, item description. the data in the excel sheet is as follows.
itemcode itemdescription
-
ABC itemABCdesc
DEF itemDEFdesc
GHI itemGHIdesc
JKL itemJKLdesc
MNO itemMNOdesc
can someone help me out??
regards,
Seenu
2007 Nov 02 9:16 AM
Hi,
Loop on first internal table and pass all the data to second internal table
n append it to second internal table.
Regards,
Prashant
2007 Nov 02 9:18 AM
Hi ,
Chk this code.
refresh it_excel.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_flname
i_begin_col = 2
i_begin_row = 3
i_end_col = 18
i_end_row = 9999
TABLES
intern = it_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 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.
Filling Data into Internal Tables IT_ITAB From Internal Table
it_excel.
CLEAR wa_itab.
LOOP AT it_excel INTO wa_excel.
case wa_excel-col .
when '1' .
wa_itab-mptyp = wa_excel-value.
when '2' .
MOVE wa_excel-value TO wa_itab-wstra.
when '3' .
wa_itab-pstxt = wa_excel-value.
when '4' .
wa_itab-tplnr = wa_excel-value.
when '5' .
wa_itab-equnr = wa_excel-value.
when '6' .
wa_itab-bautl = wa_excel-value.
when '7' .
wa_itab-iwerk = wa_excel-value.
when '8' .
wa_itab-wpgrp = wa_excel-value.
when '9' .
wa_itab-auart = wa_excel-value.
when '10' .
wa_itab-ilart = wa_excel-value.
when '11' .
wa_itab-gewerk = wa_excel-value.
when '12' .
wa_itab-wergw = wa_excel-value.
when '13' .
wa_itab-gsber = wa_excel-value.
when '14' .
wa_itab-plnty = wa_excel-value.
when '15' .
wa_itab-plnnr = wa_excel-value.
when '16' .
wa_itab-plnal = wa_excel-value.
when '17' .
wa_itab-priok = wa_excel-value.
endcase.
AT END OF row.
CONDENSE: wa_itab-mptyp , wa_itab-wstra,
wa_itab-pstxt , wa_itab-tplnr , wa_itab-equnr,
wa_itab-bautl , wa_itab-iwerk, wa_itab-wpgrp,
wa_itab-auart , wa_itab-ilart , wa_itab-gewerk,
wa_itab-wergw , wa_itab-gsber , wa_itab-plnty ,
wa_itab-plnnr , wa_itab-plnal , wa_itab-priok.
APPEND wa_itab TO it_itab.
CLEAR wa_itab.
ENDAT .
ENDLOOP.
Regards,
Shafi
2007 Nov 02 9:18 AM
Pass the values to another internal table based on offset of the first table. thats the only solution if the data in the first table is stored in fileds of type character.
i.e second_itb-item_code = first_itb_table+0( length ).
else , use move-corresponding if you have corresponding fields in first table.
Cheers
Phani.
2007 Nov 02 9:18 AM
Hi,
Loop at the itab from excel and move one field at a time
if you have header in excel sheet then discard the first row
LOOP AT i_col_row INTO wa_col_row.
v_value = wa_col_row-col.
CASE v_value.
WHEN 1.
wa_input-land1 = wa_col_row-value.
WHEN 2.
wa_input-mwskz = wa_col_row-value.
WHEN 3.
wa_input-txjcd = wa_col_row-value.
WHEN 4.
wa_input-text1 = wa_col_row-value.
WHEN 5.
wa_input-date = wa_col_row-value.
WHEN 6.
wa_input-s_per = wa_col_row-value.
WHEN 7.
wa_input-c_per = wa_col_row-value.
WHEN 8.
wa_input-ct_per = wa_col_row-value.
append wa_input to i_input
ENDCASE."CASE v_value.
endloop.
regards
Shiva
2007 Nov 02 9:19 AM
Could you be more clear..
ABC itemABCdesc means it is row number, value, col number, value????????
if yes.. then you can directly move the data into ITAB by looping at this internal able.
itab fields as COL1, COL2, COL3, COL4..
loop at ITAB.
itab1-item = itab-col2. (2nd filed value)
itab1-desc = itab-col4. (4th field value)
append itab1.
ENDLOOP.
But i think you are mssing some where...
2007 Nov 02 9:38 AM
Hello RamaJyothi,
ABC is the item code and itemABC descrition is the description of that particular item as given in the excel sheet.
the first internal table contains the data as follows
row-coloumn-value
1-1-ABC
1-2-itemABCdescription
2-1-DEF
2-2-itemDEFdescription
............
............
............
5-1-MNO
5-2-itemMNOdescription
now the data in the interal table of above format has to be brought to internal table with first coloumn as itemcode and second coloumn as item description. how can it be done
regards,
Seenu
2007 Nov 02 9:57 AM
2007 Nov 02 10:49 AM
Hi Seenu,
Try this
wa_tab = 2 columns table.
it_tab = 2 columns table.
lv_flag = 1.
Loop at it_tab into wa_tab.
if lv_flag = 1.
lv_code = column1.
lv_flag = 2.
else.
lv_desc = column1.
lv_flag = 1.
endif.
if lv_code is not initial and
lv_desc is not initial.
wa_tab-column1 = lv_code.
wa_tab-column2 = lv_desc.
append wa_tab to it_tab.
clear lv_code.
clear lv_desc.
endif.
endloop.
Hope this helps.
Benedict
2007 Nov 02 9:21 AM
Hi Seenu,
Try this.
Loop at it_tab into wa_tab.
Append wa_tab to it_tab2.
endloop.
Hope this helps.
Benedict
2007 Nov 02 9:32 AM
"If your data is already extracted into internal table use this code.
Loop AT itab1.
MOVE-CORRESPONDING itab1 to itab2.
APPEND itab2.
ENDLOOP.
"OR
"If you want extract data from Excel file use follwoing code...
TABLES : ztab.
DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF t_record ,
itemcode LIKE itab-value,
itemdesc LIKE itab-value,
END OF t_record.
DATA: BEGIN OF itb OCCURS 100,
itemcode LIKE ztab-itemcode,
kunnr LIKE ztab-itemdesc,
END OF itb.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
DATA: gd_currentrow TYPE i.
*Selection Screen Declaration
PARAMETER p_infile LIKE rlgrap-filename DEFAULT 'C:TEMPweek10.xls'.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_infile
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '2'
i_end_row = '28000'
TABLES
intern = itab
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE text-009 TYPE 'S'. "Problem uploading Excel Spreadsheet
EXIT.
ENDIF.
* Sort table by rows and colums
SORT itab BY row col.
** Get first row retrieved
READ TABLE itab INDEX 1.
*
** Set first row retrieved to current row
gd_currentrow = itab-row.
LOOP AT itab.
* Reset values for next row
IF itab-row NE gd_currentrow.
APPEND wa_record TO it_record.
CLEAR wa_record.
gd_currentrow = itab-row.
ENDIF.
CASE itab-col.
WHEN '0001'. "item code
wa_record-itemcode = itab-value.
WHEN '0002'. "item desc
wa_record-itemdesc = itab-value.
ENDCASE.
ENDLOOP.
APPEND wa_record TO it_record.
*Excel data is now contained within the internal table IT_RECORD
LOOP AT it_record INTO wa_record.
itb-itemcode = wa_record-itemcode.
itb-itemdesc = wa_record-itemdesc.
APPEND itb.
ENDLOOP.
Message was edited by:
Perez C
2007 Nov 02 9:32 AM
Hi,
If you want to move the data from one internal table to another.
1.First make sure that both the table have same structure .
2. Then, you can do the following.
itab2[] = itab1[].
3.Simply you are assinging the contents of itab1 to itab2.
But if the structure of both the table is different, the
1. loop itab1 into w_itab1.
w_ itab2-itemcode = w_itab1-itemcode.
w_itab2-itendesc = w_itab2-itemdesc.
append w_itab2 to itab2.
clear w_itab2.
endloop.
Regards,
Subha.
Regards,