ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Create SAP Function Module to get KVGR1 from KNVV

Updated on December 20, 2012
Source

(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.

Figure 1: Create function module
Figure 1: Create function module | Source
Figure 2 : Setting Attributes
Figure 2 : Setting Attributes | Source
Figure 3 : Setting Import Parameter
Figure 3 : Setting Import Parameter | Source
Figure 4: Defining Export Parameters
Figure 4: Defining Export Parameters | Source
Figure 5: Defining Exception Message
Figure 5: Defining Exception Message | Source

Create Function Module (TCode SE37)

  1. Enter Function Module name starting with a “Z” to distinguish it from SAP system function module. This is required.
  2. Enter or create a function group, again beginning with a “Z”
  3. Enter a required short description and click on the “Save” button to create the function module.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. Finally the source code which will entered through the Source code tab of the SE37 Function Builder module of the ABAP Workbench Tools.
  10. 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.
  11. 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.
  12. 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.
  13. To raise an exception in case there is no value, perform a simple if statement as below and calling the RAISE NO_VALUE. exception.

Source Code

FUNCTION Z_SD_SALESINFO.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(CUSTOMER_NBR) TYPE KUNNR
*" EXPORTING
*" VALUE(CUSTOMER_GRP) TYPE KVGR1
*" EXCEPTIONS
*" NO_VALUE
*"----------------------------------------------------------------------

select KVGR1 INTO CUSTOMER_GRP from KNVV
WHERE KUNNR eq CUSTOMER_NBR.
ENDSELECT.


IF CUSTOMER_GRP EQ ''.
RAISE NO_VALUE.
ENDIF.



ENDFUNCTION.

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.

Figure 6: SAP ABAP Workbench
Figure 6: SAP ABAP Workbench | Source

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)