Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

uploading

Former Member
0 Likes
488

what are various methods of uploading flatfile into internal table

how do u upload a flat file which contains ',' (any thing other than tabspace)

as a delimiter

4 REPLIES 4
Read only

Former Member
0 Likes
463

what are various methods of uploading flatfile into internal table

By using GUI_UPLOAD Function module -> .txt file

By using ALSM_EXCEL_TO_INTERNAL_TABLE' Function moduel -> XLS File

You get data from file as separator ',' or '#' what ever.

Get the data from file to internal table as above said Function module.

now use split command -> it will remove the comma or # symbols and place into the other internal table

Syntax.

loop at i_file.

split i_file-data at ',' into i_data-data.

append i_data.

endloop.

Reward Points if helpful

Thanks

Seshu

Read only

Former Member
0 Likes
463

hi,

we can call few function module for uploading data from flat file to internal table by using ...

UPLOAD

WS_UPLOAD . these two Fm for 4.6c version.

GUI_UPLOAD , for 4.7 version .

call method cl_gui_frontend_services=>gui_upload , also for uploading data.

<b>UPLOAD</b>

call function 'UPLOAD'

exporting

  • CODEPAGE = ''

filename = ''

filetype = 'DAT'

item = 'Your File'

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • LINE_EXIT = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • SILENT = 'S'

  • IMPORTING

  • FILESIZE =

  • CANCEL =

  • ACT_FILENAME =

  • ACT_FILETYPE =

tables

data_tab = itab

exceptions

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

others = 7

<b>GUI_UPLOAD</b>

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = PATH

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

HEADER_LENGTH = 0

TABLES

DATA_TAB = ITAB

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.

<b>WS_UPLOAD</b>

The old code in 4.5B looks like this:

\* CALL FUNCTION 'WS_UPLOAD'

*\ EXPORTING

\ CODEPAGE = ' '

*\ FILENAME = PATH

*\ FILETYPE = 'DAT'

\ HEADLEN = ' '

\ LINE_EXIT = ' '

\ TRUNCLEN = ' '

\ USER_FORM = ' '

\ USER_PROG = ' '

\ IMPORTING

\ FILELENGTH =

*\ TABLES

*\ DATA_TAB = ITAB

*\ EXCEPTIONS

*\ CONVERSION_ERROR = 1

*\ FILE_OPEN_ERROR = 2

*\ FILE_READ_ERROR = 3

*\ INVALID_TABLE_WIDTH = 4

*\ INVALID_TYPE = 5

*\ NO_BATCH = 6

*\ UNKNOWN_ERROR = 7

*\ GUI_REFUSE_FILETRANSFER = 8

*\ OTHERS = 9.

<b>upload a flat file which contains ','</b>

for uploading this u follow these steps

call method cl_gui_frontend_services=>gui_upload

exporting

filename = ' ' "provide file name

file type = 'ASC' " dafault

has_field_separator = 'X' or ' , '

changing

data_tab = ' ' "interna table

i

regards,

Ashokreddy.

Read only

Former Member
0 Likes
463

hi,

we can use GUI_UPLOAD for flatfile.(WS_upload is obsolute)

using GUI_UPLOAD we can upload files of below types.

gui_uploade file types :

'ASC' :

ASCII format. The table is transferred as text. The conversion exits are carried out. The output format additionally depends on the parameters CODEPAGE, TRUNC_TRAILING_BLANKS, and TRUNC_TRAILING_BLANKS_EOL.

'IBM' :

ASCII format with IBM codepage conversion (DOS). This format corresponds to the 'ASC' format when using target codepage 1103. This codepage is often used for data exchange by disc.

'DAT' :

Column-by-column transfer. With this format, the data is transferred as with ASC text. However, no conversion exists are carried out and the columns are separated by tab characters. This format creates files that can be uploaded again with gui_upload or ws_upload.

'DBF' :

The data is downloaded in dBase format. Because in this format the file types of the individual columns are included, import problems, for example, into Microsoft Excel can be avoided, especially when interpreting numeric values.

'WK1' :

The data is downloaded in Lotus 1-2-3 format.

'BIN' :

Binary format. The data is transferred in binary format. There is no formatting and no codepage conversion. The data is interpreted row by row and not formatted in columns. Specify the length of the data in parameter BIN_FILESIZE. The table should consist of a column of type X, because especially in Unicode systems the conversion of structured data into binary data leads to errors.

MAnditory parameters:

FILENAME

FILETYPE

TABLES

DATA_TAB -internal table.

ex:

REPORT ZSR_BDC_SESSION.

DATA: BEGIN OF ITAB OCCURS 0,

LIFNR LIKE RF02K-LIFNR,

KTOKK LIKE RF02K-KTOKK,

NAME1 LIKE LFA1-NAME1,

SORTL LIKE LFA1-SORTL,

LAND1 LIKE LFA1-LAND1,

SPRAS LIKE LFA1-SPRAS,

END OF ITAB.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'z:\flatfiles\sr1.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = ITAB

  • 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.

For excel file:

we use FM

'ALSM_EXCEL_TO_INTERNAL_TABLE'.

ex:

REPORT ZSR_BDC_XL

NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES : LFA1,RF02K.

DATA : BEGIN OF ITAB OCCURS 0,

LIFNR LIKE RF02K-LIFNR,

KTOKK LIKE RF02K-KTOKK,

NAME1 LIKE LFA1-NAME1,

SORTL LIKE LFA1-SORTL,

LAND1 LIKE LFA1-LAND1,

SPRAS LIKE LFA1-SPRAS,

END OF ITAB.

DATA : ITAB1 LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

DATA : B1 TYPE I VALUE 1,

C1 TYPE I VALUE 1,

B2 TYPE I VALUE 10,

C2 TYPE I VALUE 99.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = 'C:\xl1.XLS'

I_BEGIN_COL = B1

I_BEGIN_ROW = C1

I_END_COL = B2

I_END_ROW = C2

TABLES

INTERN = ITAB1

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.

PERFORM ORGANIZE_UPLOADED_DATA.

FORM ORGANIZE_UPLOADED_DATA .

SORT ITAB1 BY ROW

COL.

LOOP AT ITAB1.

CASE ITAB1-COL.

  • ....................................................

WHEN 1.

ITAB-LIFNR = ITAB1-VALUE.

WHEN 2.

ITAB-KTOKK = ITAB1-VALUE.

WHEN 3.

ITAB-NAME1 = ITAB1-VALUE.

WHEN 4.

ITAB-SORTL = ITAB1-VALUE.

WHEN 5.

ITAB-LAND1 = ITAB1-VALUE.

WHEN 6.

ITAB-SPRAS = ITAB1-VALUE.

  • ....................................................

ENDCASE.

AT END OF ROW.

APPEND ITAB.

CLEAR ITAB.

ENDAT.

ENDLOOP.

ENDFORM. " ORGANIZE_UPLOADED_DATA

Read only

Former Member
0 Likes
463

Hi Dileep,

various methods of uploading flatfile into internal table

By using GUI_UPLOAD Function module -> .txt file

By using ALSM_EXCEL_TO_INTERNAL_TABLE' Function moduel -> XLS File

Regards