‎2007 Jul 04 3:01 AM
hi friends....
could u plz tell me how can i upload datas from flat file to sap for the transaction MB1B....in this transaction docu date & posting dates are there so that i am asking hw can i take that dates in flat file...coud u explain me in details?????
thanks in advance
‎2007 Jul 04 3:07 AM
The below code is to upload data from an excel flat file into SAP. My requirement consists of 5 fields.
* Data declarations to download data from excel
data : it_data type standard table of alsmex_tabline initial size 0,
is_data type alsmex_tabline.
* Data declarations for downloaded data from excel in internal table for
* Floor Area
data : begin of it_tab occurs 0,
bukrs like anla-bukrs,
anln1 like anla-anln1,
anln2 like anla-anln2,
grufl like anla-grufl,
leabg type sy-datum,
end of it_tab.
selection-screen : begin of block b1 with frame title text-001.
parameters : p_ifname type rlgrap-filename obligatory.
selection-screen : end of block b1.
* At Selection Screen for Input File Name
at selection-screen on value-request for p_ifname.
* Making F4 enale at selection scree for input file location
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
importing
file_name = p_ifname.
* 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'.
move is_data-value to it_tab-grufl.
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 Jul 04 3:15 AM
In case the upload flat file is a TEXT File use the FM GUI_UPLOAD simply
Below is the code for that
* Types declaration for TY_DATATAB
TYPES : BEGIN OF ty_datatab,
matnr TYPE matnr,
stawn TYPE stawn,
END OF ty_datatab.
* Data declaration for TY_DATATAB
DATA : it_datatab TYPE STANDARD TABLE OF ty_datatab INITIAL SIZE 0,
is_datatab TYPE ty_datatab.
* Selection Screen fields
parameters : P_FILE like RLGRAP-FILENAME obligatory. " Data Set Name
* At selection-screen on value-request
at selection-screen on value-request for P_FILE.
call function 'F4_FILENAME'
exporting
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
importing
FILE_NAME = P_FILE.
work-h_filename = p_file.
* Call function to upload data from flat file to internal table
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = work-h_filename
filetype = c_asc
has_field_separator = c_x
IMPORTING
filelength = work-h_filelength
TABLES
data_tab = it_datatab
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Regards
Gopi