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

how to create a record in MARC?

Former Member
0 Likes
3,952

Hello Experts,

I have a requirement to insert a new record in MARC table with only MANDT, MATNR, WERKS!

I know that standard tables should not be updated as such!

Is there any function module or BAPI to do this? If so, could you please brief the details of how to use that?

Thanks and Best Regards,

Suresh

13 REPLIES 13
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,489

Marc gets updated for the plant data for a material.

Try BAPI_MATERIAL_SAVEDATA

Check the import parameter PLANTDATA

Read only

Former Member
Read only

Former Member
0 Likes
2,489

This message was moderated.

Read only

0 Likes
2,489

Hello Gurus,

My requirement is like this:

Only Client(MANDT), Material number(MATNR), and Plant(WERKS) needs to be passed to create a new record in MARC Table.

If we use BAPI_MATERIAL_SAVEDATA, we need to pass all the mandatory fields to the function module.

I dont have the details of the mandatory fields and then to be passed to HEADDATA of BAPI and all.

Just i will pass the MANDT, MATNR and WERKS. It has to create an entry in MARC and return.

Is there any way to make this working?

Thanks for your responses!

Thanks and Best Regards,

Suresh

Read only

0 Likes
2,489

No...while maintaining master data...you have to do all these ... "Data Consistency is the matter"

Read only

Former Member
0 Likes
2,489

Hi Suresh,

Assumptions: Material and Plants are already maintained.

You can write following code.

data : begin of it_marc occurs 0.

include structure marc.

data : end of it_marc.

data : wa_marc like marc.

wa_marc-mandt = sy-mandt.

wa_marc-matnr = '24'.

wa_marc-werks = '0101'.

append wa_marc to it_marc.

CALL FUNCTION 'ENQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'MARC'

EXCEPTIONS

foreign_lock = 1

system_failure = 2.

IF sy-subrc eq 0.

MODIFY marc FROM TABLE it_marc.

IF sy-subrc EQ 0.

COMMIT WORK .

ELSE .

ROLLBACK WORK.

ENDIF. " IF sy-subrc EQ 0.

  • Table lock on table 'MARC' is released .

CALL FUNCTION 'DEQUEUE_E_TABLEE'

EXPORTING

mode_rstable = 'E'

tabname = 'MARC'.

ENDIF. " IF sy-subrc NE 0.

Regards,

Anil Salekar

Read only

0 Likes
2,489

Hi Anil,

The way you have suggested is what i don't want to use. Since, standard SAP Tables should not be updated directly.

But, i want to know, how to use BAPI_MATERIAL_SAVEDATA to create a MARC entry.

A short example could be helpful.

Thanks and Best Regards,

Suresh

Read only

0 Likes
2,489

Hi suresh Just search in SCN ...Lot of examples are available ...

Read only

0 Likes
2,489

Hi Suresh,

Try using function module "MARCH_INSERT_INIT".There is no documentation for this function module. But looking at code inside the function module, it seems you will be able to use this function module.

Regards,

Anil Salekar

Read only

0 Likes
2,489

Hello

This code just add record to MARC:


TABLES: MARC.

PARAMETERS: P_WERKS LIKE MARC-WERKS.
PARAMETERS: P_MATNR LIKE MARC-MATNR.

DATA: XHEADDATA   LIKE BAPIMATHEAD        OCCURS 0 WITH HEADER LINE,
      XPLANTDATA  LIKE BAPI_MARC          OCCURS 0 WITH HEADER LINE,
      XPLANTDATAX LIKE BAPI_MARCX         OCCURS 0 WITH HEADER LINE,
      XRETURN     LIKE BAPI_MATRETURN2    OCCURS 0 WITH HEADER LINE.


XPLANTDATA-PLANT      = P_WERKS.
XPLANTDATA-AVAILCHECK = 'KP'.
XPLANTDATA-MRP_TYPE   = 'ND'.
APPEND XPLANTDATA.

XPLANTDATAX-PLANT      = P_WERKS.
XPLANTDATAX-AVAILCHECK = 'X'.
XPLANTDATAX-MRP_TYPE   = 'X'.
APPEND XPLANTDATAX.

REFRESH XHEADDATA.
XHEADDATA-MATERIAL      = P_MATNR.
XHEADDATA-MRP_VIEW      = 'X'.
XHEADDATA-INP_FLD_CHECK = 'W'.
APPEND XHEADDATA.

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
         EXPORTING
              HEADDATA       = XHEADDATA
              PLANTDATA      = XPLANTDATA
              PLANTDATAX     = XPLANTDATAX
         TABLES
              RETURNMESSAGES = XRETURN.
    IF SY-SUBRC = 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
                WAIT            = 'X'.
    ENDIF.

Field MANDT - is login client number.

Read only

matt
Active Contributor
0 Likes
2,489

The point that is being made, and needs to be addressed is this:If you create an entry in MARC and there isn't a corresponding entry in MARA, then you have corrupted your database. A corrupted database is a bad thing.

>If we use BAPI_MATERIAL_SAVEDATA, we need to pass all the mandatory fields to the function module.

There's a reason why they're mandatory. Because without them, you've a corrupt database.

The business requirement is not "create an entry in MARC". So, before proceeding further, please tell us what you intend to do about MARA? And what the actual "business* requirement is.

matt

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,489

Look at thread You must provide more data than the primary keys only.

I agree when you write that you don't want to update the table via SQL and that standard SAP Tables should not be updated directly. But when you don't want to provide the data that SAP has declared as mandatory, you loss in coherence. If the data must not be modified by wild Abap statement, that for this reason, there are rules to fill data in MARC and you want to bypass them,

You must provide the mandatory fields.

Ask you functional, some data may come from General material data (MARA) and there may be a reference Plant (another MARC) in your system from where you could copy the required information.

Regards,

Raymond

Read only

Former Member
0 Likes
2,489

It is possible to just create an entry in MARC by doing the following:

Use BAPI_MATERIAL_SAVEDATA.

HEADDATA-MATNR = 'Material no.'.

HEADDATA-STORAGE_VIEW = 'X'.

PLANTDATA-PLANT = 'Plant no.'.

PLANTDATAX-PLANT = 'Plant no.'.

Then pass this to the BAPI.

Thanks for all.

Thanks and Best Regards,

Suresh