SAP Tutorials Blog




 " this program is used for uploading material basic data text using xl file.

"xl file will be consists of two columns, Material number & text field without header.

REPORT zupload_basic_data.

TYPE-POOLS: truxs.
*----DATA DECLARATION

TYPES: BEGIN OF ty_excel,
         matnr TYPE ekpo-matnr,
         text  TYPE string,
       END OF ty_excel.
DATA: it_raw TYPE truxs_t_text_data.
DATA: t_excel TYPE STANDARD TABLE OF ty_excel,
      w_excel TYPE ty_excel.

DATA: BEGIN OF t_desc OCCURS 0,
        header(50) TYPE c,
      END OF t_desc,
      filename TYPE string,
      soldp    TYPE name2,
      shipp    TYPE name2.


SELECTION-SCREEN BEGIN OF BLOCK database-selection
  WITH FRAME TITLE text-001.
PARAMETERS p_file TYPE rlgrap-filename MODIF ID s1.
SELECTION-SCREEN END OF BLOCK database-selection.

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.

" reading the xl file with material & basic text

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = it_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = t_excel[]
    EXCEPTIONS
      convertion_failed    = 1
      OTHERS               = 0.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


  DATA: i_line LIKE TABLE OF tline WITH HEADER LINE,
        head   LIKE thead.

  LOOP AT t_excel INTO w_excel.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = w_excel-matnr
      IMPORTING
        output = w_excel-matnr.

    head-tdobject = 'MATERIAL'.

    head-tdname = w_excel-matnr. "Material number

    head-tdid = 'GRUN'.

    head-tdspras = 'EN'.

    i_line-tdline = w_excel-text.

    APPEND i_line.

    CALL FUNCTION 'SAVE_TEXT'
      EXPORTING
        header          = head
        savemode_direct = 'X'
      TABLES
        lines           = i_line
      EXCEPTIONS
        id              = 1
        language        = 2
        name            = 3
        object          = 4
        OTHERS          = 5.

    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_line.
  ENDLOOP.



Serkan AKKAVAK
Computer Engineer BSc
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com