Thursday, March 23, 2017

Upload material basic data text using excel file

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

13 comments:

  1. I have been a blogger too but you post much technical details. Thank you for sharing your knowledge. The creating experts was my first trainer in SAP ABAP got in depth learning from them

    http://thecreatingexperts.com/sap-abap-training-in-chennai/


    contact +91-08122241286

    ReplyDelete
  2. Thank you. sir, Really I like your post on sap remote access 24x7 available.

    ReplyDelete
  3. excellent blog,thank you for sharing a valuable information to us online abap training in hyderabad

    ReplyDelete
  4. SAP ABAP training is provided in CHENNAI.

    THE CREATING EXPERTS is one of the leading trainer in SAP who provides real time training

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    contact 8122241286

    ReplyDelete
  5. Thank you. It is such a wonderful post. it has great information it is very useful topic on sap hana online access.

    ReplyDelete
  6. Thank you for Wonderful information.

    SAP ABAP training in CHENNAI BY THE CREATING EXPERTS

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    CONTACT 8122241286

    ReplyDelete
  7. The article is great. Thanks for sharing such a amazing and information post. It is very helpful for us and I have gathered some information from this blog.

    ReplyDelete
  8. Thank you. It is such a wonderful post. it has great information it is very useful for sap tutorial videos.

    ReplyDelete
  9. Thankyou for Sharing Great Information. It is Very Helpful Information on sap tutorial videos.

    ReplyDelete
  10. Fabulous..!! Thank you.The information you provided is much usful information on sap training video tutorials.

    ReplyDelete
  11. Thank you. It is such a wonderful post. it has great information it is very useful for sap videos.

    ReplyDelete
  12. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. for more info

    ReplyDelete