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

BDC

Former Member
0 Likes
684

Hi Experts,

I am using function module ALSM_EXCEL_TO_INTERNAL_TABLE to upload data from an excel file. Do to performance reasons I have to use GUI_UPLOAD instead. The problem with this function module is that it is showing data as ####.

My internal table is

data: begin of it_ps_psa occurs 0,

pernr like pa0001-pernr,

werks like pa0001-werks,

btrtl like pa0001-btrtl,

end of it_ps_psa.

should i use a CSV file instead? Please put your valuable suggestions.. Answers will be rewarded with points.

Regards

Abdullah

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
659

Hi ismail,

u can use the fm TEXT_CONVERT_XLS_TO_SAP

TYPE-POOLS: TRUXS.

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.

DATA: I_RAW TYPE TRUXS_T_TEXT_DATA.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

  • I_FIELD_SEPERATOR =

  • I_LINE_HEADER =

i_tab_raw_data = I_RAW

i_filename = P_FILE

tables

i_tab_converted_data = RECORD[]

EXCEPTIONS

CONVERSION_FAILED = 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.

hope this helps u a bit,

all the best,

regards,

sampath

  • mark helpful answers

8 REPLIES 8
Read only

Former Member
0 Likes
659

hi

chk this thread :

**reward if helpful

regards,

madhu

Read only

Former Member
0 Likes
659

No need to use .CSV file.

See the example and do.

reward if useful.

report ZN_BDC

no standard page heading line-size 255.

TABLES : ZVH4479 ,

ZVI4479 .

DATA : I_HTAB LIKE STANDARD TABLE OF ZVH4479 WITH HEADER LINE.

DATA : I_ITAB LIKE STANDARD TABLE OF ZVI4479 WITH HEADER LINE.

DATA : V_COUNTER(2) TYPE C ,

V_COUNTER1 TYPE C ,

V_NETWR(10) TYPE C ,

V_NTGEW(10) TYPE C ,

V_FIELD TYPE STRING.

include bdcrecx1.

start-of-selection.

PERFORM SELECTION.

*PERFORM GUI_DOWNLOAD.

PERFORM GUI_UPLOAD.

*PERFORM DISPLAY.

LOOP AT I_HTAB.

V_COUNTER = 0.

perform open_group.

perform bdc_dynpro using 'ZWK34479' '0001'.

perform bdc_field using 'BDC_OKCODE'

'=CREATE'.

perform bdc_field using 'BDC_CURSOR'

'ZVI4479-NETWR(01)'.

perform bdc_field using 'ZVH4479-VBELN'

I_HTAB-VBELN.

perform bdc_field using 'ZVH4479-ERDAT'

I_HTAB-ERDAT.

perform bdc_field using 'ZVH4479-LIFNR'

I_HTAB-LIFNR.

perform bdc_field using 'ZVH4479-NAME1'

I_HTAB-NAME1.

V_NETWR = I_HTAB-NETWR.

perform bdc_field using 'ZVH4479-NETWR'

V_NETWR.

LOOP AT I_ITAB WHERE VBELN EQ I_HTAB-VBELN.

V_COUNTER = V_COUNTER + 1.

CONCATENATE 'ZVI4479-MATNR(' V_COUNTER ')' INTO V_FIELD.

perform bdc_field using V_FIELD

I_ITAB-MATNR.

CONCATENATE 'ZVI4479-MAKTX(' V_COUNTER ')' INTO V_FIELD.

perform bdc_field using V_FIELD

I_ITAB-MAKTX.

CONCATENATE 'ZVI4479-MEINS(' V_COUNTER ')' INTO V_FIELD.

perform bdc_field using V_FIELD

I_ITAB-MEINS.

CONCATENATE 'ZVI4479-NTGEW(' V_COUNTER ')' INTO V_FIELD.

V_NTGEW = I_ITAB-NTGEW.

perform bdc_field using V_FIELD

V_NTGEW.

CONCATENATE 'ZVI4479-NETWR(' V_COUNTER ')' INTO V_FIELD.

V_NETWR = I_ITAB-NETWR.

perform bdc_field using V_FIELD

V_NETWR.

if sy-tabix eq 10.

perform bdc_field using 'BDC_OKCODE'

'=enter'.

V_COUNTER1 = SY-TABIX.

CONCATENATE 'ZVI4479-NETWR(' V_COUNTER1 ')' INTO V_FIELD.

perform bdc_field using 'BDC_CURSOR'

V_FIELD.

endif.

ENDLOOP.

perform bdc_transaction using 'ZVL4479'.

perform close_group.

ENDLOOP.

&----


*& Form SELECTION

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form SELECTION .

SELECT *

INTO TABLE I_HTAB

FROM ZVH4479

WHERE VBELN EQ 'DELI1'.

SELECT *

INTO TABLE I_ITAB

FROM ZVI4479

WHERE VBELN EQ 'DELI1'.

Endform. " SELECTION

&----


*& Form GUI_DOWNLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form GUI_DOWNLOAD .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'C:\NAVNEETH1.TXT'

FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

tables

data_tab = I_HTAB

  • FIELDNAMES =

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF sy-subrc <> 0.

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

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

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'C:\NAVNEETH2.TXT'

FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

tables

data_tab = I_ITAB

  • FIELDNAMES =

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF sy-subrc <> 0.

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

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

ENDIF.

REFRESH I_HTAB.

REFRESH I_ITAB.

endform. " GUI_DOWNLOAD

&----


*& Form GUI_UPLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form GUI_UPLOAD .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\NAVNEETH1.TXT'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = I_HTAB

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

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\NAVNEETH2.TXT'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = I_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.

endform. " GUI_UPLOAD

&----


*& Form DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form DISPLAY .

LOOP AT I_HTAB.

WRITE :/1 I_HTAB-VBELN , 10 I_HTAB-ERDAT , 20 I_HTAB-ERNAM , 30 I_HTAB-LIFNR ,

40 I_HTAB-NAME1 , 50 I_HTAB-NETWR.

ENDLOOP.

LOOP AT I_ITAB.

WRITE :/1 I_ITAB-VBELN , 10 I_ITAB-POSNR , 20 I_ITAB-MATNR , 30 I_ITAB-MAKTX ,

40 I_ITAB-MEINS , 50 I_ITAB-NTGEW , 60 I_ITAB-NETWR.

ENDLOOP.

endform. " DISPLAY

Regards,

Anji

Read only

Former Member
0 Likes
659

hI..

U cannot upload Excel file using <b>GUI_upload</b> i think..

Try this...

<b> open that file in excel and use SAVE AS option ..then in file type u press the list box there u can find TAB DELIMITED file..</b>

U just save that file as Tab delimited file..

and upload it .... its working fine...

i tested it...

For the fm GUI_UPLOAD

<b>CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'D:\SAI.TXT'

HAS_FIELD_SEPARATOR = 'X'</b>

only the above two fields should be passed...

of course the table also..

Hope this solves ur problem...

reward if it helps u...

sai ramesh.

Read only

0 Likes
659

hi,

The tab limited file has to be saved by the end user. I am not sure whether this will be accepted. Is there any way where I can upload data from a *.xls file. If any other function module also helps please do let me know..

Regards

Abdullah

Read only

Former Member
0 Likes
659

hi Abdullah,

You can use GUI_UPLOAD for uploading .CSV files or .TXT files.

<b>sample code for .TXT files:</b>


CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = pa_file
   filetype                      = 'ASC'
 HAS_FIELD_SEPARATOR           = cl_abap_char_utilities=>horizontal_tab 
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    data_tab                      = lt_dattab[]
 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 e398(00) WITH 'Upload error' sy-subrc.
ENDIF.

<b>sample code for .CSV files:</b>


CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename                      = pa_file
   filetype                      = 'ASC'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    data_tab                      = lt_dattab[]
 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 e398(00) WITH 'Upload error' sy-subrc.
ENDIF.

Hope this helps,

Sajan Joseph.

Read only

Former Member
0 Likes
659

hI...

Save the excel file a TAB DELIMITED file. Now while uploading...Now in GUI upload...use the option HAS_FIELD_SEPARATOR = 'X'.

But...make sure that the DATA_TAB is also having the same structure as the excel file is having...u will get the desired result..

Ram

Message was edited by:

Rammohan Nagam

Read only

Former Member
0 Likes
660

Hi ismail,

u can use the fm TEXT_CONVERT_XLS_TO_SAP

TYPE-POOLS: TRUXS.

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.

DATA: I_RAW TYPE TRUXS_T_TEXT_DATA.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

  • I_FIELD_SEPERATOR =

  • I_LINE_HEADER =

i_tab_raw_data = I_RAW

i_filename = P_FILE

tables

i_tab_converted_data = RECORD[]

EXCEPTIONS

CONVERSION_FAILED = 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.

hope this helps u a bit,

all the best,

regards,

sampath

  • mark helpful answers

Read only

Former Member
0 Likes
659

Hiii got the function module man!!!

ALSM_EXCEL_TO_INTERNAL_TABLE

to upload EXCEL file into an internal table..

But u have .......