Creating Sales Order with One Time Materials.
Hi guys !!
A few days back, i was given a requirement which is something like:
Creation of one-time materials in background when creating sales orders manually:
For manually created sales orders the process is as follows:
- – One-time materials can be created in the background already at the time when creating/changing the sales order
- – This is needed for purchased parts only and not for manufactured parts
- – The creation of the one-time materials will be triggered in the sales order. A pop-up appears and in the pop-up the data of the one-time material can be inserted.
Advantages
- Time savings due to faster creation of material masters
Disadvantages
- Risk of duplicates if persons do not properly check if material masters are already available
Initially i thought may be some user exits will be helpful but reading the documentation it was clear that its not possible as this BAPI was more into editing screen field values at PBO of SO screens.
For my understanding, it was clear that what ever i do I got to do at PAI, so that the user enters a tag say ” #OMT” immediately before the on screen field validation the material will be created in background and all SAP structures populated.
We could have gone with SSCR key and modified the code but our Managing Consultant said NO. But then I did the following it’s still a PoC for me as I don’t have the go ahead to put in the final code with transport as the functional and client are up to cooking something 😉
I created a test enhancement ZENDE_OHNE_PRUEFUNG in subroutine ENDE_OHNE_PRUEFUNG; which gets triggered from inside the PAI module of
screen 4900 that does on screen validation on material number. (Program : SAPMV45A).
The code only triggers once when a materials #OMT is entered and not repeated as, the SAP structures for that row are updated as soon as the material number is generated.
So, I believe we can achieve the desired functionality now without SSCR key.
Now see the trick part is as soon as you hit #OMT first a pop up is displayed where you enter some data mandatory to create a material using BAPI_MATERIAL_SAVEDATA. also the pop up screen will have 2 buttons, one to create so with entered data it creates material and passes the number back to SAP, if user presses cancel the operation is aborted and back to VA01/02 screen.
so, the logic is:
1. This logic is to be executed only when in VA01 or VA02 screen the material field rv45a-matnr EQ ‘ #OMT’.
2. Call a pop up screen, get values to create the one time material.
3. Call BAPI_MATERIAL_SAVEDATA, on successful execution capture the material number.
4. Populate created material number to structure rv45a-matnr.
Very simple right, to show the pop up i wrote screen programming inside the function group of the function module called inside the enhancement
Z_OMD_N_MATCRT_380_VA.
So, its time to test now 😉
Now I enter a material with predefined identifier: #OMT.
Currently there is no point in putting values as , it won’t create any material in background as I have no info what all I will need to do so. But suppose it gets created
And its 000000000000001005 a value of an existing material that I have hard coded. I have made VKORG and VTWEG disabled for new inputs as in VBAK structure these fields are
Available, so why do we need it again.
And I press create button
So, here line 20 is the one time material.
Now say you want to change line 10 to one time material.
So, here we go we have changed it too,
Conclusion: The solution must work for VA01 and VA02; with no problems.
So, here we go we have changed it too,
Conclusion: The solution must work for VA01 and VA02; with no problems.