Create SAP Function Module to get KVGR1 from KNVV
(c) 2012 kevin languedoc (klanguedoc)
The KNVV is a table in the SAP Customer Master module. The KVGR1 fis one of five reserved fields that be used as extra information on a customer that is not available through the standard fields. These field are accessible through the menu under Additional information if the Functional Analysis who did the configuration enabled these fields.
This tutorial provides an example on how to create an externally accessible function module to query the KNVV table and return the value of the KVGR1 field based on an inputted customer number. If you no values are present and error message will be raised and returned to the calling program.
Create Function Module (TCode SE37)
- Enter Function Module name starting with a “Z” to distinguish it from SAP system function module. This is required.
- Enter or create a function group, again beginning with a “Z”
- Enter a required short description and click on the “Save” button to create the function module.
- Once the function module is loaded into the SAP Workbench, select the Attributes tab and select the “Remote-Enabled Module” if you intend to use the function module from other external application.
- On the Import tab enter an input parameter field for the customer number since the KNVV table is part of the SAP customer Master and the KVGR1 field is a reserve field. For this example I am entering CUSTOMER_NBR as parameter name, Typing will be TYPE, Associated Type is the field we want to model which will be KUNNR or the customer number field in the KNVV table. Since this is a remote enabled function, you will need to select the “Pass Value” option otherwise leaving it unchecked would pass the value by reference. Also leave the Optional option unselected as this parameter is required.
- Next you have two choices, either you define an Export field through the Export tab or you define a Structure or Table in the Tables tab. For this simple example, I will define an Export parameter through the Export tab.
- In the Export tab, enter an import parameter name as CUSTOMER_GRP, typing as TYPE, Associated type is KVGR1 and select Pass Value.This export parameter field will be used to store the KVGR1 value for the selected CUSTOMER_NBR import value.
- Move to the Exceptions tab and enter an Exception parameter : NO_VALUE and corresponding short text as “No information for this customer number”. This value will be used to raise an error if no customer group 1 value exist for this customer number.
- Finally the source code which will entered through the Source code tab of the SE37 Function Builder module of the ABAP Workbench Tools.
- When you access the Abap editor you will notice that the import, export and exception parameters have already been entered for you. Please do not touch this code.
- To get the required value, you will need to perform a simple SQL query using the ABAP syntax which can be cryptic at times. You will also notice that the SQL doesn’t exactly correspond to the standard ANSI SQL or SQL:2011 which is the latest revision of the SQL language.
- To get the customer group 1 value write the SQL code as in the sample code below which will place the value of the KVGR1 field into the Customer_Grp export field where the KUNNR field in the KNVV table equals the import value in Customer_Nbr. Be careful of the period ”.” which are very important otherwise you will get syntax errors.
- To raise an exception in case there is no value, perform a simple if statement as below and calling the RAISE NO_VALUE. exception.
*" VALUE(CUSTOMER_NBR) TYPE KUNNR
*" VALUE(CUSTOMER_GRP) TYPE KVGR1
select KVGR1 INTO CUSTOMER_GRP from KNVV
WHERE KUNNR eq CUSTOMER_NBR.
IF CUSTOMER_GRP EQ ''.
Transport Function Module to Production
To use the function module, you will need to activate by either selecting the “Activate” tool bar command (it looks like a match) or do Ctrl+F3 and save the function module. to move the function module from the Development environment to QA and eventually to Production, you will need to create a Transport Request which will be executed by a Basis operator or someone else who is qualified to perform these operations. To create a Transport Request, open the Object Navigator (T-code SE80) and select your package from the Package field, then expand the Function Groups node, then expand the Function Modules node under your function group and right click on the function module you just created. Under “Other Functions” select the “Write Transport Entry” and click on the “New Document” icon. In the corresponding utility screen, enter a short text and click the save button to generate the Transport Request number which must be sent to the appropriate person when requesting a transport.
Finally click on the Transport Organizer, expand your transport request and right click on your function module, Z_SD_SALESINFOand select the Release command from the context menu.
hopefully you have fully tested the function module within SAP using the SE37 transaction and from your external application.
More by this Author
This is a tutorial on using the SAP .Net Connector, NCO 188.8.131.52 for .Net 4 and Visual Studio 2010.
(c) klanguedoc 2010. iOS SQLite Database is a tutorial that demonstrates how to create an iOS iPhone and iPad applications with a SQLite database.
A free and complete software development proposal template with budget, ROI and CAGR formulas and instructions. Detailed instructions to help you prepare a winning software development proposal.
No comments yet.