How to create material(mm01) through function module or bapi
Hi,
this is kiran iam sap fresher.
Hi,
try this
*& Report ZKAR_MATMAS_BAPI
*& This program demonstrates how easy it is to create Material master
*& data using BAPI_MATERIAL_SAVEDATA
*& The program also generates a report post-execution displaying errors
*& as well as successful uploads
REPORT ZKAR_MATMAS_BAPI.
* TABLES
* FLAGS *
DATA: F_STOP. " Flag used to stop processing
* DATA DECLARATIONS *
DATA : V_EMPTY TYPE I, " No. of empty records
V_TOTAL TYPE I. " Total no. of records.
* STRUCTURES & INTERNAL TABLES
*BAPI structures
DATA: BAPI_HEAD LIKE BAPIMATHEAD, " Header Segment with Control Information
BAPI_MAKT LIKE BAPI_MAKT, " Material Description
BAPI_MARA1 LIKE BAPI_MARA, " Client Data
BAPI_MARAX LIKE BAPI_MARAX, " Checkbox Structure for BAPI_MARA
BAPI_MARC1 LIKE BAPI_MARC, " Plant View
BAPI_MARCX LIKE BAPI_MARCX, " Checkbox Structure for BAPI_MARC
BAPI_MBEW1 LIKE BAPI_MBEW, " Accounting View
BAPI_MBEWX LIKE BAPI_MBEWX, " Checkbox Structure for BAPI_MBEW
BAPI_RETURN LIKE BAPIRET2. " Return Parameter
*--- Internal table to hold excel file data
DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
*--- Internal table to hold Matetrial descriptions
DATA: BEGIN OF IT_MAKT OCCURS 100.
INCLUDE STRUCTURE BAPI_MAKT.
DATA: END OF IT_MAKT.
*--- Internal to hold the records in the text file
DATA : BEGIN OF IT_DATA OCCURS 100,
WERKS(4), " Plant
MTART(4), " Material type
MATNR(18), " Material number
MATKL(9) , " Material group
MBRSH(1), " Industry sector
MEINS(3), " Base unit of measure
GEWEI(3), " Weight Unit
SPART(2), " Division
EKGRP(3), " Purchasing group
VPRSV(1), " Price control indicator
STPRS(12), " Standard price
PEINH(3), " Price unit
SPRAS(2), " Language key
MAKTX(40), " Material description
END OF IT_DATA.
* SELECTION SCREEN. *
SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.
PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Input File
'C:\Material_master.XLS'.
PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session
PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines
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 SCR1.
* AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
*--- Validating file
PERFORM VALIDATE_FILE USING P_FILE.
* START-OF-SELECTION
START-OF-SELECTION.
*--- Perform to convert the Excel data into an internal table
PERFORM CONVERT_XLS_ITAB.
IF NOT IT_DATA[] IS INITIAL.
*--- Perform to delete Header lines
PERFORM DELETE_HEADER_EMPTY_RECS.
ENDIF.
* END OF SELECTION. *
END-OF-SELECTION.
*--- Perform to upload Material Master data
PERFORM UPLOAD_MATMAS.
* Form : validate_input_file
* Description : To provide F4 help for file if read from PC
FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
FILE_NAME = F_FILE
EXCEPTIONS
MASK_TOO_LONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE S010(ZLKPL_MSGCLASS). " 'Error in getting filename'.
ENDIF.
ENDFORM. " validate_input_file
*& Form CONVER_XLS_ITAB
* text
FORM CONVERT_XLS_ITAB.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_BEGCOL
I_BEGIN_ROW = P_BEGROW
I_END_COL = P_ENDCOL
I_END_ROW = P_ENDROW
TABLES
INTERN = IT_INTERN.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*--- Perform to move the data into an internal data
PERFORM MOVE_DATA.
ENDFORM. " CONVERT_XLS_ITAB
*& Form MOVE_DATA
* text
FORM MOVE_DATA.
DATA : LV_INDEX TYPE I.
FIELD-SYMBOLS <FS>.
*--- Sorting the internal table
SORT IT_INTERN BY ROW COL.
CLEAR IT_INTERN.
LOOP AT IT_INTERN.
MOVE IT_INTERN-COL TO LV_INDEX.
*--- Assigning the each record to an internal table row
ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO <FS>.
*--- Asigning the field value to a field symbol
MOVE IT_INTERN-VALUE TO <FS>.
AT END OF ROW.
APPEND IT_DATA.
CLEAR IT_DATA.
ENDAT.
ENDLOOP.
ENDFORM. " MOVE_DATA
*& Form DELETE_HEADER_EMPTY_RECS
* To delete the Header and empty records
FORM DELETE_HEADER_EMPTY_RECS.
DATA: LV_TABIX LIKE SY-TABIX.
IF NOT P_HEADER IS INITIAL.
LOOP AT IT_DATA.
IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.
DELETE IT_DATA FROM 1 TO P_HEADER.
* P_HEADER = 0.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
CLEAR IT_DATA.
*--- To delete the empty lines from internal table
LOOP AT IT_DATA.
LV_TABIX = SY-TABIX.
IF IT_DATA IS INITIAL.
V_EMPTY = V_EMPTY + 1.
DELETE IT_DATA INDEX LV_TABIX..
ENDIF.
ENDLOOP.
CLEAR IT_DATA.
*--- Total no of recs in file
DESCRIBE TABLE IT_DATA LINES V_TOTAL.
IF V_TOTAL = 0.
MESSAGE I013(ZLKPL_MSGCLASS). " No records in the file
F_STOP = 'X'.
STOP.
ENDIF.
ENDFORM. " DELETE_HEADER_EMPTY_RECS
*& Form UPLOAD_MATMAS
* to upload Material Master data
FORM UPLOAD_MATMAS .
LOOP AT IT_DATA.
* Header
UNPACK IT_DATA-MATNR TO IT_DATA-MATNR.
BAPI_HEAD-MATERIAL = IT_DATA-MATNR.
BAPI_HEAD-IND_SECTOR = IT_DATA-MBRSH.
BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.
BAPI_HEAD-BASIC_VIEW = 'X'.
BAPI_HEAD-PURCHASE_VIEW = 'X'.
BAPI_HEAD-ACCOUNT_VIEW = 'X'.
* Material Description
REFRESH IT_MAKT.
IT_MAKT-LANGU = IT_DATA-SPRAS.
IT_MAKT-MATL_DESC = IT_DATA-MAKTX.
APPEND IT_MAKT.
* Client Data - Basic
BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.
BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.
BAPI_MARA1-UNIT_OF_WT = IT_DATA-GEWEI.
BAPI_MARA1-DIVISION = IT_DATA-SPART.
BAPI_MARAX-MATL_GROUP = 'X'.
BAPI_MARAX-BASE_UOM = 'X'.
BAPI_MARAX-UNIT_OF_WT = 'X'.
BAPI_MARAX-DIVISION = 'X'.
* Plant - Purchasing
BAPI_MARC1-PLANT = IT_DATA-WERKS.
BAPI_MARC1-PUR_GROUP = IT_DATA-EKGRP.
BAPI_MARCX-PLANT = IT_DATA-WERKS.
BAPI_MARCX-PUR_GROUP = 'X'.
* Accounting
BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.
BAPI_MBEW1-PRICE_CTRL = IT_DATA-VPRSV.
BAPI_MBEW1-STD_PRICE = IT_DATA-STPRS.
BAPI_MBEW1-PRICE_UNIT = IT_DATA-PEINH.
BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.
BAPI_MBEWX-PRICE_CTRL = 'X'.
BAPI_MBEWX-STD_PRICE = 'X'.
BAPI_MBEWX-PRICE_UNIT = 'X'.
*--- BAPI to create material
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
HEADDATA = BAPI_HEAD
CLIENTDATA = BAPI_MARA1
CLIENTDATAX = BAPI_MARAX
PLANTDATA = BAPI_MARC1
PLANTDATAX = BAPI_MARCX
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA = BAPI_MBEW1
* VALUATIONDATAX = BAPI_MBEWX
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA = BAPI_MVKE1
* SALESDATAX = BAPI_MVKEX
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
IMPORTING
RETURN = BAPI_RETURN
TABLES
MATERIALDESCRIPTION = IT_MAKT
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
IF BAPI_RETURN-TYPE = 'E'.
WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,IT_DATA-MATNR.
ELSEIF BAPI_RETURN-TYPE = 'S'.
WRITE: 'Successfully created material' ,IT_DATA-MATNR.
ENDIF.
ENDLOOP.
ENDFORM. " UPLOAD_MATMAS
Similar Messages
-
How to create delta extraction through function module?
Hi all,
So far i have created the data source through full load. But currently i would like to convert the couple of function module generic extraction converted through delta.
Can anyone let me know how to convert from full load to delta using generic extraction
thanksHi,
Try these Links, helps u in getting an idea.
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/30aefb04-7043-2c10-8e92-941536eebc79?QuickLink=index&overridelayout=true
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/30f1a423-02ae-2e10-bd85-bde64e61fe7b?QuickLink=index&overridelayout=true&51947629650864
Regards,
Aravind. -
Save EAN11 field while creating POrder creation through Function module
Hi All,
I want to update EAN11 field in material master while creating Purchase Order through function module. I am using function module BAPI_PO_CREATE1 for creating purchase order. There are no structures in the PO creation FM in which EAN11 field is there. I have also tried using function module MEPO_DOC_ITEM_PROCESS for updating EAN11 field. It is not working. Please suggest some method to do that.
Note: I am receiving EAN11 through an external system by proxy.
Thanks,
ChinmayHi,
Use BAPI_MATERIAL_SAVEDATA to updat ean numbers for materials.
tables INTERNATIONALARTNOS is used to update EAN.
Regards,
Shanmugavel Chandrasekaran -
How to Create a Remotely Enabled Function Module
Hi All,
How to Create a Remotely Enabled Function Module.
I Want to Create a FM Using Sample Data , This for Practice
What Fields can i give in the Import and Export Parameters.
Please Give me one Example
Can Any one Give me the Steps to do this.
Regards
VamsiHi Vamsi,
Lets do simple example where you will first create a RFC in one server (say A) and create normal program in othere server (say B). Finally you will call the RFC in A from B.
Do the following steps for creating RFC in server A.
1. log on to server A
2. go to se37
3. Edit -> function groups-> create function group and give the function group name (say ZGRP).
4. create a FM ( say Z_TEST_RFC) in se37 providing the function group which is created just now.
5. go to attribute tab -> choose remote-enabled module from processing type.
so that your FM will become RFC.
6. provide the import parameter in import tab.
we will provide only two import parameters.
- parameter name : P_NUM1, typing: TYPE, associated type : I & <b>check the pass value</b> (all the parameters of RFC must pass by value).
- parameter name : P_NUM2, typing: TYPE, associated type : I & <b>check the pass value</b>
7. provide the export parameter in export tab.
parameter name : P_SUM, typing: TYPE, associated type : I & <b>check the pass value</b>
8. write the given simple code in source code tab.
FUNCTION Z_TEST_RFC.
P_TOT = P_NUM1 + P_NUM2.
ENDFUNCTION.
Do the following steps for creating ABAP program which will call the RFC in server B.
1. se38 - > creat a program.
2. write the given simple code.
data tot type i.
call function 'Z_TEST_RFC' destination '<b>XXXXXX</b>'
exporting
p_num1 = 10
p_num2 = 15
importing
p_tot = tot.
write tot.
please note that <b>XXXXXX</b> is RFC connection which is avialable in <b>sm59</b> transaction in server A.
-go to sm59 - > abap connection (list of RFC connection configurations are avialable). choose server B connection and replace it of <b>XXXXXX</b> in the code.
finally you can execute the normal abap program that will call the RFC and display the result.
Regards,
Sukhee -
How to create Drop-Down with Function Module REUSE_ALV_GRID_DISPLAY
Hi Experts,
I have used Reuse_alv_grid_display function module in my report for ALV output. I have a requirement to add drop down in one cell of my output. I have searched but all are suggesting through OOPS programing that I can not use.
If it is possible with the given scenerion , please help me how to write the code for it?
Thanks a bunch in advance.Hi,
You can check demo programs:
BCALV_EDIT_06
BCALV_EDIT_07
Hope it helps
Regards
Mansi -
How to create material bom through CS01 if bom created by using ppe
Hi experts,
I have created a material bom through PPE of material A. Now i want to create bom through CS01for same material A.
system shows error "A breakdown (PVS/VA) already exists in iPPE for material".
So how can create bom through CS01?
Suggest me.
Regards,
Nitin NerkarHi,
Please check and implement the below note,
[1311089|https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/sapnotes/index2.htm?numm=1311089]
Thanks
Hrishi -
How to calculate system date through function module date
Hi friends!!
i declare a variable "date like sy-datum".
now i want to add 15 days to the system date,
please give me the function module name which can do it.
xample.
date = sytem date. -> date= 13/08/2010
i want date= 28/08/2010.
please help.
Edited by: sandeep08 on Aug 13, 2010 1:53 PM
Moderator message: date calculation questions = FAQ, please search before posting.
locked by: Thomas Zloch on Aug 13, 2010 2:03 PMHi,
You can directly add 15 to the date. It will give you appropriate results.
Regards,
Aparna Alashe. -
How to update eket data by function module or BAPI?
Dear All :
I have to update all PO's vendor batch data .
I want to find a function module to execute the change , but I can't find a proper one to do the modification.
I have try to use ME_CONFIRMATION_EKET_UPD , but it seems PO need have ekbe data in advance.
Hope someone can offer me a example to update mass eket data .
I don't like to use BDC , I hope I can do the changes by functions.
Thanks .Dear All :
I have to update all PO's vendor batch data .
I want to find a function module to execute the change , but I can't find a proper one to do the modification.
I have try to use ME_CONFIRMATION_EKET_UPD , but it seems PO need have ekbe data in advance.
Hope someone can offer me a example to update mass eket data .
I don't like to use BDC , I hope I can do the changes by functions.
Thanks . -
How Procurement cost can be captured in product master through functional module?
Hi
I have following Queries
1) How Procurement cost can be captured in product master through functional module in SAP APO?
2) How we can transfer procurement cost to product master in SAP APO through BAPI?
Thanks
PoornaHi Poorna,
Could you please check FM /SAPAPO/DM_PRODUCTS_POST.
Table it_matloc of this FM can used to update Cost . -
How to use Logical database in function module?
I will create a function module in HR.
but how to use Logical database in function module ? Logical database PNP always show screen.in function (RFC) code , it is a matter.You cannot attach the LDB to the main program of the function group.
- So you may [SUBMIT|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=submit&adv=false&sortby=cm_rnd_rankvalue] a report which use the LDB and get back the data (export/import), by default in the syntax of SUBMIT the selection-screen will not be displayed
- Use [LDB_PROCESS|https://www.sdn.sap.com/irj/sdn/advancedsearch?query=ldb_process&cat=sdn_all], fill a structured table for selection, and get data back in another table
- Use [HR function modules to read Infotypes|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=hrfunctionmodulestoread+Infotypes&adv=false&sortby=cm_rnd_rankvalue].
Regards -
Printing ALV Report output through Function Modules
Hi All,
I want to print my ALV Grid output through function modules/statement (not through print option in menu).
This is because, i am generating a PDF from spool when user clicks on a button. If any changes happened in the ALV output layout, they will be captured in spool through printing it.
So can you please tell me how to print the ALV Output through FMs or sending the ALV output to spool.
Thanks & Regards,
Senthil.
Edited by: senthil nathan on May 17, 2010 2:49 PMHi Dev,
Thanks for the reply.
I want to print the ALV when the user clicks on a button in toolbar. Lets say the user has made some changes to the layout, (E.g hiding a field) and when i print that output it should use the changed layout, If i use the FM suggested by you, i cant acheive this.
If you try to print this manually, the system uses the changed layout and not the original. Thats why i want to know FMs/statement to print.
Regards,
Senthil. -
How to find out the inbound function module in the extended idoc
Hi,
how to find out the inbound function module in the extended idocs
Thanks .through we41/we42 you can find the inbound function module.......
or
thorough we19(idoc test tool) ....
give the input as message type or basic idoc..
press exec...
then you can find th button on application tool bar as inbound funtion module....
from here also you can find..........
<REMOVED BY MODERATOR>
Khasimsa
Edited by: Alvaro Tejada Galindo on Apr 14, 2008 1:34 PM -
How to Create material master workflow
Hi All,
Can anybody tell me how to create material master workflow?
i need to customize the workitem for creating data in different views in MM01 transaction with restriction to particular user.
Regards,
PritiHi,
This link is to display a material.My requirement is to create a workflow which will allow a responsible person to enter data for specific department data e.g Purchase,Accounting etc.Initially anyone can create data using basic data1 and basic data2 views.After this my workflow will be triggered and it will go to next person who is responsible to enter Purchase data and then Accounting data.
Plz help me to create different views with respect to person.
Thanks in advance. -
How to develop an Remote Enabled Function Module
Hi All,
I'm totally new to ABAP. I have a requirement to create a Remote Enabled Function Module, which I can use to call from an external program like Java using JCo.
The functionality of the Remote Function is to write some data into certain fields of the tables AFPO and JEST.
Can someone please guide me, how to do the above described task. Is there any code snippets available, that would be really gr8.
Thanks & Best Regards,
Chandrasekhar.you shuld have import parameters like this
i_aufnr tpye afpo-aufnr.
i_posnr tpye afpo-posnr.
i_matnr tpye afpo-matnr.
i_wemng tpye afpo-wemng.
i_ltrmi tpye afpo-ltrmi.
i_meins tpye afpo-meins.
i_dwerk tpye afpo-dwerk.
i_objnp tpye afpo-objnp.
i_stat type jest-stat.
in exceptions
enter_key_data.
assume all the fields are mandatory.
types: begin of t_ekpo,
aufnr like ekpo-aufnr,
posnr like ekpo-posnr,
matnr like ekpo-matnr,
wemng like ekpo-wemng,
ltrmi like ekpo-ltrmi,
meins like ekpo-meins,
dwerk like ekpo-dwerk,
objnp like ekpo-objnp, "for Status update
end of t_ekpo.
types: begin of t_jest,
objnr like jest-objnr,
stat like jest-stat,
end of t_jest
data: x_ekpo type t_ekpo,
x_jest type t_jest.
**need to validate before sending it to EKPO.
if not i_aufnr is initial
and not i_posnr is initial
and not i_objnp is initial
and not i_stat is initial.
X_ekpo-aufnr = i_aufnr.
X_ekpo-posnr = i_posnr.
X_ekpo-matnr = i_matnr.
X_ekpo-wemng = i_wemng.
X_ekpo-ltrmi = i_ltrmi.
X_ekpo-meins = i_meins.
X_ekpo-dwerk = i_dwerk.
x_ekpo-objnp = i_objnp.
modify EKPO from X_ekpo .
if sy-subrc = 0.
commit work.
endif.
x_jest-objnr = i_objnp.
x_jest-stat = i_stat.
modify JEst from X_jest .
if sy-subrc = 0.
commit work.
endif.
else.
raise exception enter_key_data.
endif.
please let me know if you need any validation on those.
regards
vijay
Message was edited by: Vijay Babu Dudla -
How to change call to the function module in the standard program
Hi Guru,
My requairment is to create the new Z function module ZJ_1B_IM_NF_DOCUMENT_FUNCTION in the MM07MFJ1 program.
I have created the Z Funtion module,
plz provide me the info how to change the call to the new custom FM from the standard program.
Points will be given to the ans.You use SE38 to change out the code. When you try and change it you will get a popup asking you for a Key, since you are changing SAP Code. If you have a Developers key you have to go to the SAP Service Marketplace and tell SAP that you are changing this code in order to get they key. After this every time you do support packs you run the risk of this getting overlaid and you will have to change it back, also if you have a problem and SAP sees that you customized this code they probably won't spend any time on your problem.
Maybe you are looking for
-
SQL to Oracle Migraton - Unable to create source model in Migration Workben
We are trying to use Oracle Migration Workbench utility to transfer data from SQL to Oracle. when we start creating the source model we get the following error :- failed to load source model ora-01401 inserted value too large for column.. this is the
-
Php configuration issue with libmysqlclient
Hi , I am getting below issue while configuring php 5.3.3 with below command ./configure --with-apxs2=/local/apps/rxapi/apache/bin/apxs --with-openssl --with-mysql=/opt/mysql/mysql --enable-dbase --with-libdir=lib/64 --prefix=/local/apps/rxapi/php5.
-
Field not Known Error in Crystal Report 11
I was using Crystal Report 8.5 earlier and i had a field named "Fee $" in the query and it was working fine when i pull the report in VB Application using Crystal Report Viewer. But when i migrated to Crystal 11 things started breaking. Crystal Repor
-
Resolution & "save as" ? for online photo book
I am making an online photo book through Snapfish. When I am done editing my images using Elements, I go to resize and make it about a 4X6 size with a dpi of 200 or so and "save as" a Jpeg. When I go to Snapfish to put my album together, I sometimes
-
Receiving defective component from Maintenance order
Hi friends, My client wants to capture the defective spares issued against maintenance order in the system.The scenario is for a maintenance order spares(components) are issued through movement type 261 and unused spares(components) are returne