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

Program does not find created material in MARA

Former Member
0 Likes
6,401

Hello Experts,

I am creating a material through calling MM01 in a dialog program.

After the transaction completed, the control returns to my program, but i cannot find my material created in MARA, even though it gets created.

Even after writing several seconds of WAIT, the select returns subrc as '4'.


CALL TRANSACTION 'MM01'.

COMMIT WORK AND WAIT.

CALL FUNCTION 'DB_COMMIT'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

         EXPORTING

           wait = 'X'.

WAIT UP TO 4 SECONDS.


SELECT SINGLE matnr FROM mara

         INTO v_matnr1

         WHERE matnr = v_matnr.

A loop which keeps on checking in MARA (using select) can be performed, but if the user cancels the transaction purposely and does not want to create the material, then the user will have to wait un-neccessarily in the loop.

Let me know what else can be done?

Thanks ,

Rajat.

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
5,935

Well the line s after CALL TRANSACTION are not useful, transaction has already triggered its own commit without wait. so if you did not execute some update OPEN-SQL statements, remove :


COMMIT WORK AND WAIT. 

CALL FUNCTION 'DB_COMMIT'

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 

    EXPORTING

           wait = 'X'.


Before trying to select the material record, first try to lock the record (ENQUEUE_EMMARAE with wait in a loop) if user has saved a material it will be kept locked by the update task until executed. then execute a single selection from MARA bypassing buffer, if not found a single WAIT 1 second would be sufficient (and often not necessary) to wait for DB server.


Also you could save another value in memory to detect actual creation of material (and actual number) with some BAdIs or a BTE like 00001250, if not found in memory, don't execute the wait.


FUNCTION z_interface_00001250.

*"--------------------------------------------------------------------

*"*"Interface locale :

*"  IMPORTING

*"     VALUE(I_MARA_NEW) LIKE  MARA STRUCTURE  MARA OPTIONAL

*"     VALUE(I_MARA_OLD) LIKE  MARA STRUCTURE  MARA OPTIONAL

* etc.

*"--------------------------------------------------------------------

  EXPORT i_mara_new-matnr TO MEMORY ID 'ZMATNR'.

ENDFUNCTION.


Regards,

Raymond


Hello Experts,

I am creating a material through calling MM01 in a dialog program.

After the transaction completed, the control returns to my program, but i cannot find my material created in MARA, even though it gets created.

Even after writing several seconds of WAIT, the select returns subrc as '4'.


CALL TRANSACTION 'MM01'.

COMMIT WORK AND WAIT.

CALL FUNCTION 'DB_COMMIT'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

         EXPORTING

           wait = 'X'.

WAIT UP TO 4 SECONDS.


SELECT SINGLE matnr FROM mara

         INTO v_matnr1

         WHERE matnr = v_matnr.

A loop which keeps on checking in MARA (using select) can be performed, but if the user cancels the transaction purposely and does not want to create the material, then the user will have to wait un-neccessarily in the loop.

Let me know what else can be done?

Thanks ,

Rajat.

19 REPLIES 19
Read only

matt
Active Contributor
0 Likes
5,935

How can your program work at all? Where is v_matnr getting set?

Read only

Former Member
0 Likes
5,935

Hello Matthew,

I forgot to mention that i just pasted a part of my code, not the whole.

So v_matnr is set, it is just not here.

Thanks,

Rajat

Read only

Former Member
0 Likes
5,935

well you may need to run the v_matnr through the conversion exit...as well depending on where that number is sourced - it may not have leading zeros or something similar in the select - but MM01 is formatting the number in internal format for you when saving

MATNR conv exits are:

MG_MATN1_RANGE                 MATN1 Conversion with Ranges
CONVERSION_EXIT_MATN1_RANGE_I  Conversion Exit MATN1, External Range -> Internal Range
CONVERSION_EXIT_MATN1_RANGE_O  Conversion Exit MATN1, Internal Range -> External Range

OMCV
CONVERSION_EXIT_MATN1_INPUT
CONVERSION_EXIT_MATN1_OUTPUT

use the right one

Read only

Former Member
0 Likes
5,935

Matthew is right Rajat - your Material number is not set in v_matnr.

Firstly, you dont need a commit - MM01 will commit the update for you.

Fortunately, material number has a PID.

Use that after MM01

get parameter id 'MAT' field v_matnr.

Should set it ok....I reckon...

sorry, didn't try it myself in test, but am confident it will work.

Read only

former_member183073
Active Participant
0 Likes
5,935

Yes Matthew have a point.

where filling v_matnr.(You can use import the MATNR from MAT parameter fetch the MATNR and query MARA table)

Read only

Former Member
0 Likes
5,935

Hello All,

Thanks for the comments. But all of this I have already done and it's not working. I will paste the some more extended code (this is not the full code):

Also the below code is working when I place a break-point inside the code and then sy-subrc after select statement has value '0'.

I cannot use the parameter-id to check whether it is set after MM01, because i am already setting it before calling the transaction.


SET PARAMETER ID 'MAT' FIELD mara-matnr

CALL TRANSACTION 'MM01'.

       COMMIT WORK AND WAIT.

       CALL FUNCTION 'DB_COMMIT'.

       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

         EXPORTING

           wait = 'X'.

       WAIT UP TO 4 SECONDS.


CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'

         EXPORTING

           input  = mara-matnr

         IMPORTING

           output = v_matnr.

       CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

         EXPORTING

           input  = v_matnr

         IMPORTING

           output = v_matnr.

       SELECT SINGLE matnr FROM mara

         INTO v_matnr1

         WHERE matnr = v_matnr.

       IF sy-subrc EQ 0.

.

The issue is, that even after commit work and wait, and other commits and waits, still the DB takes time to reflect value in MARA.

Is there any interim table which tells me whether the update has been carried out successfully or not ?

Thanks,

Rajat.

Read only

matt
Active Contributor
0 Likes
5,935

Is MARA buffered? Probably not. But if it is, try BYPASSING BUFFER. But no - there is no interim table.

Instead of waiting 4 seconds, you should first check if the data is there. If not, then loop a few times, wiating each loop, until the data is there, or you give up. That way, if the data is there quickly, you don't have any delay.

You do not need your DB_COMMIT and BAPI_TRANSACTION_COMMIT, unless you've got some other data that needs to be committed. It will have no effect on MM01.

Read only

0 Likes
5,935

Hello Matthew,

Thanks, but.


You do not need your DB_COMMIT and BAPI_TRANSACTION_COMMIT, unless you've got some other data that needs to be committed. It will have no effect on MM01.

- Agreed. I just put it there for some additional checks.

Instead of waiting 4 seconds, you should first check if the data is there. If not, then loop a few times, waiting each loop, until the data is there, or you give up. That way, if the data is there quickly, you don't have any delay.

- That would work, but in the case , when the user does a 'CANCEL' or 'EXIT' from MM01, he has to wait, while the loop completes.

Regards,

Rajat.

Read only

0 Likes
5,935

Hi Rajat,

How did you get the MATNR before the call transaction MM01?

Read only

Former Member
0 Likes
5,935

Have you done a manual check ? Please try follwoing:

1.) After BAPI_TRANSACTION_COMMIT put DEQUE_ALL.

2.) Put a break point on SELECT SINGLE matnr FROM mara. When program execution will stop there, manully check using T-Code MM03 , whether material created , if created then check entry in MARA table using t-code SE16 or SE11.

Anyways Material master upate is huge thing and it tooks time to update completly.

BR,

Prakash

Read only

Former Member
0 Likes
5,935

Hi,

are you able to see the material created in MM03 or mara table? if yes, then

after commit statement,

get parameter id 'MAT' field v_matnr.

This should do.

Regards-

Makarand

Read only

0 Likes
5,935

Hello Makarand,

Thanks for the suggestion.

Yes i can see the material in MM03, but as I am setting the parameter id 'MAT' myself before calling MM01, it would always return value in it.

Hence, I cannot use that.

Regards,

Rajat.

Read only

0 Likes
5,935

ok.. that means it is external no range.

Strange issue. Just try to condence v_matnr before the select statement.

Regards-

Makarand

Read only

0 Likes
5,935

Rajat

As already pointed out by Matthew you can put a maximum time limit lets say you try for 30 seconds in a loop if you get it you exit else you exit after 30 seconds(meaning either user cancelled it or your system is too slow:))

Nabheet

Read only

0 Likes
5,935

report  ztest.

tables mara.

data ls_mara type mara.

parameters p_matnr type matnr.

start-of-selection.

  set parameter id 'MAT' field p_matnr.

  break-point.

  call transaction 'MM01'.

  select single * from mara into ls_mara

  where matnr = p_matnr.

  if sy-subrc is initial.

    break-point.

  endif.

here pid assigned and sy-subrc is 0

then the tcode call to mm01, immediately after - but the matnr field on screen is NOT set.

Can you show me your screenshots when you execute on your system

Cheers

Read only

0 Likes
5,935

further, if i change the tcode to MM03 and use material 123, now see what happens

as you can see my material of 123 now gets set correctly - and also SAP has put leading zeros in.

so MM01 and MM03 are treating the PID differently - I have seen some tcodes  CLEAR PIDs in create mode....in the past

do a bit more debug...

Cheers

Read only

Former Member
0 Likes
5,935

Hi Rajat,

After calling transaction MM01

just code as below.

Get parameter id 'MAT'  field V_MATNR

and convert this material no as input using conversion.

Then do select query as it is.

Hope this will definitely work.

Thanks and Regards

Srimanta

Read only

matt
Active Contributor
0 Likes
5,935

Thinking outside the box for a moment, if you're needing to wrap MM01 in other functionality, perhaps this can be best achieved via a workflow.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
5,936

Well the line s after CALL TRANSACTION are not useful, transaction has already triggered its own commit without wait. so if you did not execute some update OPEN-SQL statements, remove :


COMMIT WORK AND WAIT. 

CALL FUNCTION 'DB_COMMIT'

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 

    EXPORTING

           wait = 'X'.


Before trying to select the material record, first try to lock the record (ENQUEUE_EMMARAE with wait in a loop) if user has saved a material it will be kept locked by the update task until executed. then execute a single selection from MARA bypassing buffer, if not found a single WAIT 1 second would be sufficient (and often not necessary) to wait for DB server.


Also you could save another value in memory to detect actual creation of material (and actual number) with some BAdIs or a BTE like 00001250, if not found in memory, don't execute the wait.


FUNCTION z_interface_00001250.

*"--------------------------------------------------------------------

*"*"Interface locale :

*"  IMPORTING

*"     VALUE(I_MARA_NEW) LIKE  MARA STRUCTURE  MARA OPTIONAL

*"     VALUE(I_MARA_OLD) LIKE  MARA STRUCTURE  MARA OPTIONAL

* etc.

*"--------------------------------------------------------------------

  EXPORT i_mara_new-matnr TO MEMORY ID 'ZMATNR'.

ENDFUNCTION.


Regards,

Raymond