16 Aralık 2011 Cuma

SAP/ABAP: BAPI_MATERIAL_SAVEDATA FM

*&---------------------------------------------------------------------*
*& Report  ZPPP_BAPI_MATERIAL_SAVEDATA
*&---------------------------------------------------------------------*

REPORT  ZPPP_BAPI_MATERIAL_SAVEDATA.

TABLES:BAPIMATHEAD,
BAPI_MAKT,
BAPI_MARA,
BAPI_MARAX.

DATA:BEGIN OF ITAB OCCURS 0,
MATERIAL TYPE BAPIMATHEAD-MATERIAL,
IND_SECTOR(20),
MATL_TYPE TYPE BAPIMATHEAD-MATL_TYPE,
MATL_GROUP TYPE BAPI_MARA-MATL_GROUP,
MATL_DESC TYPE BAPI_MAKT-MATL_DESC,
END OF ITAB,
IT_RETURN LIKE BAPIRET2,
IT_BAPI LIKE BAPI_MAKT OCCURS 0 WITH HEADER LINE.

DATA: GT_DATA TYPE TABLE OF ZPPT_SAVE_MATER,
GS_DATA TYPE ZPPT_SAVE_MATER.
DATA: GS_QMAT TYPE QMAT.

START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM CALL_BAPI.

*&---------------------------------------------------------------------*
*&      Form  CALL_BAPI
*&---------------------------------------------------------------------*
FORM CALL_BAPI.
IF GT_DATA IS NOT INITIAL.

DATA: BEGIN OF LS_MARA,
MTART TYPE MARA-MTART,
MEINS TYPE MARA-MEINS,
END OF LS_MARA.

DATA: LV_MAKTX TYPE MAKT-MAKTX.

LOOP AT GT_DATA INTO GS_DATA.

SELECT SINGLE MTART MEINS
FROM MARA
INTO LS_MARA
WHERE MATNR EQ GS_DATA-MATNR.

SELECT SINGLE MAKTX
FROM MAKT
INTO LV_MAKTX
WHERE MATNR EQ GS_DATA-MATNR
AND SPRAS EQ 'T'.
BAPIMATHEAD-MATERIAL = GS_DATA-MATNR.
BAPIMATHEAD-QUALITY_VIEW = 'X'.
BAPIMATHEAD-IND_SECTOR = 'M'.
BAPIMATHEAD-MATL_TYPE = LS_MARA-MTART.
BAPIMATHEAD-BASIC_VIEW = 'X'.

"    BAPI_MARA-MATL_GROUP = ITAB-MATL_GROUP.
BAPI_MARA-BASE_UOM = LS_MARA-MEINS.
"    BAPI_MARAX-MATL_GROUP = 'X'.
BAPI_MARAX-BASE_UOM = 'X'.
IT_BAPI-LANGU_ISO = 'TR'."SY-LANGU. "'T'.
IT_BAPI-MATL_DESC = LV_MAKTX.
APPEND IT_BAPI.
CLEAR IT_BAPI.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA            = BAPIMATHEAD
"        CLIENTDATA          = BAPI_MARA
"        CLIENTDATAX         = BAPI_MARAX
IMPORTING
RETURN              = IT_RETURN
TABLES
MATERIALDESCRIPTION = IT_BAPI.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .

PERFORM QMAT_INSERT.
WRITE:
/ 'TYPE: ', IT_RETURN-TYPE,
/ 'MSG.: ', IT_RETURN-MESSAGE,
/ 'ID  : ', IT_RETURN-ID,
/ 'NUMB: ', IT_RETURN-NUMBER.
ULINE.
ENDLOOP.
ENDIF.
ENDFORM.                    " call_bapi

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
FORM GET_DATA .

SELECT *
FROM ZPPT_SAVE_MATER
INTO TABLE GT_DATA
WHERE ZCHECK NE 'X'.

ENDFORM.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  QMAT_INSERT
*&---------------------------------------------------------------------*
FORM QMAT_INSERT .
SELECT SINGLE *
FROM QMAT
INTO GS_QMAT
WHERE WERKS EQ '1000'.

GS_QMAT-MATNR = GS_DATA-MATNR.

INSERT QMAT FROM GS_QMAT. COMMIT WORK.

ENDFORM.                    " QMAT_INSERT

Hiç yorum yok:

Yorum Gönder

İnsdroid

Sabahtan beri çatada çutada çatada çutada… Bitmedi yine de… Neyse, yolumuz uzun, toparlıyorum çantamı, adaptörü falan tıkıştırıyorum bir şe...