2007 Sep 18 5:18 AM
HI EVERYBODY.
IAM FACING PROBLEMS WHILE UPLOADING MY EXCEL FLAT FILE TO INTERNAL TABLE.
MY REQUIREMENT IS TO UPLOAD ANY TYPE OF FLAT FILE (EITHER TXT OR XLS OR ANY FORMAT)
CAN ANYONE HELP IN THIS ASAP.
HI EVERYBODY.
IAM FACING PROBLEMS WHILE UPLOADING MY EXCEL FLAT FILE TO INTERNAL TABLE.
MY REQUIREMENT IS TO UPLOAD ANY TYPE OF FLAT FILE (EITHER TXT OR XLS OR ANY FORMAT)
CAN ANYONE HELP IN THIS ASAP.
2007 Sep 18 5:22 AM
You can use either GUI_UPLOAD or ALSM_EXCEL_TO_INTERNAL_TABLE functions to upload data to internal table.
See the sample code below
data : it_data type standard table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.
* Start of selection
start-of-selection.
* Upload data from Excel to internal table format
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_ifname
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65356
tables
intern = it_data
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.
* Delete the heading if exists
delete it_data where row = '001'.
* Append EXCEL Data into a internal table
loop at it_data into is_data.
at new row.
clear it_tab.
endat.
if is_data-col = '001'.
move is_data-value to it_tab-bukrs.
endif.
if is_data-col = '002'.
move is_data-value to it_tab-anln1.
endif.
if is_data-col = '003'.
move is_data-value to it_tab-anln2.
endif.
if is_data-col = '004'.
call function 'CONVERSION_EXIT_IDATE_INPUT'
exporting
input = is_data-value
importing
output = it_tab-leabg.
endif.
IF is_data-col = '005'.
CALL FUNCTION 'CONVERSION_EXIT_IDATE_INPUT'
EXPORTING
input = is_data-value
IMPORTING
output = it_tab-leabg.
ENDIF.
at end of row.
append it_tab.
clear it_tab.
endat.
clear : is_data.
endloop.Regards
Gopi
2007 Sep 18 5:25 AM
Hi Naveen
What 's your problem when you upload the file ?
you can upload any type of file by checking the type of file before you use function upload .Then you use 'if ' statement to choose the correct function for each type of flat file.
Find type of flat file.
1. find length of path of file .
2. search "." in your path file for position.
3. move the type of file to variable (type of flat file is follow "." )
after that
1.if x_type = 'txt'.
call ...
elesif x_type = 'xls'.
call ...
end if.
Regards
Wiboon
Regards
Wiboon
Message was edited by:
Wiboon Chaiyabutsakul
2007 Sep 18 5:42 AM
IS THERE ANY FUNCTION MODULE THAT UPLOADS ALL TYPES OF FILE????
2007 Sep 18 5:30 AM
*--
TYPES: BEGIN OF ts_data,
mandt TYPE mandt,
user_id TYPE user_id,
group TYPE zgroup,
END OF ts_data.
*--
SELECTION-SCREEN BEGIN OF BLOCK map WITH FRAME TITLE text-001.
PARAMETERS: pa_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK map.
*--
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file.
*Get the file path
PERFORM get_path.
*--
START-OF-SELECTION.
*Process the data
PERFORM process_data USING pa_file.
&----
*& Form get_path
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_path .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
file_name = pa_file.
ENDFORM. " get_path
&----
*& Form process_data
&----
text
----
-->P_PA_FILE text
----
FORM process_data USING p_pa_file.
DATA: lt_data TYPE TABLE OF ts_data WITH HEADER LINE,
ls_data TYPE ts_data.
DATA: xcel TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
REFRESH: xcel,lt_data.
*Get the records from EXCEL sheet to internal table.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = pa_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 200
i_end_row = 5000
TABLES
intern = xcel
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.
Fill the internal table with the values
LOOP AT xcel.
lt_data-mandt = sy-mandt.
CASE xcel-col.
WHEN '0001'.
lt_data-user_id = xcel-value.
WHEN '0002'.
lt_data-ah_group = xcel-value.
ENDCASE.
reward if useful
2007 Dec 20 6:18 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |