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

upload Function module

Former Member
0 Likes
3,907

Hi all,

I tried to upload the Data from flat file into internal table but it is displaying some thing wrong please go through the program, flatfile and output and please suggest me.

Program:

data : begin of itab occurs 0,

kunnr type kna1-kunnr,

Name1 type kna1-name1,

ort01 type kna1-ort01,

land1 type kna1-land1,

end of itab.

CALL FUNCTION 'UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = 'c:/test.txt'

FILETYPE = 'asc'

  • ITEM = ' '

  • 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

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at itab.

write : / itab-kunnr, itab-name1, itab-ort01, itab-land1.

endloop.

test file have the following data sapetated by tab spaces:

0001 Ranjith nrml in

0002 mahesh nzb us

and the Output is some thing errotic as below

0001#Ranji th#nrml#in

0002#mahes h#nzb#us

Please suggest me

Thanks in advance.

8 REPLIES 8
Read only

Former Member
0 Likes
2,072

Hi Ranjith,

Use GUI_UPLOAD instead of the upload. Where you can have field seperator option.

Regards,

Ameer Baba.

Read only

former_member404244
Active Contributor
0 Likes
2,072

Hi,

use gui_upload...like this

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'c:/test.txt'

filetype = 'ASC'

has_field_separator = 'X'

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.

  • File not found.

MESSAGE e138.

ENDIF.

REGARDS,

Nagaraj

Read only

Former Member
0 Likes
2,072

Hi,

Use file type as 'DAT'.

Thanks and Best Regards,

Vikas Bittera.

Read only

Former Member
0 Likes
2,072

hI,

Better u use Gui_upload for that.

Rewards points if is useful.

Read only

Former Member
0 Likes
2,072

flie save as tab deilmeter.

Download/Upload SAP Users Favorites

  • This program allows you to transfer the user Favorites from one PC to another.

  • Written by : SAP Basis, ABAP Programming and Other IMG Stuff

  • http://www.sap-img.com

REPORT ZFAVORITES.

DATA : G_FILE(128) TYPE C.

DATA : G_PATH(80) TYPE C.

DATA : G_END(8) TYPE C.

DATA : G_SUBRC LIKE SY-SUBRC.

PARAMETERS: P_UNAME LIKE SY-UNAME DEFAULT SY-UNAME.

PARAMETERS: P_LANGU LIKE SY-LANGU DEFAULT SY-LANGU.

SELECTION-SCREEN SKIP.

PARAMETERS: P_IMP RADIOBUTTON GROUP ACT .

PARAMETERS: P_EXP RADIOBUTTON GROUP ACT DEFAULT 'X'.

SELECTION-SCREEN ULINE.

SELECTION-SCREEN BEGIN OF BLOCK FIL.

PARAMETERS: P_TYPE LIKE RLGRAP-FILETYPE DEFAULT 'ASC'.

PARAMETERS: P_PATH LIKE G_PATH DEFAULT 'C:TEMPXXX.MEN'.

SELECTION-SCREEN END OF BLOCK FIL.

DATA: IT_USER_NODES TYPE TABLE OF BXMNODES1 WITH HEADER LINE.

DATA: IT_FAV_NODES TYPE TABLE OF BXMNODES WITH HEADER LINE.

DATA: BEGIN OF IT_PCF OCCURS 0,

LINE(4096) TYPE C.

DATA: END OF IT_PCF.

INITIALIZATION.

REPLACE 'XXX' WITH SY-UNAME INTO P_PATH.

CONDENSE P_PATH NO-GAPS.

SY-TITLE = 'UPLOAD/DOWNLOAD FAVORITE'.

START-OF-SELECTION.

CLEAR IT_USER_NODES[].

CLEAR IT_FAV_NODES[].

G_FILE = P_UNAME.

IF P_UNAME <> SY-UNAME.

MESSAGE W398(00) WITH 'CURRENT USER <> USER TO BE MODIFIED!'.

ENDIF.

IF P_IMP = 'X'.

PERFORM IMPORT_FAV TABLES IT_FAV_NODES.

PERFORM WRITE_FAV_DB TABLES IT_FAV_NODES.

ELSEIF P_EXP = 'X'.

PERFORM EXPORT_FAV TABLES IT_FAV_NODES.

ENDIF.

FORM DATA_EXPORT TABLES PIT_PCF

USING P_FILE.

CALL FUNCTION 'DOWNLOAD'

EXPORTING

FILENAME = P_FILE

FILETYPE = P_TYPE

TABLES

DATA_TAB = PIT_PCF

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

GUI_REFUSE_FILETRANSFER = 8

OTHERS = 9.

IF SY-SUBRC NE 0.

WRITE: / 'FAILURE IN DOWNLOAD' , P_FILE.

ENDIF.

ENDFORM.

FORM DATA_IMPORT TABLES PIT_PCF

USING P_FILE P_SUBRC.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = P_FILE

FILETYPE = P_TYPE

TABLES

DATA_TAB = PIT_PCF

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.

IF SY-SUBRC NE 0.

WRITE: / 'UPLOAD FAILED' , P_FILE.

P_SUBRC = SY-SUBRC .

ENDIF.

ENDFORM.

FORM IMPORT_FAV TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.

G_FILE = P_PATH.

PERFORM DATA_IMPORT TABLES IT_FAV_NODES USING G_FILE G_SUBRC .

ENDFORM.

FORM EXPORT_FAV TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.

CALL FUNCTION 'BX_FAVOS_READ_ALL_NODES'

EXPORTING

USER_NAME = P_UNAME

LANGUAGE = P_LANGU

TABLES

OUTPUT_NODES_AND_TEXTS = IT_FAV_NODES.

G_FILE = P_PATH.

PERFORM DATA_EXPORT TABLES IT_FAV_NODES USING G_FILE .

ENDFORM.

FORM WRITE_FAV_DB TABLES PIT_FAV_NODES STRUCTURE IT_FAV_NODES.

CALL FUNCTION 'BX_FAVOS_WRITE_ALL_NODES'

EXPORTING

USER_NAME = P_UNAME

TARGET_CLIENT = SY-MANDT

TABLES

INPUT_NODES_AND_TEXTS = PIT_FAV_NODES.

ENDFORM.

Fast Links:

Sample Download Programs:

Download in Background in Excel Format

Download/Upload ABAP program from Local Harddisk

Get help for your ABAP problems

Do you have a ABAP Question?

SAP Books

SAP Certification, Functional, Basis Administration and ABAP Programming Reference Books

ABAP Programming Tips

ABAP Forum for Discussion and Samples Program Codes for Abapers

Best regards,

SAP Basis, ABAP Programming and Other IMG Stuff

http://www.sap-img.com

All the site contents are Copyright © www.sap-img.com and the content authors. All rights reserved.

All product names are trademarks of their respective companies. The site www.sap-img.com is in no way affiliated with SAP AG.

Every effort is made to ensure the content integrity. Information used on this site is at your own risk.

The content on this site may not be reproduced or redistributed without the express written permission of

www.sap-img.com or the content authors.

Read only

Former Member
0 Likes
2,072

Ranjith,

Change your FILETYPE = 'asc'

to FILETYPE = 'DAT'

Regards,

Ameer Baba.

Read only

Former Member
0 Likes
2,072

Use GUI_Upload and give field seperator as #.

This will solve your problem

Reward points if useful

Read only

Former Member
0 Likes
2,072

Hi

data : begin of itab occurs 0,

kunnr type kna1-kunnr,

Name1 type kna1-name1,

ort01 type kna1-ort01,

land1 type kna1-land1,

end of itab.

CALL FUNCTION '<b>GUI</b>UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = 'c:/test.txt'

FILETYPE = 'asc'

  • ITEM = ' '

  • 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

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at itab.

write : / itab-kunnr, itab-name1, itab-ort01, itab-land1.

endloop.