SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Purshase report with contract or aggerment price



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Sep 20, 2008 9:49 pm    Post subject: Purshase report with contract or aggerment price Reply with quote

Code:
REPORT  zmmrcnag MESSAGE-ID zkm
                NO STANDARD PAGE HEADING
                LINE-COUNT 65.

********** DATA DECLARATIONS - BEGIN **********************************
*TABLES
***********************************************************************

TABLES:
       ekko,                           "purchasing document header
       ekpo,                           "purchasing document item
       lfa1,                           "Vendor Master (General Section)
       t024.                           "Purchasing Groups

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

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.

SELECTION-SCREEN END OF BLOCK block0.

************************************************************************
*START-OF-SELECTION (StartSelxxx Events)
************************************************************************

START-OF-SELECTION.

*converting to date format
  PERFORM peroid_data.

*Get contracts and agreement given on selection screen
  PERFORM get_contract_agg_data.

*Get the contract or aggerment price details
  PERFORM get_price.

*Get the Vendor and puchasing group details
  PERFORM get_rec_value.

*Calculating totals
  PERFORM get_tot_value.

*PERFORM build_fieldcat.

*Display Final Output Table
  PERFORM display_alv_data .


*CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
*EXPORTING
*it_fieldcat            = it_fieldcat
*I_CALLBACK_PROGRAM     = L_REPID
*I_CALLBACK_TOP_OF_PAGE = C_FORMNAME_TOP_OF_PAGE
*I_DEFAULT              = 'X'
*I_SAVE                 = 'A'
*IS_PRINT               = L_PRINT
*IS_LAYOUT              = L_LAYOUT
*I_GRID_SETTINGS        = L_SETTING
*IT_SORT                = IT_SORT

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

  l_repid                     = sy-repid.
  l_print-no_print_selinfos   = 'X'.
  l_print-no_print_listinfos  = 'X'.
  l_layout-zebra              = 'X'.
  l_layout-min_linesize       = 255.
  l_setting-no_colwopt        = 'X'.
  l_layout-colwidth_optimize = 'X'.
  l_setting-top_p_only        = 'X'. "TOP_OF_PAGE ONLY AT PRINTING

  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
  wa_fieldcat-fix_column = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'EBELN'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'EBELN'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.

  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
  wa_fieldcat-fix_column = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'EBELP'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'EBELP'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.

  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
  wa_fieldcat-fix_column = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'M'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'MATNR'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'BUKRS'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'BUKRS'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
*type
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'BSART'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'BSART'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.

*vENDOR
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'LIFNR'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'LIFNR'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.

*NAME
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'NAME'.
  wa_fieldcat-ref_tabname = 'LFA1'.
  wa_fieldcat-ref_fieldname = 'NAME1'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
*INDUSTRY

  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'BRSCH'.
  wa_fieldcat-ref_tabname = 'LFA1'.
  wa_fieldcat-ref_fieldname = 'BRSCH'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.

*purchasing group

  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'EKGRP'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'EKGRP'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
*dESCRIPTION
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'EKNAM'.
  wa_fieldcat-ref_tabname = 'T024'.
  wa_fieldcat-ref_fieldname = 'EKNAM'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.

*pURCHASING ORG
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'EKORG'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'EKORG'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
*sTART DATE
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'KDATB'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'KDATB'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
*END DATE
  CLEAR wa_fieldcat.
*WA_FIELDCAT-COL_POS = 1.
*WA_FIELDCAT-FIX_COLUMN = 'X'.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'KDATE'.
  wa_fieldcat-ref_tabname = 'EKKO'.
  wa_fieldcat-ref_fieldname = 'KDATE'.
*WA_FIELDCAT-SELTEXT_L = TEXT-200.
  APPEND wa_fieldcat TO it_fieldcat.
*tOTAL VALUE
  CLEAR wa_fieldcat.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'TOT_VAL'.
  wa_fieldcat-ref_tabname = 'RM06E'.
  wa_fieldcat-ref_fieldname = 'GSABW'.
  wa_fieldcat-seltext_l = 'Contract Value'.
  APPEND wa_fieldcat TO it_fieldcat.

*rELEASED VALUE
  CLEAR wa_fieldcat.
  wa_fieldcat-tabname = 'IFINAL_DATA'.
  wa_fieldcat-fieldname = 'GSABW'.
  wa_fieldcat-ref_tabname = 'RM06E'.
  wa_fieldcat-ref_fieldname = 'GSABW'.
  wa_fieldcat-seltext_l = 'Released value'.
  APPEND wa_fieldcat TO it_fieldcat.

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.

*SORT idtltab BY ebeln ebelp.
*
*SELECT ebeln
*ebelp
*konnr
*ktpnr
*matnr
*menge
*netpr
*FROM ekpo
*INTO TABLE ipodata
*FOR ALL ENTRIES IN idtltab
*WHERE konnr EQ idtltab-ebeln
*AND ktpnr EQ idtltab-ebelp.
*
*
*SORT ipodata BY konnr ktpnr.
*
*LOOP AT idtltab .
*CLEAR temp_val.
*LOOP AT ipodata WHERE konnr EQ idtltab-ebeln
*AND ktpnr EQ idtltab-ebelp.
*temp_val = temp_val + ipodata-menge * ipodata-netpr.
*
*ENDLOOP.
*idtltab-gsabw = temp_val.
*MODIFY idtltab.
*
*ENDLOOP.
*

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 .

*LOOP AT idtltab.
*IF idtltab-loekz = 'L'.
*ELSE.
*temp_val = idtltab-bpumz / idtltab-bpumn * idtltab-ktmng
*/ idtltab-peinh * idtltab-netpr.
*
*temp_tot = temp_tot + temp_val.
*
*ENDIF.                             " IF IDTLTAB-LOEKZ ...
*temp_records = temp_records + 1.
*
**total deleted items
*IF idtltab-loekz = 'L'.
*deleted_items = deleted_items + 1.
*ENDIF.                             " IF IDTLTAB-LOEKZ ...

*
*
*
*AT END OF ebeln.

*READ TABLE itab WITH KEY ebeln = idtltab-ebeln BINARY SEARCH.
*total value of items not set for deletion

*itab-tot_val = temp_tot.
*total no of records

*itab-tot_items = temp_records.
*total no of items set for deletion

*itab-del_items = deleted_items.
*temp_records = 0.
*deleted_items = 0.
*
*MODIFY itab INDEX sy-tabix.
*
*temp_val = 0.
*temp_tot = 0.
*ENDAT.                             " AT END ...
*ENDLOOP.                             " LOOP AT IDTLTAB ...

*moving header and item data to final internal table

*Begin of insertion vnarayan

  DATA: BEGIN OF i_dtype OCCURS 0,
         bsart LIKE t161t-bsart,
         batxt LIKE t161t-batxt,
        END OF i_dtype.

  SELECT bsart
         batxt
    INTO TABLE i_dtype
    FROM t161t
   WHERE spras EQ sy-langu
     AND bstyp EQ c_contracts
      OR bstyp EQ c_aggrements
     .

  SORT i_dtype BY bsart.

*End of insertion vnarayan

  LOOP AT itab.
    CLEAR ifinal_data.
    MOVE-CORRESPONDING itab TO ifinal_data.

    IF ifinal_data-bsart EQ 'WK'.
      ifinal_data-rowcolor = 'C300'.
    ELSE.
      ifinal_data-rowcolor = 'C400'.
    ENDIF.

*Begin of insertion vnarayan
    READ TABLE i_dtype WITH KEY bsart = itab-bsart.
    IF sy-subrc EQ 0.
      ifinal_data-batxt = i_dtype-batxt.
    ENDIF.

*End of insertion vnarayan

    APPEND ifinal_data.

    LOOP AT idtltab WHERE ebeln EQ itab-ebeln.
      CLEAR ifinal_data.

      ifinal_data-ebeln = itab-ebeln.
      ifinal_data-ktwrt = idtltab-netpr.

      ifinal_data-txz01 = idtltab-txz01.

      ifinal_data-ebelp = idtltab-ebelp.
      ifinal_data-matnr = idtltab-matnr.
      ifinal_data-gsabw = idtltab-gsabw.
      ifinal_data-menge = idtltab-menge.
      ifinal_data-ktmng = idtltab-ktmng.
      APPEND ifinal_data.
    ENDLOOP.                           " LOOP AT IDTLTAB ...

  ENDLOOP.                             " LOOP AT ITAB ...

  SORT ifinal_data BY ebeln ebelp DESCENDING.

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

    CLEAR itab-gsabw.
    CALL FUNCTION 'ME_READ_RELEASE_DOCU'
      EXPORTING
        bukrs = itab-bukrs
        ebeln = itab-ebeln
        waers = itab-waers
        wkurs = itab-wkurs
      IMPORTING
        suwrt = itab-gsabw  "Tot release amt
      TABLES
        xado  = w_ekabf
        xados = w_ekabs.

    CLEAR temp_val.

    LOOP AT idtltab WHERE ebeln EQ itab-ebeln.
      CLEAR temp_val.
      CLEAR temp_qty.
      LOOP AT w_ekabf WHERE konnr EQ idtltab-ebeln
                AND  ktpnr EQ idtltab-ebelp.

        temp_val = temp_val + w_ekabf-netwf.
        temp_qty = temp_qty + w_ekabf-menge.

      ENDLOOP.
      idtltab-gsabw = temp_val.
      idtltab-menge = temp_qty.
      MODIFY idtltab.
    ENDLOOP.

    MODIFY itab.

  ENDLOOP.                             " LOOP AT ITAB ...

ENDFORM.                    " get_rec_value

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

  REFRESH it_fieldcat_2.
  REFRESH it_sort.

*Purchasing document number
  CLEAR fs_fieldcat.
  fs_fieldcat-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'EBELN'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'EBELN'.
  fs_fieldcat-coltext     = 'Contract Number'.  "Venkat
  fs_fieldcat-TOOLTIP     = 'Contract Number'.  "Venkat
  fs_fieldcat-key         = 'X'.
  fs_fieldcat-hotspot  = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

  fs_sort-fieldname = 'EBELN'.
  fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.
  APPEND fs_sort TO it_sort.

*Purchasing document item
  CLEAR fs_sort.
  fs_sort-fieldname = 'EBELP'.
  fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.
  APPEND fs_sort TO it_sort.
  CLEAR fs_sort.

*fs_sort-fieldname = 'LIFNR'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.
*CLEAR fs_sort.

*fs_sort-fieldname = 'EKGRP'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.
*
*CLEAR fs_sort.
*
*fs_sort-fieldname = 'EKORG'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.
*
*CLEAR fs_sort.
*
*fs_sort-fieldname = 'NAME'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.

*Company Code
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'BUKRS'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'BUKRS'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*type
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'BSART'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'BSART'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*Begin of insertion vnarayan
*Description
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'BATXT'.
  fs_fieldcat-ref_table   = 'T161T'.
  fs_fieldcat-ref_field   = 'BATXT'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.
*itab-BATXT = i_dtype-BATXT.

*End of insertion vnarayan

*CLEAR fs_sort.
*
*fs_sort-fieldname = 'BSART'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.
*APPEND fs_sort TO it_sort.

*VENDOR
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'LIFNR'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'LIFNR'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*NAME
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'NAME'.
  fs_fieldcat-ref_table   = 'LFA1'.
  fs_fieldcat-ref_field   = 'NAME1'.
  fs_fieldcat-tooltip     = 'Vendor Name'.  " vnarayan
  fs_fieldcat-coltext     = 'Vendor Name'.  " vnarayan
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*
*INDUSTRY

*CLEAR FS_FIELDCAT.
*
*FS_FIELDCAT-fix_column = 'X'.

*FS_FIELDCAT-TABNAME     = 'IFINAL_DATA'.
*FS_FIELDCAT-FIELDNAME   = 'BRSCH'.
*FS_FIELDCAT-REF_TABLE   = 'LFA1'.
*FS_FIELDCAT-ref_field   = 'BRSCH'.
*FS_FIELDCAT-KEY         = 'X'.

*APPEND FS_FIELDCAT TO IT_FIELDCAT_2.
*
*purchasing group
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'EKGRP'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'EKGRP'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*dESCRIPTION
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'EKNAM'.
  fs_fieldcat-ref_table   = 'T024'.
  fs_fieldcat-ref_field   = 'EKNAM'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.
*
*CLEAR fs_sort.
*
*fs_sort-fieldname = 'EKNAM'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.

*PURCHASING ORG
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'EKORG'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'EKORG'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*START DATE
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'KDATB'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'KDATB'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*CLEAR fs_sort.
*
*fs_sort-fieldname = 'KDATB'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.

*END DATE
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'KDATE'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'KDATE'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*CLEAR fs_sort.
*
*fs_sort-fieldname = 'KDATE'.
*fs_sort-up    = 'X'.
*FS_SORT-SUBTOT = 'X'.

*APPEND fs_sort TO it_sort.

*Purchase order item
  CLEAR fs_fieldcat.
  fs_fieldcat-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'EBELP'.
  fs_fieldcat-ref_table   = 'EKPO'.
  fs_fieldcat-ref_field   = 'EBELP'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*Material
  CLEAR fs_fieldcat.
  fs_fieldcat-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'MATNR'.
  fs_fieldcat-ref_table   = 'EKPO'.
  fs_fieldcat-ref_field   = 'MATNR'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.
*tEXT
  CLEAR fs_fieldcat.
  fs_fieldcat-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'TXZ01'.
  fs_fieldcat-ref_table   = 'EKPO'.
  fs_fieldcat-ref_field   = 'TXZ01'.
  fs_fieldcat-coltext    = 'Material description'.  "vnarayan
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*TOTAL VALUE
*CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.

*fs_fieldcat-tabname     = 'IFINAL_DATA'.
*fs_fieldcat-fieldname   = 'TOT_VAL'.
*fs_fieldcat-ref_table   = 'RM06E'.
*fs_fieldcat-ref_field   = 'GSABW'.
*fs_fieldcat-coltext = 'Contract Value'.
*FS_FIELDCAT-KEY         = 'X'.

*APPEND fs_fieldcat TO it_fieldcat_2.

  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'KTWRT'.
  fs_fieldcat-ref_table   = 'EKKO'.
  fs_fieldcat-ref_field   = 'KTWRT'.
  fs_fieldcat-coltext = 'Contract Value'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*KTWRT

*RELEASED VALUE
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'GSABW'.
  fs_fieldcat-ref_table   = 'RM06E'.
  fs_fieldcat-ref_field   = 'GSABW'.
  fs_fieldcat-coltext = 'Released Value'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*Contract qty
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'KTMNG'.
  fs_fieldcat-ref_table   = 'EKPO'.
  fs_fieldcat-ref_field   = 'KTMNG'.
  fs_fieldcat-coltext = 'Contract Qty'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

*Contract qty
  CLEAR fs_fieldcat.
*FS_FIELDCAT-fix_column = 'X'.
  fs_fieldcat-tabname     = 'IFINAL_DATA'.
  fs_fieldcat-fieldname   = 'MENGE'.
  fs_fieldcat-ref_table   = 'EKPO'.
  fs_fieldcat-ref_field   = 'MENGE'.
  fs_fieldcat-coltext = 'Released Qty'.
*FS_FIELDCAT-KEY         = 'X'.
  APPEND fs_fieldcat TO it_fieldcat_2.

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

  CONCATENATE year month day INTO date.

  r_kdatb = date.
  date+6(2) = '31'.
  date+4(2) = '12'.
  r_kdate = date.


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

ENDFORM.                    " f510_handle_hotspot_click
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.