Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Hi Friends,

Below function module code will help you to get the pricing conditions of a sales order based on the invoice number. When an invoice number is passed to the function module, it will looks for the pricing conditions associated to the sales order corresponding to the invoice number and populated to the custom internal table ZV_PRICING_CONDITION.

Structure for ZV_PRICING_CONDITION

Row

Field Name

Position

Data Element

Domain

Data type

Length

Description

1

KPOSN

1

KPOSN

NUM6

NUMC

6

Condition item number

2

KSCHL

2

KSCHA

KSCHL

CHAR

4

Condition type

3

DRUKZ

3

DRUKZ

DRUKZ

CHAR

1

Print ID for condition lines

4

KWERT

4

KWERT

WERTV7

CURR

13

Condition value

5

KBETER

5

KBETR

WERTV6

CURR

11

Rate (condition amount or percentage)

6

VTEXT

6

VTXTK

TEXT20

CHAR

20

Name

7

KAWRT

7

KAWRT

TEXT20

CURR

20

Condition base value

Main Program Code: SAPLZV_PRICING_GROUP

Error rendering macro 'code': Invalid value specified for parameter 'lang'
*******************************************************************
*   System-defined Include-files.                                *
*******************************************************************
  INCLUDE LZV_PRICING_GROUPTOP.              " Global Data
  INCLUDE LZV_PRICING_GROUPUXX.              " Function Modules
*******************************************************************
*   User-defined Include-files (if necessary).                   *
*******************************************************************
* INCLUDE LZV_PRICING_GROUPF...              " Subprograms
* INCLUDE LZV_PRICING_GROUPO...              " PBO-Modules
* INCLUDE LZV_PRICING_GROUPI...              " PAI-Modules
  INCLUDE  LZV_PRICING_GROUPFRM.              " Form

 

-------------------------------------------------------------------------------

Include Program Code:

-------------------------------------------------------------------------------

INCLUDE LZV_PRICING_GROUPTOP.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
FUNCTION-POOL ZV_PRICING_GROUP.             "MESSAGE-ID ..
*Internal tables
DATA: I_VBRK         TYPE STANDARD TABLE OF VBRK,
      I_VBRP         TYPE STANDARD TABLE OF VBRP,
      I_COMM_HEAD_I  TYPE KOMK,
      I_COMM_ITEM_I  TYPE KOMP,
      I_TKOMV      TYPE STANDARD TABLE OF KOMV,
      I_B_TKOMV     TYPE STANDARD TABLE OF KOMV,
      I_A_TKOMVD     TYPE STANDARD TABLE OF KOMVD,
      I_T685T      TYPE STANDARD TABLE OF T685T,
      I_T683S      TYPE STANDARD TABLE OF T683S,
      I_KONV         TYPE STANDARD TABLE OF KONV,
*Work areas
      WA_VBRK        TYPE VBRK,
      WA_VBRP        TYPE VBRP,
      WA_T685T       TYPE T685T,
      WA_T683S       TYPE T683S,
      WA_TKOMV       TYPE KOMV,
      WA_KONV        TYPE KONV,
      WA_PRICING_TAB TYPE ZVPRICE,
      WS_C_KWERT     TYPE KOMV-KWERT,
      W_C_POSNR      TYPE VBRP-POSNR,
      W_C_SPART      TYPE VBRK-SPART,
      WS_C_KSCHL     TYPE KOMV-KSCHL,
      WA_A_TKOMV     TYPE KOMV,
      WA_B_TKOMV     TYPE KOMV,
      WS_C_TABIX     TYPE SY-TABIX,
      WS_LINES       TYPE I.
*Work areas for forms.
DATA: I_T683S_1        TYPE STANDARD TABLE OF T683S,
      WA_T683S_1       TYPE T683S,
      WA_PRICING_TAB_1 TYPE ZVPRICE,
      WS_C_KAWRT       TYPE KOMV-KAWRT.

 

 

-------------------------------------------------------------------------------

INCLUDE LZV_PRICING_GROUPUXX.

Error rendering macro 'code': Invalid value specified for parameter 'lang'
*****************************************************************
*   THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.             *
*   NEVER CHANGE IT MANUALLY, PLEASE!                           *
*****************************************************************
INCLUDE LZV_PRICING_GROUPU01.
"Z_VPRICING_CONDITIONS
-------------------------------------------------------------------------------
INCLUDE LZV_PRICING_GROUPU01.
Error rendering macro 'code': Invalid value specified for parameter 'lang'
FUNCTION Z_VPRICING_CONDITIONS .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"    REFERENCE(W_C_VBELN) TYPE VBRK-VBELN
*"  CHANGING
*"    REFERENCE(I_PRICING_TAB) TYPE ZVPRICE_TABLE_TYPE
*"    REFERENCE(I_PRICING_TAB_1) TYPE ZVPRICE_TABLE_TYPE
*"----------------------------------------------------------------------
*----------------------------------------------------------------------*
* Description           : FM for calculating the Pricing conditions that
*                        need to be displayed on the forms which are
*                        triggered from the invoice for both I-level and CF.
*----------------------------------------------------------------------*
*get the knumv related to the billing document number form VBRK
  SELECT VBELN VKORG VTWEG SPART KNUMV
         FROM VBRK
         INTO CORRESPONDING FIELDS OF TABLE I_VBRK
         WHERE VBELN = W_C_VBELN.
  IF SY-SUBRC = 0.
    CLEAR WA_VBRK.
    READ TABLE I_VBRK INTO WA_VBRK INDEX 1.
    IF SY-SUBRC = 0.
*Header Structure for I-level, CF pricing
      I_COMM_HEAD_I-BELNR  = W_C_VBELN.
      I_COMM_HEAD_I-KNUMV  = WA_VBRK-KNUMV.
      I_COMM_HEAD_I-VKORG  = WA_VBRK-VKORG.
      I_COMM_HEAD_I-VTWEG  = WA_VBRK-VTWEG.
      I_COMM_HEAD_I-SPART  = WA_VBRK-SPART.
    ENDIF.
  ENDIF.
*get the posnr matnr related to the billing document line item numbers form VBRP
  SELECT POSNR MATNR VBELN
         FROM VBRP
         INTO CORRESPONDING FIELDS OF TABLE I_VBRP
         WHERE VBELN = W_C_VBELN.
  SORT I_VBRP BY POSNR.
*&-----------------------------------------------------------------------*
*       Start Pricing related to the i-level
*&-----------------------------------------------------------------------*
  IF WA_VBRK-SPART = '20'. "i-level
    W_C_SPART = WA_VBRK-SPART.
    CLEAR I_TKOMV.
    CALL FUNCTION 'RV_KONV_SELECT'
      EXPORTING
        COMM_HEAD_I                 = I_COMM_HEAD_I
       GENERAL_READ                = 'X'
*      READ_CONDITION_RECORD       = ' '
*     IMPORTING
*       COMM_HEAD_E                 = i_a_tkomv
      TABLES
        TKOMV                       = I_TKOMV.
*Check for the print indicators in T683S
    DESCRIBE TABLE I_TKOMV LINES WS_LINES.
    IF WS_LINES NE 0.
      SELECT STUNR KSCHL DRUKZ KVEWE KAPPL KALSM ZAEHK
          FROM T683S
          INTO CORRESPONDING FIELDS OF TABLE I_T683S
          FOR ALL ENTRIES IN I_TKOMV
          WHERE KSCHL = I_TKOMV-KSCHL
            AND DRUKZ IN ('b', 'B')
            AND KVEWE NE ''
            AND KAPPL NE ''
            AND KALSM NE ''
            AND STUNR NE ''.
*              AND zaehk NE ''.
    ENDIF.
    SORT I_T683S BY STUNR.
*logic to consolidate the line items based on the KSCHL value
    SORT I_TKOMV BY KSCHL.
    CLEAR WS_C_KWERT.
    LOOP AT I_TKOMV INTO WA_A_TKOMV.
      WS_C_TABIX = SY-TABIX + 1.
      WS_C_KWERT = WS_C_KWERT + WA_A_TKOMV-KWERT.
      CLEAR WA_B_TKOMV.
      READ TABLE I_TKOMV INTO WA_B_TKOMV INDEX WS_C_TABIX.
      IF WA_A_TKOMV-KSCHL NE WA_B_TKOMV-KSCHL.
        WA_A_TKOMV-KWERT = WS_C_KWERT.
        APPEND WA_A_TKOMV TO I_B_TKOMV.
        CLEAR WS_C_KWERT.
      ENDIF.
    ENDLOOP.
    I_TKOMV[] = I_B_TKOMV[].
    PERFORM F0001_FILL_STRUCTURE TABLES I_PRICING_TAB I_PRICING_TAB_1
                                 USING  W_C_POSNR
                                       W_C_SPART.
  ENDIF. "i-level.
*&-----------------------------------------------------------------------*
*       Start Pricing related to the CF
*&-----------------------------------------------------------------------*
  IF WA_VBRK-SPART = '10'. "CF
    W_C_SPART = WA_VBRK-SPART.
    LOOP AT I_VBRP INTO WA_VBRP.
*Item Structure for CF pricing
      I_COMM_ITEM_I-KPOSN  = WA_VBRP-POSNR.
      W_C_POSNR            = WA_VBRP-POSNR.
      I_COMM_ITEM_I-MATNR  = WA_VBRP-MATNR.
      CLEAR I_TKOMV.
      CALL FUNCTION 'RV_PRICE_PRINT_ITEM'
        EXPORTING
          COMM_HEAD_I = I_COMM_HEAD_I
          COMM_ITEM_I = I_COMM_ITEM_I
        TABLES
          TKOMV       = I_TKOMV
          TKOMVD      = I_A_TKOMVD.
*Check for the print indicators in T683S
      DESCRIBE TABLE I_TKOMV LINES WS_LINES.
      IF WS_LINES NE 0.
        SELECT STUNR KSCHL DRUKZ KVEWE KAPPL KALSM ZAEHK
          FROM T683S
          INTO CORRESPONDING FIELDS OF TABLE I_T683S
          FOR ALL ENTRIES IN I_TKOMV
          WHERE KSCHL = I_TKOMV-KSCHL
            AND DRUKZ IN ('b', 'B')
            AND KVEWE NE ''
            AND KAPPL NE ''
            AND KALSM NE ''
            AND STUNR NE ''. "#CCE
*              AND zaehk NE ''.
      ENDIF.
      PERFORM F0001_FILL_STRUCTURE TABLES I_PRICING_TAB I_PRICING_TAB_1
                                   USING  W_C_POSNR
                                          W_C_SPART.

    ENDLOOP.
  ENDIF. "CF
ENDFUNCTION.
-------------------------------------------------------------------------------
INCLUDE  LZV_PRICING_GROUPFRM.
*&---------------------------------------------------------------------*
*&  Include           LZV_PRICING_GROUPFRM
*&---------------------------------------------------------------------*
**&-----------------------------------------------------------------------*
**&     Form  f0001_fill_structure
**&-----------------------------------------------------------------------*
**---1. Check for the print indicators in T683S
**---2. Get the condition text for the corresponding KSCHL value from T685T
**---3. Filling the table i_pricing_tab that need to be exported
**------------------------------------------------------------------------*
FORM F0001_FILL_STRUCTURE TABLES I_PRICING_TAB
                                I_PRICING_TAB_1
                          USING P_W_C_POSNR TYPE VBRP-POSNR
                                P_W_C_SPART TYPE VBRK-SPART.
*Get the condition text for the corresponding KSCHL value from T685T
  DESCRIBE TABLE I_T683S LINES WS_LINES.
  IF WS_LINES NE 0.
    SELECT SPRAS
           KVEWE
           KAPPL
           KSCHL
           VTEXT
       FROM T685T
       INTO CORRESPONDING FIELDS OF TABLE I_T685T
       FOR ALL ENTRIES IN I_T683S
       WHERE SPRAS = SY-LANGU AND
             KVEWE = 'A' AND
             KAPPL = 'V' AND
             KSCHL = I_T683S-KSCHL AND
             KSCHL NE SPACE.
  ENDIF.
*Filling the table i_pricing_tab that need to be exported
  SORT I_TKOMV BY KSCHL.
  SORT I_TKOMV BY KSCHL KPOSN.
  SORT I_T685T BY KSCHL.
  LOOP AT I_T683S INTO WA_T683S.
    CLEAR: WA_TKOMV, WA_T685T.
    IF  P_W_C_SPART = '10'. "CF
      CLEAR WA_TKOMV.
      READ TABLE I_TKOMV INTO WA_TKOMV
           WITH KEY KSCHL = WA_T683S-KSCHL KPOSN = P_W_C_POSNR
           BINARY SEARCH.
    ELSE. "I-LEVEL
      CLEAR WA_TKOMV.
      READ TABLE I_TKOMV INTO WA_TKOMV WITH KEY KSCHL = WA_T683S-KSCHL BINARY SEARCH.
    ENDIF.
    IF SY-SUBRC = 0.
      WA_PRICING_TAB-KSCHL = WA_TKOMV-KSCHL.
      WA_PRICING_TAB-KPOSN = WA_TKOMV-KPOSN.
      WA_PRICING_TAB-DRUKZ = WA_TKOMV-DRUKZ.
      WA_PRICING_TAB-KWERT = WA_TKOMV-KWERT.
      WA_PRICING_TAB-KBETR = WA_TKOMV-KBETR.
      CLEAR WA_T685T.
      READ TABLE I_T685T INTO WA_T685T WITH KEY KSCHL = WA_T683S-KSCHL BINARY SEARCH.
      IF SY-SUBRC = 0.
        IF WA_PRICING_TAB-KSCHL NE 'ZSP'.
          TRANSLATE WA_T685T-VTEXT TO UPPER CASE.
          WA_PRICING_TAB-VTEXT = WA_T685T-VTEXT.
        ELSE.
          WA_PRICING_TAB-VTEXT = 'NET INVOICE'.
        ENDIF.
      ENDIF.
      APPEND WA_PRICING_TAB TO I_PRICING_TAB.
    ENDIF."sy-subrc i_tkomv
  ENDLOOP.
  IF  P_W_C_SPART = '10'. "CF
*Check for the print indicators in T683S
    DESCRIBE TABLE I_TKOMV LINES WS_LINES.
    IF WS_LINES NE 0.
      SELECT KVEWE KAPPL KALSM STUNR ZAEHK KSCHL DRUKZ
      FROM T683S
      INTO CORRESPONDING FIELDS OF TABLE I_T683S_1
      FOR ALL ENTRIES IN I_TKOMV
      WHERE KSCHL = I_TKOMV-KSCHL
            AND DRUKZ IN ('b', 'B')
              AND KVEWE NE ''
              AND KAPPL NE ''
              AND KALSM NE ''
              AND STUNR NE ''
              AND ZAEHK NE ''.
    ENDIF.
    SORT I_T683S_1 BY STUNR.
    DELETE I_T683S_1 WHERE KSCHL NE 'ZGPL'
                       AND KSCHL NE 'ZGP2'
                       AND KSCHL NE 'ZGBP'
                       AND KSCHL NE 'ZGB2'
                       AND KSCHL NE 'ZIBP'
                       AND KSCHL NE 'ZIB2'.
    CLEAR: WA_PRICING_TAB_1, WS_C_KAWRT.
    SORT I_TKOMV BY KSCHL KPOSN.
    LOOP AT I_T683S_1 INTO WA_T683S_1.
      CLEAR: WA_TKOMV, WA_T685T.
      READ TABLE I_TKOMV INTO WA_TKOMV WITH KEY KSCHL = WA_T683S_1-KSCHL KPOSN = P_W_C_POSNR BINARY SEARCH.
      IF SY-SUBRC = 0.
        WS_C_KAWRT = WS_C_KAWRT + WA_TKOMV-KAWRT.
      ENDIF."sy-subrc i_tkomv
    ENDLOOP.
    WA_PRICING_TAB_1-KPOSN = WA_TKOMV-KPOSN.
    WA_PRICING_TAB_1-KAWRT = WS_C_KAWRT.
    APPEND WA_PRICING_TAB_1 TO I_PRICING_TAB_1.
  ENDIF. "CF
ENDFORM. "f0001_fill_structure

 

-------------------------------------------------------------------------------

  • No labels