Application Development and Automation 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: 
Read only

LSMW using BAPI

Former Member
0 Likes
1,213

Hi all,

I want to upload a simple "Material Master-Basic Data View" alone using LSMW BAPI Method. I've done it using the BDC recording method and it's working fine. So Please throw some light on the BAPI Method. Any body have the steps to be followed for the BAPI method. If so please send me the link or mail to me in "mr.altruistic@gmail.com". Any help will be useful.

Thanks & Regards,

Ramakrishnan.G

6 REPLIES 6
Read only

Former Member
0 Likes
1,017

First, though the LSMW have 4 way to inbound include IDOC and BAPI, the IDOC mentioned in BAPI is different with IDOC way.

If you want to configure in a BAPI way, first you need to create a ALE message for a BAPI, you can do this in the BAPI explore, show a BAPI, and double click the ALE message field on the screen, or though the tcode BDBG.

After you create the ALE message for this BAPI, the server will automatively generate a new ALE idoc message type, and two function inbound and outbound to handle this kind of idoc. You only need to remeber the new ALE message type name.

Next, you can configure the LSMW for BAPI ,(if you don't do the first step, the BO can't been choosen in the LSMW).

Then you choose the BO and method appropriately. The target structure of this LSMW scenario is the IDOC type of you create for this BAPI.

Then left steps are similar with normally LSMW step. Something specially, you will find the ALE IDOC message is very likely the interface you can BAPI, but added a control header for IDOC.

As the LSMW only inbound in the local, the control header should keep the default value LSMW set, a file port BAPI assigned to the send port.

If everything goes well, when you run LSMW scenario, the target structure will be filled, and send to the ALE layer, just generate a ALE IDOC and send to system, the effect of it just like you call BAPI, but in a asynchronous way.

Thanks,

Read only

Former Member
0 Likes
1,017

Hi Ram,

Use

<b>BAPI_STANDARDMATERIAL_CREATE</b> bapi to upload data.

it will contain all views.

Check the following code. It uses pc file to upload data to MM01.

REPORT Z_BAPI_MAT.

**********************************************************************

  • STRUCTURE DECLARATIONS *

**********************************************************************

TABLES: BAPIMATHEAD, "Headerdata

BAPI_MARA, "Clientdata

BAPI_MARAX, "Clientdatax

BAPI_MARC, "Plantdata

BAPI_MARCX, "Plantdatax

BAPI_MAKT, "Material description

BAPIRET2. "Return messages

DATA:V_FILE TYPE STRING.

DATA:

BEGIN OF LSMW_MATERIAL_MASTER,

MATNR(018) TYPE C, "Material number

MTART(004) TYPE C, "Material type

MBRSH(001) TYPE C, "Industry sector

WERKS(004) TYPE C, "Plant

MAKTX(040) TYPE C, "Material description

DISMM(002) TYPE C, "Extra Field Added In the Program as itsrequired

MEINS(003) TYPE C, "Base unit of measure

MATKL(009) TYPE C, "Material group

SPART(002) TYPE C, "Division

LABOR(003) TYPE C, "Lab/office

PRDHA(018) TYPE C, "Product hierarchy

MSTAE(002) TYPE C, "X-plant matl status

MTPOS_MARA(004) TYPE C, "Gen item cat group

BRGEW(017) TYPE C, "Gross weight

GEWEI(003) TYPE C, "Weight unit

NTGEW(017) TYPE C, "Net weight

GROES(032) TYPE C, "Size/Dimensions

MAGRV(004) TYPE C, "Matl grp pack matls

BISMT(018) TYPE C, "Old material number

WRKST(048) TYPE C, "Basic material

PROFL(003) TYPE C, "DG indicator profile

KZUMW(001) TYPE C, "Environmentally rlvt

BSTME(003) TYPE C, "Order unit

VABME(001) TYPE C,

EKGRP(003) TYPE C, "Purchasing group

XCHPF(001) TYPE C, "Batch management

EKWSL(004) TYPE C, "Purchasing key value

WEBAZ(003) TYPE C, "GR processing time

MFRPN(040) TYPE C, "Manufacturer part number

MFRNR(010) TYPE C, "Manufacturer number

VPRSV(001) TYPE C, "Price control indicator

STPRS(015) TYPE C, "Standard price

BWPRH(014) TYPE C, "Commercial price1

BKLAS(004) TYPE C, "Valuation class

END OF LSMW_MATERIAL_MASTER.

**********************************************************************

  • INTERNAL TABLE DECLARATIONS *

**********************************************************************

*to store the input data

DATA:

BEGIN OF it_matmaster OCCURS 0.

INCLUDE STRUCTURE LSMW_MATERIAL_MASTER.

DATA:

END OF it_matmaster.

*for material description

DATA:BEGIN OF IT_MATERIALDESC OCCURS 0.

INCLUDE STRUCTURE BAPI_MAKT .

DATA:END OF IT_MATERIALDESC.

*to return messages

DATA:BEGIN OF IT_RETURN OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA:END OF IT_RETURN.

************************************************************************

  • SELECTION SCREEN

************************************************************************

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

PARAMETERS:P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1 .

************************************************************************

  • AT SELECTION SCREEN

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE.

**********************************************************************

  • TO UPLOAD THE DATA *

**********************************************************************

START-OF-SELECTION.

V_FILE = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = V_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = IT_MATMASTER

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF sy-subrc <> 0.

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

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

ENDIF.

**********************************************************************

  • DATA POPULATIONS *

**********************************************************************

LOOP AT IT_MATMASTER.

BAPIMATHEAD-MATERIAL = IT_MATMASTER-MATNR.

BAPIMATHEAD-IND_SECTOR = IT_MATMASTER-Mbrsh.

BAPIMATHEAD-MATL_TYPE = IT_MATMASTER-Mtart.

BAPIMATHEAD-BASIC_VIEW = 'X'.

BAPIMATHEAD-PURCHASE_VIEW = 'X'.

BAPIMATHEAD-ACCOUNT_VIEW = 'X'.

BAPI_MARA-MATL_GROUP = IT_MATMASTER-MATKL.

BAPI_MARA-OLD_MAT_NO = IT_MATMASTER-BISMT.

BAPI_MARA-BASE_UOM = IT_MATMASTER-MEINS.

BAPI_MARA-BASIC_MATL = IT_MATMASTER-WRKST.

BAPI_MARA-MFR_NO = IT_MATMASTER-MFRNR.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-OLD_MAT_NO = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

BAPI_MARAX-BASIC_MATL = 'X'.

BAPI_MARAX-MFR_NO = 'X'.

BAPI_MARC-PLANT = IT_MATMASTER-WERKS.

BAPI_MARC-PUR_GROUP = IT_MATMASTER-EKGRP.

BAPI_MARCX-PLANT = IT_MATMASTER-WERKS.

BAPI_MARCX-PUR_GROUP = 'X'.

IT_MATERIALDESC-LANGU = 'EN'.

IT_MATERIALDESC-MATL_DESC = IT_MATMASTER-MAKTX.

append IT_materialdesc.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

CLIENTDATA = BAPI_MARA

CLIENTDATAX = BAPI_MARAx

PLANTDATA = BAPI_MARc

PLANTDATAX = BAPI_MARcx

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

  • VALUATIONDATA =

  • VALUATIONDATAX =

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA =

  • SALESDATAX =

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

  • FLAG_ONLINE = ' '

  • FLAG_CAD_CALL = ' '

IMPORTING

RETURN = IT_RETURN

TABLES

MATERIALDESCRIPTION = IT_MATERIALDESC

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

  • RETURNMESSAGES =

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

WRITE:/ IT_RETURN-TYPE,

2 IT_RETURN-ID,

22 IT_RETURN-NUMBER,

25 IT_RETURN-MESSAGE.

  • IT_RETURN-LOG_NO,

  • IT_RETURN-LOG_MSG_NO,

  • IT_RETURN-MESSAGE_V1,

  • IT_RETURN-MESSAGE_V2,

  • IT_RETURN-MESSAGE_V3,

  • IT_RETURN-MESSAGE_V4,

  • IT_RETURN-PARAMETER,

  • IT_RETURN-ROW,

  • IT_RETURN-FIELD,

  • IT_RETURN-SYSTEM.

ENDLOOP.

Read only

Former Member
0 Likes
1,017

Ram,

I have dropped the documents to your id. check whether it is worthwhile.

Rrds

TM

Read only

Former Member
0 Likes
1,017

Check this link aswell

rgds

TM

Read only

Former Member
0 Likes
1,017

Hello,

In SAP 46C, the following bapi could be used to post the Material Data:

Business object BUS1001006

Method SAVEDATA

Message type MATMAS_BAPI

Basic type MATMAS_BAPI01

The above object uses the BAPI: BAPI_MATERIAL_SAVEDATA to post the data.

Hope this helps.

Best Regards, Murugesh AS

Read only

Former Member
0 Likes
1,017

HI

GOOD

GO THROUGH THIS LINK WHICH WILL GIVE YOU THE DETAILS IDEA OF LSMW USING BAPI.

http://sap.niraj.tripod.com/id61.html

THANKS

MRUTYUN