You are on page 1of 30

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 * * * * * *

************************************************************************ * Revision history : *

************************************************************************ * Date * Name : : Modification Id : * * * *

* Description: *

************************************************************************

*************************** DATA DECLARATIONS ************************** ***** TABLES TABLES: mara, mvke, knvv, komp. ***** TYPES TYPES: BEGIN OF gty_mvke. INCLUDE STRUCTURE mvke. TYPES: END OF gty_mvke. TYPES: BEGIN OF gty_report, vkorg vtweg matnr maktx TYPE vkorg, TYPE vtweg, TYPE matnr, TYPE maktx, "Material Description

gross_price TYPE netpr, net_price cost_price waerk prodh kunnr TYPE netpr, TYPE netpr, TYPE waerk, TYPE prodh_d, TYPE kunnr,

kunnr_land1 TYPE land1, kunnr_name1 TYPE name1, prsdt TYPE prsdt,

END OF gty_report. TYPES: BEGIN OF gty_makt, matnr maktx TYPE matnr, TYPE maktx,

END OF gty_makt. TYPES: BEGIN OF gty_vkorg_bukrs, vkorg bukrs TYPE vkorg, TYPE bukrs,

END OF gty_vkorg_bukrs. TYPES: BEGIN OF gty_marc, matnr werks lvorm TYPE matnr, TYPE werks_d, TYPE lvorm,

END OF gty_marc. ***** TYPE-POOLS TYPE-POOLS: slis. ***** INTERNAL TABLES * Standard Tables DATA: gt_komv gt_report TYPE STANDARD TABLE OF komv, TYPE STANDARD TABLE OF gty_report, slis_t_fieldcat_alv.

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.

TABLE OF gty_makt matnr,

WITH UNIQUE KEY gtsrt_mvke TYPE SORTED

TABLE OF gty_mvke matnr vkorg vtweg,

WITH UNIQUE KEY

gtsrt_marc

TYPE SORTED

TABLE OF gty_marc matnr werks,

WITH UNIQUE KEY

gtsrt_textpool

TYPE SORTED

TABLE OF textpool id key.

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. ***** 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 bukrs, TYPE name1, TYPE land1, TYPE char8, TYPE char6, TYPE flag, TYPE netpr, TYPE netpr, TYPE netpr, TYPE c TYPE c TYPE komk, TYPE komp, TYPE mara, TYPE knvv,

TYPE slis_layout_alv, TYPE disvariant, TYPE textpool.

VALUE 'X', VALUE 'A'. "Save all

gd_mat_exists_in_plant TYPE flag. ***** FIELD-SYMBOLS FIELD-SYMBOLS: <mvke> <report> <makt> TYPE gty_mvke, TYPE gty_report, TYPE gty_makt,

<vkorg_bukrs> TYPE gty_vkorg_bukrs, <textpool> TYPE textpool.

*----- SELECTION-SCREEN -----------------------------------------------***** Selections Block SELECTION-SCREEN BEGIN OF BLOCK sels WITH FRAME

TITLE text-s01. ****** ...Sales Area SELECTION-SCREEN BEGIN OF BLOCK area WITH FRAME

TITLE text-s03. SELECT-OPTIONS: s_vkorg s_vtweg PARAMETERS: p_spart FOR FOR mvke-vkorg, mvke-vtweg.

LIKE mara-spart DEFAULT '01'.

SELECTION-SCREEN END OF BLOCK area. ***** ...Product SELECTION-SCREEN BEGIN OF BLOCK prod WITH FRAME

TITLE text-s04. SELECT-OPTIONS: s_matnr FOR mvke-matnr.

SELECTION-SCREEN END OF BLOCK prod. ***** ...Additional fields for price calculation SELECTION-SCREEN BEGIN OF BLOCK addi WITH FRAME

TITLE text-s05. PARAMETERS: p_kunnr p_werks p_waers SELECTION-SCREEN SKIP 1. PARAMETERS: p_kalsm p_auart p_pstyv p_taxm1 p_taxk1 SELECTION-SCREEN SKIP 1. parameters: p_qty p_vrkme SELECTION-SCREEN SKIP 1. PARAMETERS: PARAMETERS: p_prsdt LIKE komk-prsdt DEFAULT sy-datum. CHECKBOX DEFAULT 'X'. TYPE kwmeng TYPE vrkme DEFAULT DEFAULT '1' 'KG' OBLIGATORY, OBLIGATORY. TYPE kalsmasd TYPE auart TYPE pstyv TYPE taxm1 TYPE taxk1 DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT 'RVAA01' OBLIGATORY, 'TA' 'TAN' '1' '1' OBLIGATORY, OBLIGATORY, OBLIGATORY, OBLIGATORY. LIKE knvv-kunnr LIKE komp-werks LIKE komk-waerk DEFAULT 'EUR' OBLIGATORY, OBLIGATORY, OBLIGATORY.

p_hdnogr AS

SELECTION-SCREEN END OF BLOCK addi. SELECTION-SCREEN END OF BLOCK sels. ***** Report Display Variant SELECTION-SCREEN BEGIN OF BLOCK vari WITH FRAME

TITLE text-s02. PARAMETERS: p_alvvar TYPE slis_vari. SELECTION-SCREEN END OF BLOCK vari. *************************** MAIN PROCESSING **************************** *&---------------------------------------------------------------------* *& Event INITIALIZATION *

*&---------------------------------------------------------------------* INITIALIZATION. * Set the report name, as this is needed to save/retrieve ALV variants gs_alv_dis_variant = sy-repid. * Build the Text Elements if this is the first time the program * is being run on this system PERFORM build_program_text_elements. *&---------------------------------------------------------------------* *& Event AT SELECTION-SCREEN *

*&---------------------------------------------------------------------* * F4 Drop-down for ALV variant AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_alvvar. PERFORM f4_alv_variant CHANGING p_alvvar. * Check that the ALV variant specified exists AT SELECTION-SCREEN ON p_alvvar. IF NOT p_alvvar IS INITIAL. gs_alv_dis_variant-variant = p_alvvar. CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE' EXPORTING i_save CHANGING cs_variant EXCEPTIONS wrong_input = 1 = gs_alv_dis_variant = gc_alv_var_save

not_found

= 2

program_error = 3 OTHERS * = 4.

If not found, display a message IF sy-subrc IS NOT INITIAL. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDIF.

*&---------------------------------------------------------------------* *& Event START-OF-SELECTION *

*&---------------------------------------------------------------------* START-OF-SELECTION. * Initialise everything PERFORM init_data. * Get all the materials by plant PERFORM get_all_materials_by_plant. * Read the materials PERFORM get_all_materials_by_salesarea. * Build the report data PERFORM build_report_data. *&---------------------------------------------------------------------* *& Event END-OF-SELECTION *

*&---------------------------------------------------------------------* END-OF-SELECTION. * Buld the ALV field catalog PERFORM alv_build_field_catalog. * And display the report PERFORM alv_display_report. ******************************** FORMS ********************************* *&---------------------------------------------------------------------* *& Form GET_ALL_MATERIALS_BY_SALESAREA

*&---------------------------------------------------------------------* * Get the list of materials

*----------------------------------------------------------------------* FORM get_all_materials_by_salesarea . REFRESH gtsrt_mvke. * Check that we found some materials for the plant entered on the selection * screen CHECK gtsrt_marc[] IS NOT INITIAL. * 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. "No deletion indicator set

* No SUBRC check required ENDFORM. " GET_ALL_MATERIALS_BY_SALESAREA

*&---------------------------------------------------------------------* *& Form ALV_BUILD_FIELD_CATALOG

*&---------------------------------------------------------------------* * Build the ALV field catalog

*----------------------------------------------------------------------* FORM alv_build_field_catalog . * Build the field catalog DATA: ls_fieldcat ld_col_pos CLEAR: ls_fieldcat, ld_col_pos. REFRESH gt_alv_fieldcat. *----- Macro to add a field to the catalog ------------------------------DEFINE add_field_to_catalog. add 1 to ld_col_pos. * * &1 Field Name &2 Key field - i.e. highlight TYPE slis_fieldcat_alv, TYPE i.

* * * *

&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. = 'GT_REPORT'. = &1.

Field specific handling case &1. when others.

Do nothing endcase.

Highlight this field in BLUE? if &2 is not initial. ls_fieldcat-key ls_fieldcat-emphasize endif. ls_fieldcat-seltext_l ls_fieldcat-outputlen ls_fieldcat-no_zero = &3. = &4. = &5. = 'X'. = 'C333'.

Do we hide this field? if &6 is initial. ls_fieldcat-no_out endif. append ls_fieldcat to gt_alv_fieldcat. clear: ls_fieldcat. END-OF-DEFINITION. = 'X'.

*----- 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, gc_x, gc_x,

'MAKTX' 'GROSS_PRICE' 'NET_PRICE' 'COST_PRICE' 'WAERK' 'PRODH' 'KUNNR' 'KUNNR_NAME1' 'KUNNR_LAND1' 'PRSDT' ENDFORM.

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, gc_x, gc_x, gc_x, gc_x, gc_x, gc_x, gc_x, gc_x.

" ALV_BUILD_FIELD_CATALOG

*&---------------------------------------------------------------------* *& Form ALV_DISPLAY_REPORT

*&---------------------------------------------------------------------* * Display the report

*----------------------------------------------------------------------* FORM alv_display_report . * Set the ALV display options CLEAR gs_alv_layout. gs_alv_layout-colwidth_optimize = '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.

* * * *

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

EXCEPTIONS OTHERS * No SUBRC check required ENDFORM. " ALV_DISPLAY_REPORT = 0.

*&---------------------------------------------------------------------* *& Form GET_MAKTX

*&---------------------------------------------------------------------* * Get the material description

*----------------------------------------------------------------------* FORM get_maktx USING fd_matnr TYPE matnr TYPE maktx.

CHANGING fd_maktx CLEAR fd_maktx.

* If we haven't already done so, read in all the material descriptions IF gtsrt_makt[] IS INITIAL. SELECT matnr maktx INTO TABLE gtsrt_makt FROM makt WHERE spras = sy-langu. ENDIF. * Now get the material description READ TABLE gtsrt_makt ASSIGNING <makt> WITH TABLE KEY matnr = fd_matnr. IF sy-subrc IS INITIAL. fd_maktx = <makt>-maktx. ENDIF. ENDFORM. " GET_MAKTX

*&---------------------------------------------------------------------* *& Form F4_ALV_VARIANT

*&---------------------------------------------------------------------* * Search help for variant

*----------------------------------------------------------------------* FORM f4_alv_variant CHANGING fd_var LIKE disvariant-variant. * Fill the structure needed by the report

gs_alv_dis_variant-variant = fd_var. * 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. = gc_alv_var_save

* Display error if not found IF sy-subrc IS NOT INITIAL. MESSAGE ID TYPE sy-msgid 'S'

NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

* Otherwise, update the display variant structure ELSE. fd_var = gs_alv_dis_variant-variant. ENDIF. ENDFORM. " 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. CLEAR: fs_knvv, fd_kunnr_name1,

fd_kunnr_land1. CHECK fd_kunnr IS NOT INITIAL. * Get the Customer Name SELECT SINGLE name1 land1 INTO (fd_kunnr_name1, fd_kunnr_land1) FROM kna1 WHERE kunnr = fd_kunnr. CHECK sy-subrc IS INITIAL. * 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 SUBRC check required ENDFORM. " READ_CUSTOMER

*&---------------------------------------------------------------------* *& Form BUILD_REPORT_DATA

*&---------------------------------------------------------------------* * Build the Report data

*----------------------------------------------------------------------* FORM build_report_data. CLEAR: gd_sales_area, gd_last_sales_area. * Loop around the materials found LOOP AT gtsrt_mvke ASSIGNING <mvke>. * Build the Sales area that we can use for checking later CONCATENATE <mvke>-vkorg <mvke>-vtweg INTO gd_sales_area. * "No space separation required

Change of Sales Org, redetermine the company code of the Sales Org

ON CHANGE OF <mvke>-vkorg. PERFORM get_bukrs USING <mvke>-vkorg

CHANGING gd_bukrs. ENDON. * * Every time there is a change of Sales Area, re-read the customer's Sales Area data IF gd_sales_area <> gd_last_sales_area. PERFORM read_customer USING p_kunnr <mvke>-vkorg <mvke>-vtweg CHANGING gs_knvv gd_kunnr_name1 gd_kunnr_land1. ENDIF. * Take note of the Sales Area we've just processed gd_last_sales_area = gd_sales_area. * * Every time the material changes, get the material general view details ON CHANGE OF <mvke>-matnr. PERFORM read_material USING <mvke>-matnr

CHANGING gs_mara gd_maktx gd_mat_exists_in_plant. ENDON. * * Check that the current material exists in the plant entered on the selection-screen CHECK gd_mat_exists_in_plant = gc_x. * Get the Price condition data PERFORM get_price_conditions TABLES USING gt_komv <mvke> gs_mara gs_knvv gd_bukrs CHANGING gs_komk

gs_komp gd_gross_price gd_net_price gd_cost_price gd_price_found_flag. * Add the price information to the report IF gd_price_found_flag = gc_x. 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. ENDIF. ENDLOOP. "GT_MVKE

* Sort the report SORT gt_report BY vkorg vtweg matnr. ENDFORM. " BUILD_REPORT_DATA

*&---------------------------------------------------------------------* *& Form GET_PRICE_CONDITIONS

*&---------------------------------------------------------------------* * * Read the price conditions and determine the Gross, Net + Cost price

*----------------------------------------------------------------------* FORM get_price_conditions TABLES USING ft_komv fs_mvke STRUCTURE komv TYPE mvke

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_price_found_flag TYPE * Init CLEAR: fs_komk, fs_komp, fd_price_found_flag, fd_gross_price, fd_net_price, fd_cost_price. REFRESH ft_komv.

* 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-auart_sd, TO fs_komk-kalsm, TO fs_komk, TO fs_komk, TO fs_komk. TO fs_komk-kurrf_dat, TO fs_komk-fkdat, TO fs_komk-prsdt, TO fs_komk-erdat, TO fs_komk-fbuda, TO fs_komk-audat, TO fs_komk-taxk1, "Customer Tax "#EC ENHOK "#EC ENHOK "#EC ENHOK

'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_komk-spart, TO fs_komk-belnr, TO fs_komk-knumv, TO fs_komk-waerk, TO fs_komk-hwaer, TO fs_komk-bukrs, TO fs_komk-vkorgau, TO fs_komk-werks, TO fs_komk-knrze, TO fs_komk-kunre, TO fs_komk-kunwe, TO fs_komk-konda, TO fs_komk-vbtyp, TO fs_komk-trtyp, TO fs_komk-vsbed, TO fs_komp-ix_komk.

* If any bespoke ZZ... fields exist in the HEADER table KOMK, * 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-zzfieldb. TO fs_komp, TO fs_komp. "#EC ENHOK "#EC ENHOK

TO fs_komp-mgame, TO fs_komp-mglme, TO fs_komp-lmeng, TO fs_komp-prsfd, TO fs_komp-prsok, TO fs_komp-evrwr, TO fs_komp-kursk, TO fs_komp-meins, TO fs_komp-lagme, TO fs_komp-vrkme,

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-pstyv, TO fs_komp-pmatn, TO fs_komp-kposn, TO fs_komp-taxps, TO fs_komp-aupos, TO fs_komp-spart, TO fs_komp-ix_komk, TO fs_komp-umvkz, TO fs_komp-umvkn, TO fs_komp-anz_tage,

"Material

TO fs_komp-anz_monate, TO fs_komp-anz_wochen, TO fs_komp-anz_jahre, TO fs_komp-stf_tage, TO fs_komp-stf_monate, TO fs_komp-stf_wochen, TO fs_komp-stf_jahre, TO fs_komp-aubel, TO fs_komp-werks.

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

* 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

comm_head_e comm_item_e TABLES tkomv * * * SVBAP CHANGING REBATE_DETERMINED EXCEPTIONS OTHERS this below

= fs_komk = fs_komp

= ft_komv =

= ' '

= 0.

"No SUBRC check required, as we handle

* Remove any statistical or inactive conditions DELETE ft_komv WHERE kinak = OR kstat = gc_x gc_x.

*----- 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. fd_gross_price = fs_komp-kzwi1. * If not found in subtotal 1 ELSE. * * * * * * * * * * * * * We could look for the first PRICE (KOAID=B) price condition (inactive + statistical records would already have been removed above) For performance reasons, this has been deactivated here, but could be reinstated later if need be loop at ft_komv ASSIGNING <komv> where koaid = gc_koaid_price. gd_gross_price = <komv>-kwert. exit. endloop. If the gross price is still initial, check if the "hide records with no gross price" flag was set on the selection-screen. If so, clear the

price found flag (done again for program clarity), and exit the form

* *

As the flag is not set, it means that the record will not appear on the report IF fd_gross_price IS INITIAL AND p_hdnogr = gc_x.

CLEAR fd_price_found_flag. EXIT. ENDIF. ENDIF. * If we have found a gross price, set the price found flag fd_price_found_flag = gc_x. *----- NET Price ------------------------------------------------------* Use the NETWR field instead of NETPR, in case the user enters a * quantity greater than 1 on the selection-screen. NETPR would only

* have the unit price, whereas NETWR has the price for the entire * quantity IF fs_komp-netwr IS NOT INITIAL. fd_net_price = fs_komp-netwr. * If not found in subtotal 2 ELSE. * * * Otherwise, try one of the subtotal fields (this could differ according to each pricing procedure, SAP standard puts it in subtotal 2). fd_net_price = fs_komp-kzwi2. ENDIF. *----- COST Price -----------------------------------------------------* The cost price should be returned in the field FS_KOMP-WAVWR * Inside function PRICING, the cost is derived from condition type * VPRS. SAP Standard normally brings this price in from MBEW-STPRS

* but this will not be found if no plant (i.e. valuation area) is * passed to the PRICING function - hence why this is mandatory on the * selection-screen IF fs_komp-wavwr IS NOT INITIAL. fd_cost_price = fs_komp-wavwr. ENDIF.

ENDFORM.

" GET_PRICE_CONDITIONS

*&---------------------------------------------------------------------* *& Form GET_BUKRS

*&---------------------------------------------------------------------* * Get the company code

*----------------------------------------------------------------------* FORM get_bukrs USING fd_vkorg TYPE vkorg TYPE bukrs.

CHANGING fd_bukrs * Read in all the Sales Orgs IF gth_vkorg_bukrs[] IS INITIAL. SELECT vkorg bukrs

INTO TABLE gth_vkorg_bukrs FROM tvko. ENDIF. * Now read the table READ TABLE gth_vkorg_bukrs ASSIGNING <vkorg_bukrs> WITH TABLE KEY vkorg = fd_vkorg. IF sy-subrc IS INITIAL. fd_bukrs = <vkorg_bukrs>-bukrs. ENDIF. 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_cost_price fd_maktx fd_kunnr

TYPE TYPE TYPE

netpr maktx kunnr name1 land1.

fd_kunnr_name1 TYPE fd_kunnr_land1 TYPE * Add a blank line to the report APPEND INITIAL LINE TO gt_report ASSIGNING <report>. * Then fill the relevant data MOVE-CORRESPONDING: fs_komk fs_komp fs_mara fs_mvke MOVE: fd_maktx TO <report>, TO <report>, TO <report>, TO <report>. TO <report>-maktx,

"#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>-cost_price, TO <report>-kunnr,

fd_kunnr_name1 TO <report>-kunnr_name1, fd_kunnr_land1 TO <report>-kunnr_land1. ENDFORM. " 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. CLEAR: fs_mara, fd_maktx, fd_mat_exists_in_plant. * Read the material GENERAL VIEW details SELECT SINGLE * INTO fs_mara

FROM mara WHERE matnr = fd_matnr. * Get the material description PERFORM get_maktx USING fd_matnr

CHANGING fd_maktx. * 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. * "#EC *

Table is sorted, so no BINARY SEARCH necessary

* If found, set the Mat exists in plant IF sy-subrc IS INITIAL. fd_mat_exists_in_plant = gc_x. ENDIF. ENDFORM. " READ_MATERIAL

*&---------------------------------------------------------------------* *& Form INIT_DATA

*&---------------------------------------------------------------------* * Initialise everything

*----------------------------------------------------------------------* FORM init_data . * Empty the internal tables REFRESH: gt_komv, gtsrt_mvke, gt_report, gt_alv_fieldcat, gtsrt_makt, gth_vkorg_bukrs. * Clear the variables CLEAR: 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. ENDFORM. " INIT_DATA

*&---------------------------------------------------------------------* *& Form BUILD_PROGRAM_TEXT_ELEMENTS

*&---------------------------------------------------------------------* * Build the program text elements if necesssary

*----------------------------------------------------------------------* FORM build_program_text_elements . *----- Method to add an entry to the Textpool -------------------------DEFINE m_add_to_textpool. * * * * * * &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. * Textpool Type gs_textpool-id * Textpool Key/Name gs_textpool-key * * * Text Description Note: for some reason, 8 blank spaces must be added to the start of any Selection-screen Select-options or Parameters if &1 = 'S'. move: ' &3 else. "Select-option or Parameter ' to gs_textpool-entry+0(8), to gs_textpool-entry+8. "All others, e.g. Text Elements, Report Heading = &3. = &2. = &1.

gs_textpool-entry

endif. * Also get the length of the text element gs_textpool-length = strlen( gs_textpool-entry ). insert gs_textpool into table gtsrt_textpool. 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. READ TEXTPOOL sy-repid INTO gtsrt_textpool

LANGUAGE sy-langu. * Now look for an arbitrary text element (e.g. 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'. * Table is SORTED type, so no BINARY SEARCH necessary

* If not found, start to build the text elements IF sy-subrc IS NOT INITIAL. * Start by removing whichever texts are already existing UNASSIGN <textpool>. REFRESH gtsrt_textpool. * Text-Symbols m_add_to_textpool: 'I' 'A01' 'SOrg', 'I' 'A02' 'DCh', 'I' 'A03' 'Material', 'I' 'A04' 'Description', 'I' 'A05' 'Gross Price', 'I' 'A06' 'Net Price', 'I' 'A07' 'Cost Price', 'I' 'A08' 'Curr', 'I' 'A09' 'Prod Hierarchy',

'I' 'A10' 'Customer', 'I' 'A11' 'Name', 'I' 'A12' 'Cust Country', 'I' 'A13' 'Pricing Date', 'I' 'S01' 'Selections', 'I' 'S02' 'Report', 'I' 'S03' 'Sales Area', 'I' 'S04' 'Product', 'I' 'S05' 'Additional Information for Price Calculation'. * * * * Selection-screen texts Note: for some reason, 8 blank spaces must be added to the start of any Select-options or Parameters texts. done inside the macro m_add_to_textpool: 'S' 'P_ALVVAR' 'Report Display Variant', 'S' 'P_AUART' 'Order Type', This is

'S' 'P_HDNOGR' 'Hide lines with no gross price', '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'. 'Pricing Procedure', 'Customer', 'Pricing date', 'Item Category', 'Quantity for Calculation', 'Division', 'Customer Tax Code', 'Material Tax Code', 'Sales UoM', 'Currency', 'Plant', 'Material', 'Sales Organization', 'Distribution Channel'.

Now delete the old textpool (regardless of how much was there) DELETE TEXTPOOL sy-repid LANGUAGE sy-langu.

And insert the new textpool + commit INSERT textpool sy-repid FROM gtsrt_textpool LANGUAGE sy-langu. COMMIT WORK AND WAIT.

Now we need to resubmit the program SUBMIT (sy-repid) VIA SELECTION-SCREEN. 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 . * Init REFRESH gtsrt_marc. * 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. "No deletion indicator set

* No SUBRC check required ENDFORM. " GET_ALL_MATERIALS_BY_PLANT

You might also like