BAPI - Material Save Data

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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