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

uploading .xml data to ztable

Former Member
0 Likes
806

i need to upload xl sheet data into custom table which has four fields for this i have writeen the code as

*Parameters : p_file1 type rlgrap-filename.

Data: p_file like IBIPPARMS-PATH,

p_file1 type RLGRAP-FILENAME.

*types:begin of ty_tab,

  • werks type werks_d,

  • H_SLGORT type ZSOURCE_SLOC,

  • SLOCDES type c,

  • ROUTID type werks_d,

  • end of ty_tab.

*data : itab type table of zbipl.

data : gd_filename type string.

*At selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = p_file

.

p_file1 = p_file.

data : it_tab type table of zbipl,

is_tab type zbipl.

data itdata type table of ALSMEX_TABLINE initial size 0.

*data isdata type ALSMEX_TABLINE.

data isdata like line of itdata.

if not p_file1 is initial.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file1

i_begin_col = 3

i_begin_row = 3

i_end_col = 4

i_end_row = 68

tables

intern = itdata

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

endif.

loop at itdata into isdata.

at new row.

clear is_tab.

endat.

if isdata-col = '001'.

move isdata-value to is_tab-werks.

endif.

if isdata-col = '002'.

move isdata-value to is_tab-h_slgort.

endif.

if isdata-col = '003'.

move isdata-value to is_tab-slocdes.

endif.

if isdata-col = '004'.

move isdata-value to is_tab-ROUTID .

endif.

at end of row.

append is_tab to it_tab.

endat.

clear : isdata.

endloop.

but iam not getting the data in to itab.

please helpme.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
689

HI insted of looping through the itab data , try to move the contents using the move statements.

LOOP AT itdata.

.

CASE itdata-COL.

WHEN '0001'.

MOVE itdata-VALUE TO <workarea>.

WHEN '0002'.

MOVE itdata-VALUE TO <workarea>.

ENDCASE.

AT END OF ROW.

APPEND <workarea> TO <inernal table>.

CLEAR <workarea>.

ENDAT.

ENDLOOP.

0001 represents the cell of the excel file in row wise.

i had the same prob and it was solved by using the above code.

But this code is useful when u kno for how many cells you are going to enter the data in the excel file.

<removed by moderator>

Edited by: karthikeyan.chandrasekaran on Oct 10, 2011 12:34 PM

Edited by: Thomas Zloch on Oct 10, 2011 2:19 PM

i need to upload xl sheet data into custom table which has four fields for this i have writeen the code as

*Parameters : p_file1 type rlgrap-filename.

Data: p_file like IBIPPARMS-PATH,

p_file1 type RLGRAP-FILENAME.

*types:begin of ty_tab,

  • werks type werks_d,

  • H_SLGORT type ZSOURCE_SLOC,

  • SLOCDES type c,

  • ROUTID type werks_d,

  • end of ty_tab.

*data : itab type table of zbipl.

data : gd_filename type string.

*At selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = p_file

.

p_file1 = p_file.

data : it_tab type table of zbipl,

is_tab type zbipl.

data itdata type table of ALSMEX_TABLINE initial size 0.

*data isdata type ALSMEX_TABLINE.

data isdata like line of itdata.

if not p_file1 is initial.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file1

i_begin_col = 3

i_begin_row = 3

i_end_col = 4

i_end_row = 68

tables

intern = itdata

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

endif.

loop at itdata into isdata.

at new row.

clear is_tab.

endat.

if isdata-col = '001'.

move isdata-value to is_tab-werks.

endif.

if isdata-col = '002'.

move isdata-value to is_tab-h_slgort.

endif.

if isdata-col = '003'.

move isdata-value to is_tab-slocdes.

endif.

if isdata-col = '004'.

move isdata-value to is_tab-ROUTID .

endif.

at end of row.

append is_tab to it_tab.

endat.

clear : isdata.

endloop.

but iam not getting the data in to itab.

please helpme.

4 REPLIES 4
Read only

ChandrashekharMahajan
Active Contributor
0 Likes
689

Hi Raj,

Just check below link and accordingly do the required correction to ur code.

http://wiki.sdn.sap.com/wiki/display/Snippets/Howtouse+FM'ALSM_EXCEL_TO_INTERNAL_TABLE'

Hope this will help to you.

Thanks,

Chandra

Read only

Former Member
0 Likes
690

HI insted of looping through the itab data , try to move the contents using the move statements.

LOOP AT itdata.

.

CASE itdata-COL.

WHEN '0001'.

MOVE itdata-VALUE TO <workarea>.

WHEN '0002'.

MOVE itdata-VALUE TO <workarea>.

ENDCASE.

AT END OF ROW.

APPEND <workarea> TO <inernal table>.

CLEAR <workarea>.

ENDAT.

ENDLOOP.

0001 represents the cell of the excel file in row wise.

i had the same prob and it was solved by using the above code.

But this code is useful when u kno for how many cells you are going to enter the data in the excel file.

<removed by moderator>

Edited by: karthikeyan.chandrasekaran on Oct 10, 2011 12:34 PM

Edited by: Thomas Zloch on Oct 10, 2011 2:19 PM

Read only

koolspy_ultimate
Active Contributor
0 Likes
689

Hi,

modify this as per your requirement.


REPORT z_read_xml_file.

PARAMETERS: p_filnam TYPE localfile OBLIGATORY

DEFAULT 'C:\Documents and Settings\ssaha\Desktop\test.xml'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_filnam.

DATA: l_v_fieldname TYPE dynfnam.

l_v_fieldname = p_filnam.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = l_v_fieldname

IMPORTING

file_name = p_filnam.

START-OF-SELECTION.

TYPES:

BEGIN OF ty_tab,

name TYPE string,

value TYPE string,

END OF ty_tab.

DATA:

lcl_xml_doc TYPE REF TO cl_xml_document,

v_subrc TYPE sysubrc,

v_node TYPE REF TO if_ixml_node,

v_child_node TYPE REF TO if_ixml_node,

v_root TYPE REF TO if_ixml_node,

v_iterator TYPE REF TO if_ixml_node_iterator,

v_nodemap TYPE REF TO if_ixml_named_node_map,

v_count TYPE i,

v_index TYPE i,

v_attr TYPE REF TO if_ixml_node,

v_name TYPE string,

v_prefix TYPE string,

v_value TYPE string,

v_char TYPE char2.

DATA:

itab TYPE STANDARD TABLE OF ty_tab,

wa TYPE ty_tab.

CREATE OBJECT lcl_xml_doc.

CALL METHOD lcl_xml_doc->import_from_file

EXPORTING

filename = p_filnam

RECEIVING

retcode = v_subrc.

CHECK v_subrc = 0.

v_node = lcl_xml_doc->m_document.

CHECK NOT v_node IS INITIAL.

v_iterator = v_node->create_iterator( ).

v_node = v_iterator->get_next( ).

WHILE NOT v_node IS INITIAL.

CASE v_node->get_type( ).

WHEN if_ixml_node=>co_node_element.

v_name = v_node->get_name( ).

v_nodemap = v_node->get_attributes( ).

IF NOT v_nodemap IS INITIAL
* attributes
v_count = v_nodemap->get_length( ).

DO v_count TIMES.

v_index = sy-index - 1.

v_attr = v_nodemap->get_item( v_index ).

v_name = v_attr->get_name( ).

v_prefix = v_attr->get_namespace_prefix( ).

v_value = v_attr->get_value( ).

ENDDO.

ENDIF.

WHEN if_ixml_node=>co_node_text OR

if_ixml_node=>co_node_cdata_section.
* text node
v_value = v_node->get_value( ).

MOVE v_value TO v_char.

IF v_char <> cl_abap_char_utilities=>cr_lf.

wa-name = v_name.

wa-value = v_value.

APPEND wa TO itab.

CLEAR wa.

ENDIF.

ENDCASE.
* advance to next node
v_node = v_iterator->get_next( ).

ENDWHILE.

LOOP AT itab INTO wa.

ENDLOOP.

Regards,

koolspy.

Edited by: koolspy on Oct 10, 2011 4:12 PM

Read only

Former Member
0 Likes
689

Hi,

Use this FM.


  TRANSLATE p_fname TO UPPER CASE.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator     ='X'
      i_line_header           = 'X'
      i_tab_raw_data       = it_raw
      i_filename                = p_fname
    TABLES
      i_tab_converted_data = gt_data[]
    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.

Take care,

Çağatay