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

Data Upload

Former Member
0 Likes
1,249

Hi,

I am uploading data from tab-delimited text file to SAP. While uploading i am getting anonymus character of tab. How can i remove that? or how can i upload data of which i dont know the total field length of each field but tab seperates it.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,185

Hi Arun,

I tried with same. But its picking only first field.

Thanks in advance

13 REPLIES 13
Read only

Former Member
0 Likes
1,185

Hi Prax ,

What is the type of file you are trying to upload and which function module are you using to upload.

If you are using GUI_UPLOAD

then here is a sample code which works fine

Data : Begin of it_1 occurs 0 ,

name1(25) ,

name2(25) ,

End of it_1.

data : file_name type string.

start-of-selection.

file_name = 'C:\test.txt'.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = file_name

  • FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = '#' " takes care of tab delimiter

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = it_1.

  • 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

Arun

Message was edited by:

Arun R

Read only

Former Member
0 Likes
1,185

hi Prax,

Check this out for data uploading purpose ...

http://www.sapdevelopment.co.uk/file/file_uptabpc.htm

Regards,

Santosh

Read only

Former Member
0 Likes
1,185

1) upload fiel via gui upoad and give some seperator in betwen the fields in the file say '#'.

declare 2 internal tables one as per ur data fields and other one -

data: begin of itab occurs 0,

d_char(255),

end of itab.

upload data in this table.and then u have to split it ino other tabvle itab1 as folows -

loop at itab.

split itab at '#' into itab1-field1 itab1-field2 itab1-field3.

append itab1.

clear: itab1,itab.

endloop.

u can give any arbitraroy length of firlds in Itab1 say each field 15 chars long..

hope u got my point.

amit

Read only

Former Member
0 Likes
1,185

Hi,

Please refer the links,

Regards,

Hema.

    • Reward points if it is useful.

Read only

former_member404244
Active Contributor
0 Likes
1,185

Hi,

first of all u need to declare the internal table with the flat file structure.

for example if ur flat file has 10 fields then ur internal table shouls also have same 10 fields...No use the FM GIU_UPLOAD..chek some sample code..

types: begin of t_upload,

field1 type c,

-


,

-


,

field10 type c,

end of t_upload .

data : i_upload type standard table of t_upload.

lv_file1 = (filename whcih is selected on the presentation server)

c_asc = 'ASC'

C_X = 'X'..

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file1

filetype = c_asc

has_field_separator = c_x

TABLES

data_tab = i_upload

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.

plz mark if u find useful...

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,185

hi,

if your mode of separation is ' ' or ',' or anonymus character.

loop at table .

split at ' ' or ',' into <table-f1> <table-f2>

endloop.

Read only

Former Member
0 Likes
1,185

Hi Prax,

When you upload the tab delimited file into application server, you will get # symbols in place of tab. Do not worry about this, as # only represents the tab. If you download this file back to the presentation server from application (using CG3Y transaction), you will not find any # symbols in it.

You can do any computations / file operations in the uploaded file, the # symbols will not create any problems.

PLZ REWARD POINTS IF HELPFUL

Read only

Former Member
0 Likes
1,185

I am not able to do with split option.

My string comes like,

IT-01#KFC#DEL#CCU#001300001#12122006#5680#0.7746#CCU#1452#201377#N

I tried to apply split at '#' . But it doesnt work because SAP is unable to make out tabs.

Any help.

Thanks in advance.

Read only

0 Likes
1,185

Hi Prax ,

As in my previous post , if you are using the FM GUI_UPLOAD , the assign '#' to the parameter HAS_FIELD_SEPARATOR .

This worked when i tried it out.

In case you are using some other FM ,please tell the it name

Regards

Arun

Read only

Former Member
0 Likes
1,185

Dear Prax,

Please go though the following lines of code:

************************************************************************

  • D A T A D E C L A R A T I O N *

************************************************************************

TABLES: ANEP,

BKPF.

TYPES: BEGIN OF TY_TABDATA,

MANDT LIKE SY-MANDT, " Client

ZSLNUM LIKE ZSHIFTDEPN-ZSLNUM, " Serial Number

ZASSET LIKE ZSHIFTDEPN-ZASSET, " Original asset that was transferred

ZYEAR LIKE ZSHIFTDEPN-ZYEAR, " Fiscal Year

ZPERIOD LIKE ZSHIFTDEPN-ZPERIOD, " Fiscal Period

ZSHIFT1 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 1

ZSHIFT2 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 2

ZSHIFT3 LIKE ZSHIFTDEPN-ZSHIFT1, " Shift No. 3

END OF TY_TABDATA.

*----


  • Declaration of the Internal Table with Header Line comprising of the uploaded data.

*----


DATA: BEGIN OF IT_FILE_UPLOAD OCCURS 0.

INCLUDE STRUCTURE ALSMEX_TABLINE. " Rows for Table with Excel Data

DATA: END OF IT_FILE_UPLOAD.

************************************************************************

  • S E L E C T I O N - S C R E E N *

************************************************************************

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME,

BEGIN OF BLOCK B2 WITH FRAME.

PARAMETERS: P_FNAME LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN: END OF BLOCK B2,

END OF BLOCK B1.

************************************************************************

  • E V E N T : AT S E L E C T I O N - S C R E E N *

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

  • PROGRAM_NAME = SYST-REPID

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

STATIC = 'X'

  • MASK = '.'

CHANGING

FILE_NAME = P_FNAME

  • EXCEPTIONS

  • MASK_TOO_LONG = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

************************************************************************

  • E V E N T : S T A R T - O F - S E L E C T I O N *

************************************************************************

START-OF-SELECTION.

  • --------------------------------------

  • Upload Excel file into Internal Table.

  • --------------------------------------

PERFORM UPLOAD_EXCEL_FILE.

  • -------------------------------------------------------

  • Organize the uploaded data into another Internal Table.

  • -------------------------------------------------------

PERFORM ORGANIZE_UPLOADED_DATA.

************************************************************************

  • E V E N T : E N D - O F - S E L E C T I O N *

************************************************************************

END-OF-SELECTION.

&----


*& Form UPLOAD_EXCEL_FILE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM UPLOAD_EXCEL_FILE .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = P_FNAME

I_BEGIN_COL = 1

I_BEGIN_ROW = 3

I_END_COL = 7

I_END_ROW = 32000

TABLES

INTERN = IT_FILE_UPLOAD

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.

ENDFORM. " UPLOAD_EXCEL_FILE

&----


*& Form ORGANIZE_UPLOADED_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM ORGANIZE_UPLOADED_DATA .

SORT IT_FILE_UPLOAD BY ROW

COL.

LOOP AT IT_FILE_UPLOAD.

CASE IT_FILE_UPLOAD-COL.

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

WHEN 1.

WA_TABDATA-ZSLNUM = IT_FILE_UPLOAD-VALUE.

WHEN 2.

WA_TABDATA-ZASSET = IT_FILE_UPLOAD-VALUE.

WHEN 3.

WA_TABDATA-ZYEAR = IT_FILE_UPLOAD-VALUE.

WHEN 4.

WA_TABDATA-ZPERIOD = IT_FILE_UPLOAD-VALUE.

WHEN 5.

WA_TABDATA-ZSHIFT1 = IT_FILE_UPLOAD-VALUE.

WHEN 6.

WA_TABDATA-ZSHIFT2 = IT_FILE_UPLOAD-VALUE.

WHEN 7.

WA_TABDATA-ZSHIFT3 = IT_FILE_UPLOAD-VALUE.

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

ENDCASE.

AT END OF ROW.

WA_TABDATA-MANDT = SY-MANDT.

APPEND WA_TABDATA TO IT_TABDATA.

CLEAR: WA_TABDATA.

ENDAT.

ENDLOOP.

ENDFORM. " ORGANIZE_UPLOADED_DATA

In the subroutine --> ORGANIZE_UPLOADED_DATA, data are organized as per the structure declared above.

Regards,

Abir

***********************************

  • Don't forget to award points *

Read only

Former Member
0 Likes
1,186

Hi Arun,

I tried with same. But its picking only first field.

Thanks in advance

Read only

0 Likes
1,185

Hi ,

Are you using the FM GUI_UPLOAD and yes the internal table into which the data is uploaded from the FM how many fields does it have .

I tested the code where i had two fields in the file (name1 and name2) which were tab delimited and my internal table also had 2 fileds per record and it worked fine

Please check the same and revert back to me.

Regards

Arun

Read only

Former Member
0 Likes
1,185

Thanks Arun.

It worked fine.