Bapi Creation

CREATE structure.

CREATE FUCNTION MOUDLE.

TOP INCLUDE

SOURCE CODE
FUNCTION ZBAPI_MATEARIAL_STOCK. *"---------------------------------------------------------------------*"*"Local Interface: *" IMPORTING *" VALUE(IM_MATNR) TYPE ZBAPI_MAT_STR-MATERIAL *" VALUE(IM_WERKS) TYPE ZBAPI_MAT_STR-PLANT *" EXPORTING *" VALUE(RETURN) TYPE BAPIRET2 *" TABLES *" IT_DATA STRUCTURE ZBAPI_MAT_STR *"---------------------------------------------------------------------select a~MATNR MTART MATKL werks lgort into table it_mara_mard from mara as a inner join mard as b

on a~matnr = b~matnr where a~matnr EQ im_matnr and werks eq im_werks. IF sy-subrc ne 0. return-TYPE = 'E'. return-ID = 'ZBAPI1'. return-NUMBER = '000'. return-MESSAGE = 'NO data found for entered input'. ENDIF. if not it_mara_mard[] is initial.

select a~MATNR BWKEY LBKUM maktx into table it_makt_mbew from mbew as a inner join makt as b on a~matnr = b~matnr for all entries in it_mara_mard where a~matnr eq it_mara_mard-matnr and bwkey eq it_mara_mard-werks. IF sy-subrc eq 0. sort it_makt_mbew by matnr bwkey. ENDIF.

endif.

*----prcess the 2 tbles adnd fill

the table data of it_data

LOOP AT it_mara_mard into wa_mara_mard. it_data-MATERIAL = wa_mara_mard-matnr. it_data-PLANT = wa_mara_mard-werks. it_data-MATL_TYPE = wa_mara_mard-mtart. it_data-MATL_GROUP = wa_mara_mard-matkl. it_data-STGE_LOC = wa_mara_mard-lgort. read table it_makt_mbew into wa_makt_mbew with key matnr = wa_mara_mardmatnr bwkey = wa_mara_mardwerks binary search. if sy-subrc eq 0. it_data-MATL_DESC = wa_makt_mbew-maktx.

it_data-TOTAL_VALUATED_STOCK = wa_makt_mbew-lbkum. endif. append it_data. clear it_data. ENDLOOP.

ENDFUNCTION.

RELEASE THE FM

CREATE BUSINESS OBJECT IN TCODE SWO1

GIVE THE NAME AND PROGRAM NAME , APPLICATION IS '*'

ADD FM AS METHOD.

REPERAT THE ABOVE STEP FOR COMPONENT AND OBJECTS THEN CLIKC ON BUTTON GENERATE .

GO AND CHECK bUSINESS OBJECT IN BOR ( BAPI ).

Sign up to vote on this title
UsefulNot useful