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 TO fs_komk-zzfielda,
* hdrtable2-zzfieldb 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 TO fs_komp-zzfielda,
* itemtable2-zzfieldb 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):
REPORT zo2c_price_list.
************************************************************************
* Report ZO2C_PRICE_LIST Author : Ali Crawshaw *
* *
* Date : 22/03/2010 *
* *
* Description: Report to simulate the pricing procedure and show *
* the Gross, Net and Cost price of a material *
* *
************************************************************************
* Revision history : *
************************************************************************
* Date : Modification Id : *
* Name : *
* 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 TYPE vkorg,
vtweg TYPE vtweg,
matnr TYPE matnr,
maktx TYPE maktx, "Material Description
gross_price TYPE netpr,
net_price TYPE netpr,
cost_price TYPE netpr,
waerk TYPE waerk,
prodh TYPE prodh_d,
kunnr TYPE kunnr,
kunnr_land1 TYPE land1,
kunnr_name1 TYPE name1,
prsdt TYPE prsdt,
END OF gty_report.
TYPES: BEGIN OF gty_makt,
matnr TYPE matnr,
maktx TYPE maktx,
END OF gty_makt.
TYPES: BEGIN OF gty_vkorg_bukrs,
vkorg TYPE vkorg,
bukrs TYPE bukrs,
END OF gty_vkorg_bukrs.
TYPES: BEGIN OF gty_marc,
matnr TYPE matnr,
werks TYPE werks_d,
lvorm TYPE lvorm,
END OF gty_marc.
***** TYPE-POOLS
TYPE-POOLS: slis.
***** INTERNAL TABLES
* Standard Tables
DATA: gt_komv TYPE STANDARD TABLE OF komv,
gt_report TYPE STANDARD TABLE OF gty_report,
gt_alv_fieldcat TYPE slis_t_fieldcat_alv.
* Hashed Tables
DATA: gth_vkorg_bukrs TYPE HASHED TABLE OF gty_vkorg_bukrs
WITH UNIQUE KEY vkorg.
* Sorted Tables
DATA: gtsrt_makt TYPE SORTED TABLE OF gty_makt
WITH UNIQUE KEY matnr,
gtsrt_mvke TYPE SORTED TABLE OF gty_mvke
WITH UNIQUE KEY matnr
vkorg
vtweg,
gtsrt_marc TYPE SORTED TABLE OF gty_marc
WITH UNIQUE KEY matnr
werks,
gtsrt_textpool TYPE SORTED TABLE OF textpool
WITH UNIQUE KEY id key.
*****
DATA: gs_komk TYPE komk,
gs_komp TYPE komp,
gs_mara TYPE mara,
gs_knvv TYPE knvv,
gs_alv_layout TYPE slis_layout_alv,
gs_alv_dis_variant TYPE disvariant,
gs_textpool TYPE textpool.
***** TYPE-POOLS
TYPE-POOLS: slis.
***** CONSTANTS
CONSTANTS: gc_x TYPE c VALUE 'X',
gc_alv_var_save TYPE c VALUE 'A'. "Save all types of variant
***** VARIABLES
DATA: gd_maktx TYPE maktx,
gd_bukrs TYPE bukrs,
gd_kunnr_name1 TYPE name1,
gd_kunnr_land1 TYPE land1,
gd_sales_area TYPE char8,
gd_last_sales_area TYPE char6,
gd_price_found_flag TYPE flag,
gd_gross_price TYPE netpr,
gd_net_price TYPE netpr,
gd_cost_price TYPE netpr,
gd_mat_exists_in_plant TYPE flag.
***** FIELD-SYMBOLS
FIELD-SYMBOLS: <mvke> TYPE gty_mvke,
<report> TYPE gty_report,
<makt> 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 FOR mvke-vkorg,
s_vtweg FOR mvke-vtweg.
PARAMETERS: p_spart 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 LIKE knvv-kunnr OBLIGATORY,
p_werks LIKE komp-werks OBLIGATORY,
p_waers LIKE komk-waerk DEFAULT 'EUR' OBLIGATORY.
SELECTION-SCREEN SKIP 1.
PARAMETERS: p_kalsm TYPE kalsmasd DEFAULT 'RVAA01' OBLIGATORY,
p_auart TYPE auart DEFAULT 'TA' OBLIGATORY,
p_pstyv TYPE pstyv DEFAULT 'TAN' OBLIGATORY,
p_taxm1 TYPE taxm1 DEFAULT '1' OBLIGATORY,
p_taxk1 TYPE taxk1 DEFAULT '1' OBLIGATORY.
SELECTION-SCREEN SKIP 1.
parameters: p_qty TYPE kwmeng DEFAULT '1' OBLIGATORY,
p_vrkme TYPE vrkme DEFAULT 'KG' OBLIGATORY.
SELECTION-SCREEN SKIP 1.
PARAMETERS: p_prsdt LIKE komk-prsdt DEFAULT sy-datum.
PARAMETERS: p_hdnogr AS CHECKBOX DEFAULT 'X'.
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 = gc_alv_var_save
CHANGING
cs_variant = gs_alv_dis_variant
EXCEPTIONS
wrong_input = 1
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 vkorg IN s_vkorg
AND vtweg IN s_vtweg
AND 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 TYPE slis_fieldcat_alv,
ld_col_pos TYPE i.
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
* &3 Text Headomg
* &4 Output Length
* &5 Remove leading zeros
* &6 Show field
ls_fieldcat-col_pos = ld_col_pos.
ls_fieldcat-tabname = 'GT_REPORT'.
ls_fieldcat-fieldname = &1.
* Field specific handling
case &1.
when others.
* Do nothing
endcase.
* Highlight this field in BLUE?
if &2 is not initial.
ls_fieldcat-key = 'X'.
ls_fieldcat-emphasize = 'C333'.
endif.
ls_fieldcat-seltext_l = &3.
ls_fieldcat-outputlen = &4.
ls_fieldcat-no_zero = &5.
* Do we hide this field?
if &6 is initial.
ls_fieldcat-no_out = 'X'.
endif.
append ls_fieldcat to gt_alv_fieldcat.
clear: ls_fieldcat.
END-OF-DEFINITION.
*----- Get the Column Titles ---------------------------------------------
add_field_to_catalog:
* Field Name Key Text Len NoZero Show field
'VKORG' space text-a01 4 space gc_x,
'VTWEG' space text-a02 2 space gc_x,
'MATNR' gc_x text-a03 18 space gc_x,
'MAKTX' space text-a04 35 space gc_x,
'GROSS_PRICE' space text-a05 12 space gc_x,
'NET_PRICE' gc_x text-a06 12 space gc_x,
'COST_PRICE' space text-a07 12 space gc_x,
'WAERK' space text-a08 3 space gc_x,
'PRODH' space text-a09 12 space gc_x,
'KUNNR' space text-a10 10 gc_x gc_x,
'KUNNR_NAME1' space text-a11 12 space gc_x,
'KUNNR_LAND1' space text-a12 12 space gc_x,
'PRSDT' space text-a13 10 space gc_x.
ENDFORM. " 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 = 255.
* 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 = sy-repid
* i_callback_pf_status_set = 'SET_CUSTOM_ALV_PF_STATUS'
* i_callback_user_command = 'HANDLE_ALV_EVENTS'
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
is_layout = gs_alv_layout
it_fieldcat = gt_alv_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = gc_alv_var_save
is_variant = gs_alv_dis_variant
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* 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 = 0.
* No SUBRC check required
ENDFORM. " ALV_DISPLAY_REPORT
*&---------------------------------------------------------------------*
*& Form GET_MAKTX
*&---------------------------------------------------------------------*
* Get the material description
*----------------------------------------------------------------------*
FORM get_maktx USING fd_matnr TYPE matnr
CHANGING fd_maktx TYPE 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 = gc_alv_var_save
IMPORTING
es_variant = gs_alv_dis_variant
EXCEPTIONS
OTHERS = 1.
* Display error if not found
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid
TYPE '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 TYPE kunnr
fd_vkorg TYPE vkorg
fd_vtweg TYPE vtweg
CHANGING fs_knvv 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 vkorg = fd_vkorg
AND vtweg = fd_vtweg
AND 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 gt_komv
USING <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 gt_komv
USING <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 ft_komv STRUCTURE komv
USING fs_mvke TYPE mvke
fs_mara TYPE mara
fs_knvv TYPE knvv
fd_bukrs TYPE bukrs
CHANGING fs_komk TYPE komk
fs_komp TYPE komp
fd_gross_price TYPE netpr
fd_net_price TYPE netpr
fd_cost_price TYPE netpr
fd_price_found_flag TYPE flag.
* 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 TO fs_komk, "#EC ENHOK
fs_mara TO fs_komk, "#EC ENHOK
fs_knvv TO fs_komk. "#EC ENHOK
MOVE: p_prsdt TO fs_komk-kurrf_dat,
p_prsdt TO fs_komk-fkdat,
p_prsdt TO fs_komk-prsdt,
p_prsdt TO fs_komk-erdat,
p_prsdt TO fs_komk-fbuda,
p_prsdt TO fs_komk-audat,
p_taxk1 TO fs_komk-taxk1, "Customer Tax Code
p_auart TO fs_komk-auart,
p_auart TO fs_komk-auart_sd,
p_kalsm TO fs_komk-kalsm,
'V' TO fs_komk-kappl,
p_spart TO fs_komk-spart,
'$000000001' TO fs_komk-belnr,
'$000000001' TO fs_komk-knumv,
p_waers TO fs_komk-waerk,
p_waers TO fs_komk-hwaer,
fd_bukrs TO fs_komk-bukrs,
fs_mvke-vkorg TO fs_komk-vkorgau,
p_werks TO fs_komk-werks,
fs_knvv-kunnr TO fs_komk-knrze,
fs_knvv-kunnr TO fs_komk-kunre,
fs_knvv-kunnr TO fs_komk-kunwe,
fs_knvv-konda TO fs_komk-konda,
'C' TO fs_komk-vbtyp,
'H' TO fs_komk-trtyp,
'01' TO fs_komk-vsbed,
'1' TO fs_komp-ix_komk.
* If any bespoke ZZ... fields exist in the HEADER table KOMK,
* these should be filled here
* MOVE: hdrtable1-zzfielda TO fs_komk-zzfielda,
* hdrtable2-zzfieldb TO fs_komk-zzfieldb.
MOVE-CORRESPONDING: fs_mara TO fs_komp, "#EC ENHOK
fs_mvke TO fs_komp. "#EC ENHOK
MOVE: p_qty TO fs_komp-mgame,
p_qty TO fs_komp-mglme,
p_qty TO fs_komp-lmeng,
'X' TO fs_komp-prsfd,
'X' TO fs_komp-prsok,
'X' TO fs_komp-evrwr,
'1' TO fs_komp-kursk,
p_vrkme TO fs_komp-meins,
p_vrkme TO fs_komp-lagme,
p_vrkme TO fs_komp-vrkme,
p_taxm1 TO fs_komp-taxm1, "Material Tax Code
p_pstyv TO fs_komp-pstyv,
fs_mara-matnr TO fs_komp-pmatn,
'000010' TO fs_komp-kposn,
'000010' TO fs_komp-taxps,
'000010' TO fs_komp-aupos,
p_spart TO fs_komp-spart,
'1' TO fs_komp-ix_komk,
'1' TO fs_komp-umvkz,
'1' TO fs_komp-umvkn,
'1' TO fs_komp-anz_tage,
'1' TO fs_komp-anz_monate,
'1' TO fs_komp-anz_wochen,
'1' TO fs_komp-anz_jahre,
'1' TO fs_komp-stf_tage,
'1' TO fs_komp-stf_monate,
'1' TO fs_komp-stf_wochen,
'1' TO fs_komp-stf_jahre,
'$TEMP' TO fs_komp-aubel,
p_werks 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 TO fs_komp-zzfielda,
* itemtable2-zzfieldb TO fs_komp-zzfieldb.
* Call the Pricing module
CALL FUNCTION 'PRICING'
EXPORTING
calculation_type = 'B' "Carry out new Pricing
comm_head_i = fs_komk
comm_item_i = fs_komp
* PRELIMINARY = ' '
* NO_CALCULATION = ' '
IMPORTING
comm_head_e = fs_komk
comm_item_e = fs_komp
TABLES
tkomv = ft_komv
* SVBAP =
* CHANGING
* REBATE_DETERMINED = ' '
EXCEPTIONS
OTHERS = 0. "No SUBRC check required, as we handle this below
* Remove any statistical or inactive conditions
DELETE ft_komv
WHERE kinak = gc_x
OR kstat = 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
CHANGING fd_bukrs TYPE 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 ft_komv STRUCTURE komv "#EC NEEDED
USING fs_mvke TYPE mvke
fs_mara TYPE mara
fs_komk TYPE komk
fs_komp TYPE komp
fd_gross_price TYPE netpr
fd_net_price TYPE netpr
fd_cost_price TYPE netpr
fd_maktx TYPE maktx
fd_kunnr TYPE kunnr
fd_kunnr_name1 TYPE name1
fd_kunnr_land1 TYPE land1.
* Add a blank line to the report
APPEND INITIAL LINE TO gt_report ASSIGNING <report>.
* Then fill the relevant data
MOVE-CORRESPONDING: fs_komk TO <report>, "#EC ENHOK
fs_komp TO <report>, "#EC ENHOK
fs_mara TO <report>, "#EC ENHOK
fs_mvke TO <report>. "#EC ENHOK
MOVE: fd_maktx TO <report>-maktx,
fd_gross_price TO <report>-gross_price,
fd_net_price TO <report>-net_price,
fd_cost_price TO <report>-cost_price,
fd_kunnr 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
CHANGING fs_mara TYPE mara
fd_maktx TYPE 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 = &1.
* Textpool Key/Name
gs_textpool-key = &2.
* 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'. "Select-option or Parameter
move: ' ' to gs_textpool-entry+0(8),
&3 to gs_textpool-entry+8.
else. "All others, e.g. Text Elements, Report Heading
gs_textpool-entry = &3.
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. This is
* done inside the macro
m_add_to_textpool:
'S' 'P_ALVVAR' 'Report Display Variant',
'S' 'P_AUART' 'Order Type',
'S' 'P_HDNOGR' 'Hide lines with no gross price',
'S' 'P_KALSM' 'Pricing Procedure',
'S' 'P_KUNNR' 'Customer',
'S' 'P_PRSDT' 'Pricing date',
'S' 'P_PSTYV' 'Item Category',
'S' 'P_QTY' 'Quantity for Calculation',
'S' 'P_SPART' 'Division',
'S' 'P_TAXK1' 'Customer Tax Code',
'S' 'P_TAXM1' 'Material Tax Code',
'S' 'P_VRKME' 'Sales UoM',
'S' 'P_WAERS' 'Currency',
'S' 'P_WERKS' 'Plant',
'S' 'S_MATNR' 'Material',
'S' 'S_VKORG' 'Sales Organization',
'S' 'S_VTWEG' 'Distribution Channel'.
* Report Title
m_add_to_textpool:
'R' space 'Price List Report'.
* 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 werks = p_werks
AND lvorm = space. "No deletion indicator set
* No SUBRC check required
ENDFORM. " GET_ALL_MATERIALS_BY_PLANT
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.