Application Development 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: 

how to download XML file to ITAB

Former Member
0 Kudos
177

hi friends

this is my urgent req. how to download XML file to Local itab

any other function or sample program available.

with luv.

pauldharma

5 REPLIES 5

Former Member
0 Kudos
97

Hi,

The XML document can be stored in an ABAP variable rxml of the type STRING or XSTRING, or in an internal standard table sxml of the elementary line type C. Hence, I believe, your issue with the lenght can be resovled with this types.

For rxml, you specify an interface reference variable of the type IF_IXML_OSTREAM that points to an IXML output stream.

For rxml, you specify an interface reference variable of the type IF_IXML_DOCUMENT that points to an IXML document.

With the stream factory you have several options. Before you call your CALL TRANSFORMATION, you setup your stream factory for these different options.

1. You want to write the file to the application server file system. You want to create your OSTREAM as a binary string. In this example b_xml is an empty binary string. OSTEAM will be the reference variable of tyep IF_IXML_OSTREAM.

ostream =

streamfactory->create_ostream_xstring( b_xml ).

You get the output lenght with the following:

ressize = ostream->get_num_written_raw( ).

You can then send the entire string to the file system with the following:

transfer b_xml to filename1 length ressize.

try the following code

TYPES: BEGIN OF ty_mara,

matnr LIKE mara-matnr,

mbrsh LIKE mara-mbrsh,

mtart LIKE mara-mtart,

maktx LIKE makt-maktx,

meins LIKE mara-meins,

END OF ty_mara.

DATA: it_mara TYPE table of ty_mara WITH HEADER LINE.

parameters : p_file like RLGRAP-FILENAME.

data : itab type table of ALSMEX_TABLINE WITH HEADER LINE.

start-of-selection.

*

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = 1

i_begin_row = 1

i_end_col = 5

i_end_row = 4

tables

intern = itab.

loop at itab.

CASE ITAB-COL.

WHEN '1'.

it_mara-matnr = ITAB-VALUE.

WHEN '2'.

it_mara-mbrsh = ITAB-VALUE.

WHEN '3'.

it_mara-mbrsh = ITAB-VALUE.

WHEN '4'.

it_mara-maktx = ITAB-VALUE.

WHEN '5'.

it_mara-meins = ITAB-VALUE.

ENDCASE.

AT END OF ROW.

APPEND it_mara.

CLEAR it_mara.

ENDAT.

endloop.

loop at it_mara.

write 😕 it_mara-matnr.

endloop.

Former Member
0 Kudos
97

Hi,

Try using the Function - SMUM_XML_PARSE. This will upload an XMl file into an internal table.

Check this thread

Regards,

Satish

Former Member
0 Kudos
97

Hi,

please check this code.

Uploading Excel file to SAP Using Function Module ALSM_EXCEL_TO_INTERNAL_TABLE

REPORT ZEXCELUPLOAD. 
PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01, 
            begcol TYPE i DEFAULT 1 NO-DISPLAY, 
            begrow TYPE i DEFAULT 1 NO-DISPLAY, 
            endcol TYPE i DEFAULT 100 NO-DISPLAY, 
            endrow TYPE i DEFAULT 32000 NO-DISPLAY. 
* Tick don't append header 
PARAMETERS: kzheader AS CHECKBOX. 

DATA: BEGIN OF intern OCCURS 0. 
        INCLUDE STRUCTURE  alsmex_tabline. 
DATA: END OF intern. 

DATA: BEGIN OF intern1 OCCURS 0. 
        INCLUDE STRUCTURE  alsmex_tabline. 
DATA: END OF intern1. 

DATA: BEGIN OF t_col OCCURS 0, 
       col LIKE alsmex_tabline-col, 
       size TYPE i. 
DATA: END OF t_col. 

DATA: zwlen TYPE i, 
      zwlines TYPE i. 

DATA: BEGIN OF fieldnames OCCURS 3, 
        title(60), 
        table(6), 
        field(10), 
        kz(1), 
      END OF fieldnames. 
* No of columns 
DATA: BEGIN OF data_tab OCCURS 0, 
       value_0001(50), 
       value_0002(50), 
       value_0003(50), 
       value_0004(50), 
       value_0005(50), 
       value_0006(50), 
       value_0007(50), 
       value_0008(50), 
       value_0009(50), 
       value_0010(50), 
       value_0011(50), 
       value_0012(50), 
       value_0013(50), 
       value_0014(50), 
       value_0015(50), 
       value_0016(50), 
       value_0017(50), 
       value_0018(50), 
       value_0019(50), 
       value_0020(50), 
       value_0021(50), 
       value_0022(50), 
       value_0023(50), 
       value_0024(50), 
       value_0025(50), 
       value_0026(50), 
       value_0027(50), 
       value_0028(50), 
       value_0029(50), 
       value_0030(50), 
       value_0031(50), 
       value_0032(50), 
       value_0033(50), 
       value_0034(50), 
       value_0035(50), 
       value_0036(50), 
       value_0037(50), 
       value_0038(50), 
       value_0039(50), 
       value_0040(50), 
       value_0041(50), 
       value_0042(50), 
       value_0043(50), 
       value_0044(50), 
       value_0045(50), 
       value_0046(50), 
       value_0047(50), 
       value_0048(50), 
       value_0049(50), 
       value_0050(50), 
       value_0051(50), 
       value_0052(50), 
       value_0053(50), 
       value_0054(50), 
       value_0055(50), 
       value_0056(50), 
       value_0057(50), 
       value_0058(50), 
       value_0059(50), 
       value_0060(50), 
       value_0061(50), 
       value_0062(50), 
       value_0063(50), 
       value_0064(50), 
       value_0065(50), 
       value_0066(50), 
       value_0067(50), 
       value_0068(50), 
       value_0069(50), 
       value_0070(50), 
       value_0071(50), 
       value_0072(50), 
       value_0073(50), 
       value_0074(50), 
       value_0075(50), 
       value_0076(50), 
       value_0077(50), 
       value_0078(50), 
       value_0079(50), 
       value_0080(50), 
       value_0081(50), 
       value_0082(50), 
       value_0083(50), 
       value_0084(50), 
       value_0085(50), 
       value_0086(50), 
       value_0087(50), 
       value_0088(50), 
       value_0089(50), 
       value_0090(50), 
       value_0091(50), 
       value_0092(50), 
       value_0093(50), 
       value_0094(50), 
       value_0095(50), 
       value_0096(50), 
       value_0097(50), 
       value_0098(50), 
       value_0099(50), 
       value_0100(50). 
DATA: END OF data_tab. 
DATA: tind(4) TYPE n. 
DATA: zwfeld(19). 
FIELD-SYMBOLS: <fs1>. 

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. 

  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. 

END-OF-SELECTION. 

  LOOP AT intern. 
    intern1 = intern. 
    CLEAR intern1-row. 
    APPEND intern1. 
  ENDLOOP. 

  SORT intern1 BY col. 
  LOOP AT intern1. 
    AT NEW col. 
      t_col-col = intern1-col. 
      APPEND t_col. 
    ENDAT. 
    zwlen = strlen( intern1-value ). 
    READ TABLE t_col WITH KEY col = intern1-col. 
    IF sy-subrc EQ 0. 
      IF zwlen > t_col-size. 
        t_col-size = zwlen. 
*                          Internal Table, Current Row Index 
        MODIFY t_col INDEX sy-tabix. 
      ENDIF. 
    ENDIF. 
  ENDLOOP. 

  DESCRIBE TABLE t_col LINES zwlines. 

  SORT intern BY row col. 
  IF kzheader = 'X'. 
    LOOP AT intern. 
      fieldnames-title = intern-value. 
      APPEND fieldnames. 
      AT END OF row. 
        EXIT. 
      ENDAT. 
    ENDLOOP. 
  ELSE. 
    DO zwlines TIMES. 
      WRITE sy-index TO fieldnames-title. 
      APPEND fieldnames. 
    ENDDO. 
  ENDIF. 

  SORT intern BY row col. 
  LOOP AT intern. 
    IF kzheader = 'X' 
    AND intern-row = 1. 
      CONTINUE. 
    ENDIF. 
    tind = intern-col. 
    CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld. 
    ASSIGN (zwfeld) TO <fs1>. 
    <fs1> = intern-value. 
    AT END OF row. 
      APPEND data_tab. 
      CLEAR data_tab. 
    ENDAT. 
  ENDLOOP. 

  CALL FUNCTION 'DISPLAY_BASIC_LIST' 
       EXPORTING 
            file_name     = filename 
       TABLES 
            data_tab      = data_tab 
            fieldname_tab = fieldnames. 

*-- End of Program

Uploading Excel file to SAP Using Function Module TEXT_CONVERT_XLS_TO_SAP

REPORT  zupload_excel_to_itab.

TYPE-POOLS: truxs.

PARAMETERS: p_file TYPE  rlgrap-filename.

TYPES: BEGIN OF t_datatab,
      col1(30)    TYPE c,
      col2(30)    TYPE c,
      col3(30)    TYPE c,
      END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
      wa_datatab type t_datatab.

DATA: it_raw TYPE truxs_t_text_data.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.


***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  'X'
      i_tab_raw_data           =  it_raw       " WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = it_datatab[]    "ACTUAL 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.


***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
  LOOP AT it_datatab INTO wa_datatab.
    WRITE:/ wa_datatab-col1,
            wa_datatab-col2,
            wa_datatab-col3.
  ENDLOOP.

here are the links for further details

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

http://www.sap-img.com/abap/upload-direct-excel.htm

reward if helpful

raam

prasanth_kasturi
Active Contributor
0 Kudos
97

hi

try the following code

TYPES: BEGIN OF ty_mara,

matnr LIKE mara-matnr,

mbrsh LIKE mara-mbrsh,

mtart LIKE mara-mtart,

maktx LIKE makt-maktx,

meins LIKE mara-meins,

END OF ty_mara.

DATA: it_mara TYPE table of ty_mara WITH HEADER LINE.

parameters : p_file like RLGRAP-FILENAME.

data : itab type table of ALSMEX_TABLINE WITH HEADER LINE.

start-of-selection.

*

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = 1

i_begin_row = 1

i_end_col = 5

i_end_row = 4

tables

intern = itab.

loop at itab.

CASE ITAB-COL.

WHEN '1'.

it_mara-matnr = ITAB-VALUE.

WHEN '2'.

it_mara-mbrsh = ITAB-VALUE.

WHEN '3'.

it_mara-mbrsh = ITAB-VALUE.

WHEN '4'.

it_mara-maktx = ITAB-VALUE.

WHEN '5'.

it_mara-meins = ITAB-VALUE.

ENDCASE.

AT END OF ROW.

APPEND it_mara.

CLEAR it_mara.

ENDAT.

endloop.

loop at it_mara.

write 😕 it_mara-matnr.

endloop.

The XML document can be stored in an ABAP variable rxml of the type STRING or XSTRING, or in an internal standard table sxml of the elementary line type C. Hence, I believe, your issue with the lenght can be resovled with this types.

For rxml, you specify an interface reference variable of the type IF_IXML_OSTREAM that points to an IXML output stream.

For rxml, you specify an interface reference variable of the type IF_IXML_DOCUMENT that points to an IXML document.

With the stream factory you have several options. Before you call your CALL TRANSFORMATION, you setup your stream factory for these different options.

1. You want to write the file to the application server file system. You want to create your OSTREAM as a binary string. In this example b_xml is an empty binary string. OSTEAM will be the reference variable of tyep IF_IXML_OSTREAM.

ostream =

streamfactory->create_ostream_xstring( b_xml ).

You get the output lenght with the following:

ressize = ostream->get_num_written_raw( ).

You can then send the entire string to the file system with the following:

transfer b_xml to filename1 length ressize.

regards

prasanth

venkat_o
Active Contributor
0 Kudos
97

Hi Raj, Use Function module TEXT_CONVERT_XML_TO_SAP. Regards, Venkat.O