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

Problem with MATERIAL_MAINTAIN_DARK

Former Member
0 Likes
2,668

Hi,

I want to create a material master with MATERIAL_MAINTAIN_DARK.

But I always get error MG - 159 (type Error):

"The material cannot be created since no maintainable data exists"

Here's the coding:

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'

EXPORTING

material_type = wa_matyp

industry_sector = wa_branch

TABLES

material_number = it_bapimatinr.

READ TABLE it_bapimatinr INDEX 1 INTO wa_bapimatinr.

wa_mara-mandt = sy-mandt. wa_mara-matnr = wa_bapimatinr-material.

wa_mara-mtart = wa_matyp. wa_mara-mbrsh = wa_branch.

wa_mara-matkl = wa_wagru. wa_mara-prdha = wa_hierar.

wa_mara-vpsta = 'KVDPBEALGQ'.

wa_mara-pstat = 'KVDPBELGQ'.

wa_mara-tcode = 'MM01'.

wa_mara-tranc = 1. wa_mara-d_ind = 1.

wa_mara-kz_mat_res = 'X'.

APPEND wa_mara TO it_mara.

wa_makt-mandt = sy-mandt. wa_makt-matnr = wa_bapimatinr-material.

wa_makt-spras = 'D'. wa_makt-maktx = wa_txtde.

wa_makt-tranc = 1. wa_makt-d_ind = 2.

APPEND wa_makt TO it_makt.

wa_marc-mandt = sy-mandt. wa_marc-matnr = wa_bapimatinr-material.

wa_marc-werks = wa_werk.

wa_marc-tranc = 1. wa_marc-d_ind = 3.

APPEND wa_marc TO it_marc.

wa_mard-mandt = sy-mandt. wa_mard-matnr = wa_bapimatinr-material.

wa_mard-werks = wa_werk. wa_mard-lgort = wa_lgort.

wa_mard-tranc = 1. wa_mard-d_ind = 4.

APPEND wa_mard TO it_mard.

wa_mvke-mandt = sy-mandt. wa_mvke-matnr = wa_bapimatinr-material.

wa_mvke-vkorg = wa_vkorg. wa_mvke-vtweg = wa_vtweg.

wa_mvke-prodh = wa_hierar.

wa_mvke-tranc = 1. wa_mvke-d_ind = 5.

APPEND wa_mvke TO it_mvke.

CALL FUNCTION 'MATERIAL_MAINTAIN_DARK'

EXPORTING

flag_muss_pruefen = ' '

sperrmodus = ' '

p_kz_no_warn = 'N'

kz_prf = 'I'

user = sy-uname

TABLES

amara_ueb = it_mara

amakt_ueb = it_makt

amarc_ueb = it_marc

amard_ueb = it_mard

amvke_ueb = it_mvke

amerrdat = it_error "Fehlerliste

EXCEPTIONS

kstatus_empty = 1

tkstatus_empty = 2

t130m_error = 3

internal_error = 4

too_many_errors = 5

update_error = 6

error_propagate_header = 7

OTHERS = 8.

IF sy-subrc = 0. COMMIT WORK. ENDIF.

Best regards,

Werner.

7 REPLIES 7
Read only

Former Member
0 Likes
1,735

Hi Werner,

You don't need to give the MANDT field.

Most likely the issue is in the views you are passing with the vpsta and pstat. Each view requires it's own minimum set up data.

Try simply to start with the K view (header view). See if the material gets created and then extend the views if this works.

Regards,

Frank Umans

Read only

0 Likes
1,735

Hi Frank,

thanks for your answer, I have already tried this!

But I get the same error!

Best regards,

Werner.

Message was edited by:

Werner Köß

Read only

0 Likes
1,735

Hi,

I suppose the problem lies within the function module "Material_maintain_dark". In this, amfieldres is the key structure which is used for updating/creation of materials. I observe that this field is missing in ur program.

The assignment of the values to the fields in this also should be done through field-symbols. For eg.

data : v_tcnt like sy-tabix.

--


for basic view of material--

"transaction counter for data transfer

v_tcnt = v_tcnt + 1.

move-corresponding wa_mara to mara_ueb.

mara_ueb-tcode = 'MM01'.

mara_ueb-tranc = v_tcnt.

append mara_ueb to amara_ueb.

clear v_tcnt.

----


--


for plant view--

move-corresponding wa_marc to marc_ueb.

v_tcnt = v_tcnt + 1.

marc_ueb-tranc = v_tcnt.

concatenate 'MARC_UEB-' 'MTVFP' into v_field1.

concatenate 'MARC-' 'MTVFP' into v_field2.

assign (v_field1) to <f1>.

mfieldres-fname = name. "v_field2

mfieldres-tranc = v_tcnt.

append mfieldres to amfieldres.

----


Now use the mfieldres in the function module 'material_maintain_dark'... and execute.

One way of checking if the material has been created or not is:

while debugging, all the materials and the corresponding fields to be created will be lined up in "amfieldres" before reaching the func. module. after execution of the function module, the list of materials which would *remain* in the "amfieldres" internal table are the ones which would not have been created.The rest which are not seen in the internal table would be created.

<REMOVED BY MODERATOR>

Thanks,

Archana

Edited by: Alvaro Tejada Galindo on Feb 11, 2008 5:59 PM

Read only

0 Likes
1,735

Hi,

i don't use this f.m. anymore because it didn't work.

We solved it with another f.m. so I don't try this f.m.

But thank you anyways!

Read only

0 Likes
1,735

Hi Archana,

I too have problem using this FM - Material_maintain_dark.

Even after appending the req. entries in amfieldres, am not able to create a material.

Do we need to use/run any other function modules before or after executing this FM? I mean can we create a material using this FM alone? My req. is to create a material and extend it to multiple plants, sales views, etc. in 4.6B system and I dont find any other BAPI or FM which will meet my req. other than this FM.

I think I wld be missing some flags or initial values.

So I request you to send me the complete code demonstrating this FM to create and extend a material.

Please try to provide your suggestions/feedback asap as am running out of time.

Regards,

Dev

Read only

0 Likes
1,735

Hi Werner,

Am also working on the same req. to create and extend a material to multiple plants,sales views etc in the older system 4.6B. I saw your reply that you are not using Material_maintain_dark for this purpose.

I request you to let me know, how did you achieve this and could you please send me the complete code/Info.

Regards,

Dev

Read only

0 Likes
1,735

Hi Dev,

Below is the code of the function module,

SORT AMARA_UEB BY TRANC.

SORT AMFIELDRES BY TRANC D_IND FNAME.

DELETE ADJACENT DUPLICATES FROM AMARA_UEB COMPARING TRANC.

DELETE ADJACENT DUPLICATES FROM AMFIELDRES COMPARING TRANC D_IND FNAME.

CALL FUNCTION 'MATERIAL_MAINTAIN_DARK'

EXPORTING

KZ_ACTIV_CAD = SPACE

FLAG_MUSS_PRUEFEN = SPACE

  • SPERRMODUS = 'E'

MAX_ERRORS = 0

P_KZ_NO_WARN = 'E'

KZ_PRF = SPACE

KZ_VERW = 'X'

KZ_AEND = 'X'

KZ_DISPO = 'X'

KZ_TEST = ' '

KZ_MDIP = ' '

KZ_MPRP = ' '

KZ_ALE = ' '

KZ_ACTV = ' '

  • IMPORTING

  • MATNR_LAST =

  • NUMBER_ERRORS_TRANSACTION =

TABLES

AMARA_UEB = AMARA_UEB

  • AMAKT_UEB =

AMARC_UEB = AMARC_UEB

  • AMARD_UEB =

  • AMFHM_UEB =

  • amarm_ueb = amarm_ueb

  • AMEA1_UEB =

  • ambew_ueb =

  • ASTEU_UEB =

  • ASTMM_UEB =

  • AMLGN_UEB =

  • AMLGT_UEB =

  • AMPGD_UEB =

  • AMPOP_UEB =

  • AMVEG_UEB =

  • AMVEU_UEB =

AMVKE_UEB = AMVKE_UEB

  • ALTX1_UEB =

  • AMPRW_UEB =

AMFIELDRES = AMFIELDRES

AMERRDAT = AMERRDAT

EXCEPTIONS

KSTATUS_EMPTY = 1

TKSTATUS_EMPTY = 2

T130M_ERROR = 3

INTERNAL_ERROR = 4

TOO_MANY_ERRORS = 5

UPDATE_ERROR = 6

OTHERS = 7.

-


Make sure that the structures AMARA_UEB, AMARC_UEB, AMVKE_UEB (whichever is required)are all properly appended by the proper values.

AMFIELDRES is an important structure here, which is solely responsible for updating all the values.Do get back, in case of any issues.

Reward points if helpful.

Thanks,

Archana