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

Determining the itab structure dynamically while Uploading from Excel

Former Member
0 Likes
593

Hi,

I am working on an uploadation program where the data will come from Excel File.We have a condition that file will contain minimum two columns. We dont have any fixed file format or no of cols will be there. This is a vendor classification upload prog. We ll have Vendor number(mandatory) and minimum one classification value will be there in the file. There might be columns which will not be relevant for update .

Initially i am uploading file to a character variable as shown below.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_filename_string

filetype = 'ASC'

has_field_separator = 'X'

dat_mode = ''

header_length = '40'

TABLES

data_tab = i_text_data.

Where i_text_data TYPE truxs_t_text_data.

(types truxs_t_text_data(4096) type c occurs 0.)

After this i am converting this xls format to SAP as shown.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

  • I_FIELD_SEPERATOR = 'X'

  • I_LINE_HEADER = 'X'

i_tab_raw_data = i_text_data

i_filename = p_file

TABLES

i_tab_converted_data = <f_fs_up>.

Where <F_FS_UP> is created dynamically from a fieldcatalog..

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = iu_alv_cat

IMPORTING

ep_table = d_ref_up.

ASSIGN d_ref_up->* TO <f_fs_up>.

Here we are having a fixed format of<f_fs_up> to which we are getting the excel datas.

As per the requirement we dont know the name and no of cols will be there in excel.

So could you tell me how to create <f_fs_up> as per the excel format????

Thanks,

SAM.

1 REPLY 1
Read only

Former Member
0 Likes
337

Hi Sam,

Take a look at this code !!! this will give you an idea to

code your logic...

Here you have to know the field names that you will be passing

in the excel sheet .. here i hve taken an example of LFA1 table :

Hope it will be useful to u ..


REPORT  Z_07_TESTPRG3 line-size 1000.
tables: lfa1.

types: begin of t_text,
        text(1000) type c,
       end of t_text.

TYPES: begin of t_lfa1,
         LIFNR type lfa1-lifnr,
         LAND1 type lfa1-LAND1,
         NAME1 type lfa1-NAME1,
         NAME2 type lfa1-NAME2,
         ORT01 type lfa1-ORT01,
       end of t_lfa1.

types: begin of t_test2,
          fld1(10) type c,
       end of t_Test2.

data: i_text type standard table of t_text with header line.
data: i_lfa1 type standard table of t_lfa1 with header line.


data: rcount type i.
data: i_test2 type standard table of t_test2 with header line.
call function 'GUI_UPLOAD'
  exporting
    filename                      = 'filename' '"give uploading file name here
  tables
    data_tab                      = i_text
          .


read table i_text index 1.

SPLIT i_text AT ',' INTO TABLE i_test2 in character mode.

******* dynamic program *********
data: code_tab(72) type c occurs 10 with header line.
data: lin(3).
data: name(8) type c.
data: n(4) type c value '1'.
data: n1 type i value 1.
data: delim1(5) type c value ','.
data: off type i.
data: temp(1000) type c.

types: begin of t_len,
         len(3) type c,
       end of t_len.
field-symbols: <FS_1>.

data: i_len type standard table of t_len with header line.
***********************
APPEND 'PROGRAM SUBPOOL.' TO CODE_tab.
append 'form dyn1 tables i_Text.' to code_tab.

concatenate 'Types:' 'Begin of t_type,' into code_tab separated by space.
append code_tab.

loop at i_test2.

case i_test2-fld1.

when 'LIFNR'.
   append 'LIFNR type LFA1-LIFNR,' to code_tab.
   assign lfa1-lifnr to <FS_1>.
   DESCRIBE FIELD <FS_1> LENGTH i_len-LEN IN CHARACTER MODE.
   append i_len.

when 'LAND1'.
   append 'LAND1 type LFA1-LAND1,' to code_tab.
    assign lfa1-land1 to <FS_1>.
   DESCRIBE FIELD <FS_1> LENGTH i_len-LEN IN CHARACTER MODE.
   append i_len.

when 'NAME1'.
   append 'NAME1 type LFA1-NAME1,' to code_tab.
   assign lfa1-name1 to <FS_1>.
   DESCRIBE FIELD <FS_1> LENGTH i_len-LEN IN CHARACTER MODE.
   append i_len.

when 'NAME2'.
   append 'NAME2 type LFA1-NAME2,' to code_tab.
   assign lfa1-name2 to <FS_1>.
   DESCRIBE FIELD <FS_1> LENGTH i_len-LEN IN CHARACTER MODE.
   append i_len.

when 'ORT01'.
   append 'ORT01 type LFA1-ORT01,' to code_tab.
   assign lfa1-ort01 to <FS_1>.
   DESCRIBE FIELD <FS_1> LENGTH i_len-LEN IN CHARACTER MODE.
   append i_len.
endcase.


endloop.
append 'end of t_type.' to code_tab.
append 'data: i_type type standard table of t_type with header line.' to code_tab.
append 'perform form1 in program Z_07_TESTPRG3 tables i_type.' to code_tab.
append 'endform.' to code_tab.

GENERATE SUBROUTINE POOL code_tab
                    NAME name
                    LINE lin.

if name is not initial.
perform dyn1 in program (name) tables i_text.
endif.

****************************************************************
form form1 tables i_type.

clear : code_tab, lin, name, i_type.
refresh : code_tab, i_type.
data: delim(1) type c value ','.
data: l_n(2) type c.


delete i_text index 1.
read table i_len index 1.
n1 = i_len-len.
n = 1.
describe table i_test2 lines rcount.
rcount = rcount - 1.
l_n = 1.
loop at i_text.
do rcount times.
FIND ',' IN i_text MATCH OFFSET off.
temp = i_text+off.
shift temp left in character mode.
write i_text+0(off) to i_text.
write temp to i_text+n1.
n = n + 1.
read table i_len index n.
n1 = n1 + i_len-len.
enddo.
read table i_len index 1.
n1 = i_len-len.
n = 1.
modify i_text index l_n.
l_n = l_n + 1.
i_type = i_Text.
append i_type.

endloop.

loop at i_type.
write i_type.
write: /.
endloop.
endform.


Happy coding ;;;;;----- )))))

Regards

SJ