Price List Report - Simulate a Pricing Procedure

Purpose
The purpose of this document is to describe the functionality provided by a new program "ZO2C_PRICE_LIST" which can be used to simulate a pricing procedure and provide a "price list" report for a range of materials specified on the selection-screen.

Audience
This document is intended for use by SAP SD functional consultants and end users who wish to see the Gross/Net/Cost Price of a range of materials.

Uploading program ZO2C_PRICE_LIST

The program source code is given in later section "Program Source Code". This source code can be uploaded into any SAP system by using the "Upload" function from transaction SE38. The name of the program can be modified to adhere to local SAP program naming standards, as required. The program was created on SAP ECC version 6.0, but may work on some earlier SAP release versions. All program text elements will be generated automatically (in English) upon running the program for the first time.

Selection-Screen
A brief description of the selection-screen is given below. The Sales Area and Product sections are used to restrict the range of materials for which the Price List is to be generated. Additionally, the "plant" field is also used to restrict the report to show only materials which exist in the specified plant. The "Additional Information for Price Calculation" section contains some of the information which is needed for the simulation of a pricing procedure. A SAP Standard Pricing Procedure, Order Type and Item Category are defaulted by the program. However, as most SAP installations will have custom (Y..., Z...) versions of these, it may be necessary to change these default values when the program is executed on the local SAP system. A quantity of 1 KG is also defaulted. This can modified if the price list needs to be generated for larger quantities (which takes scaled price conditions into account). The pricing date is defaulted to the current date, and this is the date on which all price conditions must be valid. All materials where no gross price is found will be suppressed from the report if the "Hide lines with no gross price" flag is ticked. Finally, an ALV report variant can be specified in the last section of the selection-screen.

Report Layout
The program produces a simple ALV report with the pricing information for each material found. The population of each column is the report is given below:

Column

SAP Field

Description

SOrg

MVKEVKORG

Sales Organisation

D Ch

MVKEVTWEG

Distribution Channel

Material

MVKEMATNR

Material Number Only the materials which exist for the specified Sales Area (in table MVKE) and specified Plant (in table MARC) will appear in the report. Materials where the deletion indicator is set at either plant or Sales Area level will be excluded from the report.

Description

MAKTMAKTX

Material Description in the logon language

Gross Price

KOMPKZWI1

As a default, the gross price is taken from the Subtotal 1 field in the Pricing Procedure.If Subtotal 1 is used for an alternative purpose in the local SAP system, the subroutine "GET_PRICE_CONDITIONS" will need to be updated to calculate in the Gross Price in a different way. Program ZO2C_PRICE_LIST contains a 2nd way of determining the Gross Price - where it will use the condition rate from the 1st active non-statistical condition type found of class "B" (Prices). For performance reasons, this alternative gross price determination is deactivated in the supplied source code, but this can be reactivated by a local developer if need be. The relevant coding is also contained in subroutine "GET_PRICE_CONDITIONS". * loop at ft_komv ASSIGNING <komv> * * * where koaid = gc_koaid_price. gd_gross_price = <komv>-kwert. exit.

* endloop.

Net Price

KOMPNETWR

The net price calculated by the pricing procedure is used for this column. Note: this is not the unit net price (NETPR), but the total net price (NETWR) for the quantity entered on the selection-screen.

Cost Price

KOMPWAVWR

The total cost price calculated by the pricing procedure. This is normally derived from statistical condition type VPRS in the pricing procedure, which itself is taken from the standard price in the material master (MBEW-STPRS).

Curr

KOMKWAERK

The currency used in the pricing procedure

Product Hierarchy

MVKEPRODH

The product hierarchy from the sales view of the material

Customer

P_KUNNR

The customer number entered on the selection-screen

Name

KNA1NAME1

The first line of the customer's name

Cust Country

KNA1LAND1

The customer country

Pricing Date

P_PRSDT

The pricing date entered on the selection-screen

Note: the Gross, Net and Cost Price columns will always be calculated using the quantity specified on the selection screen. i.e. they will show the total prices, not the unit prices.

Custom Pricing Fields
If the local SAP pricing procedures contain custom (e.g. ZZ...) fields in the header or item field catalogues, it will be necessary to populate these custom fields in this program. A developer will need to update subroutine "GET_PRICE_CONDITIONS" in the sections below to fill each custom field.

* If any bespoke ZZ... fields exist in the HEADER table KOMK, * these should be filled here * MOVE: * hdrtable1-zzfielda hdrtable2-zzfieldb TO fs_komk-zzfielda, TO fs_komk-zzfieldb.

* If any bespoke ZZ... fields exist in the ITEM table KOMP (or append * structure KOMPAZ), these should be filled here * MOVE: * itemtable1-zzfielda itemtable2-zzfieldb TO fs_komp-zzfielda, TO fs_komp-zzfieldb.

This is very similar to the way in which the custom fields are passed to the pricing communication structures in the SAP standard userexits below (in program MV45AFZZ):

y y

USEREXIT_PRICING_PREPARE_TKOMK (Header) USEREXIT_PRICING_PREPARE_TKOMP (Item)

Program Source Code

REPORT

zo2c_price_list.

************************************************************************ * Report ZO2C_PRICE_LIST * * * * Description: Report to simulate the pricing procedure and show * the Gross, Net and Cost price of a material Date : 22/03/2010 Author : Ali Crawshaw * * * * * *

kunnr_land1 TYPE land1. "Material Description gross_price TYPE netpr. TYPE prodh_d. . INCLUDE STRUCTURE mvke. knvv. TYPES: BEGIN OF gty_report.* * ************************************************************************ * Revision history : * ************************************************************************ * Date * Name : : Modification Id : * * * * * Description: * ************************************************************************ *************************** DATA DECLARATIONS ************************** ***** TABLES TABLES: mara. komp. TYPE netpr. mvke. vkorg vtweg matnr maktx TYPE vkorg. TYPES: END OF gty_mvke. TYPE matnr. TYPE vtweg. net_price cost_price waerk prodh kunnr TYPE netpr. TYPE kunnr. TYPE maktx. ***** TYPES TYPES: BEGIN OF gty_mvke. prsdt TYPE prsdt. TYPE waerk. kunnr_name1 TYPE name1.

TYPE bukrs. TYPE maktx. WITH UNIQUE KEY gtsrt_marc TYPE SORTED TABLE OF gty_marc matnr werks. slis_t_fieldcat_alv. TYPE lvorm. ***** INTERNAL TABLES * Standard Tables DATA: gt_komv gt_report TYPE STANDARD TABLE OF komv. vkorg bukrs TYPE vkorg.END OF gty_report. END OF gty_makt. WITH UNIQUE KEY . TYPES: BEGIN OF gty_makt. TYPE werks_d. gt_alv_fieldcat TYPE * Hashed Tables DATA: gth_vkorg_bukrs TYPE HASHED TABLE OF WITH UNIQUE KEY * Sorted Tables DATA: gtsrt_makt TYPE SORTED gty_vkorg_bukrs vkorg. TYPES: BEGIN OF gty_marc. WITH UNIQUE KEY gtsrt_mvke TYPE SORTED TABLE OF gty_mvke matnr vkorg vtweg. END OF gty_marc. END OF gty_vkorg_bukrs. ***** TYPE-POOLS TYPE-POOLS: slis. TABLE OF gty_makt matnr. matnr maktx TYPE matnr. TYPE STANDARD TABLE OF gty_report. matnr werks lvorm TYPE matnr. TYPES: BEGIN OF gty_vkorg_bukrs.

***** FIELD-SYMBOLS FIELD-SYMBOLS: <mvke> <report> <makt> TYPE gty_mvke. ***** CONSTANTS CONSTANTS: gc_x gc_alv_var_save types of variant ***** VARIABLES DATA: gd_maktx gd_bukrs gd_kunnr_name1 gd_kunnr_land1 gd_sales_area gd_last_sales_area gd_price_found_flag gd_gross_price gd_net_price gd_cost_price TYPE maktx. TYPE netpr. TYPE komp. TYPE netpr. <vkorg_bukrs> TYPE gty_vkorg_bukrs. TYPE disvariant. TYPE land1. . TYPE knvv. VALUE 'X'. VALUE 'A'. TYPE gty_makt. TYPE char6. TYPE textpool. WITH UNIQUE KEY ***** DATA: gs_komk gs_komp gs_mara gs_knvv gs_alv_layout gs_alv_dis_variant gs_textpool ***** TYPE-POOLS TYPE-POOLS: slis. TYPE gty_report. TYPE bukrs. TYPE netpr. <textpool> TYPE textpool. TYPE flag. TYPE slis_layout_alv. "Save all gd_mat_exists_in_plant TYPE flag. TYPE c TYPE c TYPE komk. TYPE char8. TYPE mara.gtsrt_textpool TYPE SORTED TABLE OF textpool id key. TYPE name1.

SELECTION-SCREEN END OF BLOCK prod. ***** . OBLIGATORY. p_hdnogr AS ..*----. OBLIGATORY. TYPE kwmeng TYPE vrkme DEFAULT DEFAULT '1' 'KG' OBLIGATORY. SELECT-OPTIONS: s_matnr FOR mvke-matnr. OBLIGATORY. PARAMETERS: PARAMETERS: p_prsdt LIKE komk-prsdt DEFAULT sy-datum.. OBLIGATORY. ***** . mvke-vtweg.. PARAMETERS: p_kunnr p_werks p_waers SELECTION-SCREEN SKIP 1. TYPE kalsmasd TYPE auart TYPE pstyv TYPE taxm1 TYPE taxk1 DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT 'RVAA01' OBLIGATORY. PARAMETERS: p_kalsm p_auart p_pstyv p_taxm1 p_taxk1 SELECTION-SCREEN SKIP 1. ****** . SELECTION-SCREEN END OF BLOCK area. LIKE mara-spart DEFAULT '01'.Sales Area SELECTION-SCREEN BEGIN OF BLOCK area WITH FRAME TITLE text-s03.. parameters: p_qty p_vrkme SELECTION-SCREEN SKIP 1. LIKE knvv-kunnr LIKE komp-werks LIKE komk-waerk DEFAULT 'EUR' OBLIGATORY. OBLIGATORY.. OBLIGATORY. CHECKBOX DEFAULT 'X'.SELECTION-SCREEN -----------------------------------------------***** Selections Block SELECTION-SCREEN BEGIN OF BLOCK sels WITH FRAME TITLE text-s01.Product SELECTION-SCREEN BEGIN OF BLOCK prod WITH FRAME TITLE text-s04..Additional fields for price calculation SELECTION-SCREEN BEGIN OF BLOCK addi WITH FRAME TITLE text-s05. 'TA' 'TAN' '1' '1' OBLIGATORY. SELECT-OPTIONS: s_vkorg s_vtweg PARAMETERS: p_spart FOR FOR mvke-vkorg.

SELECTION-SCREEN END OF BLOCK addi. * Build the Text Elements if this is the first time the program * is being run on this system PERFORM build_program_text_elements. gs_alv_dis_variant-variant = p_alvvar. SELECTION-SCREEN END OF BLOCK vari. PERFORM f4_alv_variant CHANGING p_alvvar. *************************** MAIN PROCESSING **************************** *&---------------------------------------------------------------------* *& Event INITIALIZATION * *&---------------------------------------------------------------------* INITIALIZATION. * Set the report name. PARAMETERS: p_alvvar TYPE slis_vari. CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE' EXPORTING i_save CHANGING cs_variant EXCEPTIONS wrong_input = 1 = gs_alv_dis_variant = gc_alv_var_save . *&---------------------------------------------------------------------* *& Event AT SELECTION-SCREEN * *&---------------------------------------------------------------------* * F4 Drop-down for ALV variant AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_alvvar. ***** Report Display Variant SELECTION-SCREEN BEGIN OF BLOCK vari WITH FRAME TITLE text-s02. as this is needed to save/retrieve ALV variants gs_alv_dis_variant = sy-repid. * Check that the ALV variant specified exists AT SELECTION-SCREEN ON p_alvvar. IF NOT p_alvvar IS INITIAL. SELECTION-SCREEN END OF BLOCK sels.

* Buld the ALV field catalog PERFORM alv_build_field_catalog. ENDIF. ******************************** FORMS ********************************* *&---------------------------------------------------------------------* *& Form GET_ALL_MATERIALS_BY_SALESAREA *&---------------------------------------------------------------------* * Get the list of materials . MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. display a message IF sy-subrc IS NOT INITIAL. *&---------------------------------------------------------------------* *& Event END-OF-SELECTION * *&---------------------------------------------------------------------* END-OF-SELECTION.not_found = 2 program_error = 3 OTHERS * = 4. * Initialise everything PERFORM init_data. * Build the report data PERFORM build_report_data. * Read the materials PERFORM get_all_materials_by_salesarea. * Get all the materials by plant PERFORM get_all_materials_by_plant. * And display the report PERFORM alv_display_report. ENDIF. *&---------------------------------------------------------------------* *& Event START-OF-SELECTION * *&---------------------------------------------------------------------* START-OF-SELECTION. If not found.

* Check that we found some materials for the plant entered on the selection * screen CHECK gtsrt_marc[] IS NOT INITIAL. . * Build the field catalog DATA: ls_fieldcat ld_col_pos CLEAR: ls_fieldcat. *----.i. * Get all the materials for this Sales Area SELECT * INTO TABLE gtsrt_mvke FROM mvke FOR ALL ENTRIES IN gtsrt_marc WHERE matnr EQ gtsrt_marc-matnr AND AND AND vkorg IN s_vkorg vtweg IN s_vtweg lvorm = space.e. "No deletion indicator set * No SUBRC check required ENDFORM. TYPE i. " GET_ALL_MATERIALS_BY_SALESAREA *&---------------------------------------------------------------------* *& Form ALV_BUILD_FIELD_CATALOG *&---------------------------------------------------------------------* * Build the ALV field catalog *----------------------------------------------------------------------* FORM alv_build_field_catalog . highlight TYPE slis_fieldcat_alv. add 1 to ld_col_pos. REFRESH gtsrt_mvke.Macro to add a field to the catalog ------------------------------DEFINE add_field_to_catalog. REFRESH gt_alv_fieldcat. * * &1 Field Name &2 Key field . ld_col_pos.*----------------------------------------------------------------------* FORM get_all_materials_by_salesarea .

*----. gc_x. ls_fieldcat-no_out endif. = &4. when others. * Do we hide this field? if &6 is initial. = 'GT_REPORT'. = &1. gc_x. clear: ls_fieldcat. END-OF-DEFINITION.* * * * &3 Text Headomg &4 Output Length &5 Remove leading zeros &6 Show field ls_fieldcat-col_pos ls_fieldcat-tabname ls_fieldcat-fieldname = ld_col_pos. = 'C333'. = 'X'. append ls_fieldcat to gt_alv_fieldcat. ls_fieldcat-key ls_fieldcat-emphasize endif. ls_fieldcat-seltext_l ls_fieldcat-outputlen ls_fieldcat-no_zero = &3. * Field specific handling case &1.Get the Column Titles --------------------------------------------add_field_to_catalog: * Field Name field 'VKORG' 'VTWEG' 'MATNR' Key space space gc_x Text text-a01 text-a02 text-a03 Len 4 2 18 NoZero Show space space space gc_x. * Do nothing endcase. . = &5. = 'X'. * Highlight this field in BLUE? if &2 is not initial.

. gc_x. gc_x. gc_x. gs_alv_layout-colwidth_optimize = 'X'. space space gc_x space space space space space space space text-a04 text-a05 text-a06 text-a07 text-a08 text-a09 text-a10 text-a11 text-a12 text-a13 35 12 12 12 3 12 10 12 12 10 space space space space space space gc_x space space space gc_x. gc_x. " ALV_BUILD_FIELD_CATALOG *&---------------------------------------------------------------------* *& Form ALV_DISPLAY_REPORT *&---------------------------------------------------------------------* * Display the report *----------------------------------------------------------------------* FORM alv_display_report . gc_x. * Set the ALV display options CLEAR gs_alv_layout.'MAKTX' 'GROSS_PRICE' 'NET_PRICE' 'COST_PRICE' 'WAERK' 'PRODH' 'KUNNR' 'KUNNR_NAME1' 'KUNNR_LAND1' 'PRSDT' ENDFORM. gc_x. gc_x. gs_alv_layout-min_linesize * And display the report * Call the ALV CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING * * * I_INTERFACE_CHECK I_BYPASSING_BUFFER I_BUFFER_ACTIVE i_callback_program * * * * * i_callback_pf_status_set i_callback_user_command I_CALLBACK_TOP_OF_PAGE I_CALLBACK_HTML_TOP_OF_PAGE I_CALLBACK_HTML_END_OF_LIST = ' ' = ' ' = ' ' = sy-repid = 'SET_CUSTOM_ALV_PF_STATUS' = 'HANDLE_ALV_EVENTS' = ' ' = ' ' = ' ' = 255. gc_x. gc_x.

* * * * I_STRUCTURE_NAME I_BACKGROUND_ID I_GRID_TITLE I_GRID_SETTINGS is_layout it_fieldcat = = ' ' = = = gs_alv_layout = gt_alv_fieldcat[] = = = = = = 'X' = gc_alv_var_save = gs_alv_dis_variant = = = = = 0 = 0 = 0 = 0 = 0 = 0 = = = = = * * * * * * IT_EXCLUDING IT_SPECIAL_GROUPS IT_SORT IT_FILTER IS_SEL_HIDE I_DEFAULT i_save is_variant * * * * * * * * * * * * * * * * * * IT_EVENTS IT_EVENT_EXIT IS_PRINT IS_REPREP_ID I_SCREEN_START_COLUMN I_SCREEN_START_LINE I_SCREEN_END_COLUMN I_SCREEN_END_LINE I_HTML_HEIGHT_TOP I_HTML_HEIGHT_END IT_ALV_GRAPHICS IT_HYPERLINK IT_ADD_FIELDCAT IT_EXCEPT_QINFO IR_SALV_FULLSCREEN_ADAPTER IMPORTING E_EXIT_CAUSED_BY_CALLER ES_EXIT_CAUSED_BY_USER TABLES t_outtab = = = gt_report .

*&---------------------------------------------------------------------* *& Form GET_MAKTX *&---------------------------------------------------------------------* * Get the material description *----------------------------------------------------------------------* FORM get_maktx USING fd_matnr TYPE matnr TYPE maktx.EXCEPTIONS OTHERS * No SUBRC check required ENDFORM. CHANGING fd_maktx CLEAR fd_maktx. * Now get the material description READ TABLE gtsrt_makt ASSIGNING <makt> WITH TABLE KEY matnr = fd_matnr. " GET_MAKTX *&---------------------------------------------------------------------* *& Form F4_ALV_VARIANT *&---------------------------------------------------------------------* * Search help for variant *----------------------------------------------------------------------* FORM f4_alv_variant CHANGING fd_var LIKE disvariant-variant. ENDFORM. ENDIF. ENDIF. IF sy-subrc IS INITIAL. read in all the material descriptions IF gtsrt_makt[] IS INITIAL. * If we haven't already done so. SELECT matnr maktx INTO TABLE gtsrt_makt FROM makt WHERE spras = sy-langu. " ALV_DISPLAY_REPORT = 0. * Fill the structure needed by the report . fd_maktx = <makt>-maktx.

fd_var = gs_alv_dis_variant-variant.gs_alv_dis_variant-variant = fd_var. . = gc_alv_var_save * Display error if not found IF sy-subrc IS NOT INITIAL. fd_kunnr_name1. * Look for any existing variants CALL FUNCTION 'REUSE_ALV_VARIANT_F4' EXPORTING is_variant = gs_alv_dis_variant i_save IMPORTING es_variant = gs_alv_dis_variant EXCEPTIONS OTHERS = 1. MESSAGE ID TYPE sy-msgid 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. * Otherwise. ENDFORM. CLEAR: fs_knvv. " F4_ALV_VARIANT *&---------------------------------------------------------------------* *& Form READ_CUSTOMER *&---------------------------------------------------------------------* * Get the Customer details from KNA1 + KNVV *----------------------------------------------------------------------* FORM read_customer USING fd_kunnr fd_vkorg fd_vtweg CHANGING fs_knvv TYPE kunnr TYPE vkorg TYPE vtweg TYPE knvv fd_kunnr_name1 TYPE name1 fd_kunnr_land1 TYPE land1. update the display variant structure ELSE. ENDIF.

* NO SUBRC check required ENDFORM. * Look to see if we have a customer SELECT SINGLE * INTO fs_knvv FROM knvv WHERE kunnr = fd_kunnr AND AND AND vkorg = fd_vkorg vtweg = fd_vtweg spart = p_spart. * "No space separation required Change of Sales Org.fd_kunnr_land1. CHECK fd_kunnr IS NOT INITIAL. * Build the Sales area that we can use for checking later CONCATENATE <mvke>-vkorg <mvke>-vtweg INTO gd_sales_area. * Loop around the materials found LOOP AT gtsrt_mvke ASSIGNING <mvke>. redetermine the company code of the Sales Org . * Get the Customer Name SELECT SINGLE name1 land1 INTO (fd_kunnr_name1. CLEAR: gd_sales_area. gd_last_sales_area. fd_kunnr_land1) FROM kna1 WHERE kunnr = fd_kunnr. " READ_CUSTOMER *&---------------------------------------------------------------------* *& Form BUILD_REPORT_DATA *&---------------------------------------------------------------------* * Build the Report data *----------------------------------------------------------------------* FORM build_report_data. CHECK sy-subrc IS INITIAL.

* Get the Price condition data PERFORM get_price_conditions TABLES USING gt_komv <mvke> gs_mara gs_knvv gd_bukrs CHANGING gs_komk . re-read the customer's Sales Area data IF gd_sales_area <> gd_last_sales_area. PERFORM read_material USING <mvke>-matnr CHANGING gs_mara gd_maktx gd_mat_exists_in_plant. ENDIF. get the material general view details ON CHANGE OF <mvke>-matnr. PERFORM get_bukrs USING <mvke>-vkorg CHANGING gd_bukrs. PERFORM read_customer USING p_kunnr <mvke>-vkorg <mvke>-vtweg CHANGING gs_knvv gd_kunnr_name1 gd_kunnr_land1. ENDON. * Take note of the Sales Area we've just processed gd_last_sales_area = gd_sales_area. * * Check that the current material exists in the plant entered on the selection-screen CHECK gd_mat_exists_in_plant = gc_x. * * Every time the material changes.ON CHANGE OF <mvke>-vkorg. ENDON. * * Every time there is a change of Sales Area.

PERFORM add_line_to_report TABLES USING gt_komv <mvke> gs_mara gs_komk gs_komp gd_gross_price gd_net_price gd_cost_price gd_maktx p_kunnr gd_kunnr_name1 gd_kunnr_land1. * Add the price information to the report IF gd_price_found_flag = gc_x.gs_komp gd_gross_price gd_net_price gd_cost_price gd_price_found_flag. ENDFORM. "GT_MVKE * Sort the report SORT gt_report BY vkorg vtweg matnr. ENDIF. Net + Cost price *----------------------------------------------------------------------* FORM get_price_conditions TABLES USING ft_komv fs_mvke STRUCTURE komv TYPE mvke . " BUILD_REPORT_DATA *&---------------------------------------------------------------------* *& Form GET_PRICE_CONDITIONS *&---------------------------------------------------------------------* * * Read the price conditions and determine the Gross. ENDLOOP.

fd_price_found_flag. TO fs_komk-fbuda. TO fs_komk. fs_komp.fs_mara fs_knvv fd_bukrs CHANGING fs_komk fs_komp fd_gross_price fd_net_price fd_cost_price TYPE TYPE TYPE TYPE TYPE TYPE TYPE TYPE mara knvv bukrs komk komp netpr netpr netpr flag. fd_cost_price. TO fs_komk. TO fs_komk-fkdat. TO fs_komk. TO fs_komk-auart_sd. TO fs_komk-erdat. TO fs_komk-taxk1. fd_price_found_flag TYPE * Init CLEAR: fs_komk. TO fs_komk-prsdt. fd_gross_price. REFRESH ft_komv. "Customer Tax "#EC ENHOK "#EC ENHOK "#EC ENHOK . fd_net_price. TO fs_komk-audat. TO fs_komk-kurrf_dat. TO fs_komk-kalsm. * MARA and MVKE below may not be too relevant for the header level. but * they are still moved to FS_KOMK here just in case any relevant fields * are found at the header level MOVE-CORRESPONDING: fs_mvke fs_mara fs_knvv MOVE: p_prsdt p_prsdt p_prsdt p_prsdt p_prsdt p_prsdt p_taxk1 Code p_auart p_auart p_kalsm TO fs_komk-auart.

TO fs_komk-vkorgau. TO fs_komk-vbtyp. TO fs_komk-belnr. TO fs_komk-vsbed. * If any bespoke ZZ. TO fs_komp. TO fs_komp-lagme. TO fs_komp-lmeng. TO fs_komk-bukrs. TO fs_komk-konda. TO fs_komk-trtyp. TO fs_komk-hwaer. TO fs_komp. TO fs_komp-ix_komk. TO fs_komp-prsok. TO fs_komk-waerk. fields exist in the HEADER table KOMK. TO fs_komk-zzfieldb. ..'V' p_spart '$000000001' '$000000001' p_waers p_waers fd_bukrs fs_mvke-vkorg p_werks fs_knvv-kunnr fs_knvv-kunnr fs_knvv-kunnr fs_knvv-konda 'C' 'H' '01' '1' TO fs_komk-kappl. TO fs_komp-evrwr. TO fs_komp-vrkme. TO fs_komk-knrze. TO fs_komk-werks. * these should be filled here * MOVE: * hdrtable1-zzfielda hdrtable2-zzfieldb MOVE-CORRESPONDING: fs_mara fs_mvke MOVE: p_qty p_qty p_qty 'X' 'X' 'X' '1' p_vrkme p_vrkme p_vrkme TO fs_komk-zzfielda. TO fs_komk-kunwe. TO fs_komk-knumv. "#EC ENHOK "#EC ENHOK TO fs_komp-mgame. TO fs_komk-kunre.. TO fs_komp-mglme. TO fs_komk-spart. TO fs_komp-prsfd. TO fs_komp-kursk. TO fs_komp-meins.

* Call the Pricing module CALL FUNCTION 'PRICING' EXPORTING calculation_type comm_head_i comm_item_i * * PRELIMINARY NO_CALCULATION IMPORTING = 'B' = fs_komk = fs_komp = ' ' = ' ' "Carry out new Pricing . TO fs_komp-pstyv. TO fs_komp-werks. TO fs_komp-ix_komk. * If any bespoke ZZ. TO fs_komp-aupos. TO fs_komp-stf_monate. TO fs_komp-stf_tage.. TO fs_komp-anz_tage. TO fs_komp-pmatn. TO fs_komp-kposn. TO fs_komp-umvkn. TO fs_komp-umvkz.p_taxm1 Tax Code p_pstyv fs_mara-matnr '000010' '000010' '000010' p_spart '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '$TEMP' p_werks TO fs_komp-taxm1. TO fs_komp-stf_jahre. fields exist in the ITEM table KOMP (or append * structure KOMPAZ). TO fs_komp-spart. TO fs_komp-anz_jahre. these should be filled here * MOVE: * itemtable1-zzfielda itemtable2-zzfieldb TO fs_komp-zzfielda. TO fs_komp-aubel. "Material TO fs_komp-anz_monate. TO fs_komp-stf_wochen. TO fs_komp-zzfieldb. TO fs_komp-anz_wochen. TO fs_komp-taxps..

comm_head_e comm_item_e TABLES tkomv * * * SVBAP CHANGING REBATE_DETERMINED EXCEPTIONS OTHERS this below = fs_komk = fs_komp = ft_komv = = ' ' = 0. exit. and exit the form . * * * * * * * * * * * * * We could look for the first PRICE (KOAID=B) price condition (inactive + statistical records would already have been removed above) For performance reasons. If the gross price is still initial. * If not found in subtotal 1 ELSE. check if the "hide records with no gross price" flag was set on the selection-screen. as we handle * Remove any statistical or inactive conditions DELETE ft_komv WHERE kinak = OR kstat = gc_x gc_x. this has been deactivated here. clear the price found flag (done again for program clarity).GROSS Price -----------------------------------------------------* This is normally stored in subtotal 1 in some of the SAP standard pricing * procedures (this may need to be changed for some SPA installations) IF fs_komp-kzwi1 IS NOT INITIAL. gd_gross_price = <komv>-kwert. If so. endloop. fd_gross_price = fs_komp-kzwi1. but could be reinstated later if need be loop at ft_komv ASSIGNING <komv> where koaid = gc_koaid_price. *----. "No SUBRC check required.

* If we have found a gross price. SAP Standard normally brings this price in from MBEW-STPRS * but this will not be found if no plant (i. fd_cost_price = fs_komp-wavwr.hence why this is mandatory on the * selection-screen IF fs_komp-wavwr IS NOT INITIAL. . * If not found in subtotal 2 ELSE.COST Price -----------------------------------------------------* The cost price should be returned in the field FS_KOMP-WAVWR * Inside function PRICING. NETPR would only * have the unit price. ENDIF. ENDIF. EXIT.NET Price ------------------------------------------------------* Use the NETWR field instead of NETPR. *----.* * As the flag is not set. *----. fd_net_price = fs_komp-netwr. valuation area) is * passed to the PRICING function . whereas NETWR has the price for the entire * quantity IF fs_komp-netwr IS NOT INITIAL. the cost is derived from condition type * VPRS. set the price found flag fd_price_found_flag = gc_x. CLEAR fd_price_found_flag. ENDIF. try one of the subtotal fields (this could differ according to each pricing procedure. SAP standard puts it in subtotal 2). * * * Otherwise. ENDIF. fd_net_price = fs_komp-kzwi2. it means that the record will not appear on the report IF fd_gross_price IS INITIAL AND p_hdnogr = gc_x.e. in case the user enters a * quantity greater than 1 on the selection-screen.

ENDFORM. " GET_PRICE_CONDITIONS *&---------------------------------------------------------------------* *& Form GET_BUKRS *&---------------------------------------------------------------------* * Get the company code *----------------------------------------------------------------------* FORM get_bukrs USING fd_vkorg TYPE vkorg TYPE bukrs. ENDFORM. " GET_BUKRS *&---------------------------------------------------------------------* *& Form ADD_LINE_TO_REPORT *&---------------------------------------------------------------------* * Add a line to the report *----------------------------------------------------------------------* FORM add_line_to_report TABLES USING ft_komv fs_mvke fs_mara fs_komk fs_komp STRUCTURE komv "#EC NEEDED TYPE TYPE TYPE TYPE mvke mara komk komp netpr netpr fd_gross_price TYPE fd_net_price TYPE . fd_bukrs = <vkorg_bukrs>-bukrs. * Now read the table READ TABLE gth_vkorg_bukrs ASSIGNING <vkorg_bukrs> WITH TABLE KEY vkorg = fd_vkorg. ENDIF. IF sy-subrc IS INITIAL. ENDIF. SELECT vkorg bukrs INTO TABLE gth_vkorg_bukrs FROM tvko. CHANGING fd_bukrs * Read in all the Sales Orgs IF gth_vkorg_bukrs[] IS INITIAL.

fd_mat_exists_in_plant.fd_cost_price fd_maktx fd_kunnr TYPE TYPE TYPE netpr maktx kunnr name1 land1. TO <report>. " ADD_LINE_TO_REPORT *&---------------------------------------------------------------------* *& Form READ_MATERIAL *&---------------------------------------------------------------------* * Read the material details (from MARA/MAKT) *----------------------------------------------------------------------* FORM read_material USING fd_matnr TYPE matnr TYPE mara TYPE maktx CHANGING fs_mara fd_maktx fd_mat_exists_in_plant TYPE flag. TO <report>-kunnr. TO <report>-cost_price. * Read the material GENERAL VIEW details SELECT SINGLE * INTO fs_mara . CLEAR: fs_mara. * Then fill the relevant data MOVE-CORRESPONDING: fs_komk fs_komp fs_mara fs_mvke MOVE: fd_maktx TO <report>. "#EC ENHOK "#EC ENHOK "#EC ENHOK "#EC ENHOK fd_gross_price TO <report>-gross_price. fd_net_price fd_cost_price fd_kunnr TO <report>-net_price. TO <report>. fd_kunnr_land1 TO <report>-kunnr_land1. fd_maktx. ENDFORM. fd_kunnr_name1 TO <report>-kunnr_name1. fd_kunnr_name1 TYPE fd_kunnr_land1 TYPE * Add a blank line to the report APPEND INITIAL LINE TO gt_report ASSIGNING <report>. TO <report>. TO <report>-maktx.

FROM mara WHERE matnr = fd_matnr. gd_kunnr_name1. ENDFORM. so no BINARY SEARCH necessary * If found. ENDIF. gd_bukrs. set the Mat exists in plant IF sy-subrc IS INITIAL. * Empty the internal tables REFRESH: gt_komv. gth_vkorg_bukrs. gt_alv_fieldcat. fd_mat_exists_in_plant = gc_x. . gtsrt_makt. * "#EC * Table is sorted. * Clear the variables CLEAR: gd_maktx. gt_report. " READ_MATERIAL *&---------------------------------------------------------------------* *& Form INIT_DATA *&---------------------------------------------------------------------* * Initialise everything *----------------------------------------------------------------------* FORM init_data . gd_kunnr_land1. gtsrt_mvke. * Check that the material exists in the plant entered on the selection * screen READ TABLE gtsrt_marc TRANSPORTING NO FIELDS WITH TABLE KEY matnr = fd_matnr werks = p_werks. * Get the material description PERFORM get_maktx USING fd_matnr CHANGING fd_maktx.

move: ' &3 else. Report Heading = &3.gd_sales_area. *----. ENDFORM.g. * * * * * * &1 = Text Element Type S = Selection-Screen I = Text Symbol &2 = Text Key (Selection-screen field name or text-symbol xxx id) &3 = Text Description Initialise clear gs_textpool. Text Elements. = &1.Method to add an entry to the Textpool -------------------------DEFINE m_add_to_textpool. "All others. to gs_textpool-entry+8. = &2. " INIT_DATA *&---------------------------------------------------------------------* *& Form BUILD_PROGRAM_TEXT_ELEMENTS *&---------------------------------------------------------------------* * Build the program text elements if necesssary *----------------------------------------------------------------------* FORM build_program_text_elements . * Textpool Type gs_textpool-id * Textpool Key/Name gs_textpool-key * * * Text Description Note: for some reason. e. gd_last_sales_area. gd_cost_price. gd_gross_price. gs_textpool-entry . gd_price_found_flag. gd_net_price. "Select-option or Parameter ' to gs_textpool-entry+0(8). 8 blank spaces must be added to the start of any Selection-screen Select-options or Parameters if &1 = 'S'.

'I' 'A05' 'Gross Price'. 'I' 'A08' 'Curr'. READ TEXTPOOL sy-repid INTO gtsrt_textpool LANGUAGE sy-langu. * Text-Symbols m_add_to_textpool: 'I' 'A01' 'SOrg'. * Also get the length of the text element gs_textpool-length = strlen( gs_textpool-entry ). 'I' 'A02' 'DCh'. so no BINARY SEARCH necessary * If not found.endif. 'I' 'A03' 'Material'. * Table is SORTED type. A01) to see if we have already * built the text elements on a previous run of the program READ TABLE gtsrt_textpool ASSIGNING <textpool> WITH TABLE KEY id = 'I' key = 'A01'. 'I' 'A09' 'Prod Hierarchy'. * Start by removing whichever texts are already existing UNASSIGN <textpool>. 'I' 'A07' 'Cost Price'. insert gs_textpool into table gtsrt_textpool. *----. 'I' 'A04' 'Description'. start to build the text elements IF sy-subrc IS NOT INITIAL. END-OF-DEFINITION.End of Method --------------------------------------------------* Read the textpool for this program to see if the text elements have * already been loaded REFRESH gtsrt_textpool.g. REFRESH gtsrt_textpool. 'I' 'A06' 'Net Price'. * Now look for an arbitrary text element (e. .

'Quantity for Calculation'. 'Currency'. 8 blank spaces must be added to the start of any Select-options or Parameters texts. 'Material'. 'I' 'S01' 'Selections'. This is 'S' 'P_HDNOGR' 'Hide lines with no gross price'. 'I' 'A12' 'Cust Country'. 'I' 'S02' 'Report'. 'I' 'S04' 'Product'. 'Sales Organization'.'I' 'A10' 'Customer'. 'Item Category'. 'Distribution Channel'. 'Material Tax Code'. 'Plant'. 'Customer Tax Code'. . 'I' 'S05' 'Additional Information for Price Calculation'. 'I' 'A13' 'Pricing Date'. 'S' 'P_AUART' 'Order Type'. 'Division'. 'I' 'A11' 'Name'. 'Customer'. 'S' 'P_KALSM' 'S' 'P_KUNNR' 'S' 'P_PRSDT' 'S' 'P_PSTYV' 'S' 'P_QTY' 'S' 'P_SPART' 'S' 'P_TAXK1' 'S' 'P_TAXM1' 'S' 'P_VRKME' 'S' 'P_WAERS' 'S' 'P_WERKS' 'S' 'S_MATNR' 'S' 'S_VKORG' 'S' 'S_VTWEG' * Report Title m_add_to_textpool: 'R' space 'Price List Report'. 'I' 'S03' 'Sales Area'. * * * * Selection-screen texts Note: for some reason. 'Sales UoM'. 'Pricing Procedure'. done inside the macro m_add_to_textpool: 'S' 'P_ALVVAR' 'Report Display Variant'. 'Pricing date'.

* Now we need to resubmit the program SUBMIT (sy-repid) VIA SELECTION-SCREEN. " GET_ALL_MATERIALS_BY_PLANT . ENDIF. ENDFORM. " BUILD_PROGRAM_TEXT_ELEMENTS *&---------------------------------------------------------------------* *& Form GET_ALL_MATERIALS_BY_PLANT *&---------------------------------------------------------------------* * * Get all the materials for the plant entered on the selection screen *----------------------------------------------------------------------* FORM get_all_materials_by_plant . * Get all the materials found for the plant SELECT matnr werks lvorm INTO TABLE gtsrt_marc FROM marc WHERE matnr IN s_matnr AND AND werks = lvorm = p_werks space. * And insert the new textpool + commit INSERT textpool sy-repid FROM gtsrt_textpool LANGUAGE sy-langu. "No deletion indicator set * No SUBRC check required ENDFORM. COMMIT WORK AND WAIT. * Init REFRESH gtsrt_marc.* Now delete the old textpool (regardless of how much was there) DELETE TEXTPOOL sy-repid LANGUAGE sy-langu.