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
873

Hi Experts,

I have an excel file. The first column contains personnel number, the second contains personnel area and the third contains personnel subarea. How do I upload this into an in internal table

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.

using function module gui_upload. The values that I am getting are all being displayed as ####. Please help me solve this problem.

Regards

Abdullah

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
833

you need to handle this with FM

<b>ALSM_EXCEL_TO_INTERNAL_TABLE</b>

report zp2.
**excel to internal table .
DATA: BEGIN OF intern OCCURS 0.
        INCLUDE STRUCTURE  alsmex_tabline.
DATA: END OF intern.

TABLES :ZXXXXX.
DATA: ITAB LIKE ZXXXXXX OCCURS 0 WITH HEADER LINE.
DATA: WA_ITAB LIKE ITAB OCCURS 0 WITH HEADER LINE.
data : v_new type i,
       col type i.
data : v_row(4) type n.

PARAMETERS: filename LIKE rlgrap-filename,
            begcol TYPE i DEFAULT 1     NO-DISPLAY,
            begrow TYPE i DEFAULT 1     NO-DISPLAY,
            endcol TYPE i DEFAULT 20     NO-DISPLAY,
            endrow TYPE i DEFAULT 560 NO-DISPLAY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
       EXPORTING
            mask      = '*.xls'
            static    = 'X'
       CHANGING
            file_name = filename.

start-of-selection.
*fetch the same from the excel in the matrix form
*case okay
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       EXPORTING
            filename                = filename
            i_begin_col             = begcol
            i_begin_row             = begrow
            i_end_col               = endcol
            i_end_row               = endrow
       TABLES
            intern                  = intern
       EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.

  IF sy-subrc <> 0.
   WRITE:/ 'Upload Error ', SY-SUBRC.
  ENDIF.


  clear intern.
  LOOP AT intern.

*  if intern-row ne v_row.
    at new col.
      v_new = 1.
    endat.
    if v_new = 1.
      clear v_new.
        col = intern-col.
        CASE  col .
         when '1'.
         itab-laufd = intern-value. "ur excel columns
         when '2'.
         itab-matnr = intern-value.
         when '3'.
         itab-werks = intern-value.
         when '4'.
         itab-parent = intern-value.
         endcase.
     endif.

    at end of row.
      append itab. clear itab.
    endat.
*  endif.
  endloop.
loop at itab.
  write : /1(150) itab-laufd right-justified, 12(18) itab-matnr, 34(6)
itab-werks.
endloop.

This is a code to handle the upload jsut modify with ur columns..

regards,

vijay

8 REPLIES 8
Read only

Former Member
0 Likes
833

Try uploading file into internal table containing the <b>CHAR</b> type fields ..and it may resolve your problem,,,

Assign the points if it helps..

Regards,

Gaurang

Read only

Former Member
0 Likes
833

Hi,

In the function module "GUI_UPLOAD" set the parameter

HAS SEPERATOR = 'X'.

This shud work.

Thanks.

Rashmi.

Read only

naren112
Explorer
0 Likes
833

Hi Abdulla ,

FOR UPLOADING DATA FROM EXCEL FILE , USE FUNCTION MODULE -

FORM UPLOAD_DATA.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING..

..........

DON'T USE WS_UPLOAD ..

IT'S WORKING I HAV DONE CUSTOMER MASTER UPLOAD UDING THIS FUNCTION MODULE ..

REGARDS ,

NARENDER B

IF HELP FULL GIVE POINTS .

Read only

Former Member
0 Likes
834

you need to handle this with FM

<b>ALSM_EXCEL_TO_INTERNAL_TABLE</b>

report zp2.
**excel to internal table .
DATA: BEGIN OF intern OCCURS 0.
        INCLUDE STRUCTURE  alsmex_tabline.
DATA: END OF intern.

TABLES :ZXXXXX.
DATA: ITAB LIKE ZXXXXXX OCCURS 0 WITH HEADER LINE.
DATA: WA_ITAB LIKE ITAB OCCURS 0 WITH HEADER LINE.
data : v_new type i,
       col type i.
data : v_row(4) type n.

PARAMETERS: filename LIKE rlgrap-filename,
            begcol TYPE i DEFAULT 1     NO-DISPLAY,
            begrow TYPE i DEFAULT 1     NO-DISPLAY,
            endcol TYPE i DEFAULT 20     NO-DISPLAY,
            endrow TYPE i DEFAULT 560 NO-DISPLAY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
       EXPORTING
            mask      = '*.xls'
            static    = 'X'
       CHANGING
            file_name = filename.

start-of-selection.
*fetch the same from the excel in the matrix form
*case okay
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       EXPORTING
            filename                = filename
            i_begin_col             = begcol
            i_begin_row             = begrow
            i_end_col               = endcol
            i_end_row               = endrow
       TABLES
            intern                  = intern
       EXCEPTIONS
            inconsistent_parameters = 1
            upload_ole              = 2
            OTHERS                  = 3.

  IF sy-subrc <> 0.
   WRITE:/ 'Upload Error ', SY-SUBRC.
  ENDIF.


  clear intern.
  LOOP AT intern.

*  if intern-row ne v_row.
    at new col.
      v_new = 1.
    endat.
    if v_new = 1.
      clear v_new.
        col = intern-col.
        CASE  col .
         when '1'.
         itab-laufd = intern-value. "ur excel columns
         when '2'.
         itab-matnr = intern-value.
         when '3'.
         itab-werks = intern-value.
         when '4'.
         itab-parent = intern-value.
         endcase.
     endif.

    at end of row.
      append itab. clear itab.
    endat.
*  endif.
  endloop.
loop at itab.
  write : /1(150) itab-laufd right-justified, 12(18) itab-matnr, 34(6)
itab-werks.
endloop.

This is a code to handle the upload jsut modify with ur columns..

regards,

vijay

Read only

Former Member
0 Likes
833

hi Abdullah,

If you are using <b>EXCEL</b> file (and not any CSV or TAB DELIMITED), you can

try the following logic:

Assuming you have a selection screen field for entering file name,



types:
    begin of t_itab,
       pernr type p0001-pernr,
       werks type p0001-werks,
       btrtl type p0001-btrtl,
    end of t_itab.

data:
    gt_alsmex    type table of alsmex_tabline,
    gs_alsmex    type          alsmex_tabline,
    gv_integ        type i,
    gs_itab type t_itab, 
    gt_itab type table of t_itab.

at selection-screen on value-request for p_file.
    call function 'WS_FILENAME_GET'
    exporting
        def_filename     = ''
        def_path         = ''
        mask             = ',*.xls.'
        mode             = 'O'
        title            = 'Select upload file'
    importing
        filename         = p_file
    exceptions
        inv_winsys       = 1
        no_batch         = 2
        selection_cancel = 3
        selection_error  = 4
        others           = 5.
start-of-selection.
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
        filename                      = p_file
        i_begin_col                   = '1'
        i_begin_row                   = '2' "1 row for heading
        i_end_col                     = '3'
        i_end_row                     = '9999'
    tables
        intern                        = gt_alsmex
    exceptions
        inconsistent_parameters       = 1
        upload_ole                    = 2
        others                        = 3            .
    if sy-subrc <> 0.
        message i000(00) with 'Invalid file'.
        leave program.
    endif.            .
    sort gt_alsmex by row.
    clear gv_integ.
    describe table gt_alsmex lines gv_integ.
    check not gv_integ is initial.
    read table gt_alsmex into gs_alsmex index gv_integ.
    gv_integ = gs_alsmex-row.
    data:
        lv_rowno(4) type n.
    do gv_integ times.
        lv_rowno = lv_rowno + 1.
        loop at gt_alsmex into gs_alsmex where row = lv_rowno .
            case gs_alsmex-col.
                when '0001'.
                    gs_itab-pernr      = gs_alsmex-value.
                when '0002'.
                    gs_itab-werks    = gs_alsmex-value.
                when '0003'.
                    gs_itab-btrtl = gs_alsmex-value.
            endcase.
        endloop.
        append gs_itab to gt_itab.
        clear gs_itab.
    enddo.

Hope this helps,

Sajan Joseph.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
833

Hi,

As suggested,did you declared it as character?

data: begin of it_ps_psa occurs 0,

pernr(8) type c,

werks(4) type c,

btrtl(4) type c,

end of it_ps_psa.

Read only

Former Member
0 Likes
833

Hi,

If you are directly uploading excel file, u can use the following FM.

ALSM_EXCEL_TO_INTERNAL_TABLE

else u have to convert the excel file into formatted text (space delimited ) that is in prn file then upload.

u will get exact result..

Senthil Kumar

Read only

0 Likes
833

Hi everybody,

thanks 4 your inputs. The function module ALSM_EXCEL_TO_INTERNAL_TABLE

helped solve the problem.

Regards

Abdullah