Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI or RFC to create material

Former Member
0 Kudos

Hi folks,

Could any one tell me, if there is any BAPI or RFC to create Material in Material master....if so pls tel me the name and how to use the BAPI...thanks in advance,

santosh.

3 REPLIES 3

Former Member
0 Kudos

BAPI_MATERIAL_SAVEDATA is the best one. if you want for mass data maintenance use savereplica instead of savedata.(BAPI_MATERIAL_SAVEREPLICA)

here is a link...

http://www.jt77.com/development1/programming-24945.html

Edited by: Jyothi on Feb 11, 2008 1:37 PM

Former Member
0 Kudos

Check out this related thread

Regards,

Santosh

Former Member
0 Kudos

HI CHECK OU THIS PROGRAM

*&----


*

*& Report ZBAPI_MATERIAL_SAVEDATA

*&

*&----


*

**& AUTHOR *

*&----


*& PURPOSE : THIS REPORT USES BAPI MATERIAL SAVE DATA TO UPDATE AND CREATE

*& THE MATERIAL

*&

*&

*&

*&

*&----


*

REPORT ZBAPI_MATERIAL_SAVEDATA NO STANDARD PAGE HEADING MESSAGE-ID (ZHNC).

TYPES:BEGIN OF TY_MAT,

MATERIAL(4),

IND_SECTOR(1),

MATL_TYPE(4),

      • BASIC_VIEW(1),*

      • SALES_VIEW(1),*

      • PURCHASE_VIEW(1),*

    • STORAGE_VIEW(1),*

MATL_GROUP(9),

BASE_UOM(3),

BASE_UOM_ISO(3),

    • MATL_GROUP1(1),*

    • BASE_UOM1(1),*

    • BASE_UOM_ISO1(1),*

PLANT(4),

DEL_FLAG(1),

PUR_GROUP(3),

BASE_QTY(13),

    • PLANT2(4),*

    • DEL_FLAG5(1),*

    • PUR_GROUP1(1),*

    • BASE_QTY1(1),*

    • PLANT3(4),*

STGE_LOC(4),

MRP_IND(1),

    • PLANT4(4),*

    • STGE_LOC1(4),*

    • MRP_IND1(1),*

SALES_ORG(4),

DISTR_CHAN(2),

DEL_FLAG1(1),

MIN_ORDER(13),

    • SALES_ORG1(4),*

    • DISTR_CHAN1(2),*

    • DEL_FLAG2(1),*

    • MIN_ORDER1(1),*

LANGU(2),

MATL_DESC(40),

END OF TY_MAT.

DATA: IT_DATA TYPE TABLE OF TY_MAT,

WA_DATA LIKE LINE OF IT_DATA.

*decalraing flag

data: v_flag value ''.

*DECLARING WORK AREAs TO BE PASSED TO THE FUNCTION MODULE.

DATA: BAPI_HEAD LIKE BAPIMATHEAD,

BAPI_CLIENTDATA LIKE BAPI_MARA,

BAPI_CLIENTDATAX LIKE BAPI_MARAX,

BAPI_PLANTDATA LIKE BAPI_MARC,

BAPI_PLANTDATAX LIKE BAPI_MARCX,

BAPI_STORAGELOCATIONDATA LIKE BAPI_MARD,

BAPI_STORAGELOCATIONDATAX LIKE BAPI_MARDX,

BAPI_SALESDATA LIKE BAPI_MVKE,

BAPI_SALESDATAX LIKE BAPI_MVKEX,

BAPI_MAKT LIKE BAPI_MAKT,

BAPI_RETURN LIKE BAPIRET2.

*INTERNAL TABLE TO HOLD THE MATERIAL DESCRIPTION

DATA: BEGIN OF IT_MAKT OCCURS 0.

INCLUDE STRUCTURE BAPI_MAKT.

DATA END OF IT_MAKT.

DATA:BEGIN OF IT_RET OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA END OF IT_RET.

*INTERNAL TABLE TO HOLD HEADER DATA

DATA: IT_EXCEL TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

*SELECTION-SCREEN ELEMENTS

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETER: FNAME TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT 'C:\Documents and Settings\Administrator\Desktop\MATMAS.XLS' .

PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,

P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY,

P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,

P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.

SELECTION-SCREEN END OF BLOCK B1.

*DECLARATION OF EXCELAL TABLE

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FNAME.

PERFORM F_GET_FILE USING FNAME.

START-OF-SELECTION.

PERFORM F_XLS_ITAB USING FNAME

CHANGING IT_EXCEL.

PERFORM F_MOVE_DATA.

perform F_GET_DATA.

*&----


*

*& Form F_GET_FILE

*&----


*

    • text*

*----


*

    • -->P_FNAME text*

    • <--P_SY_SUBRC text*

*----


*

FORM F_GET_FILE USING P_FNAME LIKE FNAME.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

PROGRAM_NAME = SYST-REPID

DYNPRO_NUMBER = SYST-DYNNR

    • FIELD_NAME = ' '*

    • STATIC = ' '*

    • MASK = ' '*

CHANGING

FILE_NAME = P_FNAME

    • EXCEPTIONS*

    • MASK_TOO_LONG = 1*

    • OTHERS = 2*

.

IF SY-SUBRC <> 0.

MESSAGE E006(ZHNC).

ENDIF.

ENDFORM. " F_GET_FILE

*&----


*

*& Form F_XLS_ITAB

*&----


*

    • text*

*----


*

    • -->P_FNAME text*

    • <--P_IT_EXCEL text*

*----


*

FORM F_XLS_ITAB USING P_FNAME

CHANGING P_IT_EXCEL.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = FNAME

I_BEGIN_COL = P_BEGCOL

I_BEGIN_ROW = P_BEGROW

I_END_COL = P_ENDCOL

I_END_ROW = P_ENDROW

TABLES

INTERN = IT_EXCEL

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.*

ENDIF.

ENDFORM. " F_XLS_ITAB

*&----


*

*& Form F_MOVE_DATA

*&----


*

    • text*

*----


*

    • --> p1 text*

    • <-- p2 text*

*----


*

FORM F_MOVE_DATA .

DATA : LV_INDEX TYPE I.

FIELD-SYMBOLS <FS>.

*--- Sorting the internal table

SORT IT_EXCEL BY ROW COL.

CLEAR IT_EXCEL.

LOOP AT IT_EXCEL.

MOVE IT_EXCEL-COL TO LV_INDEX.

*--- Assigning the each record to an internal table row

ASSIGN COMPONENT LV_INDEX OF STRUCTURE WA_DATA TO <FS>.

*--- Asigning the field value to a field symbol

MOVE IT_EXCEL-VALUE TO <FS>.

AT END OF ROW.

APPEND WA_DATA TO IT_DATA.

CLEAR WA_DATA.

ENDAT.

ENDLOOP.

***

ENDFORM. " F_MOVE_DATA

*&----


*

*& Form F_GET_DATA

*&----


*

    • text*

*----


*

    • --> p1 text*

    • <-- p2 text*

*----


*

FORM F_GET_DATA .

LOOP AT IT_DATA INTO WA_DATA.

MOVE-CORRESPONDING WA_DATA TO BAPI_HEAD.

BAPI_HEAD-BASIC_VIEW ='X'.

BAPI_HEAD-SALES_VIEW ='X'.

BAPI_HEAD-PURCHASE_VIEW ='X'.

BAPI_HEAD-STORAGE_VIEW ='X'.

MOVE-CORRESPONDING WA_DATA TO BAPI_CLIENTDATA.

BAPI_CLIENTDATAX-MATL_GROUP = 'X'.

BAPI_CLIENTDATAX-BASE_UOM = 'X'.

BAPI_CLIENTDATAX-BASE_UOM_ISO = 'X'.

MOVE-CORRESPONDING WA_DATA TO BAPI_PLANTDATA.

BAPI_PLANTDATAX-PLANT = BAPI_PLANTDATA-PLANT.

BAPI_PLANTDATAX-DEL_FLAG = 'X'.

BAPI_PLANTDATAX-PUR_GROUP = 'X'.

BAPI_PLANTDATAX-BASE_QTY = 'X'.

MOVE-CORRESPONDING WA_DATA TO BAPI_STORAGELOCATIONDATA.

BAPI_STORAGELOCATIONDATA-PLANT = BAPI_PLANTDATA-PLANT.

BAPI_STORAGELOCATIONDATAX-PLANT = BAPI_STORAGELOCATIONDATA-PLANT.

BAPI_STORAGELOCATIONDATAX-STGE_LOC = BAPI_STORAGELOCATIONDATA-STGE_LOC.

BAPI_STORAGELOCATIONDATAX-MRP_IND = 'X'.

MOVE-CORRESPONDING WA_DATA TO BAPI_SALESDATA.

BAPI_SALESDATAX-SALES_ORG = BAPI_SALESDATA-SALES_ORG.

BAPI_SALESDATAX-DISTR_CHAN = BAPI_SALESDATA-DISTR_CHAN.

BAPI_SALESDATAX-DEL_FLAG = BAPI_SALESDATA-DEL_FLAG.

BAPI_SALESDATAX-MIN_ORDER = 'X'.

REFRESH IT_MAKT.

IT_MAKT-LANGU = WA_DATA-LANGU.

IT_MAKT-MATL_DESC = WA_DATA-MATL_DESC.

APPEND IT_MAKT.

CLEAR IT_RET.

REFRESH IT_RET.

PERFORM F_CALL_BAPI.

READ TABLE IT_RET WITH KEY TYPE = 'S'.

IF SY-SUBRC EQ 0.

PERFORM F_BAPI_COMMIT.

WRITE:/ 'MATERIAL CREATED OR UPDATED SUCESSFULLY WITH MATERIAL NO',WA_DATA-MATERIAL.

ELSE.

MESSAGE E000(ZHNC) WITH 'ERROR IN CREATING THE MATERIAL'.

*WRITE: / 'ERROR IN CREATIN MATERIAL',IT_RET-MESSAGE.

*PERFORM F_DOWNLOAD.

ENDIF.

*ENDIF.

ENDLOOP.

ENDFORM. " F_GET_DATA

*&----


*

*& Form F_CALL_BAPI

*&----


*

    • text*

*----


*

    • --> p1 text*

    • <-- p2 text*

*----


*

FORM F_CALL_BAPI .

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

HEADDATA = BAPI_HEAD

CLIENTDATA = BAPI_CLIENTDATA

CLIENTDATAX = BAPI_CLIENTDATAX

PLANTDATA = BAPI_PLANTDATA

PLANTDATAX = BAPI_PLANTDATAX

STORAGELOCATIONDATA = BAPI_STORAGELOCATIONDATA

STORAGELOCATIONDATAX = BAPI_STORAGELOCATIONDATAX

SALESDATA = BAPI_SALESDATA

SALESDATAX = BAPI_SALESDATAX

IMPORTING

RETURN = IT_RET

TABLES

MATERIALDESCRIPTION = IT_MAKT

    • UNITSOFMEASURE =*

    • UNITSOFMEASUREX =*

    • INTERNATIONALARTNOS =*

    • MATERIALLONGTEXT =*

    • TAXCLASSIFICATIONS =*

    • RETURNMESSAGES =*

    • PRTDATA =*

    • PRTDATAX =*

    • EXTENSIONIN =*

    • EXTENSIONINX =*

.

APPEND IT_RET.

ENDFORM. " F_CALL_BAPI

*&----


*

*& Form F_BAPI_COMMIT

*&----


*

    • text*

*----


*

    • --> p1 text*

    • <-- p2 text*

*----


*

FORM F_BAPI_COMMIT .

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    • EXPORTING*

    • WAIT =*

    • IMPORTING*

    • RETURN =*

.

ENDFORM. " F_BAPI_COMMIT

IF U WANT THE EXCEL FILE I CAN SEND U

PLZ REWARD POINTS TO HELP ANSWERS