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

BAPI_MATERIAL_SAVEDATA

Former Member
0 Likes
4,542

Please, help me with this message, I can't create a material.

When I consult the parameter return RETURNMESSAGES, it contains the following.

Thanks for the help

this is my code.

   *&---------------------------------------------------------------------*
*& Report  ZMM_PE_TL10_2F
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*


*———————————————————————*
* Report Name : YGECICI
*———————————————————————*
* Author : Mehmet Avşar
* Location : @Altunizade – Uskudar / Istanbul
* Date / Time : 05 Jan 2007
* Subject : User Exits of Transaction Codes
*———————————————————————*
REPORT ZMM_PE_TL10_2F MESSAGE-ID 00
No Standard Page Heading
Line-Size 200
Line-Count 65.

*TO CREATE MATERIAL USING BAPI.

**********************************************************************
* STRUCTURE DECLARATIONS *
**********************************************************************

TABLES: BAPIMATHEAD, "Headerdata
BAPI_MARA, "Clientdata
BAPI_MARAX, "Clientdatax
BAPI_MARC, "Plantdata
BAPI_MARCX, "Plantdatax
BAPI_MAKT, "Material description
BAPI_MBEW, "VALUATION DATA
BAPI_MBEWX,
BAPI_MARM,
BAPI_MARMX,
bapi_mean,
BAPIRET2. "Return messages

DATA:V_FILE TYPE STRING. "input data file

DATA:
BEGIN OF LSMW_MATERIAL_MASTER,
MATNR(018) TYPE C, "Material number
MTART(004) TYPE C, "Material type
WERKS(004) TYPE C, "Plant
LGORT(004) type C,
MAKTX(040) TYPE C, "Material description
MEINS(003) TYPE C, "Base unit of measure
MATKL(009) TYPE C, "Material group
SPART(002) TYPE C, "Division
GEWEI(003) TYPE C, "Weight unit
MSBOOKPART(018) TYPE C,
EKGRP(003) TYPE C, "Purchasing group
TAXIM(001) TYPE C,
MPROF(004) TYPE C,
MFRPN(040) TYPE C, "Manufacturer part number
MFRNR(010) TYPE C, "Manufacturer number
BWTTY(001) TYPE C,
VPRSV(001) TYPE C, "Price control indicator
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.

*FOR gross wt
data: begin of it_uom occurs 0.
        include structure BAPI_MARM.
data:end of it_uom.

DATA: BEGIN OF IT_UOMX OCCURS 0.
        INCLUDE STRUCTURE BAPI_MARMX.
DATA:END OF IT_UOMX.

data:begin of it_mean occurs 0.
        include structure bapi_mean.
data:end of it_mean.

DATA:BEGIN OF IT_MLTX OCCURS 0.
        INCLUDE STRUCTURE BAPI_MLTX.
DATA:END OF IT_MLTX.
*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.

*ELSE.
*DELETE IT_MATMASTER INDEX 1.
  ENDIF.

**********************************************************************
* DATA POPULATIONS *
**********************************************************************
data: returnmessages TYPE bapi_matreturn2 OCCURS 0.

data: MATERIALNUMBER LIKE BAPIMATINR OCCURS 0.
data: RETURN LIKE BAPIRETURN1.
data: str_material LIKE BAPIMATINR.

  LOOP AT IT_MATMASTER.

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
      EXPORTING
        material_type    = IT_MATMASTER-MTART
        industry_sector  = 'A'
        required_numbers = 1
      IMPORTING
        return           = return
      TABLES
        material_number  = MATERIALNUMBER.


    IF return-type EQ 'S'.
          READ TABLE MATERIALNUMBER INTO str_material INDEX 1.
      IF sy-subrc EQ 0.
        BAPIMATHEAD-MATERIAL = str_material-material.
      ENDIF.
    ENDIF.


*HEADER DATA
    "BAPIMATHEAD-MATERIAL = IT_MATMASTER-MATNR.
    BAPIMATHEAD-IND_SECTOR = 'A'.
    BAPIMATHEAD-MATL_TYPE = IT_MATMASTER-MTART.
    BAPIMATHEAD-BASIC_VIEW = 'X'.
    BAPIMATHEAD-PURCHASE_VIEW = 'X'.
    BAPIMATHEAD-ACCOUNT_VIEW = 'X'.
*CLIENTDATA
    BAPI_MARA-MATL_GROUP = IT_MATMASTER-MATKL.
    BAPI_MARA-DIVISION = IT_MATMASTER-SPART.
    BAPI_MARA-BASE_UOM = IT_MATMASTER-MEINS.
    BAPI_MARA-MANU_MAT = IT_MATMASTER-MFRPN.
    BAPI_MARA-MFR_NO = IT_MATMASTER-MFRNR.
    BAPI_MARA-DOCUMENT = IT_MATMASTER-MSBOOKPART.
*PLANT DATA
    BAPI_MARC-PLANT = IT_MATMASTER-WERKS.
    BAPI_MARC-PUR_GROUP = IT_MATMASTER-EKGRP.
    BAPI_MARCX-PLANT = IT_MATMASTER-WERKS.

*VALUATION DATA
    BAPI_MBEW-VAL_AREA   = IT_MATMASTER-WERKS.
    BAPI_MBEW-PRICE_CTRL = IT_MATMASTER-VPRSV.
    BAPI_MBEW-VAL_CLASS = IT_MATMASTER-BKLAS.

    BAPI_MBEWX-VAL_AREA   = IT_MATMASTER-WERKS.

    IT_MATERIALDESC-MATL_DESC = IT_MATMASTER-MAKTX.
    append IT_materialdesc.


    IT_UOM-UNIT_OF_WT = IT_MATMASTER-GEWEI.
    APPEND IT_UOM.

    "append it_mean.

    "it_mltx-text_name = it_matmaster-matnr.
    "APPEND IT_MLTX.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
    EXPORTING
    headdata = BAPIMATHEAD
    CLIENTDATA = BAPI_MARA
    CLIENTDATAX = BAPI_MARAX
    PLANTDATA = BAPI_MARC
    PLANTDATAX = BAPI_MARCX
    VALUATIONDATA = BAPI_MBEW
    VALUATIONDATAX = BAPI_MBEWX
    IMPORTING
    RETURN = IT_RETURN
    TABLES
    MATERIALDESCRIPTION = IT_MATERIALDESC
    UNITSOFMEASURE = IT_UOM
    "UNITSOFMEASUREX = IT_UOMX
    "INTERNATIONALARTNOS = it_mean
* MATERIALLONGTEXT = IT_MLTX
* TAXCLASSIFICATIONS =
RETURNMESSAGES = returnmessages
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
    .

    read table it_return with key TYPE = 'S'.
    if sy-subrc = 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
      .
*else.
*
*CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
** IMPORTING
** RETURN =
* .
*
    endif.

    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.

9 REPLIES 9
Read only

Arun_Prabhu_K
Active Contributor
0 Likes
3,866

Hello Enrique Aguirre.

     Check whether preceding zeroes are there in MATNR that you are passing to BAPI?  

     If not, use FM CONVERSION_EXIT_ALPHA_INPUT to pad preceding zeroes.

     This you could have avoided if you had declared MATNR like below:


BEGIN OF LSMW_MATERIAL_MASTER,

MATNR(018) TYPE C, "Material number

MATNR type MATNR, "Material Number

     By this way of declaration, automatically zeroes will be padded up.

     As possible, declare variables with reference to standard table-field (like MARA-matnr) or standard data element (MATNR).

Regards.

Read only

0 Likes
3,866

Thanks.

I have the following error because there is a field that is obligatory for the material, the field is MSBOOKPARTNO which is known as Natureza for the company I work with.

My Question is How I can send this value in the BAPI_MATERIAL_SAVEDATA in order to create the material?

Thanks very much

Read only

Former Member
0 Likes
3,866

Hi,

You are generating the material number and passing in the BAPI. While generating the number it is the output material number and not the input of material.

The below BAPI is generating the only internal number

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
      EXPORTING
        material_type    = IT_MATMASTER-MTART
        industry_sector  = 'A'
        required_numbers = 1
      IMPORTING
        return           = return
      TABLES
        material_number  = MATERIALNUMBER.


    IF return-type EQ 'S'.
          READ TABLE MATERIALNUMBER INTO str_material INDEX 1.
      IF sy-subrc EQ 0.

* before passing in the BAPI!



call function  'CONVERSION_EXIT_MATN1_INPUT'
        exporting  input          =
str_material-material

        importing  output         str_material-material        exceptions
             length_error         = 01
             others               = 02.
     check sy-subrc is initial.

 


        BAPIMATHEAD-MATERIAL = str_material-material.
      ENDIF.
    ENDIF.

Read only

0 Likes
3,866

I have the following error because there is a field that is obligatory for the material, the field is MSBOOKPARTNO which is known as Natureza for the company I work with.

My Question is How I can send this value in the BAPI_MATERIAL_SAVEDATA in order to create the material?

Thanks you very much

Read only

former_member210857
Participant
0 Likes
3,866

Hi Enrique,

                You need to convert the material number to an internal format because conversion routine is set in the domain level of the MATNR.

You can check it is the domain MATNR.

Similarly check for all input parameters in the Bapi  BAPI_MATERIAL_SAVEDATA

Regards,

Subeesh Kannottil

Read only

0 Likes
3,866

I have the following error because there is a field that is obligatory for the material, the field is MSBOOKPARTNO which is known as Natureza for the company I work with.

My Question is How I can send this value in the BAPI_MATERIAL_SAVEDATA in order to create the material?

Thanks very much

Read only

0 Likes
3,866

Hi,

Is it a customized field in MARA!  where exactly the field is using currently!

Read only

0 Likes
3,866

this looks like an IS-MEDIA or IS-DRM system

this other forum post looks similar

Read only

0 Likes
3,866

Thanks Clinton, I will review the link.