Posted: Sat Sep 20, 2008 9:49 pm Post subject: Purshase report with contract or aggerment price
Code:
REPORT zmmrcnag MESSAGE-ID zkm
NO STANDARD PAGE HEADING
LINE-COUNT 65.
********** DATA DECLARATIONS - BEGIN **********************************
*TABLES
***********************************************************************
***********************************************************************
*DATA - INTERNAL TABLES
***********************************************************************
DATA: BEGIN OF w_ekabs OCCURS 10.
INCLUDE STRUCTURE ekabs.
DATA: END OF w_ekabs.
DATA: BEGIN OF w_ekabf OCCURS 10.
INCLUDE STRUCTURE ekabf.
DATA: END OF w_ekabf.
*table for header details
DATA: BEGIN OF itab OCCURS 0,
bukrs LIKE ekko-bukrs, "Company code
ebeln LIKE ekko-ebeln, "Purchasing document numb(agreement#)
bsart LIKE ekko-bsart, " type
*ernam LIKE ekko-ernam, "Name of person who created object
lifnr LIKE ekko-lifnr, "Vendor number
*unsez LIKE ekko-unsez, "commodity
ekgrp LIKE ekko-ekgrp, "Purchasing group
ekorg LIKE ekko-ekorg, "Purchasing organization
kdatb LIKE ekko-kdatb, "start of validity period
kdate LIKE ekko-kdate, "end of validity period.
waers LIKE ekko-waers, "Currency key
wkurs LIKE ekko-wkurs, "Exchange rate
eknam LIKE t024-eknam, "Purch group descr
gsabw LIKE rm06e-gsabw, "Total value released
ktwrt LIKE ekko-ktwrt, " total value
tot_val LIKE rm06e-gsabw, "Total value of agreement
tot_items TYPE i, "total of items on agreement
name LIKE lfa1-name1, "vendor name
konzs LIKE lfa1-konzs, "Group key
del_items TYPE i, "total of deleted items
brsch LIKE lfa1-brsch. "industry
*revlv LIKE ekpo-revlv. "Revision level
DATA: END OF itab.
*table for vendor details
DATA: BEGIN OF ivendor OCCURS 0,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
konzs LIKE lfa1-konzs,
END OF ivendor.
*table for purchase group
DATA: BEGIN OF igroup OCCURS 0,
ekgrp LIKE t024-ekgrp,
eknam LIKE t024-eknam,
END OF igroup.
*table for item details
DATA: BEGIN OF idtltab OCCURS 0,
ebeln LIKE ekpo-ebeln, "Purchasing document number
ebelp LIKE ekpo-ebelp, "Purchasing document numb(agreement#)
loekz LIKE ekpo-loekz, "Deletion indicator in purchasing document
matnr LIKE ekpo-matnr, "Material number
ktmng LIKE ekpo-ktmng, "Target quantity
meins LIKE ekpo-meins, "Order unit
bprme LIKE ekpo-bprme, "Order price unit (purchasing)
bpumz LIKE ekpo-bpumz, "conversion of order price unit into ord
bpumn LIKE ekpo-bpumn, "Denominator for conv. of order price uni
netpr LIKE ekpo-netpr, "Net price in purchasing document
peinh LIKE ekpo-peinh, "Price unit
netwr LIKE ekpo-netwr, "Net order value in PO currency
revlv LIKE ekpo-revlv, "Revision level
txz01 LIKE ekpo-txz01,
gsabw LIKE rm06e-gsabw, "Total value released
menge LIKE ekpo-menge.
DATA: END OF idtltab.
*< released amount.
DATA: BEGIN OF ipodata OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
konnr LIKE ekpo-konnr,
ktpnr LIKE ekpo-ktpnr,
matnr LIKE ekpo-matnr,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
END OF ipodata.
*final table to display alv
DATA: BEGIN OF ifinal_data OCCURS 0.
INCLUDE STRUCTURE itab.
DATA: ebelp LIKE ekpo-ebelp,
matnr LIKE ekpo-matnr,
ktmng LIKE ekpo-ktmng, "Target quantity
menge LIKE ekpo-menge,
txz01 LIKE ekpo-txz01,
batxt LIKE t161t-batxt, " Description of type " vnarayan
rowcolor(4) TYPE c, " ALV Rowcolor
END OF ifinal_data.
DATA: dtlctr TYPE p,
temp_val LIKE rm06e-gsabw,
temp_qty LIKE ekpo-ktmng,
temp_records TYPE i,
conv_qty LIKE ekpo-ktmng,
temp_tot LIKE rm06e-gsabw.
DATA deleted_items TYPE i.
*Begin of insertion vnarayan
CONSTANTS c_contracts TYPE c VALUE 'K'.
CONSTANTS c_aggrements TYPE c VALUE 'L'.
*end of insertion vnarayan
************************************************************************
*Fieldcatalog
***********************************************************************
TYPE-POOLS: slis.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
DATA: ok_code LIKE sy-ucomm,
g_repid LIKE sy-repid,
gs_print TYPE lvc_s_prnt,
gs_layout TYPE lvc_s_layo,
mycontainer TYPE scrfname VALUE 'BCALVC_EVENT1_CONT1',
custom_container TYPE REF TO cl_gui_custom_container,
grid1 TYPE REF TO cl_gui_alv_grid.
*Field Catalog for ALV Control
DATA:
fs_fieldcat TYPE lvc_s_fcat,
it_fieldcat_2 LIKE TABLE OF fs_fieldcat.
DATA:
fs_sort LIKE lvc_s_sort,
it_sort LIKE TABLE OF fs_sort.
*Begin of insertion vnarayan
*Class Definition to handle Double click
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS :
handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id es_row_no.
ENDCLASS. "lcl_event_handler DEFINITION
*Method implementation
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_hotspot_click.
PERFORM f510_handle_hotspot_click USING e_row_id
e_column_id
es_row_no.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_event_handler IMPEMENTATION
DATA : gr_event_handler TYPE REF TO lcl_event_handler.
*End of insertion vnarayan
***********************************************************************
*Selection screen (Select-options,Parameters)
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK block0 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
s_lifnr FOR ekko-lifnr, "Vendor number
*s_brsch FOR lfa1-brsch, "industry
s_unsez FOR ekko-unsez, "commodity
s_ekgrp FOR ekko-ekgrp, "Purchasing group
s_ekorg FOR ekko-ekorg. "Purchasing organization
PARAMETERS: p_period(7) TYPE c OBLIGATORY.
DATA:
r_kdatb LIKE ekko-kdatb, "start of validity period
r_kdate LIKE ekko-kdate. "end of validity period.
*TABLES
*t_outtab = IFINAL_DATA
*EXCEPTIONS
*OTHERS = 1.
*---------------------------------------------------------------------
** Form build_fieldcat
*---------------------------------------------------------------------
*text
----------------------------------------------------------------------
*--> p1 text
*<-- p2 text
----------------------------------------------------------------------
FORM build_fieldcat .
DATA: l_layout TYPE slis_layout_alv,
l_repid TYPE sy-repid,
l_print TYPE slis_print_alv,
l_setting TYPE lvc_s_glay.
ENDFORM. " build_fieldcat
*---------------------------------------------------------------------
** Form get_contract_agg_data
*---------------------------------------------------------------------
*Get all contracts and agreement data for the given selection criteria
----------------------------------------------------------------------
*There are no interface parameters to be passed to this subroutine.
----------------------------------------------------------------------
FORM get_contract_agg_data .
SELECT bukrs
ebeln
bsart
lifnr
ekgrp
ekorg
kdatb
kdate
waers
wkurs
ktwrt
FROM ekko INTO CORRESPONDING FIELDS
OF TABLE itab
WHERE lifnr IN s_lifnr
AND unsez IN s_unsez
AND ekgrp IN s_ekgrp
AND ekorg IN s_ekorg
*AND kdatb GE r_kdatb
AND kdate EQ r_kdate
AND ( bstyp = 'K' OR bstyp = 'L' ).
IF sy-subrc 0.
MESSAGE s055.
*WRITE: /'No Records were selected for entered parameters'.
STOP.
ENDIF. " IF SY-SUBRC ...
ENDFORM. " get_contract_agg_data
*---------------------------------------------------------------------
** Form get_price
*---------------------------------------------------------------------
*Get the contract or aggerment price details selected data in above *
*perfrom *
----------------------------------------------------------------------
*There are no interface parameters to be passed to this subroutine.
----------------------------------------------------------------------
FORM get_price .
SORT itab BY ebeln.
SELECT ebeln " Purchasing Document Number
ebelp " Item Number of Purchasing...
loekz " Deletion indicator in...
matnr " Material Number
ktmng " Target quantity
meins " Order unit
bprme " Order Price Unit (Purchasing)
bpumz " Numerator for conversion of...
bpumn " Denominator for conv. of...
netpr " Net price in purchasing...
peinh " Price unit
netwr " Net order value in PO currency
revlv " Revision Level
txz01 " MATEIRAL TEXT
FROM ekpo
APPENDING TABLE idtltab FOR ALL ENTRIES IN itab
WHERE ebeln = itab-ebeln.
ENDFORM. " get_price
*---------------------------------------------------------------------
** Form get_tot_value
*---------------------------------------------------------------------
*Calculate a total value of agreement
*---------------------------------------------------------------------
*This subroutine is used get vendor and purchase organization details
----------------------------------------------------------------------
FORM get_tot_value .
ENDFORM. " get_tot_value
*---------------------------------------------------------------------
** Form get_rec_value
*---------------------------------------------------------------------
*Get the value of the contract and total value released for a purchase
*order,company,currency and excahnge rate
*---------------------------------------------------------------------
*This subroutine is used get vendor and purchase organization details
----------------------------------------------------------------------
FORM get_rec_value .
DATA: itab_temp LIKE itab OCCURS 0 WITH HEADER LINE.
itab_temp] = itab[.
SORT itab_temp BY lifnr.
DELETE ADJACENT DUPLICATES FROM itab_temp COMPARING lifnr.
*Get vendor data
SELECT lifnr " Account Number of the Vendor
name1 " Name 1
konzs " Group key
INTO TABLE ivendor
FROM lfa1
FOR ALL ENTRIES IN itab_temp
WHERE lifnr EQ itab_temp-lifnr.
*Get Purchage group data
SELECT ekgrp " Purchasing group
eknam " Description of purchasing group
INTO TABLE igroup
FROM t024.
SORT ivendor BY lifnr.
SORT igroup BY ekgrp.
LOOP AT itab.
CLEAR ivendor.
CLEAR igroup.
*Read vendor data
READ TABLE ivendor WITH KEY lifnr = itab-lifnr
BINARY SEARCH.
IF sy-subrc = 0.
*itab-brsch = lfa1-brsch. "Industry key
itab-name = ivendor-name1. "vendor name
itab-konzs = ivendor-konzs. "group key
ENDIF. " IF SY-SUBRC ...
*Read purchage data
READ TABLE igroup WITH KEY ekgrp = itab-ekgrp
BINARY SEARCH.
IF sy-subrc = 0.
itab-eknam = igroup-eknam. "Group description
ENDIF. " IF SY-SUBRC ...
*---------------------------------------------------------------------
** Form display_alv_data
*---------------------------------------------------------------------
*This subroutine is used display ALV List
----------------------------------------------------------------------
*There are no interface parameters to be passed to this subroutine.
----------------------------------------------------------------------
FORM display_alv_data .
CALL SCREEN 100.
ENDFORM. " display_alv_data
*---------------------------------------------------------------------
** Module PBO OUTPUT
*---------------------------------------------------------------------
*This module is used to initialize and to create the contanter.
*Display the data
----------------------------------------------------------------------
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN'.
IF custom_container IS INITIAL.
*create a custom container control for our ALV Control
CREATE OBJECT custom_container
EXPORTING
container_name = mycontainer
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'The control could not be created'(010).
ENDIF. " IF SY-SUBRC ...
*create an instance of alv control
CREATE OBJECT grid1
EXPORTING i_parent = custom_container.
*
*Set a titlebar for the grid control
*
gs_layout-grid_title = 'Contract and Aggrement details'(100).
gs_layout-info_fname = 'ROWCOLOR'.
gs_layout-cwidth_opt = 'X'.
*reserve two lines for the PRINT_END_OF_PAGE event
gs_print-reservelns = 2.
*Prepare field catelog
PERFORM fill_field_catelog_detail .
*Begin of insertion vnarayan
*create instance of the class
CREATE OBJECT gr_event_handler.
SET HANDLER gr_event_handler->handle_hotspot_click FOR grid1.
*End of insertion vnarayan
CALL METHOD grid1->set_table_for_first_display
EXPORTING
is_print = gs_print
is_layout = gs_layout
CHANGING
it_sort = it_sort
it_fieldcatalog = it_fieldcat_2[]
it_outtab = ifinal_data[].
ENDIF. " IF CUSTOM_CONTAINER ...
*Controls are not integrated into the TAB-Order
*Call "set_focus" if you want to make sure that 'the cursor'
*is active in your control.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid1.
ENDMODULE. " PBO OUTPUT
*---------------------------------------------------------------------
** Form fill_field_catelog_detail
*---------------------------------------------------------------------
*This subroutine is used to fill Catalog Table for Detail List
----------------------------------------------------------------------
*There are no interface parameters to be passed to this subroutine.
----------------------------------------------------------------------
FORM fill_field_catelog_detail .
ENDFORM. " fill_field_catelog_detail
*---------------------------------------------------------------------
** Module PAI INPUT
*---------------------------------------------------------------------
*text
----------------------------------------------------------------------
MODULE pai INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'CANCEL'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CHANG'.
PERFORM call_transaction.
ENDCASE. " CASE SY-UCOMM ...
ENDMODULE. " PAI INPUT
*---------------------------------------------------------------------
** Form peroid_data
*---------------------------------------------------------------------
*--> p1 text
*<-- p2 text
----------------------------------------------------------------------
*This subroutine is used to format selection screen period data
*into date format. it takes the end date of the year into r_kdatb
----------------------------------------------------------------------
*There are no interface parameters to be passed to this subroutine.
----------------------------------------------------------------------
FORM peroid_data .
DATA: day(2),
month(2),
year(4),
date(8).
day = '01'.
month = p_period(2).
year = p_period+3(4).
ENDFORM. " peroid_data
*---------------------------------------------------------------------
** Form CALL_TRANSACTION
*---------------------------------------------------------------------
*--> p1 text
*<-- p2 text
----------------------------------------------------------------------
*This subroutine is used capture the list index and
*value of purchase order number
----------------------------------------------------------------------
FORM call_transaction .
DATA:
lt_rows TYPE lvc_t_row, " ALV control: Table rows
lt_rows_r TYPE lvc_s_row, " ALV control: Table rows
lt_no_rows TYPE i. " No of Row selected
*Get no of Row Selected
CALL METHOD grid1->get_selected_rows
IMPORTING
et_index_rows = lt_rows.
DESCRIBE TABLE lt_rows LINES lt_no_rows.
IF lt_no_rows 1.
MESSAGE i008 WITH 'Select a Single row'.
ELSE.
READ TABLE lt_rows INTO lt_rows_r INDEX 1.
IF sy-subrc EQ 0.
READ TABLE ifinal_data INDEX lt_rows_r-index.
IF sy-subrc EQ 0.
PERFORM change_detail USING ifinal_data-ebeln.
ENDIF. " IF SY-SUBRC ...
ENDIF. " IF SY-SUBRC ...
ENDIF. " IF lt_no_rows 1.
ENDFORM. " CALL_TRANSACTION
*---------------------------------------------------------------------
** Form CHANGE_DETAIL
*---------------------------------------------------------------------
*-->P_IFINAL_DATA_EBELN text
*-->P_ENDIF text
----------------------------------------------------------------------
*This subroutine is used call the transaction 'ME32' to change
*contract details
----------------------------------------------------------------------
FORM change_detail USING p_ebeln.
SET PARAMETER ID 'VRT' FIELD p_ebeln.
CALL TRANSACTION 'ME32' AND SKIP FIRST SCREEN.
ENDFORM. " CHANGE_DETAIL
*---------------------------------------------------------------------
** Form f510_handle_hotspot_click
*---------------------------------------------------------------------
*This subroutine is used handle hotspot click
*this require three interface parameters row number,columnname and *
*rowid
----------------------------------------------------------------------
*-->P_E_ROW_ID text
*-->P_E_COLUMN_ID text
*-->P_ES_ROW_NO text
----------------------------------------------------------------------
FORM f510_handle_hotspot_click USING p_e_row_id TYPE lvc_s_row
p_e_column_id TYPE lvc_s_col
p_es_row_no TYPE lvc_s_roid.
READ TABLE ifinal_data INDEX p_es_row_no-row_id.
IF sy-subrc EQ 0.
SET PARAMETER ID 'VRT' FIELD ifinal_data-ebeln.
CALL TRANSACTION 'ME33' AND SKIP FIRST SCREEN.
ENDIF. " IF sy-subrc eq 0
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.