Skip to Content
author's profile photo Former Member
Former Member

problem in alv reports

hello dear,

how can i calculate total from a fields to get value,i am using table bset and i have to calculate total of fields fwste in according to hkont and belnr to get exice amount please refer some related programs.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

9 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 04:37 AM

    Hi,

    If you are using ALV Grid display, you will get all the options in the output of the report display for adding the values, for sorting the values and also for the download of the data to the local pc.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 24, 2008 at 04:43 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 05:40 AM

    Hi,

    If you use function madule 'REUSE_ALV_GRID_DISPLAY' or 'REUSE_ALV_LIST_DISPLAY' then all the options (colum alignment, sorting, filtering, totals, sub totals & etc) you will get .

    Regards

    Md.MahaboobKhan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 06:34 AM

    Hi ,

    If you want total for a particular column at the end , the

    WA_FLD_CATALOG-FIELDNAME = P_FIELDNAME.

    WA_FLD_CATALOG-TABNAME = P_REF_TABLE.

    WA_FLD_CATALOG-SELTEXT_S = P_SCRTEXT.

    WA_FLD_CATALOG-SELTEXT_M = P_SCRTEXT.

    WA_FLD_CATALOG-SELTEXT_L = P_SCRTEXT.

    WA_FLD_CATALOG-OUTPUTLEN = 15.

    WA_FLD_CATLOG_DO_SUM = 'X' "<=======Display column total

    APPEND WA_FLD_CATALOG TO IT_FLD_CATALOG.

    -


    or if you want to sum two or more field to generate the thierd field , then you need to add one more field in your internal table , then loop thrue the table and add the field you want to generate the resultant field , change field catalog for the added column.

    i.e. you need to write the login to do the some of field's

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 06:56 AM

    Hi,

    You just try this FM 'REUSE_ALV_GRID_DISPLAY' or 'REUSE_ALV_LIST_DISPLAY' and you will get the same.

    Regards,

    Anki.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 08:54 AM

    Hi,

    Find the code below which souits your requirement.

    TYPE-POOLS : slis.
    
    TYPES : BEGIN OF itab_t,
    ebeln LIKE ekpo-ebeln,
    lifnr LIKE ekko-lifnr,
    ekorg LIKE ekko-ekorg,
    ekgrp LIKE ekko-ekgrp,
    werks LIKE ekpo-werks,
    ebelp LIKE ekpo-ebelp,
    matnr LIKE ekpo-matnr,
    menge LIKE ekpo-menge,
    netpr LIKE ekpo-netpr,
    d, "Dummy field to fire the Subtotal text event
    END OF itab_t.
    
    DATA: itab TYPE TABLE OF itab_t.
    DATA: tab TYPE itab_t.
    DATA : itab1 LIKE eket OCCURS 0 WITH HEADER LINE.
    
    DATA: t_fcat TYPE slis_t_fieldcat_alv,
    it_sort TYPE slis_t_sortinfo_alv,
    t_events TYPE slis_t_event,
    listhead TYPE slis_t_listheader,
    ls_layout TYPE slis_layout_alv.
    
    START-OF-SELECTION.
    
      SELECT a~ebeln
      a~lifnr
      a~ekorg
      a~ekgrp
      b~werks
      b~ebelp
      b~matnr
      b~menge
      b~netpr
      UP TO 100 ROWS
      INTO CORRESPONDING FIELDS OF TABLE itab
      FROM ekko AS a INNER JOIN ekpo AS b
      ON a~ebeln = b~ebeln.
    
    END-OF-SELECTION.
    
      PERFORM fill_fcat USING t_fcat.
    
      PERFORM fill_event USING t_events.
    
      PERFORM fill_layout.
      PERFORM display.
    
    *&---------------------------------------------------------------------*
    *&      Form  fill_fcat
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_T_FCAT   text
    *----------------------------------------------------------------------*
    FORM fill_fcat USING p_t_fcat TYPE slis_t_fieldcat_alv.
    
      DATA : lfcat TYPE slis_fieldcat_alv,
    
      colpos TYPE i VALUE '0'.
    
      DATA : ls_sort TYPE slis_sortinfo_alv.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'EBELN'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'EBELN'.
      lfcat-ref_tabname = 'EKKO'.
      lfcat-hotspot = 'X'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'LIFNR'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'LIFNR'.
      lfcat-ref_tabname = 'EKKO'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'EKORG'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'EKORG'.
      lfcat-ref_tabname = 'EKKO'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'EKGRP'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'EKGRP'.
      lfcat-ref_tabname = 'EKKO'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'WERKS'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'WERKS'.
      lfcat-ref_tabname = 'EKPO'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'EBELP'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'EBELP'.
      lfcat-ref_tabname = 'EKPO'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'MATNR'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'MATNR'.
      lfcat-ref_tabname = 'EKPO'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'MENGE'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'MENGE'.
      lfcat-ref_tabname = 'EKPO'.
      lfcat-do_sum = 'X'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'NETPR'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'NETPR'.
      lfcat-ref_tabname = 'EKPO'.
      lfcat-do_sum = 'X'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
    
      colpos = colpos + 1.
      lfcat-col_pos = colpos.
      lfcat-fieldname = 'D'.
      lfcat-tabname = 'ITAB'.
      lfcat-ref_fieldname = 'EBELN'.
      lfcat-ref_tabname = 'EKKO'.
      lfcat-no_out = 'X'.
      APPEND lfcat TO p_t_fcat.
      CLEAR lfcat.
    
      ls_sort-spos = 1.
      ls_sort-fieldname = 'EBELN'.
      ls_sort-tabname = 'ITAB'.
      ls_sort-up = 'X'.
      ls_sort-group = 'UL'.
    
    
      APPEND ls_sort TO it_sort.
      CLEAR ls_sort.
    
      ls_sort-spos = 2.
      ls_sort-fieldname = 'D'.
      ls_sort-tabname = 'ITAB'.
      ls_sort-up = 'X'.
      ls_sort-group = 'UL'.
      ls_sort-subtot = 'X'.
    
      APPEND ls_sort TO it_sort.
    ENDFORM. " fill_fcat
    
    *&---------------------------------------------------------------------*
    *&      Form  fill_event
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_T_EVENTS text
    *----------------------------------------------------------------------*
    FORM fill_event USING p_t_events TYPE slis_t_event.
    
      DATA : ls_event TYPE slis_alv_event.
    
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = p_t_events
        EXCEPTIONS
          list_type_wrong = 1
          OTHERS          = 2.
      IF sy-subrc NE 0.
    
      ENDIF.
    
      READ TABLE p_t_events WITH KEY name = slis_ev_top_of_page
      INTO ls_event.
      IF sy-subrc = 0.
        MOVE 'TOP_OF_PAGE' TO ls_event-form.
        APPEND ls_event TO p_t_events.
      ENDIF.
    
      READ TABLE p_t_events WITH KEY name = slis_ev_subtotal_text
      INTO ls_event.
      IF sy-subrc = 0.
        MOVE 'SUBTOTAL' TO ls_event-form.
        APPEND ls_event TO p_t_events.
      ENDIF.
    
    ENDFORM. " FILL_EVENT
    
    *&---------------------------------------------------------------------*
    *&      Form  subtotal
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->I_LISTHEAD text
    *      -->I_SUBTOTAL text
    *----------------------------------------------------------------------*
    FORM subtotal USING i_listhead STRUCTURE tab
    i_subtotal TYPE slis_subtot_text.
    *criteria type slis_fieldname,
      DATA: keyword LIKE dd03p-reptext,
      criteria_text(255) TYPE c,
      max_len LIKE dd03p-outputlen,
      display_text_for_subtotal(255) TYPE c.
    
      IF i_subtotal-criteria = 'D'.
        i_subtotal-display_text_for_subtotal = 'Test Subtotal text'.
        "here you need to do some calculations and assing the data
        "back to total line
      ENDIF.
    
    ENDFORM.                    "SUBTOTAL
    
    *&---------------------------------------------------------------------*
    *&      Form  top_of_page
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM top_of_page.
    
      DATA : s_listhead TYPE slis_listheader.
    
      CLEAR s_listhead.
      s_listhead-typ = 'H'.
      s_listhead-info = 'SIMPLE REPORT'.
      APPEND s_listhead TO listhead.
    
      s_listhead-typ = 'S'.
      s_listhead-key = 'EBELN'.
      s_listhead-info = 'ALV'.
      APPEND s_listhead TO listhead.
    
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = listhead
          i_logo             = 'ENJOYSAP_LOGO'.
    ENDFORM. "TOP_OF_PAGE
    
    *&---------------------------------------------------------------------*
    *&      Form  fill_layout
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM fill_layout .
    
      ls_layout-zebra = 'X'.
      ls_layout-detail_popup = 'X'.
      ls_layout-key_hotspot = 'X'.
      ls_layout-window_titlebar = 'Test Title'.
      ls_layout-totals_text = 'GRAND TOTAL'.
      ls_layout-subtotals_text = 'SUB'.
    
    ENDFORM. " fill_layout
    
    *&---------------------------------------------------------------------*
    *&      Form  display
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM display .
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = sy-repid
          it_sort            = it_sort[]
          it_events          = t_events
          it_fieldcat        = t_fcat
        TABLES
          t_outtab           = itab
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
      IF sy-subrc NE 0.
    
      ENDIF.
    ENDFORM. " display

    Hope this helps,

    Murthy.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      yes it help me lot but not totally i want to calculate exise and vat in respect to purchse invoice number from me23n as i am doing alv reports so how can i get the solution plz refer some program like before so i can solve my problem.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 10:23 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      again i get stuck because i have to put matnr mblnr maktx menge meins belnr excise vat and netvalue with mseg makt bseg and ekpo tables.i have to calculate excise and vat in respect to purchase invoice document number so please refer some related program which include all these functionality.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 24, 2008 at 10:25 AM

    If you want to calculate th e third filed based on other two, you would need to do it programatically using control break statements like AT NEW / AT END OF ect ..

    Below is sample program which does summary based on mrp controllers and other parameeters.

    • Modification Log
    • Program Name:ZCD0R_PDC_PERCENT_FILL
    • Author:Santosh Sarda
    • Date Written:7/19/2007
    • Request #:CDXK961051
    • Requested by:Blanca Ramirez.
    • Description: Get the percent fill of PDC Service Parts Requirements
    • Program Specifications:Service Store Percent Fill
    • Mod date Programmer Reference Description
    REPORT zcd0r_pdc_percent_fill. ************************************************************************ *
    • Includes
    • types
    • tables
    • types
    *
    • internal tables
    • Work Areas
    • internal data fields
    • Internal table for field catalogue
    • Internal table for sort and sum
    • Structure for layout control settings
    • Structure for sort and Sum
    • Parameters and Selection Options
    • Initialization
    • at selection screen
    • event Start of Selection
    • Get ReQuired Data
    • Calculate % FILL MRP Controllerwise.
    • Calculate % Fill material wise.
    • forms
    * ----
    • This Subroutine does not take any parameters.
    *07/19/2007 Santosh S. CDXK961051 Initial Creation *08/01/2007 Santosh S. CDXK961295 Layout change ************************************************************************ *eject ************************************************************************ ************************************************************************ ************************************************************************ ************************************************************************ TYPE-POOLS : slis. ************************************************************************
    • Select data as per selection screen conditions .
    ************************************************************************ TABLES:vbep, " Sales Document: Schedule Line Data vbap, " Sales Document: Item Data vbak, " Sales Document: Header Data marc. " Plant Data for Material ************************************************************************
    • This Subroutine does not take any parameters.
    ************************************************************************ TYPES: BEGIN OF t_vbak, vbeln TYPE vbak-vbeln, "Sales document kunnr TYPE vbak-kunnr, "Sold-to party END OF t_vbak, BEGIN OF t_vbap, vbeln TYPE vbap-vbeln, "Sales document posnr TYPE vbap-posnr, "Item werks TYPE vbap-werks, "Plant matnr TYPE vbap-matnr, "Material END OF t_vbap, BEGIN OF t_marc, werks TYPE marc-werks, "Plant matnr TYPE marc-matnr, "Material dispo TYPE marc-dispo, "MRP Controller END OF t_marc, BEGIN OF t_makt, matnr TYPE makt-matnr, "Material maktx TYPE makt-maktx, "Material Description END OF t_makt, BEGIN OF t_vbpa, vbeln TYPE vbpa-vbeln, "Sales document parvw TYPE vbpa-parvw, "Partner Function kunnr TYPE vbpa-kunnr, "Ship To Party END OF t_vbpa, BEGIN OF t_t024d, werks TYPE t024d-werks, "Plant dispo TYPE t024d-dispo, "MRP Controller dsnam TYPE t024d-dsnam, "Controller Name END OF t_t024d, BEGIN OF t_vbep, vbeln TYPE vbep-vbeln, "Sales document posnr TYPE vbep-posnr, "Item etenr TYPE vbep-etenr, "Schedule line edatu TYPE vbep-edatu, "Delivery Date wmeng TYPE vbep-wmeng, "Order quantity END OF t_vbep, BEGIN OF t_vbep_all, vbeln TYPE vbep-vbeln, "Sales document posnr TYPE vbep-posnr, "Item etenr TYPE vbep-etenr, "Schedule line matnr TYPE marc-matnr, "Material maktx TYPE makt-maktx, "Material Description dispo TYPE t024d-dispo, "MRP Controller dsnam TYPE t024d-dsnam, "Controller Name edatu TYPE vbep-edatu, "Delivery Date wmeng TYPE vbep-wmeng, "Order Quantity olfmng TYPE olfmng, "Open Quantity soldto TYPE vbak-kunnr, "Sold To Party shipto TYPE vbpa-kunnr, "Ship To Party END OF t_vbep_all, BEGIN OF t_marc_all, werks TYPE marc-werks, "Plant matnr TYPE marc-matnr, "Material dispo TYPE marc-dispo, "MRP Controller maktx TYPE makt-maktx, "Material Description dsnam TYPE t024d-dsnam, "Controller Name END OF t_marc_all, BEGIN OF t_output, dispo TYPE marc-dispo, "MRP Controller dsnam TYPE t024d-dsnam, "Controller Name matnr TYPE vbap-matnr, "Material maktx TYPE makt-maktx, "Material Description vbeln TYPE vbak-vbeln, "Sales document posnr TYPE vbap-posnr, "Item edatu TYPE vbep-edatu, "Delivery Date wmeng TYPE i, "Order Quantity shipqty TYPE i, "Shipped Quantity olfmng TYPE i, "Open Quantity fill TYPE olfmng, "%Fill materialfill TYPE olfmng, controllerfill TYPE olfmng, soldto TYPE vbak-kunnr, "Sold To Party shipto TYPE vbpa-kunnr, "Ship To Party END OF t_output, BEGIN OF t_date, edatu TYPE sy-datum, "Delivery date END OF t_date. *******************
    • Do Nothing
    • Do Nothing
    • Do Nothing
    • Do Nothing
    Begin Of CDXK961295******************************** TYPES:BEGIN OF t_sum_mrpcontro, dispo TYPE marc-dispo, "MRP Controller dsnam TYPE t024d-dsnam, "Controller Name wmeng TYPE i, "Order Quantity shipqty TYPE i, "Shipped Quantity olfmng TYPE i, "Open Quantity controllerfill TYPE olfmng, END OF t_sum_mrpcontro, BEGIN OF t_sum_material, dispo TYPE marc-dispo, "MRP Controller dsnam TYPE t024d-dsnam, "Controller Name matnr TYPE vbap-matnr, "Material maktx TYPE makt-maktx, "Material Description wmeng TYPE i, "Order Quantity shipqty TYPE i, "Shipped Quantity olfmng TYPE i, "Open Quantity materialfill TYPE olfmng, END OF t_sum_material. *******************
    • Get Data from VBEP: schedule line data within Date range of EDATU.
    End Of CDXK961295
    • This Subroutine does not take any parameters.
    ******************************** ************************************************************************
    • Do Nothing .
    ************************************************************************ DATA: i_vbak TYPE STANDARD TABLE OF t_vbak, i_vbap TYPE STANDARD TABLE OF t_vbap, i_marc TYPE STANDARD TABLE OF t_marc, i_makt TYPE STANDARD TABLE OF t_makt, i_vbpa TYPE STANDARD TABLE OF t_vbpa, i_t024d TYPE STANDARD TABLE OF t_t024d, i_vbep TYPE STANDARD TABLE OF t_vbep, i_vbep_all TYPE STANDARD TABLE OF t_vbep_all, i_marc_all TYPE STANDARD TABLE OF t_marc_all, o_output TYPE STANDARD TABLE OF t_output, i_date TYPE STANDARD TABLE OF t_date, i_sum_mrpcontro TYPE STANDARD TABLE OF t_sum_mrpcontro,"CDXK961295 i_sum_material TYPE STANDARD TABLE OF t_sum_material. "CDXK961295 ************************************************************************ ************************************************************************ DATA: wa_vbak LIKE LINE OF i_vbak, wa_vbap LIKE LINE OF i_vbap, wa_marc LIKE LINE OF i_marc, wa_makt LIKE LINE OF i_makt, wa_vbpa LIKE LINE OF i_vbpa, wa_t024d LIKE LINE OF i_t024d, wa_vbep LIKE LINE OF i_vbep, wa_vbep_all LIKE LINE OF i_vbep_all, wa_marc_all LIKE LINE OF i_marc_all, wa_output LIKE LINE OF o_output, wa_date LIKE LINE OF i_date, wa_sum_mrpcontro LIKE LINE OF i_sum_mrpcontro, "CDXK961295 wa_sum_material LIKE LINE OF i_sum_material. "CDXK961295 ************************************************************************
    • Process material and mrp controller data.
    ************************************************************************ CONSTANTS: c_spras(2) TYPE c VALUE 'EN', "To get material Description In EN c_parvw(2) TYPE c VALUE 'WE', "To get Ship to party ( SH=WE ) c_act_auth_03 LIKE tactz-actvt VALUE '03', "03 --> Plant check c_x TYPE c VALUE 'X', "Field catelogue c_c TYPE c value 'C'. "field catelogue DATA: g_date TYPE sy-datum, "To keep track of delivery date g_totalopen TYPE olfmng, "To Split OLFMNG in given date range g_tabix TYPE sy-tabix. "To keep loop track *Declartion of t_code for authority check. DATA: g_tcode LIKE sy-tcode. "variable for TCODE. **************************
    • This Subroutine does not take any parameters.
    ALVObject********************************** DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
    • Process VBEP data with material data.
    i_sort TYPE slis_t_sortinfo_alv,
    • This Subroutine does not take any parameters.
    fs_layout TYPE slis_layout_alv, fs_sort LIKE LINE OF i_sort , *internal table to set pf status i_extab TYPE standard table of slis_extab. ************************************************************************ ************************************************************************ SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001. SELECT-OPTIONS: s_werks FOR marc-werks OBLIGATORY, " Producing Plant s_matnr FOR marc-matnr, " Material s_dispo FOR marc-dispo. " MRP Controller SELECTION-SCREEN END OF BLOCK blk1. SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002. SELECT-OPTIONS: s_vkorg FOR vbak-vkorg , " Sales Organisation s_vbeln FOR vbak-vbeln , " Sales Order s_auart FOR vbak-auart DEFAULT 'ZLCW' TO 'ZLIF', " Sales Doc Type s_lgort FOR vbap-lgort, " Storage Location s_kunnr FOR vbak-kunnr DEFAULT '99999PDY00', " Sold to party s_edatu FOR vbep-edatu OBLIGATORY. " Delivery Date SELECTION-SCREEN END OF BLOCK blk2. **********************
    • This subroutine is copied from transaction ZCSRS to get open quantity.
    • Naming Conventions have been changed as per standards.
    BEGIN OF CDXK961295
    • This Subroutine does not take any parameters.
    **************************** *To add select radiobutton group for choosing layout as per users *requirement to see detail or summary. SELECTION-SCREEN BEGIN OF BLOCK blk3 WITH FRAME TITLE text-026. PARAMETER r_lay1 RADIOBUTTON GROUP r1. PARAMETER r_lay2 RADIOBUTTON GROUP r1 DEFAULT 'X'. PARAMETER r_lay3 RADIOBUTTON GROUP r1. SELECTION-SCREEN END OF BLOCK blk3. **********************
    • Consider only Sch Agmts here to proceed further
    • CHECK NOT t_sch_agmts[] IS INITIAL.
    • Doc Flow entries from VBFA
    • Sales Document: Item Status from VBUP
    • Sch Line items from VBEP
    • Sch Agmt Items from VBAP
    • Now, use the FM for each line item and get the open qty. Make a copy
    • of iT_SCH_AGMTS for use later on.
    • Call the FM now
    END OF CDXK961295***************************** ************************************************************************
    • To populate final output table
    ************************************************************************ INITIALIZATION. PERFORM t_code_check. ************************************************************************
    • This Subroutine does not take any parameters.
    ************************************************************************ *Check Authorisation For Plant. AT SELECTION-SCREEN ON s_werks. PERFORM plant_auth_check. *Validate MRP Controller. AT SELECTION-SCREEN ON s_dispo. PERFORM validate_mrp_controller. *Validate Document type. AT SELECTION-SCREEN ON s_auart. PERFORM validate_doc_type. ************************************************************************
    • if s_edatu-high value is enterd by user
    • if only s_edatu-low value is enterd by user
    • sort for getting orders with shedule lines in reverse order TO adjust
    • open quantity as per earliest delivery date.
    ************************************************************************ START-OF-SELECTION. *Check Delivery Dates Entered By user and MODIFY the same. PERFORM chk_del_date. PERFORM get_data. *Loop To Process Number Of Single Values Entered Of EDATU. LOOP AT s_edatu . g_tabix = sy-tabix. READ TABLE i_date INTO wa_date INDEX g_tabix. IF sy-subrc = 0. g_date = wa_date-edatu. PERFORM get_vbep_data. "Get Data from VBEP PERFORM process_material_data. "Material Detail PERFORM process_data. "Process Data PERFORM get_rem_quantity. "Get Open Qty From FM PERFORM get_final_output. "Add data to output table CLEAR: i_vbep[],i_vbep_all[]. ENDIF. " IF SY-SUBRC = 0. ENDLOOP. " LOOP AT s_edatu . **********************
    • To Calculate TOTAL % fill MRP ControllerWise
    BEGIN OF CDXK961295
    • This subroutine does not take any parameters.
    **************************** *Display alv as per layout selection. IF r_lay1 = 'X'. PERFORM calc_mrpcontroller_%fill. PERFORM calc_material_%fill. PERFORM fill_catalogue. " Fill catelogue PERFORM display_output. " Display OUTPUT ON AlV GRID using FM. ELSEIF r_lay2 = 'X'. PERFORM process_sum_mrpcontro. PERFORM fill_catelogue_mrpcontro. " Fill catelogue PERFORM display_sum_mrpcontro. " Display OUTPUT ON AlV GRID using FM ELSEIF r_lay3 = 'X'. PERFORM process_sum_material. PERFORM fill_catelogue_material. " Fill catelogue PERFORM display_sum_material. " Display OUTPUT ON AlV GRID using FM. ENDIF. " IF r_lay1 = 'X'. **********************END OF CDXK961295
    • This subroutine does not take any parameter.
    **************************** ************************************************************************ *********************************************************************** &----
    • To fill FieldCatelogue to be passed to FM
    *& Form chk_del_date
    • This Subroutine does not take any parameters.
    &----
    • To sort output on MRP Controller AND Material and do subtotal.
    • Sort on controller name ,material description to get
    • displayed controller name and material description along with mrp
    • controller and material at subtotals level.
    *check if delivery date is less than today,then modify date till today *else search in given range. ----
    • Call alv display function module
    • This Subroutine does not take any parameters.
    • SORT AS per MRP Controller,Material and delete duplicates.
    • Set the Layout attributes
    • Call FUNCTION MODULE FOR DISPLAY
    • DO NOTHING
    ----
    FORM chk_del_date. LOOP AT s_edatu. wa_date = s_edatu-high. IF s_edatu-low LT sy-datum AND s_edatu-high LT sy-datum. s_edatu-high = sy-datum. s_edatu-option = 'BT'. MODIFY s_edatu. ENDIF. "IF s_edatu-low LT sy-datum AND s_edatu-high LT sy-datum. APPEND wa_date TO i_date. CLEAR:wa_date. ENDLOOP. " LOOP AT s_edatu. ENDFORM. " chk_del_date
    • Check authorization against transaction code
    &----
    • This subroutine does not take any parameters.
    *& Form get_data &----
    • Validate Document type.
    • This subroutine does not take any parameters.
    ----
    • Authorisation and validation of Plant
    ----
    • This subroutine does not take any parameters.
    FORM get_data. *Get data from VBAK SD agreement and Sold To Party SELECT vbeln kunnr FROM vbak INTO TABLE i_vbak WHERE vbeln IN s_vbeln AND kunnr IN s_kunnr AND auart IN s_auart AND vkorg IN s_vkorg. IF sy-subrc = 0. SORT i_vbak BY vbeln. ELSE. MESSAGE e208(00) WITH 'No Scheduling Agreements Found '(003). ENDIF. " IF SY-SUBRC = 0. *Get data from VBAP item data and related material for SD Agrrement from *VBAK IF NOT i_vbak[] IS INITIAL. SELECT vbeln posnr werks matnr FROM vbap INTO TABLE i_vbap FOR ALL ENTRIES IN i_vbak WHERE vbeln EQ i_vbak-vbeln AND werks IN s_werks AND matnr IN s_matnr AND lgort IN s_lgort AND abgru EQ space. IF sy-subrc = 0. SORT i_vbap BY vbeln posnr. ELSE. MESSAGE e368(00) WITH 'No SD Agreements Found for Plant'(004) s_werks. ENDIF. " IF SY-SUBRC = 0 ENDIF. "IF NOT i_vbak[] IS INITIAL IF NOT i_vbap[] IS INITIAL. *Get data from MARC material and MRP Controller for given PLANT. SELECT werks matnr dispo FROM marc INTO TABLE i_marc FOR ALL ENTRIES IN i_vbap WHERE werks EQ i_vbap-werks AND matnr EQ i_vbap-matnr AND dispo IN s_dispo. IF sy-subrc = 0. SORT i_marc BY werks matnr. ELSE.
    • Validation for PlantSELECT SINGLE WERKS
    ENDIF. " IF SY-SUBRC = 0. *To DELETE Entries from VBAP AS per dispo from select option . LOOP AT i_vbap INTO wa_vbap. READ TABLE i_marc INTO wa_marc WITH KEY werks = wa_vbap-werks matnr = wa_vbap-matnr BINARY SEARCH. IF sy-subrc <> 0. DELETE i_vbap. CONTINUE. ENDIF. " IF SY-SUBRC <> 0. ENDLOOP. " LOOP AT i_vbap INTO wa_vbap. *Get Ship To Party FROM VBPA. SELECT vbeln parvw kunnr FROM vbpa INTO TABLE i_vbpa FOR ALL ENTRIES IN i_vbap WHERE vbeln EQ i_vbap-vbeln AND parvw EQ c_parvw. IF sy-subrc = 0. SORT i_vbpa BY vbeln. DELETE ADJACENT DUPLICATES FROM i_vbpa COMPARING vbeln. ELSE. ENDIF. " IF SY-SUBRC = 0. ENDIF. " IF i_vbap[] IS INITIAL IF NOT i_marc[] IS INITIAL. *Get Material Description in English from MAKT. SELECT matnr maktx FROM makt INTO TABLE i_makt FOR ALL ENTRIES IN i_marc WHERE matnr EQ i_marc-matnr AND spras = c_spras. IF sy-subrc = 0 . SORT i_makt BY matnr. DELETE ADJACENT DUPLICATES FROM i_makt COMPARING matnr. ELSE.
    • Validate MRP Controller
    ENDIF. " IF SY-SUBRC = 0 . *Get MRP Controller Name from T024D. SELECT werks dispo dsnam FROM t024d INTO TABLE i_t024d FOR ALL ENTRIES IN i_marc WHERE werks EQ i_marc-werks AND dispo EQ i_marc-dispo. IF sy-subrc = 0 . SORT i_t024d BY werks dispo. ELSE.
    • This subroutine does not take any parameters.
    ENDIF. " IF SY-SUBRC = 0 . ENDIF. " IF NOT i_marc[] IS INITIAL ENDFORM. " get_data &----
    *& Form get_vbep_data &----
    • Display summary by MRP Controller
    • This subroutine does not take any parameter.
    ----
    • Field Catelogue for summary by MRP Controller
    • This Subroutine doen not take any parameter
    ----
    FORM get_vbep_data. IF NOT i_vbap[] IS INITIAL. IF s_edatu-low GE sy-datum AND s_edatu-high IS INITIAL. SELECT vbeln posnr etenr edatu wmeng FROM vbep INTO TABLE i_vbep FOR ALL ENTRIES IN i_vbap WHERE vbeln EQ i_vbap-vbeln AND posnr EQ i_vbap-posnr AND edatu EQ s_edatu-low. ELSE. SELECT vbeln posnr etenr edatu wmeng FROM vbep INTO TABLE i_vbep FOR ALL ENTRIES IN i_vbap WHERE vbeln = i_vbap-vbeln AND posnr = i_vbap-posnr AND edatu BETWEEN s_edatu-low and s_edatu-high. ENDIF. "IF s_edatu-low GE sy-datum AND s_edatu-high IS INITIAL. IF sy-subrc = 0 . ELSE. MESSAGE e208(00) WITH 'No Scheduling Agreements Found Within Given Delivery Date'(018). ENDIF. " IF SY-SUBRC = 0 . ENDIF. " i_vbap[] IS INITIAL. ENDFORM. " get_vbep_data
    • Call alv display function module
    &----
    • This Subroutine does not take any parameters.
    *& Form process_material_data
    • SORT AS per MRP Controller and delete duplicates.
    • Do nothing
    • Set the Layout attributes
    • Call FUNCTION MODULE FOR DISPLAY
    • DO NOTHING
    &----
    • This subRoutine calculates summary line by material and store in
    • internal table to display as in alv
    • this subroutine does not take any parameter.
    ----
    • Fills Field Catelogue for alv display for summary by material
    ----
    • This subRoutine does not take any parameter.
    FORM process_material_data. *To get Mterial Description and MRP Controller. LOOP AT i_marc INTO wa_marc . wa_marc_all-werks = wa_marc-werks. wa_marc_all-matnr = wa_marc-matnr. wa_marc_all-dispo = wa_marc-dispo. READ TABLE i_t024d INTO wa_t024d WITH KEY werks = wa_marc-werks dispo = wa_marc-dispo BINARY SEARCH. IF sy-subrc = 0. wa_marc_all-dsnam = wa_t024d-dsnam. ENDIF. " IF SY-SUBRC = 0 READ TABLE i_makt INTO wa_makt WITH KEY matnr = wa_marc-matnr BINARY SEARCH. IF sy-subrc = 0. wa_marc_all-maktx = wa_makt-maktx. ENDIF. " IF SY-SUBRC = 0. APPEND wa_marc_all TO i_marc_all. CLEAR :wa_marc_all,wa_marc,wa_t024d,wa_makt. ENDLOOP. " i_marc INTO wa_marc *Sort by palnt,material. SORT i_marc_all BY werks matnr. ENDFORM. " process_material_data &----
    *& Form process_data
    • Call Function module For Display of summary my material.
    &----
    • This SubRoutine Does not take any parameter.
    • SORT AS per MRP Controller,Material and delete duplicates.
    • do nothing.
    • Set the Layout attributes
    • Call FUNCTION MODULE FOR DISPLAY
    • DO NOTHING
    ----
    • Fills fieldcatelogue to be passed to ALV
    • p_output--> internal table for field catelogue type i_fieldcat.
    ----
    FORM process_data. *To get i-vbep_all IF NOT i_vbep IS INITIAL. LOOP AT i_vbep INTO wa_vbep. wa_vbep_all-vbeln = wa_vbep-vbeln. wa_vbep_all-posnr = wa_vbep-posnr. wa_vbep_all-etenr = wa_vbep-etenr. wa_vbep_all-edatu = wa_vbep-edatu. wa_vbep_all-wmeng = wa_vbep-wmeng. READ TABLE i_vbap INTO wa_vbap WITH KEY vbeln = wa_vbep-vbeln posnr = wa_vbep-posnr BINARY SEARCH. IF sy-subrc = 0. wa_vbep_all-matnr = wa_vbap-matnr. READ TABLE i_marc_all INTO wa_marc_all WITH KEY werks = wa_vbap-werks matnr = wa_vbap-matnr BINARY SEARCH. IF sy-subrc = 0. wa_vbep_all-dispo = wa_marc_all-dispo. wa_vbep_all-dsnam = wa_marc_all-dsnam. wa_vbep_all-maktx = wa_marc_all-maktx. ENDIF. " IF SY-SUBRC = 0. ENDIF. " IF SY-SUBRC = 0. READ TABLE i_vbak INTO wa_vbak WITH KEY vbeln = wa_vbep-vbeln BINARY SEARCH. IF sy-subrc = 0. wa_vbep_all-soldto = wa_vbak-kunnr. ENDIF. " IF SY-SUBRC = 0. READ TABLE i_vbpa INTO wa_vbpa WITH KEY vbeln = wa_vbep-vbeln BINARY SEARCH. IF sy-subrc = 0. wa_vbep_all-shipto = wa_vbpa-kunnr. ENDIF. " IF SY-SUBRC = 0. APPEND wa_vbep_all TO i_vbep_all. CLEAR: wa_vbep,wa_vbap,wa_marc_all,wa_vbep_all,wa_vbak,wa_vbpa. ENDLOOP. " LOOP AT i_vbep ENDIF. "i_vbep is INITIAL ENDFORM. " process_data &----
    *& Form get_rem_quantity &----
    ----
    ----
    FORM get_rem_quantity. *Types Declaration TYPES: BEGIN OF lt_sch_agmts , vbeln LIKE vbak-vbeln, "Sales Document posnr LIKE vbap-posnr, "Item No END OF lt_sch_agmts, BEGIN OF lt_doc_types, vbeln LIKE vbak-vbeln, "Sales Document vbtyp LIKE vbak-vbtyp, "Document type END OF lt_doc_types. *Internal Tables Declaration. DATA: it_vbfa_data TYPE STANDARD TABLE OF vbfa, it_vbup_data TYPE STANDARD TABLE OF vbup, it_vbep_data TYPE STANDARD TABLE OF vbepvb, it_vbap_data TYPE STANDARD TABLE OF vbapvb, it_sub_vbfa_data TYPE STANDARD TABLE OF vbfa, it_sub_vbup_data TYPE STANDARD TABLE OF vbup, it_sub_vbep_data TYPE STANDARD TABLE OF vbepvb, it_sub_vbap_data TYPE STANDARD TABLE OF vbapvb, it_sch_agmts TYPE STANDARD TABLE OF lt_sch_agmts, it_doc_types TYPE STANDARD TABLE OF lt_doc_types. *Work area declaration. DATA: l_vbfa_data LIKE LINE OF it_vbfa_data, l_vbup_data LIKE LINE OF it_vbup_data, l_vbep_data LIKE LINE OF it_vbep_data, l_vbap_data LIKE LINE OF it_vbap_data, l_sub_vbfa_data LIKE LINE OF it_sub_vbfa_data, l_sub_vbup_data LIKE LINE OF it_sub_vbup_data, l_sub_vbep_data LIKE LINE OF it_sub_vbep_data, l_sub_vbap_data LIKE LINE OF it_sub_vbap_data, l_sch_agmts LIKE LINE OF it_sch_agmts, l_doc_types LIKE LINE OF it_doc_types. *ranges RANGES: r_vbtyp FOR vbak-vbtyp. *local variables DATA: l_tabix LIKE sy-tabix. CLEAR r_vbtyp[]. r_vbtyp-sign = 'I'. r_vbtyp-option = 'EQ'. r_vbtyp-low = 'E'. APPEND r_vbtyp. CLEAR r_vbtyp. r_vbtyp-sign = 'I'. r_vbtyp-option = 'EQ'. r_vbtyp-low = 'F'. APPEND r_vbtyp. CLEAR r_vbtyp. CLEAR it_doc_types[]. IF NOT i_vbep_all[] IS INITIAL. SELECT vbeln vbtyp INTO TABLE it_doc_types FROM vbak FOR ALL ENTRIES IN i_vbep_all WHERE vbeln = i_vbep_all-vbeln. ENDIF. SORT it_doc_types BY vbtyp. DELETE it_doc_types WHERE NOT vbtyp IN r_vbtyp. SORT it_doc_types BY vbeln. LOOP AT i_vbep_all INTO wa_vbep_all. READ TABLE it_doc_types INTO l_doc_types WITH KEY vbeln = wa_vbep_all-vbeln BINARY SEARCH. IF sy-subrc = 0 . l_sch_agmts-vbeln = wa_vbep_all-vbeln. l_sch_agmts-posnr = wa_vbep_all-posnr. APPEND l_sch_agmts TO it_sch_agmts. CLEAR l_sch_agmts. ENDIF. CLEAR : wa_vbep_all,l_doc_types. ENDLOOP. SORT it_sch_agmts. DELETE ADJACENT DUPLICATES FROM it_sch_agmts COMPARING vbeln posnr. IF NOT it_sch_agmts[] IS INITIAL. SELECT * FROM vbfa INTO TABLE it_vbfa_data FOR ALL ENTRIES IN it_sch_agmts WHERE vbelv = it_sch_agmts-vbeln AND posnv = it_sch_agmts-posnr. SELECT * FROM vbup INTO TABLE it_vbup_data FOR ALL ENTRIES IN it_sch_agmts WHERE vbeln = it_sch_agmts-vbeln AND posnr = it_sch_agmts-posnr. SELECT * FROM vbep INTO TABLE it_vbep_data FOR ALL ENTRIES IN it_sch_agmts WHERE vbeln = it_sch_agmts-vbeln AND posnr = it_sch_agmts-posnr. SELECT * FROM vbap INTO TABLE it_vbap_data FOR ALL ENTRIES IN it_sch_agmts WHERE vbeln = it_sch_agmts-vbeln AND posnr = it_sch_agmts-posnr. LOOP AT it_sch_agmts INTO l_sch_agmts . CLEAR: it_sub_vbfa_data[], it_sub_vbup_data[],it_sub_vbep_data[], it_sub_vbap_data[]. LOOP AT it_vbfa_data INTO l_vbfa_data WHERE vbelv = l_sch_agmts-vbeln AND posnv = l_sch_agmts-posnr. l_sub_vbfa_data = l_vbfa_data. APPEND l_sub_vbfa_data TO it_sub_vbfa_data. CLEAR : l_sub_vbfa_data,l_vbfa_data. ENDLOOP. "LOOP AT it_vbfa_data into l_vbfa_data LOOP AT it_vbup_data INTO l_vbup_data WHERE vbeln = l_sch_agmts-vbeln AND posnr = l_sch_agmts-posnr. l_sub_vbup_data = l_vbup_data. APPEND l_sub_vbup_data TO it_sub_vbup_data. CLEAR : l_sub_vbup_data,l_vbup_data. ENDLOOP. " LOOP AT it_vbup_data Into l_vbup_data LOOP AT it_vbep_data INTO l_vbep_data WHERE vbeln = l_sch_agmts-vbeln AND posnr = l_sch_agmts-posnr. l_sub_vbep_data = l_vbep_data. APPEND l_sub_vbep_data TO it_sub_vbep_data. CLEAR : l_sub_vbep_data,l_vbep_data. ENDLOOP. " LOOP AT it_vbep_data INTO l_vbep_data LOOP AT it_vbap_data INTO l_vbap_data WHERE vbeln = l_sch_agmts-vbeln AND posnr = l_sch_agmts-posnr. l_sub_vbap_data = l_vbap_data. APPEND l_sub_vbap_data TO it_sub_vbap_data. CLEAR : l_sub_vbap_data, l_vbap_data. ENDLOOP. " LOOP AT it_vbap_data INTO l_vbap_data CALL FUNCTION 'RV_SCHEDULE_CHECK_DELIVERIES' EXPORTING fbeleg = l_sch_agmts-vbeln fposnr = l_sch_agmts-posnr TABLES fvbfa = it_sub_vbfa_data fvbup = it_sub_vbup_data fxvbep = it_sub_vbep_data fvbap = it_sub_vbap_data EXCEPTIONS fehler_bei_lesen_fvbup = 1 fehler_bei_lesen_fxvbep = 2 OTHERS = 3. IF sy-subrc EQ 0. LOOP AT i_vbep_all INTO wa_vbep_all WHERE vbeln = l_sch_agmts-vbeln. l_tabix = sy-tabix. READ TABLE it_sub_vbep_data INTO l_sub_vbep_data WITH KEY vbeln = wa_vbep_all-vbeln posnr = wa_vbep_all-posnr etenr = wa_vbep_all-etenr. IF sy-subrc EQ 0. wa_vbep_all-olfmng = l_sub_vbep_data-olfmng. MODIFY i_vbep_all FROM wa_vbep_all INDEX l_tabix TRANSPORTING olfmng. ENDIF. " IF SY-SUBRC EQ 0. ENDLOOP. " LOOP AT i_vbep_all INTO wa_vbep_all ENDIF. " IF SY-SUBRC EQ 0. CLEAR l_sch_agmts. ENDLOOP. "LOOP AT it_sch_agmts INTO l_sch_agmts . ENDIF. "IF NOT it_sch_agmts[] IS INITIAL. ENDFORM. " get_rem_quantity &----
    *& Form get_final_output &----
    ----
    ----
    FORM get_final_output. DATA:l_vbeln LIKE vbep-vbeln, "Sales Document l_posnr LIKE vbep-posnr, "Item l_edatu LIKE vbep-edatu, "Delivery Date l_tabix TYPE sy-tabix. "Index IF NOT i_vbep_all IS INITIAL. *Delete records which are beyond given deleivery date only. LOOP AT i_vbep_all INTO wa_vbep_all. l_vbeln = wa_vbep_all-vbeln. l_posnr = wa_vbep_all-posnr. l_edatu = wa_vbep_all-edatu. AT NEW posnr. IF NOT g_date IS INITIAL. IF l_edatu > g_date. DELETE i_vbep_all WHERE vbeln = l_vbeln AND posnr = l_posnr. IF sy-subrc = 0. CONTINUE. ENDIF. " IF SY-SUBRC = 0. ENDIF. " IF l_edatu > g_date. ELSE. IF l_edatu > s_edatu-low. DELETE i_vbep_all WHERE vbeln = l_vbeln AND posnr = l_posnr. IF sy-subrc = 0. CONTINUE. ENDIF. "IF SY-SUBRC = 0. ENDIF. "IF l_edatu > s_edatu-low. ENDIF. " g_date IS INITIAL ENDAT. " AT NEW posnr. *Delete Records where order quantity is 0 and open quantity is also 0. IF wa_vbep_all-wmeng EQ 0 AND wa_vbep_all-olfmng EQ 0. DELETE i_vbep_all. "Deletes current row. ENDIF. " IF wa_vbep_all-wmeng EQ 0 AND wa_vbep_all-olfmng EQ 0. CLEAR:wa_vbep_all,l_vbeln,l_posnr. ENDLOOP. " LOOP AT i_vbep_all INTO wa_vbep_all. SORT i_vbep_all DESCENDING. LOOP AT i_vbep_all INTO wa_vbep_all. l_tabix = sy-tabix. AT NEW posnr . SUM. g_totalopen = wa_vbep_all-olfmng. ENDAT. " AT NEW posnr . IF g_totalopen > 0 AND wa_vbep_all-wmeng > 0. IF wa_vbep_all-wmeng < g_totalopen. wa_vbep_all-olfmng = wa_vbep_all-wmeng. g_totalopen = g_totalopen - wa_vbep_all-wmeng. ELSEIF wa_vbep_all-wmeng GE g_totalopen. wa_vbep_all-olfmng = g_totalopen. g_totalopen = 0. ENDIF. " IF wa_vbep_all-wmeng < g_totalopen. MODIFY i_vbep_all FROM wa_vbep_all INDEX l_tabix TRANSPORTING olfmng. ENDIF. " IF g_totalopen > 0 AND wa_vbep_all-wmeng > 0. ENDLOOP. " LOOP AT i_vbep_all INTO wa_vbep_all. *Sort Back In Ascending Order SORT i_vbep_all. *DELETE Records where open quantity is 0 . IF NOT i_vbep_all IS INITIAL. DELETE i_vbep_all WHERE wmeng = 0 . ENDIF. " IF NOT i_vbep_all IS INITIAL. *DELETE Records to get records within delivery date range. IF NOT g_date IS INITIAL. DELETE i_vbep_all WHERE edatu > g_date. ELSEIF g_date IS INITIAL. DELETE i_vbep_all WHERE edatu > s_edatu-low. ENDIF. " IF NOT g_date IS INITIAL. *Populate Final Output Internal Table LOOP AT i_vbep_all INTO wa_vbep_all. wa_output-dispo = wa_vbep_all-dispo. wa_output-dsnam = wa_vbep_all-dsnam. wa_output-matnr = wa_vbep_all-matnr. wa_output-maktx = wa_vbep_all-maktx. wa_output-vbeln = wa_vbep_all-vbeln. wa_output-posnr = wa_vbep_all-posnr. wa_output-edatu = wa_vbep_all-edatu. wa_output-dispo = wa_vbep_all-dispo. wa_output-wmeng = wa_vbep_all-wmeng. wa_output-olfmng = wa_vbep_all-olfmng. wa_output-soldto = wa_vbep_all-soldto. wa_output-shipto = wa_vbep_all-shipto. wa_output-shipqty = wa_vbep_all-wmeng - wa_vbep_all-olfmng. wa_output-fill = ( wa_output-shipqty / wa_vbep_all-wmeng ) * 100. APPEND wa_output TO o_output. CLEAR: wa_output,wa_vbep_all. ENDLOOP. " LOOP AT i_vbep_all INTO wa_vbep_all. ENDIF. " IF NOT i_vbep_all IS INITIAL. ENDFORM. " get_final_output &----
    *& Form process_output &----
    ----
    ----
    FORM calc_mrpcontroller_%fill. DATA:l_shipqty TYPE olfmng, "Shipped Quantity l_wmeng LIKE vbep-wmeng, "Order Quantity l_fill TYPE olfmng, "%fill l_dispo LIKE t024d-dispo. "Mrp Controller IF NOT o_output IS INITIAL. SORT o_output BY dispo. LOOP AT o_output INTO wa_output. l_dispo = wa_output-dispo. AT NEW dispo. SUM. l_shipqty = wa_output-shipqty. l_wmeng = wa_output-wmeng. ENDAT. " AT NEW dispo l_fill = ( l_shipqty / l_wmeng ) * 100 . wa_output-controllerfill = l_fill. MODIFY o_output FROM wa_output TRANSPORTING controllerfill WHERE dispo = l_dispo. CLEAR:wa_output. ENDLOOP. "LOOP AT o_output INTO wa_output. ENDIF. "IF NOT o_output IS INITIAL. ENDFORM. " calc_mrpcontroller_%fill &----
    *& Form calc_material_%fill &----
    *To Calculate Total % Fill By Material. ----
    ----
    FORM calc_material_%fill. DATA: l_shipqty TYPE olfmng, "Shipped Quantity l_wmeng TYPE vbep-wmeng, "Order Quantity l_fill TYPE olfmng, "%fill l_matnr TYPE mara-matnr. "Material IF NOT o_output IS INITIAL. SORT o_output BY dispo matnr. LOOP AT o_output INTO wa_output. l_matnr = wa_output-matnr. AT NEW matnr. SUM. l_shipqty = wa_output-shipqty. l_wmeng = wa_output-wmeng. ENDAT. " AT NEW matnr. l_fill = ( l_shipqty / l_wmeng ) * 100 . wa_output-materialfill = l_fill. MODIFY o_output FROM wa_output TRANSPORTING materialfill WHERE matnr = l_matnr. CLEAR:wa_output. ENDLOOP. "LOOP AT o_output INTO wa_output. ENDIF. "IF NOT o_output IS INITIAL. ENDFORM. " calc_material_%fill &----
    *& Form fill_catalogue &----
    ----
    ----
    FORM fill_catalogue. CLEAR: i_fieldcat[]. PERFORM build_fieldcat using 1 'DISPO' 'O_OUTPUT' 15 ' ' 'MRP Controller'(005) ' ' i_fieldcat. PERFORM build_fieldcat using 2 'DSNAM' 'O_OUTPUT' 15 ' ' 'Controller Name'(006) ' ' i_fieldcat. PERFORM build_fieldcat using 3 'MATNR' 'O_OUTPUT' 10 ' ' 'Material'(007) c_c i_fieldcat. PERFORM build_fieldcat using 4 'MAKTX' 'O_OUTPUT' 20 ' ' 'Material Description'(008) ' ' i_fieldcat. PERFORM build_fieldcat using 5 'VBELN' 'O_OUTPUT' 12 ' ' 'SD Agreement'(009) c_c i_fieldcat. PERFORM build_fieldcat using 6 'POSNR' 'O_OUTPUT' 4 ' ' 'Item'(010) ' ' i_fieldcat. PERFORM build_fieldcat using 7 'EDATU' 'O_OUTPUT' 13 ' ' 'Delivery Date'(011) ' ' i_fieldcat. PERFORM build_fieldcat using 8 'WMENG' 'O_OUTPUT' 20 c_x 'Scheduled Quantity'(012) c_c i_fieldcat. PERFORM build_fieldcat using 9 'SHIPQTY' 'O_OUTPUT' 16 c_x 'Shipped Quantity'(013) c_c i_fieldcat. PERFORM build_fieldcat using 10 'OLFMNG' 'O_OUTPUT' 12 c_x 'REM Quantity'(014) c_c i_fieldcat. PERFORM build_fieldcat using 11 'FILL' 'O_OUTPUT' 6 ' ' '% Fill Per SchedLine'(025) c_c i_fieldcat. PERFORM build_fieldcat using 12 'MATERIALFILL' 'O_OUTPUT' 21 ' ' 'Tot %Fill By Material'(023) c_c i_fieldcat. PERFORM build_fieldcat using 13 'CONTROLLERFILL' 'O_OUTPUT' 24 ' ' 'Tot %Fill By MRP Contro.'(024) c_c i_fieldcat. PERFORM build_fieldcat using 14 'SOLDTO' 'O_OUTPUT' 8 ' ' 'SoldTo'(016) ' ' i_fieldcat. PERFORM build_fieldcat using 15 'SHIPTO' 'O_OUTPUT' 8 ' ' 'ShipTo'(017) ' ' i_fieldcat. *Sort by mrp Controller. fs_sort-spos = 1. fs_sort-fieldname = 'DISPO'. fs_sort-up = c_x. APPEND fs_sort TO i_sort. CLEAR fs_sort. *Sort and subtotal by controller description and subtotal. fs_sort-spos = 2. fs_sort-fieldname = 'DSNAM'. fs_sort-up = c_x. fs_sort-subtot = c_x. APPEND fs_sort TO i_sort. CLEAR fs_sort. *Sort by material. fs_sort-spos = 3. fs_sort-fieldname = 'MATNR'. fs_sort-up = c_x. APPEND fs_sort TO i_sort. CLEAR fs_sort. *Sort and subtotal by material description. fs_sort-spos = 4. fs_sort-fieldname = 'MAKTX'. fs_sort-up = c_x. fs_sort-subtot = c_x. APPEND fs_sort TO i_sort. CLEAR fs_sort. ENDFORM. " fill_catalogue &----
    *& Form display_output &----
    ----
    ----
    FORM display_output. IF o_output IS INITIAL. MESSAGE e208(00) WITH text-022. ELSE. SORT o_output BY dispo matnr vbeln posnr edatu. ENDIF. " IF o_output IS INITIAL. MOVE c_x TO fs_layout-colwidth_optimize. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING is_layout = fs_layout it_fieldcat = i_fieldcat it_sort = i_sort i_save = 'A' TABLES t_outtab = o_output. IF sy-subrc <> 0. ENDIF. ENDFORM. " display_output &----
    *& Form t_code_check &----
    ----
    ----
    FORM t_code_check. **validate authorization against transaction code SELECT tcode FROM tstc UP TO 1 ROWS INTO g_tcode WHERE pgmna = sy-repid. ENDSELECT. IF sy-subrc = 0. AUTHORITY-CHECK OBJECT 'S_TCODE' ID 'TCD' FIELD g_tcode. IF sy-subrc NE 0. MESSAGE e261(sf) WITH g_tcode. ENDIF. "IF SY-SUBRC NE 0. ENDIF. "IF SY-SUBRC = 0. ENDFORM. " t_code_check &----
    *& Form validate_doc_type &----
    ----
    ----
    FORM validate_doc_type. DATA:l_auart LIKE tvak-auart. "validate document type SELECT auart FROM tvak UP TO 1 ROWS INTO l_auart WHERE auart IN s_auart. ENDSELECT. IF sy-subrc NE 0 AND NOT l_auart IS INITIAL . MESSAGE e000(oo) WITH 'Please enter a valid document type'(019). ENDIF. ENDFORM. " validate_doc_type &----
    *& Form plant_auth_check &----
    ----
    ----
    FORM plant_auth_check. *Types declaration for werks TYPES:BEGIN OF lt_werks, werks TYPE marc-werks, END OF lt_werks. *internal table and wrk area to hold multiple plants DATA :li_werks TYPE STANDARD TABLE OF lt_werks, l_werks LIKE LINE OF li_werks. SELECT werks FROM t001w INTO TABLE li_werks WHERE werks IN s_werks. IF sy-subrc EQ 0. LOOP AT li_werks INTO l_werks. AUTHORITY-CHECK OBJECT 'Z_MM_PLANT' ID 'ACTVT' FIELD c_act_auth_03 ID 'WERKS' FIELD l_werks ID 'TCD' FIELD g_tcode. IF sy-subrc NE 0. MESSAGE e004(co) WITH l_werks. ENDIF. " IF SY-SUBRC NE 0.. ENDLOOP. " LOOP AT li_werks INTO l_werks.. ELSE. MESSAGE e174(q3) WITH s_werks. ENDIF. " IF SY-SUBRC EQ 0..... ENDFORM. " plant_auth_check &----
    *& Form validate_mrp_controller &----
    ----
    ----
    FORM validate_mrp_controller. DATA: l_dispo LIKE t024d-dispo. "mrp Controller SELECT dispo FROM t024d UP TO 1 ROWS INTO l_dispo WHERE dispo IN s_dispo. ENDSELECT. IF sy-subrc NE 0 AND NOT l_dispo IS INITIAL. MESSAGE e000(oo) WITH 'Please enter a valid MRP Controller'(020). ENDIF. "SY-SUBRC NE 0 AND NOT l_dispo IS INITIAL. ENDFORM. " validate_mrp_controller **********************BEGIN OF CDXK961295**************************** &----
    *& Form display_summary &----
    ----
    ----
    FORM process_sum_mrpcontro. DATA:l_shipqty TYPE olfmng, "Shipped Quantity l_wmeng LIKE vbep-wmeng, "Order Quantity l_fill TYPE olfmng, "%fill l_olfmng TYPE olfmng. "Open Quantity IF NOT o_output IS INITIAL. SORT o_output BY dispo. LOOP AT o_output INTO wa_output. wa_sum_mrpcontro-dispo = wa_output-dispo. wa_sum_mrpcontro-dsnam = wa_output-dsnam. AT END OF dispo. SUM. wa_sum_mrpcontro-shipqty = wa_output-shipqty. wa_sum_mrpcontro-wmeng = wa_output-wmeng. wa_sum_mrpcontro-olfmng = wa_output-olfmng. l_fill = ( wa_output-shipqty / wa_output-wmeng ) * 100 . wa_sum_mrpcontro-controllerfill = l_fill. APPEND wa_sum_mrpcontro TO i_sum_mrpcontro. ENDAT. " AT END OF dispo CLEAR:wa_sum_mrpcontro,wa_output, l_fill. ENDLOOP. "LOOP AT o_output INTO wa_output. SORT i_sum_mrpcontro BY dispo. *Calculate 'total' and add as lastline to internal table . LOOP AT i_sum_mrpcontro INTO wa_sum_mrpcontro. l_shipqty = l_shipqty + wa_sum_mrpcontro-shipqty. l_wmeng = l_wmeng + wa_sum_mrpcontro-wmeng. l_olfmng = l_olfmng + wa_sum_mrpcontro-olfmng. CLEAR:wa_sum_mrpcontro. ENDLOOP. "LOOP AT i_sum_mrpcontro l_fill = ( l_shipqty / l_wmeng ) * 100 . wa_sum_mrpcontro-dsnam = 'Total'(015). wa_sum_mrpcontro-wmeng = l_wmeng. wa_sum_mrpcontro-shipqty = l_shipqty. wa_sum_mrpcontro-olfmng = l_olfmng. wa_sum_mrpcontro-controllerfill = l_fill. APPEND wa_sum_mrpcontro TO i_sum_mrpcontro. ENDIF. "IF NOT o_output IS INITIAL. ENDFORM. " process_sum_mrpcontro. &----
    *& Form fill_catelogue_summary &----
    ----
    ----
    FORM fill_catelogue_mrpcontro. CLEAR: i_fieldcat[]. PERFORM build_fieldcat using 1 'DISPO' 'I_SUM_MRPCONTRO' 15 ' ' 'MRP Controller'(005) ' ' i_fieldcat. PERFORM build_fieldcat using 2 'DSNAM' 'I_SUM_MRPCONTRO' 15 ' ' 'Controller Name'(006) ' ' i_fieldcat. PERFORM build_fieldcat using 3 'WMENG' 'I_SUM_MRPCONTRO' 20 ' ' 'Scheduled Quantity'(012) c_c i_fieldcat. PERFORM build_fieldcat using 4 'SHIPQTY' 'I_SUM_MRPCONTRO' 16 ' ' 'Shipped Quantity'(013) c_c i_fieldcat. PERFORM build_fieldcat using 5 'OLFMNG' 'I_SUM_MRPCONTRO' 12 ' ' 'REM Quantity'(014) c_c i_fieldcat. PERFORM build_fieldcat using 6 'CONTROLLERFILL' 'I_SUM_MRPCONTRO' 24 ' ' 'Tot %Fill By MRP Contro.'(024) c_c i_fieldcat. ENDFORM. " fill_catelogue_mrpcontro. &----
    *& Form display_output &----
    ----
    ----
    FORM display_sum_mrpcontro. IF i_sum_mrpcontro IS INITIAL. MESSAGE e208(00) WITH text-022. ELSE. ENDIF. " IF o_output IS INITIAL. fs_layout-colwidth_optimize = c_x. *To disable option of sort,and sum. DATA:lr_extab TYPE slis_extab. lr_extab-fcode = '&OUP'. APPEND lr_extab TO i_extab. lr_extab-fcode = '&ODN'. APPEND lr_extab TO i_extab. lr_extab-fcode = '&UMC'. APPEND lr_extab TO i_extab. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING is_layout = fs_layout it_fieldcat = i_fieldcat i_save = 'A' IT_EXCLUDING = i_extab TABLES t_outtab = i_sum_mrpcontro. IF sy-subrc <> 0. ENDIF. ENDFORM. " display_sum_mrpcontro &----
    *& Form process_sum_material &----
    ----
    ----
    FORM process_sum_material. DATA:l_shipqty TYPE olfmng, "Shipped Quantity l_wmeng LIKE vbep-wmeng, "Order Quantity l_fill TYPE olfmng, "%fill l_olfmng TYPE olfmng. "Open Quantity IF NOT o_output IS INITIAL. SORT o_output BY dispo matnr. LOOP AT o_output INTO wa_output. wa_sum_material-dispo = wa_output-dispo. wa_sum_material-dsnam = wa_output-dsnam. wa_sum_material-matnr = wa_output-matnr. wa_sum_material-maktx = wa_output-maktx. AT END OF matnr. SUM. l_fill = ( wa_output-shipqty / wa_output-wmeng ) * 100 . wa_sum_material-wmeng = wa_output-wmeng. wa_sum_material-shipqty = wa_output-shipqty. wa_sum_material-olfmng = wa_output-olfmng. wa_sum_material-materialfill = l_fill. APPEND wa_sum_material TO i_sum_material. ENDAT. " AT END OF matnr CLEAR:wa_sum_material,wa_output, l_fill. ENDLOOP. "LOOP AT o_output INTO wa_output. SORT i_sum_material BY dispo matnr. *Calculate 'total' and add as lastline to internal table . LOOP AT i_sum_material INTO wa_sum_material. l_shipqty = l_shipqty + wa_sum_material-shipqty. l_wmeng = l_wmeng + wa_sum_material-wmeng. l_olfmng = l_olfmng + wa_sum_material-olfmng. CLEAR:wa_sum_material. ENDLOOP. "LOOP AT i_sum_material l_fill = ( l_shipqty / l_wmeng ) * 100 . wa_sum_material-dsnam = 'Total'(015). wa_sum_material-wmeng = l_wmeng. wa_sum_material-shipqty = l_shipqty. wa_sum_material-olfmng = l_olfmng. wa_sum_material-materialfill = l_fill. APPEND wa_sum_material TO i_sum_material. ENDIF. "IF NOT o_output IS INITIAL. ENDFORM. " process_sum_material &----
    *& Form fill_catelogue_material &----
    ----
    ----
    FORM fill_catelogue_material. CLEAR: i_fieldcat[]. PERFORM build_fieldcat using 1 'DISPO' 'I_SUM_MATERIAL' 15 ' ' 'MRP Controller'(005) ' ' i_fieldcat. PERFORM build_fieldcat using 2 'DSNAM' 'I_SUM_MATERIAL' 15 ' ' 'Controller Name'(006) ' ' i_fieldcat. PERFORM build_fieldcat using 3 'MATNR' 'I_SUM_MATERIAL' 10 ' ' 'Material'(007) c_c i_fieldcat. PERFORM build_fieldcat using 4 'MAKTX' 'I_SUM_MATERIAL' 20 ' ' 'Material Description'(008) ' ' i_fieldcat. PERFORM build_fieldcat using 5 'WMENG' 'I_SUM_MATERIAL' 20 ' ' 'Scheduled Quantity'(012) c_c i_fieldcat. PERFORM build_fieldcat using 6 'SHIPQTY' 'I_SUM_MATERIAL' 16 ' ' 'Shipped Quantity'(013) c_c i_fieldcat. PERFORM build_fieldcat using 7 'OLFMNG' 'I_SUM_MATERIAL' 12 ' ' 'REM Quantity'(014) c_c i_fieldcat. PERFORM build_fieldcat using 8 'MATERIALFILL' 'I_SUM_MATERIAL' 24 ' ' 'Tot %Fill By Material'(023) c_c i_fieldcat. ENDFORM. " fill_catelogue_material &----
    *& Form display_sum_material &----
    ----
    ----
    FORM display_sum_material. IF i_sum_material IS INITIAL. MESSAGE e208(00) WITH text-022. ELSE. ENDIF. " IF o_output IS INITIAL. fs_layout-colwidth_optimize = c_x. *To disable option of sort,and sum. DATA:lr_extab TYPE slis_extab. lr_extab-fcode = '&OUP'. APPEND lr_extab TO i_extab. lr_extab-fcode = '&ODN'. APPEND lr_extab TO i_extab. lr_extab-fcode = '&UMC'. APPEND lr_extab TO i_extab. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING is_layout = fs_layout it_fieldcat = i_fieldcat IT_EXCLUDING = i_extab i_save = 'A' TABLES t_outtab = i_sum_material. IF sy-subrc <> 0. ENDIF. ENDFORM. " display_sum_material &----
    *& Form Build field catelogue &----
    ----
    *This subroutine takes paremeters. *p_colpos-->column no. in alv *p_fieldname-->name of column in internal table type char *p_tabname-->name of internal table type char *p-outputlen--> output length of column. *p_do_sum--> flag to set subtotal *p_coltext--> column heading type char *p_just--> flag to set center justify type char ----
    FORM build_fieldcat USING p_colpos p_fieldname p_tabname p_outputlen p_do_sum p_coltext p_just p_output like i_fieldcat[]. DATA : l_fieldcat LIKE LINE OF i_fieldcat. "wrk area for field catelog l_fieldcat-col_pos = p_colpos. l_fieldcat-fieldname = p_fieldname. l_fieldcat-tabname = p_tabname. l_fieldcat-outputlen = p_outputlen. l_fieldcat-do_sum = p_do_sum. l_fieldcat-seltext_l = p_coltext. l_fieldcat-just = p_just. APPEND l_fieldcat TO p_output. CLEAR l_fieldcat. ENDFORM. " BUILD_FIELDCAT **********************END OF CDXK961295****************************

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 22, 2009 at 01:18 PM

    yes

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.