Skip to Content
author's profile photo Former Member
Former Member

Can't create EAN/UPC using BAPI_MATERIAL_SAVEDATA

Hi I'm trying to create a material using the bapi: BAPI_MATERIAL_SAVEDATA

I'm able to create the matter as long as I don't try to assign/create EAN

If I try to assign/create EAN I get the following message:

First specify the main EAN for the unit EA

In my program I'm only assigning the values in the following fields (see code below):

it_intartnum-unit

it_intartnum-ean_cat

Because if I go to transaction MM02 all I have to do is assign a value to ean_cat (NUMTP) field and it automatically generates and assigns an EAN/UPC.

Can you please tell me which structures/fields I need to fill to get this bapi to work?

Here's the code that i have so far:

REPORT zmm_upload_captaris .

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

  • STRUCTURE DECLARATIONS *

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

TABLES: bapimathead, "Headerdata

bapi_mara, "Clientdata

bapi_marax, "Checkbox Structure for BAPI_MARA

bapi_marc, "Plantdata

bapi_marcx, "Checkbox Structure for BAPI_MARC

bapi_makt, "Material description

bapi_mbew, "Valuation Data

bapi_mbewx, "Checkbox Structure for BAPI_MBEW

bapiret2, "Return messages

bapi_mean. "International Article Numbers (EANs)

DATA:v_file TYPE string.

DATA:

BEGIN OF lsmw_material_master,

matnr(018) TYPE c, "Material number

mbrsh(001) TYPE c, "Industry sector

mtart(004) TYPE c, "Material type

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

mtpos_mara(004) TYPE c, "Gen item cat group

gewei(003) TYPE c, "Weight unit

werks(004) TYPE c, "Plant

ekgrp(003) TYPE c, "Purchasing group

ekwsl(004) TYPE c, "Purchasing key value

dismm(002) TYPE c, "MRP Type

dispo(003) TYPE c, "MRP Controller

beskz(001) TYPE c, "Procurement Type

sobsl(002) TYPE c, "Special procurement type

lgpro(004) TYPE c, "Issue Storage Location

lgfsb(004) TYPE c, "Default storage location for external procurement

plifz(003) TYPE c, "Planned delivery time in days

fhori(003) TYPE c, "Scheduling Margin Key for Floats

perkz(001) TYPE c, "Period indicator

mtvfp(002) TYPE c, "Checking Group for Availability Check

iprkz(001) TYPE c, "Period indicator for shelf life expiration date

prctr(010) TYPE c, "Profit Center

bklas(004) TYPE c, "Valuation Class

peinh(005) TYPE c, "Price Unit

vprsv(001) TYPE c, "Price Control Indicator

ean11(018) TYPE c, "International Article Number (EAN/UPC)

numtp(002) TYPE c, "Category of International Article Number (EAN)

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 international article numbers

DATA: BEGIN OF it_intartnum OCCURS 0.

INCLUDE STRUCTURE bapi_mean.

DATA: END OF it_intartnum.

DATA: BEGIN OF it_unitofmeas OCCURS 0.

INCLUDE STRUCTURE bapi_marm.

DATA: END OF it_unitofmeas.

DATA: BEGIN OF it_unitofmeasx OCCURS 0.

INCLUDE STRUCTURE bapi_marmx.

DATA: END OF it_unitofmeasx.

*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'

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.

*Add leading zeros to profit center

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = it_matmaster-prctr

IMPORTING

output = it_matmaster-prctr.

*Filling the bapi header

bapimathead-material = it_matmaster-matnr.

bapimathead-ind_sector = it_matmaster-mbrsh.

bapimathead-matl_type = it_matmaster-mtart.

*Selecting views

bapimathead-basic_view = 'X'.

bapimathead-storage_view = 'X'.

IF it_matmaster-mtart NE 'ZGPO'.

bapimathead-purchase_view = 'X'.

bapimathead-mrp_view = 'X'.

bapimathead-account_view = 'X'.

ENDIF.

*Material Description

REFRESH it_materialdesc.

it_materialdesc-langu = 'EN'.

it_materialdesc-matl_desc = it_matmaster-maktx.

APPEND it_materialdesc.

*Other fields

bapi_mara-base_uom = it_matmaster-meins.

bapi_mara-matl_group = it_matmaster-matkl.

bapi_mara-division = it_matmaster-spart.

bapi_mara-item_cat = it_matmaster-mtpos_mara.

bapi_mara-unit_of_wt = it_matmaster-gewei.

bapi_marc-plant = it_matmaster-werks.

bapi_marc-pur_group = it_matmaster-ekgrp.

bapi_mara-pur_valkey = it_matmaster-ekwsl.

bapi_marc-mrp_type = it_matmaster-dismm.

bapi_marc-mrp_ctrler = it_matmaster-dispo.

bapi_marc-proc_type = it_matmaster-beskz.

bapi_marc-spproctype = it_matmaster-sobsl.

bapi_marc-iss_st_loc = it_matmaster-lgpro.

bapi_marc-sloc_exprc = it_matmaster-lgfsb.

bapi_marc-plnd_delry = it_matmaster-plifz.

bapi_marc-sm_key = it_matmaster-fhori.

bapi_marc-period_ind = it_matmaster-perkz.

bapi_marc-availcheck = it_matmaster-mtvfp.

bapi_mara-period_ind_expiration_date = it_matmaster-iprkz.

bapi_marc-profit_ctr = it_matmaster-prctr.

bapi_mbew-val_class = it_matmaster-bklas.

bapi_mbew-price_unit = it_matmaster-peinh.

bapi_mbew-price_ctrl = it_matmaster-vprsv.

bapi_mbew-val_area = it_matmaster-werks. "Valuation area = Plant

*International Article Numbers

REFRESH it_intartnum.

it_intartnum-unit = it_matmaster-meins.

it_intartnum-ean_upc = it_matmaster-ean11.

it_intartnum-ean_cat = it_matmaster-numtp.

APPEND it_intartnum.

  • REFRESH it_unitofmeas.

  • it_unitofmeas-ean_upc = it_matmaster-ean11.

  • it_unitofmeas-ean_cat = it_matmaster-numtp.

  • APPEND it_unitofmeas.

  • REFRESH it_unitofmeasx.

  • it_unitofmeasx-ean_upc = 'X'.

  • it_unitofmeasx-ean_cat = 'X'.

  • APPEND it_unitofmeasx.

*Flags for above fields

bapi_marax-base_uom = 'X'.

bapi_marax-matl_group = 'X'.

bapi_marax-division = 'X'.

bapi_marax-item_cat = 'X'.

bapi_marax-unit_of_wt = 'X'.

bapi_marcx-plant = it_matmaster-werks.

bapi_marcx-pur_group = 'X'.

bapi_marax-pur_valkey = 'X'.

bapi_marcx-mrp_type = 'X'.

bapi_marcx-mrp_ctrler = 'X'.

bapi_marcx-proc_type = 'X'.

bapi_marcx-spproctype = 'X'.

bapi_marcx-iss_st_loc = 'X'.

bapi_marcx-sloc_exprc = 'X'.

bapi_marcx-plnd_delry = 'X'.

bapi_marcx-sm_key = 'X'.

bapi_marcx-period_ind = 'X'.

bapi_marcx-availcheck = 'X'.

bapi_marcx-profit_ctr = 'X'.

bapi_mbewx-val_class = 'X'.

bapi_mbewx-price_unit = 'X'.

bapi_mbewx-price_ctrl = 'X'.

bapi_mbewx-val_area = it_matmaster-werks. "Valuation area = Plant

IF it_matmaster-mtart EQ 'ZGPO'.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = bapimathead

clientdata = bapi_mara

clientdatax = bapi_marax

plantdata = bapi_marc

plantdatax = bapi_marcx

IMPORTING

return = it_return

TABLES

materialdescription = it_materialdesc

  • unitsofmeasure = it_unitofmeas

  • unitsofmeasurex = it_unitofmeasx

internationalartnos = it_intartnum.

ELSE.

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.

ENDIF.

WRITE:/ it_return-type,

2 it_return-id,

22 it_return-number,

50 it_return-message.

ENDLOOP.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 27, 2009 at 07:28 AM

    Surely it will work, i have done in my last company. I have use BAPI_MATERIAL_MAINTAINDATA_RT.

    But try passing EA to it_unitofmeas as well if there is any field. I will try to get the code ASAP as of now it is not with me. But i am sure it will work. All the best.

    For my FM i have passed to the structures

    E1BPE1MARMRT - ALT_UNIT -EA

    E1BPE1MARMRT - ALT_UNIT_ISO -EA

    E1BPE1MARMRTX - ALT_UNIT -EA

    E1BPE1MARMRTX - ALT_UNIT_ISO -EA

    Edited by: Phanindra Annaparthi on Feb 27, 2009 8:43 AM

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Phanindra. Its working now!!! ---> 10 points

      I assigned values to the tables:

      it_unitofmeas

      it_unitofmeasx

      and now its working perfectly...EAN is getting assigned and saved.

      here's the final code...

       
      REPORT  zmm_upload_captaris                     .
      
      
      
      **********************************************************************
      *                STRUCTURE  DECLARATIONS                             *
      **********************************************************************
      
      TABLES: bapimathead,  "Headerdata
              bapi_mara,    "Clientdata
              bapi_marax,   "Checkbox Structure for BAPI_MARA
              bapi_marc,    "Plantdata
              bapi_marcx,   "Checkbox Structure for BAPI_MARC
              bapi_makt,    "Material description
              bapi_mbew,    "Valuation Data
              bapi_mbewx,   "Checkbox Structure for BAPI_MBEW
              bapiret2.     "Return messages
      
      DATA:v_file TYPE string.
      
      
      DATA:
        BEGIN OF lsmw_material_master,
          matnr(018) TYPE c,  "Material number
          mbrsh(001) TYPE c,  "Industry sector
          mtart(004) TYPE c,  "Material type
          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
          mtpos_mara(004) TYPE c,  "Gen item cat group
          gewei(003) TYPE c,  "Weight unit
          werks(004) TYPE c,  "Plant
          ekgrp(003) TYPE c,  "Purchasing group
          ekwsl(004) TYPE c,  "Purchasing key value
          dismm(002) TYPE c,  "MRP Type
          dispo(003) TYPE c,  "MRP Controller
          beskz(001) TYPE c,  "Procurement Type
          sobsl(002) TYPE c,  "Special procurement type
          lgpro(004) TYPE c,  "Issue Storage Location
          lgfsb(004) TYPE c,  "Default storage location for external procurement
          plifz(003) TYPE c,  "Planned delivery time in days
          fhori(003) TYPE c,  "Scheduling Margin Key for Floats
          perkz(001) TYPE c,  "Period indicator
          mtvfp(002) TYPE c,  "Checking Group for Availability Check
          iprkz(001) TYPE c,  "Period indicator for shelf life expiration date
          prctr(010) TYPE c,  "Profit Center
          bklas(004) TYPE c,  "Valuation Class
          peinh(005) TYPE c,  "Price Unit
          vprsv(001) TYPE c,  "Price Control Indicator
          ean11(018) TYPE c,  "International Article Number (EAN/UPC)
          numtp(002) TYPE c,  "Category of International Article Number (EAN)
        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 international article numbers
      DATA: BEGIN OF it_intartnum OCCURS 0.
              INCLUDE STRUCTURE bapi_mean.
      DATA: END OF it_intartnum.
      
      DATA: BEGIN OF it_unitofmeas OCCURS 0.
              INCLUDE STRUCTURE bapi_marm.
      DATA: END OF it_unitofmeas.
      
      DATA: BEGIN OF it_unitofmeasx OCCURS 0.
              INCLUDE STRUCTURE bapi_marmx.
      DATA: END OF it_unitofmeasx.
      
      *to return messages
      DATA: BEGIN OF it_return OCCURS 0.
              INCLUDE STRUCTURE bapiret2.
      DATA: END OF it_return.
      
      DATA: BEGIN OF it_commitret OCCURS 0.
              INCLUDE STRUCTURE bapiret2.
      DATA: END OF it_commitret.
      
      
      
      ************************************************************************
      *  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'
          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.
      
      *Add leading zeros to profit center
          CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
            EXPORTING
              input  = it_matmaster-prctr
            IMPORTING
              output = it_matmaster-prctr.
      
      *Filling the bapi header
          bapimathead-material = it_matmaster-matnr.
          bapimathead-ind_sector = it_matmaster-mbrsh.
          bapimathead-matl_type = it_matmaster-mtart.
      *Selecting views
          bapimathead-basic_view = 'X'.
          bapimathead-storage_view = 'X'.
          IF it_matmaster-mtart NE 'ZGPO'.
            bapimathead-purchase_view = 'X'.
            bapimathead-mrp_view = 'X'.
            bapimathead-account_view = 'X'.
          ENDIF.
      
      *Material Description
          REFRESH it_materialdesc.
          it_materialdesc-langu = 'EN'.
          it_materialdesc-matl_desc = it_matmaster-maktx.
          APPEND it_materialdesc.
      *Other fields
          bapi_mara-base_uom = it_matmaster-meins.
          bapi_mara-matl_group = it_matmaster-matkl.
          bapi_mara-division = it_matmaster-spart.
          bapi_mara-item_cat = it_matmaster-mtpos_mara.
          bapi_mara-unit_of_wt = it_matmaster-gewei.
          bapi_marc-plant = it_matmaster-werks.
          bapi_marc-pur_group = it_matmaster-ekgrp.
          bapi_mara-pur_valkey = it_matmaster-ekwsl.
          bapi_marc-mrp_type = it_matmaster-dismm.
          bapi_marc-mrp_ctrler = it_matmaster-dispo.
          bapi_marc-proc_type = it_matmaster-beskz.
          bapi_marc-spproctype = it_matmaster-sobsl.
          bapi_marc-iss_st_loc = it_matmaster-lgpro.
          bapi_marc-sloc_exprc = it_matmaster-lgfsb.
          bapi_marc-plnd_delry = it_matmaster-plifz.
          bapi_marc-sm_key = it_matmaster-fhori.
          bapi_marc-period_ind = it_matmaster-perkz.
          bapi_marc-availcheck = it_matmaster-mtvfp.
          bapi_mara-period_ind_expiration_date = it_matmaster-iprkz.
          bapi_marc-profit_ctr = it_matmaster-prctr.
          bapi_mbew-val_class = it_matmaster-bklas.
          bapi_mbew-price_unit = it_matmaster-peinh.
          bapi_mbew-price_ctrl = it_matmaster-vprsv.
          bapi_mbew-val_area = it_matmaster-werks.      "Valuation area = Plant
      *International Article Numbers
          REFRESH it_intartnum.
          it_intartnum-unit = it_matmaster-meins.
          it_intartnum-unit_iso = it_matmaster-meins.
          it_intartnum-ean_upc = it_matmaster-ean11.
          it_intartnum-ean_cat = it_matmaster-numtp.
          APPEND it_intartnum.
      
          REFRESH it_unitofmeas.
          it_unitofmeas-ALT_UNIT = it_matmaster-meins.
          it_unitofmeas-alt_unit_iso = it_matmaster-meins.
          it_unitofmeas-ean_upc = it_matmaster-ean11.
          it_unitofmeas-ean_cat = it_matmaster-numtp.
          APPEND it_unitofmeas.
      
          REFRESH it_unitofmeasx.
          it_unitofmeasx-ALT_UNIT = it_matmaster-meins.
          it_unitofmeasx-alt_unit_iso = it_matmaster-meins.
          it_unitofmeasx-ean_upc = 'X'.
          it_unitofmeasx-ean_cat = 'X'.
          APPEND it_unitofmeasx.
      
      *Flags for above fields
          bapi_marax-base_uom = 'X'.
          bapi_marax-matl_group = 'X'.
          bapi_marax-division = 'X'.
          bapi_marax-item_cat = 'X'.
          bapi_marax-unit_of_wt = 'X'.
          bapi_marcx-plant = it_matmaster-werks.
          bapi_marcx-pur_group = 'X'.
          bapi_marax-pur_valkey = 'X'.
          bapi_marcx-mrp_type = 'X'.
          bapi_marcx-mrp_ctrler = 'X'.
          bapi_marcx-proc_type = 'X'.
          bapi_marcx-spproctype = 'X'.
          bapi_marcx-iss_st_loc = 'X'.
          bapi_marcx-sloc_exprc = 'X'.
          bapi_marcx-plnd_delry = 'X'.
          bapi_marcx-sm_key = 'X'.
          bapi_marcx-period_ind = 'X'.
          bapi_marcx-availcheck = 'X'.
          bapi_marcx-profit_ctr = 'X'.
          bapi_mbewx-val_class = 'X'.
          bapi_mbewx-price_unit = 'X'.
          bapi_mbewx-price_ctrl = 'X'.
          bapi_mbewx-val_area = it_matmaster-werks.      "Valuation area = Plant
      
      
          IF it_matmaster-mtart EQ 'ZGPO'.
            CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
              EXPORTING
                headdata            = bapimathead
                clientdata          = bapi_mara
                clientdatax         = bapi_marax
                plantdata           = bapi_marc
                plantdatax          = bapi_marcx
              IMPORTING
                return              = it_return
              TABLES
                materialdescription = it_materialdesc
                unitsofmeasure      = it_unitofmeas
                unitsofmeasurex     = it_unitofmeasx
                internationalartnos = it_intartnum.
          ELSE.
            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.
          ENDIF.
      
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait   = 'X'
            IMPORTING
              return = it_commitret.
      
      
          WRITE:/    it_return-type,
                     2   it_return-id,
                     22  it_return-number,
                     50  it_return-message.
        ENDLOOP.
      

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.