0% found this document useful (0 votes)
339 views3 pages

BAPI - Material Save Data

This document describes uploading material text to SAP using BAPIs. It details converting an Excel file to an internal table, passing the table values to the BAPI_MATERIAL_SAVEDATA function along with other required fields, committing the transaction, and returning any errors.

Uploaded by

Gjkk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
339 views3 pages

BAPI - Material Save Data

This document describes uploading material text to SAP using BAPIs. It details converting an Excel file to an internal table, passing the table values to the BAPI_MATERIAL_SAVEDATA function along with other required fields, committing the transaction, and returning any errors.

Uploaded by

Gjkk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

*&---------------------------------------------------------------------*

*& Report ZMM_MATERIALTEXT_UPLOAD


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmm_materialtext_upload.

TYPES : BEGIN OF ty_bapi,


matnr TYPE string,
werks TYPE string,
text TYPE string,
END OF ty_bapi .

DATA : it_bapi TYPE TABLE OF ty_bapi INITIAL SIZE 0,


w_bapi TYPE ty_bapi.

DATA : it_text TYPE TABLE OF bapi_mltx,


wa_text TYPE bapi_mltx.

DATA : it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,


wa_return TYPE bapiret2.

DATA : wa_headdata TYPE bapimathead,


wa_plantdata TYPE bapi_marc,
wa_palntdatax TYPE bapi_marcx.

DATA : w_rawdata TYPE truxs_t_text_data.


DATA : w_fname TYPE string.

*&---------------------------------------------------------------------*
*& Selection Screen Declarations
*&---------------------------------------------------------------------*
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-b01.
PARAMETERS : p_fname TYPE rlgrap-filename,
p_header TYPE i DEFAULT 1.
SELECTION-SCREEN : END OF BLOCK b1.

***********************************************F4 Help ******************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'


EXPORTING
program_name = sy-repid
CHANGING
file_name = p_fname.

***************************************** Converting Text to XLS ******

START-OF-SELECTION .

w_fname = p_fname.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER = 'X'
i_tab_raw_data = w_rawdata
i_filename = p_fname
TABLES
i_tab_converted_data = it_bapi[].

DO p_header TIMES.
DELETE it_bapi INDEX 1.
ENDDO.

****************************************************** passing values to BA


PI **********

IF it_bapi[] IS NOT INITIAL.

clear : wa_headdata,
wa_palntdatax,
wa_plantdata.
"wa_text .
LOOP AT it_bapi INTO w_bapi.

* wa_headdata-material = w_bapi-matnr .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_bapi-matnr
IMPORTING
output = wa_headdata-material.
wa_headdata-purchase_view = 'X'.
wa_plantdata-plant = w_bapi-werks .
wa_palntdatax-plant = w_bapi-werks .
wa_text-applobject = 'MATERIAL'.
wa_text-text_name = wa_headdata-material.
* wa_text-text_name = w_bapi-matnr .
wa_text-text_id = 'BEST'.
wa_text-langu = sy-langu .
wa_text-text_line = w_bapi-text .

APPEND wa_text TO it_text .

CLEAR : wa_text .

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'


EXPORTING
headdata = wa_headdata
plantdata = wa_plantdata
plantdatax = wa_palntdatax
IMPORTING
return = wa_return
TABLES
materiallongtext = it_text.

APPEND wa_return TO it_return .


CLEAR : wa_return .

refresh : it_text .
ENDLOOP.
ENDIF.

****************************************ERROR MSG*********************

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'


EXPORTING
wait = 'X'
IMPORTING
return = it_return.

LOOP AT it_return.
WRITE / it_return-message.
ENDLOOP.

You might also like