Calculation in Alv Report

Hi SDN's
I need to calculate Total(Cost1Cost2Cost3 = Total) in my alv report
Date          Acc.no  Doc.Typ   Cost1  Cost2  cost3   Total
20061206   123        GG         121     23        45       ????
20070203   405         BL         234     67        89       ????
How to calculate the total
Thanks
Kumar

Hi Kumar,
It is not possible to calculate total using ALV. We can calculate cost1 cost2 cost3 separately. You have to calculate separately and build internal table. You can color that column as total.
giving sample code.
1.
LOOP AT i_tab .
  i_tab-total = i_tab-cost1 + i_tab-cost2 + i_tab-cost3.
  MODIFY i_tab INDEX sy-tabix TRANSPORTING total.
  CLEAR i_tab.
ENDLOOP.
2.
Change the color of the column. While building fieldcatalog set emphasize = 'C25' like that . u will get the color.
emphasize (highlight column in color)
Value range: SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
'X' = The column is highlighted in the default color for color highlighting.
'Cxyz' = The column is highlighted in the coded color:
C: Color (coding must start with C)
x: Color number
y: Intensified
z: Inverse
  w_field-fieldname = 'TOTAL' .
  w_field-tabname = 'I_TAB'.
  w_field-emphasize = 'C26'.
  w_field-seltext_m = 'Total'.
  append w_field to i_field.
  clear w_field.
I hope that it helps u .
Regards,
Venkat.O

Similar Messages

  • Problem with subtotal calculation in ALV reports

    Hi All,
       I am doing one program for calculating subtoals in ALV . For this i want to display subtotal text at each envey subtotal 's row.
    For that i have created one form 'SUB_SUBTOT_TEXT' and it has given to IT_EVENTS-FORM. But SUB_SUBTOT_TEXT Form is not called by IT_EVENTS event.
    what are all the mandatories for displaying subtotal text.
    Can any one please help me.
    Thanks in Advance.

    Hi Sree,
    *& Table declaration
    &----TABLES: ekko.&----
    *& Type pool declaration
    TYPE-POOLS: slis. " Type pool for ALV&----
    *& Selection screen
    SELECT-OPTIONS: s_ebeln FOR ekko-ebeln.&----
    *& Type declaration
    &----* Type declaration for internal table to store EKPO data
    TYPES: BEGIN OF x_data,
           ebeln  TYPE char30,  " Document no.
           ebelp  TYPE ebelp,   " Item no
           matnr  TYPE matnr,   " Material no
           matnr1 TYPE matnr,   " Material no
           werks  TYPE werks_d, " Plant
           werks1 TYPE werks_d, " Plant
           ntgew  TYPE entge,   " Net weight
           gewe   TYPE egewe,   " Unit of weight                          
           END OF x_data.&----
    *& Internal table declaration
    DATA:* Internal table to store EKPO data
      i_ekpo TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
    Internal table for storing field catalog information
      i_fieldcat TYPE slis_t_fieldcat_alv,
    Internal table for Top of Page info. in ALV Display
      i_alv_top_of_page TYPE slis_t_listheader,
    Internal table for ALV Display events
      i_events TYPE slis_t_event,
    Internal table for storing ALV sort information
      i_sort TYPE  slis_t_sortinfo_alv,
      i_event TYPE slis_t_event.&----
    *& Work area declaration
    &----DATA:
      wa_ekko TYPE x_data,
      wa_layout     TYPE slis_layout_alv,
      wa_events         TYPE slis_alv_event,
      wa_sort TYPE slis_sortinfo_alv.&----
    *& Constant declaration
    &----CONSTANTS:
       c_header   TYPE char1
                  VALUE 'H',                    "Header in ALV
       c_item     TYPE char1
                  VALUE 'S'.&----
    *& Start-of-selection event
    &----START-OF-SELECTION.* Select data from ekpo
      SELECT ebeln " Doc no
             ebelp " Item
             matnr " Material
             matnr " Material
             werks " Plant
             werks " Plant
             ntgew " Quantity
             gewei " Unit
             FROM ekpo
             INTO TABLE i_ekpo
             WHERE ebeln IN s_ebeln
             AND ntgew NE '0.00'.  IF sy-subrc = 0.
        SORT i_ekpo BY ebeln ebelp matnr .
      ENDIF.* To build the Page header
      PERFORM sub_build_header.* To prepare field catalog
      PERFORM sub_field_catalog.* Perform to populate the layout structure
      PERFORM sub_populate_layout.* Perform to populate the sort table.
      PERFORM sub_populate_sort.* Perform to populate ALV event
      PERFORM sub_get_event.END-OF-SELECTION.* Perform to display ALV report
      PERFORM sub_alv_report_display.
    *&      Form  sub_build_header
          To build the header
          No Parameter
    FORM sub_build_header .* Local data declaration
      DATA: l_system     TYPE char10 ,          "System id
            l_r_line     TYPE slis_listheader,  "Hold list header
            l_date       TYPE char10,           "Date
            l_time       TYPE char10,           "Time
            l_success_records TYPE i,           "No of success records
            l_title(300) TYPE c.                " Title
    Title  Display
      l_r_line-typ = c_header.               " header
      l_title = 'Test report'(001).
      l_r_line-info = l_title.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR l_r_line.* Run date Display
      CLEAR l_date.
      l_r_line-typ  = c_item.                " Item
      WRITE: sy-datum  TO l_date MM/DD/YYYY.
      l_r_line-key = 'Run Date :'(002).
      l_r_line-info = l_date.
      APPEND l_r_line TO i_alv_top_of_page.
      CLEAR: l_r_line,
             l_date.ENDFORM.                    " sub_build_header
    *&      Form  sub_field_catalog
          Build Field Catalog
          No Parameter
    FORM sub_field_catalog .*  Build Field Catalog
      PERFORM sub_fill_alv_field_catalog USING:     '01' '01' 'EBELN' 'I_EKPO' 'L'
         'Doc No'(003) ' ' ' ' ' ' ' ',     '01' '02' 'EBELP' 'I_EKPO' 'L'
         'Item No'(004) 'X' 'X' ' ' ' ',     '01' '03' 'MATNR' 'I_EKPO' 'L'
         'Material No'(005) 'X' 'X' ' ' ' ',     '01' '03' 'MATNR1' 'I_EKPO' 'L'
         'Material No'(005) ' ' ' ' ' ' ' ',
         '01' '04' 'WERKS' 'I_EKPO' 'L'
         'Plant'(006) 'X' 'X' ' ' ' ',     '01' '04' 'WERKS1' 'I_EKPO' 'L'
         'Plant'(006) ' ' ' ' ' ' ' ',     '01' '05' 'NTGEW' 'I_EKPO' 'R'
         'Net Weight'(007) ' ' ' ' 'GEWE' 'I_EKPO'.ENDFORM.                    " sub_field_catalog&----
    *&     Form  sub_fill_alv_field_catalog
    *&     For building Field Catalog
    *&     p_rowpos   Row position
    *&     p_colpos   Col position
    *&     p_fldnam   Fldname
    *&     p_tabnam   Tabname
    *&     p_justif   Justification
    *&     p_seltext  Seltext
    *&     p_out      no out
    *&     p_tech     Technical field
    *&     p_qfield   Quantity field
    *&     p_qtab     Quantity table
    FORM sub_fill_alv_field_catalog  USING  p_rowpos    TYPE sycurow
                                            p_colpos    TYPE sycucol
                                            p_fldnam    TYPE fieldname
                                            p_tabnam    TYPE tabname
                                            p_justif    TYPE char1
                                            p_seltext   TYPE dd03p-scrtext_l
                                            p_out       TYPE char1
                                            p_tech      TYPE char1
                                            p_qfield    TYPE slis_fieldname
                                            p_qtab      TYPE slis_tabname.* Local declaration for field catalog
      DATA: wa_lfl_fcat    TYPE  slis_fieldcat_alv.  wa_lfl_fcat-row_pos        =  p_rowpos.     "Row
      wa_lfl_fcat-col_pos        =  p_colpos.     "Column
      wa_lfl_fcat-fieldname      =  p_fldnam.     "Field Name
      wa_lfl_fcat-tabname        =  p_tabnam.     "Internal Table Name
      wa_lfl_fcat-just           =  p_justif.     "Screen Justified
      wa_lfl_fcat-seltext_l      =  p_seltext.    "Field Text
      wa_lfl_fcat-no_out         =  p_out.        "No output
      wa_lfl_fcat-tech           =  p_tech.       "Technical field
      wa_lfl_fcat-qfieldname     =  p_qfield.     "Quantity unit
      wa_lfl_fcat-qtabname       =  p_qtab .      "Quantity table  IF p_fldnam = 'NTGEW'.
        wa_lfl_fcat-do_sum  = 'X'.
      ENDIF.
      APPEND wa_lfl_fcat TO i_fieldcat.
      CLEAR wa_lfl_fcat.
    ENDFORM.                    " sub_fill_alv_field_catalog&----
    *&      Form  sub_populate_layout
          Populate ALV layout
          No Parameter
    FORM sub_populate_layout .  CLEAR wa_layout.
      wa_layout-colwidth_optimize = 'X'." Optimization of Col widthENDFORM.                    " sub_populate_layout&----
    *&      Form  sub_populate_sort
          Populate ALV sort table
          No Parameter
    FORM sub_populate_sort .* Sort on material
      wa_sort-spos = '01' .
      wa_sort-fieldname = 'MATNR'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.* Sort on plant
      wa_sort-spos = '02'.
      wa_sort-fieldname = 'WERKS'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    ENDFORM.                    " sub_populate_sort&----
    *&      Form  sub_get_event
          Get ALV grid event and pass the form name to subtotal_text
          event
          No Parameter
    FORM sub_get_event .
      CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE
    'SUBTOTAL_TEXT'.  DATA: l_s_event TYPE slis_alv_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 4
        IMPORTING
          et_events       = i_event
        EXCEPTIONS
          list_type_wrong = 0
          OTHERS          = 0.* Subtotal
      READ TABLE i_event  INTO l_s_event
                        WITH KEY name = slis_ev_subtotal_text.
      IF sy-subrc = 0.
        MOVE c_formname_subtotal_text TO l_s_event-form.
        MODIFY i_event FROM l_s_event INDEX sy-tabix.
      ENDIF.ENDFORM.                    " sub_get_event&----
    *&      Form  sub_alv_report_display
          For ALV Report Display
          No Parameter
    FORM sub_alv_report_display .
      DATA: l_repid TYPE syrepid .
      l_repid = sy-repid .* This function module for displaying the ALV report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = l_repid
          i_callback_top_of_page   = 'SUB_ALV_TOP_OF_PAGE'
          is_layout                = wa_layout
          it_fieldcat              = i_fieldcat
          it_sort = i_sort
          it_events                = i_event
          i_default                = 'X'
          i_save                   = 'A'
        TABLES
          t_outtab                 = i_ekpo
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
       MESSAGE i000 WITH 'Error in ALV report display'(055).
      ENDIF.ENDFORM.                    " sub_alv_report_display&----
          FORM sub_alv_top_of_page
          Call ALV top of page
          No parameter
    ----FORM sub_alv_top_of_page.                                   "#EC CALLED* To write header for the ALV
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = i_alv_top_of_page.
    ENDFORM.                    "alv_top_of_page&----
    *&      Form  subtotal_text
          Build subtotal text
          P_total  Total
          p_subtot_text Subtotal text info
    FORM subtotal_text CHANGING
                   p_total TYPE any
                   p_subtot_text TYPE slis_subtot_text.
    Material level sub total
      IF p_subtot_text-criteria = 'MATNR'.
        p_subtot_text-display_text_for_subtotal
        = 'Material level total'(009).
      ENDIF.* Plant level sub total
      IF p_subtot_text-criteria = 'WERKS'.
        p_subtot_text-display_text_for_subtotal = 'Plant level total'(010).
      ENDIF.
    ENDFORM.                    "subtotal_text
    Hopes its helpful.
    Regards,
    Raj.

  • Regd: Calculation of TOTAL field in ALV report

    Hi All,
    We have a scenario that we are not getting the total value for numeric fields in ALV report.
    Below i have given the code used for it.
    G_KEY = 'X'.
      G_NOKEY = SPACE.
      G_SUM = 'X'.
      G_NOSUM = SPACE.
      PERFORM BUILD_FIELDCAT USING 'VBELN'  G_KEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'BLDAT'  G_NOKEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'VGBEL'  G_KEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'POSNR'  G_KEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'MATNR'  G_KEY G_NOSUM..
      PERFORM BUILD_FIELDCAT USING 'LFIMG'  G_NOKEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'VRKME'  G_NOKEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'NETPR'  G_NOKEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'BRTWR'  G_NOKEY G_NOSUM.
      PERFORM BUILD_FIELDCAT USING 'VALUE_INR'  G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'B_DUTY'     G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'S_TOTAL1'   G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'CV_DUTY'    G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'C_CVD'      G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'S_TOTAL2'   G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'C_DUTY'     G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'S_TOTAL3'   G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'A_DUTY'     G_NOKEY G_SUM.
      PERFORM BUILD_FIELDCAT USING 'T_DUTY'     G_NOKEY G_SUM.
    PERFORM BUILD_LAYOUT.
      PERFORM BUILD_DISPLAY.
    *&      Form  DISPLAY
          text
    FORM BUILD_DISPLAY.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
      I_INTERFACE_CHECK                 = ' '
      I_BYPASSING_BUFFER                = ' '
      I_BUFFER_ACTIVE                   = ' '
      I_CALLBACK_PROGRAM                = ' '
      I_CALLBACK_PF_STATUS_SET          = ' '
      I_CALLBACK_USER_COMMAND           = ' '
      I_CALLBACK_TOP_OF_PAGE            = ' '
      I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
      I_CALLBACK_HTML_END_OF_LIST       = ' '
      I_STRUCTURE_NAME                  =
      I_BACKGROUND_ID                   = ' '
         I_GRID_TITLE                      = TEXT-000
      I_GRID_SETTINGS                   =
       IS_LAYOUT                         = IG_LAYOUT
         IT_FIELDCAT                       = IG_FIELDCAT
      IT_EXCLUDING                      =
      IT_SPECIAL_GROUPS                 =
      IT_SORT                           =
      IT_FILTER                         =
      IS_SEL_HIDE                       =
      I_DEFAULT                         = 'X'
         I_SAVE                            = 'A'
      IS_VARIANT                        =
      IT_EVENTS                         =
      IT_EVENT_EXIT                     =
      IS_PRINT                          =
      IS_REPREP_ID                      =
      I_SCREEN_START_COLUMN             = 0
      I_SCREEN_START_LINE               = 0
      I_SCREEN_END_COLUMN               = 0
      I_SCREEN_END_LINE                 = 0
      I_HTML_HEIGHT_TOP                 = 0
      I_HTML_HEIGHT_END                 = 0
      IT_ALV_GRAPHICS                   =
      IT_HYPERLINK                      =
      IT_ADD_FIELDCAT                   =
      IT_EXCEPT_QINFO                   =
      IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
        TABLES
          T_OUTTAB                          = IG_INBOUND
       EXCEPTIONS
         PROGRAM_ERROR                     = 1
         OTHERS                            = 2
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "DISPLAY
    *&      Form  BUILD_FIELDCAT
          text
         -->G_FIELDNAME  text
         -->L_KEY        text
         -->L_SUM        text
    FORM BUILD_FIELDCAT USING L_FIELDNAME LIKE DD03L-FIELDNAME L_KEY TYPE C L_SUM TYPE C.
      CLEAR WG_FIELDCAT_LN.
      ADD 1 TO G_COL_POS.
      WG_FIELDCAT_LN-REF_TABNAME = 'IG_INBOUND'.
      WG_FIELDCAT_LN-FIELDNAME = L_FIELDNAME.
      WG_FIELDCAT_LN-KEY = L_KEY.
      WG_FIELDCAT_LN-DO_SUM = L_SUM.
      WG_FIELDCAT_LN-COL_POS = G_COL_POS.
      WG_FIELDCAT_LN-NO_OUT = SPACE.
      WG_FIELDCAT_LN-QFIELDNAME = SPACE.
      WG_FIELDCAT_LN-HOTSPOT = SPACE.
      APPEND WG_FIELDCAT_LN TO IG_FIELDCAT.
    ENDFORM.                    "BUILD_FIELDCAT
    *&      Form  BUILD_LAYOUT
          text
    FORM BUILD_LAYOUT.
    IG_LAYOUT-TOTALS_TEXT = 'Total Amount'.
    *IG_LAYOUT-SUBTOTALS_TEXT = 'A'.
    IG_LAYOUT-ZEBRA = 'X'.
    ENDFORM.
    Help and Sugesstions will be much appreciated.
    Thanks & Regds.
    Ramesh.

    This is sample program for the same
    REPORT  Z_50657_ALV_EX2
            NO STANDARD PAGE HEADING
            LINE-COUNT 65(3)
            LINE-SIZE 220
            MESSAGE-ID ZZ.
    *                             Type Pools                               *
    TYPE-POOLS: SLIS, ICON.
    *                              Tables                                  *
    TABLES: VBAK. "Sales Document Data
    *                         Internal Tables                              *
    * TABLE TO HOLD DATA OF SALES DOCUMENT
    DATA: BEGIN OF IT_VBAK OCCURS 0,
          VBELN LIKE VBAK-VBELN, "Sales Document
          VBTYP LIKE VBAK-VBTYP, "SD document category
          AUDAT LIKE VBAK-AUDAT, "Document date (date received/sent)
          AUGRU LIKE VBAK-AUGRU, "Order reason (reason for the business)
          AUART LIKE VBAK-AUART, "Sales Document Type
          NETWR LIKE VBAK-NETWR, "Net Sales Order in Doc. Currency
          WAERK LIKE VBAK-WAERK, "SD document currency
          ICON TYPE ICON-ID,     "traffic lights
          END OF IT_VBAK.
    *                             Work Areas                               *
    *WORK AREAS DEFINED FOR ALV'S
    DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,      "field catalog
          IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,     "field catalog ITAB
          WA_SORT TYPE SLIS_SORTINFO_ALV,           "SORT work area
          IT_SORT TYPE SLIS_T_SORTINFO_ALV,         "SORT ITAB
          LAYOUT TYPE SLIS_LAYOUT_ALV,              "LAYOUT
          WA_FCODE TYPE SLIS_EXTAB,                 "FUN CODE
          I_FCODE_EXTAB TYPE SLIS_T_EXTAB,
          WA_EVENTS TYPE SLIS_ALV_EVENT,
          IT_EVENTS TYPE SLIS_T_EVENT.
    *                       Selection-Screen                               *
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
    SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
    PARAMETERS: P_VBTYP LIKE VBAK-VBTYP DEFAULT 'C'.
    SELECTION-SCREEN END OF BLOCK B1.
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
    PARAMETERS: LIST RADIOBUTTON GROUP G1,
                GRID RADIOBUTTON GROUP G1.
    SELECTION-SCREEN END OF BLOCK B2.
    *                     At  Selection-Screen                             *
    *VALIDATION
    *                       Start of Selection                             *
    START-OF-SELECTION.
    *POPULATION OF DATA INTO INTERNAL TABLE ITAB
      PERFORM GET_DATA.
    *DEFINE USER DEFINED FIELDCATALOG
      PERFORM DEFINE_FIELDCATALOG.
    *SUBTOTALS AND TOTALS DISPLAY USING SORT
      PERFORM SORT_LIST.
    *CHANGE FCODE OF STATUS
      PERFORM CHANGE_FCODE.
    *CHECK RADIOBUTTON OPTION AND ACCORDINGLY FINAL DISPLAY
      PERFORM CHECK_OPTION.
    *&      Form  GET_DATA
    *       text
    FORM GET_DATA.
      SELECT VBELN
             VBTYP
             AUDAT
             AUGRU
             AUART
             NETWR
             WAERK FROM VBAK INTO TABLE IT_VBAK
             WHERE VBELN IN S_VBELN AND VBTYP = P_VBTYP
             AND ERDAT > '01.01.2004' AND NETWR > 0.
      LOOP AT IT_VBAK.
        IF IT_VBAK-NETWR < 10000.
          IT_VBAK-ICON = '@08@'.
        ELSEIF IT_VBAK-NETWR > 100000.
          IT_VBAK-ICON = '@0A@'.
        ELSE.
          IT_VBAK-ICON = '@09@'.
        ENDIF.
        MODIFY IT_VBAK INDEX SY-TABIX.
      ENDLOOP.
    ENDFORM.                    "GET_DATA
    *&      Form  CHECK_OPTION
    *       text
    FORM CHECK_OPTION.
      WA_EVENTS-NAME = 'TOP_OF_PAGE'.
      WA_EVENTS-FORM = 'TOP'.
      APPEND WA_EVENTS TO IT_EVENTS.
      CLEAR WA_EVENTS.
      WA_EVENTS-NAME = 'END_OF_LIST'.
      WA_EVENTS-FORM = 'END_LIST'.
      APPEND WA_EVENTS TO IT_EVENTS.
      CLEAR WA_EVENTS.
      IF LIST = 'X'.
        PERFORM LIST_DISP.
      ENDIF.
      IF GRID = 'X'.
        PERFORM GRID_DISP.
      ENDIF.
    ENDFORM.                    "CHECK_OPTION
    *&      Form  DEFINE_FIELDCATALOG
    *       text
    FORM DEFINE_FIELDCATALOG.
      WA_FIELDCAT-COL_POS = 1.
      WA_FIELDCAT-FIELDNAME = 'ICON'.
      WA_FIELDCAT-SELTEXT_L = 'ICON'.
      WA_FIELDCAT-ICON = 'X'.
      WA_FIELDCAT-OUTPUTLEN = 8.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 2.
      WA_FIELDCAT-FIELDNAME = 'VBELN'.
      WA_FIELDCAT-SELTEXT_L = 'SALES DOC NO.'.
      WA_FIELDCAT-OUTPUTLEN = 10.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 3.
      WA_FIELDCAT-FIELDNAME = 'AUDAT'.
      WA_FIELDCAT-SELTEXT_L = 'CREATED ON'.
      WA_FIELDCAT-OUTPUTLEN = 10.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 4.
      WA_FIELDCAT-FIELDNAME = 'VBTYP'.
      WA_FIELDCAT-SELTEXT_L = 'CATEGORY'.
      WA_FIELDCAT-OUTPUTLEN = 1.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 6.
      WA_FIELDCAT-FIELDNAME = 'AUGRU'.
      WA_FIELDCAT-SELTEXT_L = 'REASON'.
      WA_FIELDCAT-OUTPUTLEN = 3.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 5.
      WA_FIELDCAT-FIELDNAME = 'AUART'.
      WA_FIELDCAT-SELTEXT_L = 'DOC TYPE'.
      WA_FIELDCAT-OUTPUTLEN = 4.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 7.
      WA_FIELDCAT-FIELDNAME = 'NETWR'.
      WA_FIELDCAT-SELTEXT_L = 'NET VALUE'.
      WA_FIELDCAT-OUTPUTLEN = 17.
      WA_FIELDCAT-DECIMALS_OUT = 2.
    *  WA_FIELDCAT-DO_SUM = 'X'.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
      WA_FIELDCAT-COL_POS = 8.
      WA_FIELDCAT-FIELDNAME = 'WAERK'.
      WA_FIELDCAT-SELTEXT_L = 'UNIT'.
      WA_FIELDCAT-OUTPUTLEN = 50.
      WA_FIELDCAT-TABNAME = 'IT_VBAK'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR WA_FIELDCAT.
    ENDFORM.                    "DEFINE_FIELDCATALOG
    *&      Form  DEFINE_LAYOUT
    *       text
    FORM DEFINE_LAYOUT.
      LAYOUT-ZEBRA = 'X'.
      LAYOUT-SUBTOTALS_TEXT = 'SUBTOTAL SUM'.
      LAYOUT-WINDOW_TITLEBAR = 'EXERCISE 2'.
      LAYOUT-TOTALS_TEXT  = 'TOTAL'.
    ENDFORM.                    "DEFINE_LAYOUT
    *&      Form  SORT_LIST
    *       text
    FORM SORT_LIST.
      WA_SORT-FIELDNAME = 'VBELN'.
      WA_SORT-TABNAME = 'IT_VBAK'.
      WA_SORT-SPOS = 1.
      WA_SORT-UP = 'X'.
      WA_SORT-SUBTOT = 'X'.
      APPEND WA_SORT TO IT_SORT.
      CLEAR WA_SORT.
      WA_SORT-FIELDNAME = 'NETWR'.
      WA_SORT-TABNAME = 'IT_VBAK'.
      WA_SORT-UP = 'X'.
      WA_SORT-SPOS = 2.
      WA_SORT-SUBTOT = 'X'.
      APPEND WA_SORT TO IT_SORT.
      CLEAR WA_SORT.
    ENDFORM.                    "SORT_LIST
    *&      Form  LIST_DISP
    *       text
    FORM LIST_DISP.
      PERFORM DEFINE_LAYOUT.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
       EXPORTING
         I_CALLBACK_PROGRAM             = SY-REPID
         IT_FIELDCAT                    = IT_FIELDCAT
         IS_LAYOUT                      = LAYOUT
         IT_SORT                        = IT_SORT
         I_CALLBACK_PF_STATUS_SET       = 'STATUS'
         IT_EXCLUDING                   = I_FCODE_EXTAB
         I_CALLBACK_USER_COMMAND        = 'USER_COMMAND'
         IT_EVENTS                      = IT_EVENTS[]
    *   IMPORTING
    *     E_EXIT_CAUSED_BY_CALLER        =
    *     ES_EXIT_CAUSED_BY_USER         =
        TABLES
         T_OUTTAB                       = IT_VBAK
    *   EXCEPTIONS
    *     PROGRAM_ERROR                  = 1
    *     OTHERS                         = 2
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "LIST_DISP
    *&      Form  GRID_DISP
    *       text
    FORM GRID_DISP.
      PERFORM DEFINE_LAYOUT.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = SY-REPID
          IS_LAYOUT                = LAYOUT
          IT_FIELDCAT              = IT_FIELDCAT
          IT_SORT                  = IT_SORT
          I_CALLBACK_PF_STATUS_SET = 'STATUS'
          IT_EXCLUDING             = I_FCODE_EXTAB
          I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
          IT_EVENTS                = IT_EVENTS[]
        TABLES
          T_OUTTAB                 = IT_VBAK.
    * EXCEPTIONS
    *   PROGRAM_ERROR                     = 1
    *   OTHERS                            = 2
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "GRID_DISP
    *&      Form  STATUS
    *       text
    *      -->P_EXTAB    text
    FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'STATUS' EXCLUDING P_EXTAB.
    ENDFORM.                    "STATUS
    *&      Form  USER_COMMAND
    *       text
    *      -->R_UCOMM      text
    *      -->RS_SELFIELD  text
    FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                                   RS_SELFIELD TYPE SLIS_SELFIELD.
      CASE R_UCOMM.
        WHEN 'BACK' OR 'CANC' OR 'EXIT'.
          LEAVE TO SCREEN 0.
        WHEN '&IC1'.
          SET PARAMETER ID 'AUN' FIELD RS_SELFIELD-VALUE.
          CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
      ENDCASE.
    ENDFORM.                    "USER_COMMAND
    *&      Form  CHANGE_FCODE
    *       text
    FORM CHANGE_FCODE.
      WA_FCODE = 'PRNT'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&OAD'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&AVE'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&EB9'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&SUM'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&UMC'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&XPA'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
      WA_FCODE = '&OMP'.
      APPEND WA_FCODE TO I_FCODE_EXTAB.
    ENDFORM.                    "CHANGE_FCODE
    *&      Form  TOP
    *       text
    FORM TOP.
      IF LIST = 'X'.
        WRITE:/ SY-ULINE.
        WRITE:/ 'DATE:', SY-DATUM,55 'INTELLIGROUP ASIA PVT LTD'.
        WRITE:/ 'TIME:', SY-UZEIT.
        WRITE:/ 'USER NAME:', SY-UNAME,60 SY-TITLE.
        WRITE:/ 'PAGE', SY-PAGNO.
        WRITE:/ SY-ULINE.
      ENDIF.
      IF GRID = 'X'.
        DATA: LS_LINE TYPE SLIS_LISTHEADER,
              E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
    *   Listenüberschrift: Typ H
        CLEAR LS_LINE.
        LS_LINE-TYP  = 'H'.
    *   LS_LINE-KEY:  not used for this type
        LS_LINE-INFO = 'Summary'.
        APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
    *   Kopfinfo: Typ S
        CLEAR LS_LINE.
        LS_LINE-TYP  = 'S'.
        LS_LINE-KEY  = 'Intelligroup'.
        LS_LINE-INFO = ''.
        APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
        LS_LINE-KEY  = 'ASIA'.
        LS_LINE-INFO = 'PVT LTD'.
        APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
    *   Aktionsinfo: Typ A
        CLEAR LS_LINE.
        LS_LINE-TYP  = 'A'.
    *   LS_LINE-KEY:  not used for this type
        LS_LINE-INFO = 'truman'.
        APPEND LS_LINE TO  E04_LT_TOP_OF_PAGE.
        CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
          EXPORTING
            IT_LIST_COMMENTARY = E04_LT_TOP_OF_PAGE
            I_LOGO             = 'ENJOY_SAP_LOGO'.
      ENDIF.
    ENDFORM.                    "TOP
    *&      Form  END_LIST
    *       text
    FORM END_LIST.
      IF LIST = 'X'.
        SKIP 2.
        WRITE:/60 'END OF PAGE'.
      ENDIF.
      IF GRID = 'X'.
          DATA: LS_LINE TYPE SLIS_LISTHEADER,
              E04_LT_END_OF_LIST TYPE SLIS_T_LISTHEADER.
    *   Listenüberschrift: Typ H
        CLEAR LS_LINE.
        LS_LINE-TYP  = 'H'.
    *   LS_LINE-KEY:  not used for this type
        LS_LINE-INFO = 'Summary'.
        APPEND LS_LINE TO E04_LT_END_OF_LIST.
    *   Kopfinfo: Typ S
        CLEAR LS_LINE.
        LS_LINE-TYP  = 'S'.
        LS_LINE-KEY  = 'Intelligroup'.
        LS_LINE-INFO = ''.
        APPEND LS_LINE TO E04_LT_END_OF_LIST.
        LS_LINE-KEY  = 'ASIA'.
        LS_LINE-INFO = 'PVT LTD'.
        APPEND LS_LINE TO E04_LT_END_OF_LIST.
    *   Aktionsinfo: Typ A
        CLEAR LS_LINE.
        LS_LINE-TYP  = 'A'.
    *   LS_LINE-KEY:  not used for this type
        LS_LINE-INFO = TEXT-105.
        APPEND LS_LINE TO  E04_LT_END_OF_LIST.
        CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
          EXPORTING
            IT_LIST_COMMENTARY = E04_LT_END_OF_LIST.
      ENDIF.
    ENDFORM.                    "END_LIST

  • Clear the values in the ALV report after calculating Subtotals

    Hi All,
    In my ALV report, I am displaying subtotals by passing DO_SUM in the Field Catalog.
    Now my problem is in the display I do not want the individual values to be displayed, I want to hide the values in the column(Not the whole column) but I want to display the subtotal of these values in the Subtotal Row.
    Example:
    Item1   10   20
    Item2   20   30
    Item3   10   50
               40   100
    As per our requirements, the output should be
    Item1
    Item2
    Item3
              40   100
    How can this be done? Please suggest.

    Populate i_sort table for the fields for which u want subtotal as shown below:
    *&      Form  sub_populate_sort
          Populate ALV sort table
          No Parameter
    FORM sub_populate_sort .
    Sort on material
      wa_sort-spos = '01' .
      wa_sort-fieldname = 'MATNR'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    Sort on plant
      wa_sort-spos = '02'.
      wa_sort-fieldname = 'WERKS'.
      wa_sort-tabname = 'I_EKPO'.
      wa_sort-up = 'X'.
      wa_sort-subtot = 'X'.
      APPEND wa_sort TO i_sort .
      CLEAR wa_sort.
    ENDFORM.                    " sub_populate_sort
    Then when populating the field catalog tables use:
    wa_lfl_fcat-no_out         =  'X'.        "No output
    Then display ur data:
    This function module for displaying the ALV report
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = l_repid
          i_callback_top_of_page   = 'SUB_ALV_TOP_OF_PAGE'
          is_layout                = wa_layout
          it_fieldcat              = i_fieldcat
          it_sort = i_sort
          it_events                = i_event
          i_default                = 'X'
          i_save                   = 'A'
        TABLES
          t_outtab                 = i_ekpo
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
    Regards,
    Joy.

  • How to calculate totals in Blocked ALV Report

    Hi All,
    Can any body tell how to calculate totals & sub totals in
    Blocked ALV Report[Blocked List].
    Thanks in advance
    Thanks & Regards,
    Rayeezuddin.

    read this it might help
    Sums                                                       
    15. No_sumchoice(1) TYPE c : This parameter allows the choice for summing up
    Only by fieldcatalog.
    Value set: SPACE, 'X'
    'X' = fields which are to be summed, passed by the calling program (FIELDCAT-DO_SUM = 'X'). The user should not be able to change this value interactively.
    16. No_totalline(1) TYPE c : Removes the option of having totals after sub-totals.
    Value set: SPACE, 'X'
    'X' = no total record is to be output. Subtotals can still be calculated and output. The fields in the subtotals are flagged DO_SUM = 'X' in the field list.
    17. No_subchoice(1) TYPE c : Does not allow the user to interactively change the field chosen for subtotals.
    Value set: SPACE, 'X'
    'X' = value whose change triggers subtotals, provided by the calling program. The user should not be able to change this value interactively.
    18. No_subtotals(1) TYPE c : No subtotals possible          
    Value set: SPACE, 'X'
    'X' = no subtotals.
    19. Numc_sum(1)  TYPE c : Totals only possible for NUMC-Fields.
    20. No_unit_splitting TYPE c: No separate total lines by inh.units   
    21.totals_before_items TYPE c: Display totals before the items   
    22. Totals_only(1) TYPE c :  Show only totals      
    Value set: SPACE, 'X'
    'X' = only total records are output.
    23. Totals_text(60) TYPE c : Text for 1st col. in totals   
    Value set: SPACE, string (max.60)
    ' ' = The first column in the total record contains an appropriate number of '*'s to indicate the total by default. If the first column is wide enough, the string 'Total' is output after the asterisks.
    'String’ = The string passed is output after the total indicated by '*', if the column is wide enough.
    24. Subtotals_text(60) TYPE c : Texts for subtotals
    Value set: SPACE, string (max.60)
    ' ' = In the first column of subtotal records, the subtotal is indicated by an appropriate number of '*' by default. If the first column is not a subtotal criterion, the string 'Total' is output after the asterisks, if the column is wide enough.
    'String’ = the string passed is output after the subtotal indicated by '*', if the column is wide enough and the first column is not a subtotal criterion. If it is a subtotal criterion, its value is repeated after the total, if the column is wide enough.
    ELSE TELL ME I WILL PASTE COMPLETE HELP
    regards

  • Help required on ALV REPORT

    Hi,
    Please help with a solution:
    my requirement is to add the following to an existing program.
    i need to add 3 fields from a new table(a table which is not used in the program).
    the fields are :
    Vendor Part No. : Field ZWTYVND-Z_WTY_MAT_VPN
    Mail To Vendor No.:  Field ZWTYVND-Z_WTY_LIFNR_MAIL
    Mail To Vendor Name:  Field ZWTYVND-WTY_NAME1
    here is the program code:
    REPORT  zwtyrep008
            LINE-SIZE 500
            MESSAGE-ID zpp02.
    *& Report  ZWTYREP008                                                  *
    *$*$----------------------------------------------------------------$*$*
    *$*$---T A B L E S--------------------------------------------------$*$*
    *$*$----------------------------------------------------------------$*$*
    TABLES: wty_pnwtyh_dia,    "
            wty_pnwtyv_dia,
            mara,
            usr21,
            pnwtyv,
            adrp,
            s084.
    *$*$----------------------------------------------------------------$*$*
    *$*$ CONSTANTS
    *$*$----------------------------------------------------------------$*$*
    CONSTANTS: true(1)                                VALUE 'X',
               false(1)                               VALUE ' '.
    CONSTANTS: c_year_low(4)                          VALUE '1960',
               c_year_high(4)                         VALUE '9999',
               c_zero        LIKE wty_pvwty_dia-valiv VALUE '0.00',
               c_claim_to_process TYPE i              VALUE 3000.
    CONSTANTS: c_save(1)               VALUE 'U'.
    *$*$----------------------------------------------------------------$*$*
    *$*$ TYPES
    *$*$----------------------------------------------------------------$*$*
    TYPE-POOLS: slis, pwty.
    TYPES: BEGIN OF lt_period,
                   year(4),
                   poper(2),
                   start     TYPE d,
                   end       TYPE d,
          END   OF lt_period.
    TYPES: BEGIN OF tp_charac_value,
                 atwrt LIKE cawn-atwrt,
           END   OF tp_charac_value.
    TYPES: BEGIN OF tp_submit_records,
                 header_guid   LIKE wty_pnwtyv_dia-header_guid,
                 versn         LIKE wty_pnwtyv_dia-versn,
                 prev_version  LIKE wty_pnwtyv_dia-prev_version,
                 kateg         LIKE wty_pnwtyv_dia-kateg,
                 aktiv         LIKE wty_pnwtyv_dia-aktiv,
                 pnguid        LIKE wty_pnwtyv_dia-pnguid,
                 knumv         LIKE wty_pnwtyv_dia-knumv,
           END   OF tp_submit_records.
    TYPES: BEGIN OF tp_cond_table,
                 kschl  LIKE konv-kschl,
                 zaehk  LIKE konv-zaehk,
                 kinak  LIKE konv-kinak,
                 kbetr  LIKE konv-kbetr,
           END   OF tp_cond_table.
    *$*$----------------------------------------------------------------$*$*
    *$*$---I N T E R N A L   T A B L E S--------------------------------$*$*
    *$*$----------------------------------------------------------------$*$*
    * Report table to display with ALV
    DATA: t_detail_info TYPE STANDARD TABLE OF zwty_claim_avg_rep_det
                        WITH HEADER LINE
                        INITIAL SIZE 0.
    FIELD-SYMBOLS:<fs_detail_info> LIKE LINE OF t_detail_info.
    DATA: t_summary_alv TYPE STANDARD TABLE OF zwty_claim_avg_rep_sum
                        WITH HEADER LINE
                        INITIAL SIZE 0.
    FIELD-SYMBOLS:<fs_summary_alv>  LIKE LINE OF t_summary_alv.
    DATA: t_detail_alv  TYPE STANDARD TABLE OF zwty_claim_avg_rep_det
                        WITH HEADER LINE
                        INITIAL SIZE 0.
    FIELD-SYMBOLS:<fs_detail_alv> LIKE LINE OF t_detail_alv.
    DATA: it_submit_records TYPE HASHED TABLE OF tp_submit_records
                           WITH UNIQUE KEY header_guid versn
                           WITH HEADER LINE
                           INITIAL SIZE 0.
    FIELD-SYMBOLS: <fs_submit_rec_vs2> TYPE tp_submit_records.
    DATA: it_period TYPE HASHED TABLE OF lt_period
                    WITH UNIQUE KEY year poper
                    WITH HEADER LINE
                    INITIAL SIZE 0.
    FIELD-SYMBOLS: <fs_it_period>      LIKE LINE OF it_period.
    DATA: it_pvwty_dia_all  TYPE wty_pvwty_dia_tab.
    FIELD-SYMBOLS: <fs_pvwty_dia_es3> LIKE LINE OF it_pvwty_dia_all.
    DATA: it_cond_table TYPE STANDARD TABLE OF tp_cond_table
                        WITH HEADER LINE
                        INITIAL SIZE 0.
    FIELD-SYMBOLS: <fs_cond_table> TYPE tp_cond_table.
    *$*$----------------------------------------------------------------$*$*
    *$*$---G L O B A L  D A T A  ---------------------------------------$*$*
    *$*$----------------------------------------------------------------$*$*
    DATA: gt_fieldcat_sum   TYPE slis_t_fieldcat_alv,
          gt_fieldcat_det  TYPE slis_t_fieldcat_alv,
          gtw_fieldcat     LIKE LINE OF gt_fieldcat_sum,
          gt_top_of_page   TYPE slis_t_listheader,
          gtw_top_of_page  LIKE LINE OF gt_top_of_page,
          gt_end_of_page   TYPE slis_t_listheader,
          gtw_end_of_page  LIKE LINE OF gt_end_of_page,
          gs_layout        TYPE slis_layout_alv,
          gt_excluding     TYPE slis_t_extab,
          gtw_excluding    LIKE LINE OF gt_excluding,
          gs_variant1       TYPE disvariant,
          gs_variant2       TYPE disvariant,
          eventcat         TYPE slis_t_event,         "EVENEMENT
          eventcat_ln      LIKE LINE OF eventcat,     "LIGNE D'EVENEMENT
          gt_sort          TYPE slis_t_sortinfo_alv,
          gtw_sort         LIKE LINE OF gt_sort.
    DATA: wa_lis_progname  LIKE sy-cprog,
          wa_low_date      TYPE d,
          wa_high_date     TYPE d,
          wa_index_mat     TYPE i,
          wa_index_link    TYPE i,
          wa_level_alv     TYPE i.
    DATA: g_callback_pgm(40)          TYPE c,
          g_callback_user_command(30) TYPE c.
    DATA: my_print TYPE  slis_print_alv.
    FIELD-SYMBOLS: <fs_pvwty_dia> TYPE wty_pvwty_dia.
    * SELECTION SCREEN                                          *
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN BEGIN OF BLOCK post WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_cpudt FOR s084-spmon NO-EXTENSION,
                    s_postdt FOR  wty_pnwtyv_dia-fkdat NO-EXTENSION.
    SELECTION-SCREEN END   OF BLOCK post.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
    SELECT-OPTIONS: s_vend  FOR pnwtyv-v_parnr NO INTERVALS.
    SELECT-OPTIONS: s_clgrp FOR wty_pnwtyh_dia-clmgrp.
    SELECTION-SCREEN SKIP 1.
    SELECT-OPTIONS: s_model  FOR  wty_pnwtyh_dia-z_wty_model.
    SELECT-OPTIONS: s_matnr  FOR  mara-matnr.
    SELECTION-SCREEN END   OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK lay WITH FRAME TITLE text-004.
    PARAMETERS: varn1  TYPE slis_vari MEMORY ID fit_alv_gl,  "Dis. variant
                varn2  TYPE slis_vari.
    SELECTION-SCREEN END   OF BLOCK lay.
    *$*$----------------------------------------------------------------$*$*
    *$*$---A T  S E L E C T I O N - S C R E E N-------------------------$*$*
    *$*$----------------------------------------------------------------$*$*
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR varn1.
      PERFORM alv_variant_f4 USING '0001' CHANGING varn1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR varn2.
      PERFORM alv_variant_f4 USING '0002' CHANGING varn2.
    AT SELECTION-SCREEN ON BLOCK post.  "Validate posting parameters
      PERFORM validate_posting_parameter.
    AT SELECTION-SCREEN ON s_model.     "Validate model
      PERFORM validate_model.
    AT SELECTION-SCREEN ON s_vend.      "Validate vendor
      PERFORM validate_vendor.
    AT SELECTION-SCREEN ON s_matnr.      "Validate material
      PERFORM validate_material.
    AT SELECTION-SCREEN ON s_clgrp.     "Validate claim group
      PERFORM validate_claim_group.
    AT SELECTION-SCREEN OUTPUT.
    * Initialization.
    INITIALIZATION.
    * Initialize default display variant for ALV report
      CLEAR gs_variant1.
      MOVE sy-repid TO: gs_variant1-report,
                        gs_variant2-report.
      gs_variant1-handle = '0001'.
      gs_variant2-handle = '0002'.
      wa_lis_progname   = sy-repid.
      PERFORM set_default_variant CHANGING gs_variant1
                                           varn1.
      PERFORM set_default_variant CHANGING gs_variant2
                                           varn2.
      PERFORM get_fin_period USING c_year_low c_year_high.
      PERFORM set_period_to_analyse.
    *$*$----------------------------------------------------------------$*$*
    *$*$---S T A R T - O F - S E L E C T I O N--------------------------$*$*
    *$*$----------------------------------------------------------------$*$*
    START-OF-SELECTION.
      PERFORM select_claim_to_process.
    *$*$----------------------------------------------------------------$*$*
    *$*$---E N D - O F - S E L E C T I O N------------------------------$*$*
    *$*$----------------------------------------------------------------$*$*
    END-OF-SELECTION.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
       EXPORTING
    *        PERCENTAGE       = 0
         text             =  text-m02.
      IF sy-batch = 'X'.
        PERFORM set_print_alv_grid.
      ENDIF.
      PERFORM show_alv_grid.
    *&      Form  PRINT_DETAIL_ALV
    FORM show_alv_grid.
    * Prepare ALV_GRID before display
    * ===============================
      PERFORM init_field.
      PERFORM init_layout.
      PERFORM init_fieldcat.
      PERFORM init_excluding.
      PERFORM init_event.
    *  SORT report_data BY bukrs werks.
      PERFORM call_alv_list_display_level_1.
    ENDFORM.                    " PRINT_DETAIL
    *&      Form  VARIANT_F4   copied from RPCWCCK3
    *       Display a list of all available display variants for the ALV.
    *      <--P_varn1  Return the selected variant and return
    FORM variant_f4 CHANGING p_varn1 TYPE disvariant-variant.
      DATA: l_variant LIKE disvariant.
    * Get the list of available variants for the report
      l_variant-report = sy-repid.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = l_variant
          i_save     = 'A'
        IMPORTING
          es_variant = l_variant.
      p_varn1 = l_variant-variant.
    ENDFORM.                               " VARIANT_F4
    *&      Form  INIT_FIELD
    FORM init_field.
      MOVE sy-repid          TO g_callback_pgm.
      MOVE 'MY_USER_COMMAND' TO g_callback_user_command.
    ENDFORM.                    " INIT_FIELD
    *&      Form  INIT_LAYOUT
    FORM init_layout.
      gs_layout-window_titlebar   = sy-title.
      gs_layout-colwidth_optimize = 'X'.
      gs_layout-expand_all        = 'X'.
      gs_layout-no_subtotals      = ''.
      gs_layout-key_hotspot       = 'X'.         " Afficher Hotspot
      gs_layout-zebra             = 'X'.
      gs_layout-group_change_edit = 'X'.
      gs_layout-f2code            = 'DISPLAY'.
    * gs_layout-max_linesize      = 400.
    * gs_layout-totals_only       = 'X'.
    ENDFORM.                    " INIT_LAYOUT
    *&      Form  INIT_FIELDCAT
    FORM init_fieldcat.
      DATA: lt_fieldcatalog    TYPE lvc_t_fcat,
            ltw_fieldcatalog   TYPE lvc_s_fcat.
      REFRESH: lt_fieldcatalog,
               gt_fieldcat_sum,
               gt_fieldcat_det.
      CLEAR   gtw_sort.
      REFRESH gt_sort.
    * ==============================================
    * Set the label column for summary report leve 1
    * ==============================================
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = 'ZWTY_CLAIM_AVG_REP_SUM'
          i_client_never_display = 'X'
        CHANGING
          ct_fieldcat            = lt_fieldcatalog.
    *                             FIELD     pos sub  up  down Group
      PERFORM create_sort USING: 'V_PARNR'   1  'X'  'X'  ' '   'X',
                                 'NAME'      2  'X'  'X'  ' '   'X',
                                 'MAKTX'     3  'X'  'X'  ' '   'X',
                                 'MATNR'     4  'X'  'X'  ' '   'X'.
      LOOP AT lt_fieldcatalog INTO ltw_fieldcatalog.
        CLEAR: gtw_fieldcat.
        MOVE-CORRESPONDING ltw_fieldcatalog TO gtw_fieldcat.
        PERFORM set_alv_field_desc USING  ltw_fieldcatalog '1'.
        APPEND gtw_fieldcat TO gt_fieldcat_sum.
      ENDLOOP.
      PERFORM set_hot_spot TABLES gt_fieldcat_sum USING 'CLAIM_NB'.
    * =========================================
    * Field Catalog for Detail report (level 2)
    * =========================================
      REFRESH: lt_fieldcatalog.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = 'ZWTY_CLAIM_AVG_REP_DET'
          i_client_never_display = 'X'
        CHANGING
          ct_fieldcat            = lt_fieldcatalog.
      LOOP AT lt_fieldcatalog INTO ltw_fieldcatalog.
        CLEAR: gtw_fieldcat.
        MOVE-CORRESPONDING ltw_fieldcatalog TO gtw_fieldcat.
        PERFORM set_alv_field_desc USING  ltw_fieldcatalog '2'.
        APPEND gtw_fieldcat TO gt_fieldcat_det.
      ENDLOOP.
      PERFORM set_hot_spot TABLES gt_fieldcat_det USING 'CLMNO'.
    ENDFORM.                    " INIT_FIELDCAT
    *&      Form  INIT_SORT
    FORM create_sort USING  p_fieldname p_spos
                            p_subtot            TYPE char1
                            p_up                TYPE char1
                            p_down              TYPE char1
                            p_group             TYPE char1.
      CLEAR: gtw_sort.
      gtw_sort-fieldname = p_fieldname.
      gtw_sort-spos      = p_spos.
      gtw_sort-subtot    = p_subtot.
      gtw_sort-up        = p_up.
      gtw_sort-down      = p_down.
      gtw_sort-group     = p_group.
      APPEND gtw_sort TO gt_sort.
    ENDFORM.                    "create_sort
    *&      Form  INIT_EXCLUDING
    *       Exclude des option de l'application tool bar
    FORM init_excluding.
      CLEAR   gtw_excluding.
      REFRESH gt_excluding.
      gtw_excluding-fcode   = '&ABC'.
      APPEND gtw_excluding TO gt_excluding.
    ENDFORM.                    " INIT_EXCLUDING
    *&      Form  call_alv_list_display_level_1
    FORM call_alv_list_display_level_1.
    * DATA: l_i_save  VALUE 'U'.   "User-specific variants only
      DATA: l_i_save  VALUE 'A'.   "Any type of variants
      gs_variant1-report  = sy-repid.
      gs_variant1-variant = varn1.
      gs_layout-colwidth_optimize = true.
      wa_level_alv = 1.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = g_callback_pgm
          i_callback_user_command = g_callback_user_command
          is_layout               = gs_layout
          it_fieldcat             = gt_fieldcat_sum
          it_excluding            = gt_excluding
          it_sort                 = gt_sort
          i_save                  = l_i_save
          is_variant              = gs_variant1
          it_events               = eventcat
          is_print                = my_print
        TABLES
          t_outtab                = t_summary_alv
        EXCEPTIONS
          program_error           = 1
          OTHERS                  = 2.
    ENDFORM.                    " call_alv_list_display_level_1
    *&      Form  INIT_EVENT
    *       Determine quelle routine a executer selon l'event
    FORM init_event.
      eventcat_ln-name = 'TOP_OF_PAGE'.
      eventcat_ln-form = 'ALV_PAGE_HEADER'.
      APPEND eventcat_ln TO eventcat.
      eventcat_ln-name = 'END_OF_PAGE'.
      eventcat_ln-form = 'FOOTER_PAGE'.
      APPEND eventcat_ln TO eventcat.
    ENDFORM.                    " INIT_EVENT
    *&      Form  ALV_PAGE_HEADER
    FORM alv_page_header.
      DATA: l_date_time(22),
            l_char7(7),
            l_char10(10).
      DATA: p_date(10) TYPE c.
      DATA: p_time(8)  TYPE c.
      DATA: p_name(80) TYPE c.
    * Format current date and time
      WRITE sy-datum TO p_date USING EDIT MASK '____/__/__'.
      WRITE sy-uzeit TO p_time USING EDIT MASK '__:__:__'.
      CONCATENATE p_date '-' p_time
                  INTO l_date_time SEPARATED BY space.
    * Set the user name
      SELECT SINGLE
             persnumber addrnumber INTO (usr21-persnumber, usr21-addrnumber)
                 FROM  usr21
                 WHERE bname = sy-uname.
      SELECT SINGLE name_first name_last
             INTO   (adrp-name_first, adrp-name_last )
             FROM   adrp
             WHERE  persnumber = usr21-persnumber.
      CONCATENATE adrp-name_first adrp-name_last INTO p_name
      SEPARATED BY space.
      REFRESH gt_top_of_page.
      CLEAR   gtw_top_of_page.
    * Program title ------------------------------------------------
      CLEAR gtw_top_of_page.
      gtw_top_of_page-typ  = 'H'.
      gtw_top_of_page-info = sy-title.
      APPEND gtw_top_of_page TO gt_top_of_page.
      CLEAR gtw_top_of_page.
      gtw_top_of_page-typ     = 'S'.
      gtw_top_of_page-key  = 'Parameters :'.
    * Period / Posting Date -----------------------------------------
      IF s_cpudt[] IS INITIAL.
        WRITE s_postdt-low TO l_char10.
        CONCATENATE gtw_top_of_page-info
                    text-104
                    l_char10
               INTO gtw_top_of_page-info SEPARATED BY space.
        IF NOT s_postdt-high IS INITIAL.
          WRITE s_postdt-high TO l_char10.
          CONCATENATE gtw_top_of_page-info
                      text-105
                      l_char10
                      INTO gtw_top_of_page-info SEPARATED BY space.
        ENDIF.
        APPEND gtw_top_of_page TO gt_top_of_page.
      ELSE.
        CONCATENATE s_cpudt-low(4) '/' s_cpudt-low+4(2)
                    INTO l_char7 .
        CONCATENATE gtw_top_of_page-info
                    text-103
                    l_char7
                    INTO gtw_top_of_page-info SEPARATED BY space.
        IF s_cpudt-high NE space.
          CONCATENATE s_cpudt-high(4) '/' s_cpudt-high+4(2)
                      INTO l_char7 .
          CONCATENATE gtw_top_of_page-info
                      text-105
                      l_char7
                      INTO gtw_top_of_page-info SEPARATED BY space.
        ENDIF.
        APPEND gtw_top_of_page TO gt_top_of_page.
      ENDIF.
    * Display wich level we display -----------------------------
    *  IF wa_level_alv > 1.
    *    CLEAR gtw_top_of_page.
    *    IF wa_level_alv = 2.
    *      gtw_top_of_page-info = t_summary_alv-v_parnr.
    *      SHIFT gtw_top_of_page-info LEFT DELETING LEADING '0'.
    *    ENDIF.
    *    gtw_top_of_page-typ     = 'S'.
    *    gtw_top_of_page-key  = 'Partner:'.
    *    APPEND gtw_top_of_page TO gt_top_of_page.
    *  ENDIF.
    * Executed by -----------------------------------------------
      CLEAR gtw_top_of_page.
      gtw_top_of_page-typ     = 'S'.
      gtw_top_of_page-key  = 'Report executed by :'.
      gtw_top_of_page-info =  p_name.
    * * Date & time of execution --------------------------------
      APPEND gtw_top_of_page TO gt_top_of_page.
      gtw_top_of_page-key  = 'DATE :'.
      gtw_top_of_page-info = l_date_time.
      APPEND gtw_top_of_page TO gt_top_of_page.
    * Name of the report ----------------------------------------
      CLEAR gtw_top_of_page.
      gtw_top_of_page-typ  = 'A'.
    * LS_LINE-KEY:  not used for this type
      gtw_top_of_page-info = sy-repid.
      APPEND gtw_top_of_page TO gt_top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = gt_top_of_page.
    *  IF sy-batch = 'X' AND sy-linsz > 255 AND l_ctr_newpage = 0.
    *    NEW-PAGE PRINT ON LINE-SIZE 255.   "Pour wrapper !!!!!!
    *  ENDIF.
    ENDFORM.                    "ALV_PAGE_HEADER
    *&      Form  footer_page
    FORM footer_page.
      DATA: l_footer(300),
            l_page_no(5).
      l_page_no   = sy-pagno.
      CONCATENATE 'Page' l_page_no INTO l_footer SEPARATED BY space.
      SKIP 2.
      WRITE:/001 l_footer(sy-linsz) CENTERED.
    ENDFORM.                    "footer_page
    *&      Form  MY_USER_COMMAND
    *       text
    *      -->P_SY_UCOMM  text
    *      -->P_GS_SELFIELD  text
    FORM my_user_command USING    p_sy_ucomm
                                  p_gs_selfield TYPE slis_selfield.
      DATA: l_claim_no         LIKE mcshier-hiername,
            lv_tcode_last(15).
    * ======================================================
    * Call TX WTY to display the claim. Only possible at the
    * detail report(level 3)
    * ======================================================
      CASE p_gs_selfield-fieldname.
        WHEN 'CLMNO'.
          READ TABLE t_detail_alv INDEX p_gs_selfield-tabindex.
          SHIFT t_detail_alv-clmno LEFT DELETING LEADING '0'.
          l_claim_no = t_detail_alv-clmno.
          CONCATENATE sy-tcode syst-modno
                      INTO lv_tcode_last.
          EXPORT wty_tcode_last_memoid FROM lv_tcode_last TO MEMORY
                                       ID    'WTY_TCODE_LAST_MEMOID'.
          SET PARAMETER ID 'CLMNO' FIELD l_claim_no.
          CALL TRANSACTION 'WTY' AND SKIP FIRST SCREEN.
        WHEN 'CLAIM_NB'.
    *     =====================================
    *     Display the next level of information
    *     =====================================
          CASE  wa_level_alv.
            WHEN 1.
              REFRESH: t_detail_alv.
              wa_level_alv = 2.
              READ TABLE t_summary_alv INDEX p_gs_selfield-tabindex.
              LOOP AT t_detail_info
                      ASSIGNING <fs_detail_info>
                      WHERE v_parnr    EQ t_summary_alv-v_parnr
                        AND crncy      EQ t_summary_alv-crncy
                        AND item_type  EQ t_summary_alv-item_type
                        AND ov_meinh   EQ t_summary_alv-ov_meinh
                        AND iv_meinh   EQ t_summary_alv-iv_meinh
                        AND matnr      EQ t_summary_alv-matnr.
                MOVE-CORRESPONDING <fs_detail_info> TO t_detail_alv.
                APPEND t_detail_alv.
              ENDLOOP.
              CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
                EXPORTING
                  i_callback_program      = g_callback_pgm
                  i_callback_user_command = g_callback_user_command
                  is_layout               = gs_layout
                  it_fieldcat             = gt_fieldcat_det
                  it_excluding            = gt_excluding
    *              it_sort                 = gt_sort
                  i_save                  = c_save
                  is_variant              = gs_variant2
                  it_events               = eventcat
                  is_print                = my_print
                TABLES
                  t_outtab                = t_detail_alv
                EXCEPTIONS
                  program_error           = 1
                  OTHERS                  = 2.
              wa_level_alv = 1.
          ENDCASE.
      ENDCASE.
    ENDFORM.                    " MY_USER_COMMAND
    *       FORM PRINT_ALV_GRID                                           *
    *       Print the report not on screen for special batch processing.  *
    *  -->  IT         Table to print  -   Z_HRF_BEN_CONF_FLEX
    FORM set_print_alv_grid.
      my_print-print              = 'X'.  "Force printing
      my_print-no_print_selinfos  = 'X'.
      my_print-no_print_listinfos = 'X'.
      my_print-no_new_page        = ''.   "Separate spool files
      my_print-prnt_title         = 'X'.
      my_print-prnt_info          = 'X'.
      my_print-reserve_lines      = 3.
    ENDFORM.                    "set_print_alv_grid
    *&      Form  ALV_VARIANT_F4
    FORM alv_variant_f4 USING    p_handle
                        CHANGING p_vari.
      DATA: rs_variant LIKE disvariant.
      DATA: nof4 TYPE c.
      CLEAR nof4.
      LOOP AT SCREEN.
        IF screen-name = p_vari.
          IF screen-input = 0.
            nof4 = 'X'.
          ENDIF.
        ENDIF.
      ENDLOOP.
      rs_variant-report   = sy-repid.
      rs_variant-username = sy-uname.
      rs_variant-handle   = p_handle.
      CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
        EXPORTING
          is_variant = rs_variant
          i_save     = 'A'
        IMPORTING
          es_variant = rs_variant
        EXCEPTIONS
          OTHERS     = 1.
      IF sy-subrc = 0 AND nof4 EQ space.
        p_vari = rs_variant-variant.
      ENDIF.
    ENDFORM.                               " ALV_VARIANT_F4
    *&      Form  validate_model
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM validate_model .
      DATA: l_matnr LIKE mara-matnr.
      SELECT SINGLE matnr
             INTO  l_matnr
             FROM  mara
             WHERE matnr IN s_model
               AND mtart EQ 'ZKMA'.
      IF sy-subrc NE 0.
        MESSAGE e000 WITH text-e07.
      ENDIF.
    ENDFORM.                    " validate_model
    *&      Form  select_claim_to_process
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM select_claim_to_process .
      DATA: lt_pnwtyh_dia     TYPE wty_pnwtyh_dia_tab,
            lt_pnwtyv_dia     TYPE wty_pnwtyv_dia_tab,
            lt_pvwty_dia      TYPE wty_pvwty_dia_tab,
            lt_pnwtyh_dia_tmp TYPE wty_pnwtyh_dia_tab,
            lt_pnwtyv_dia_tmp TYPE wty_pnwtyv_dia_tab,
            lt_pvwty_dia_tmp  TYPE wty_pvwty_dia_tab,
            lt_pvwty_dia_mat  TYPE wty_pvwty_dia_tab,
            lt_sel_fkdat      TYPE pwty_sel_fkdat_pt,
            lt_sel_v_parnr    TYPE pwty_sel_v_parnr_pt,
            lt_sel_clmty      TYPE pwty_sel_clmty_pt,
            lt_sel_clmgrp     TYPE pwty_sel_clmgrp_pt.
      DATA: lst_sel_fkdat LIKE LINE OF lt_sel_fkdat,
            lst_sel_clmty LIKE LINE OF lt_sel_clmty.
      DATA: BEGIN OF lt_clmno OCCURS 0,
                  clmno   LIKE pnwtyh-clmno,
            END   OF lt_clmno,
            lt_clmno_tmp   LIKE lt_clmno OCCURS 0,
            lt_claim    TYPE pwty_sel_clmno_pt,
            wa_clmno    LIKE LINE OF lt_claim.
      DATA: l_nb_claim         TYPE i.
      RANGES: lr_model FOR wty_pnwtyh_dia-z_wty_model.
      FIELD-SYMBOLS: <lfs_pnwtyh_dia>    LIKE LINE OF lt_pnwtyh_dia,
                     <lfs_pnwtyv_dia>    LIKE LINE OF lt_pnwtyv_dia,
                     <lfs_pvwty_dia_es2> LIKE LINE OF lt_pvwty_dia,
                     <lfs_pvwty_dia_mat> LIKE LINE OF lt_pvwty_dia_mat.
      REFRESH: lt_pnwtyh_dia, lt_pnwtyv_dia,lt_pvwty_dia, lt_sel_clmty,
               lr_model, t_detail_info, t_summary_alv, lt_pvwty_dia_mat.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
       EXPORTING
    *    PERCENTAGE       = 0
         text             =  text-m01. "Extracting claim
    * ========================
    * Get the Claim to process
    * ========================
    *  SELECT clmno
    *         INTO  TABLE lt_clmno
    *         FROM  pnwtyh
    *         WHERE z_wty_convflg  EQ space
    *           AND z_wty_error    EQ space
    *  wa_clmno-sign   = 'I'.
    *  wa_clmno-option = 'EQ'.
    *  LOOP AT lt_clmno.
    *    wa_clmno-low     = lt_clmno-clmno.
    *    APPEND wa_clmno  TO lt_claim.
    *  ENDLOOP.
      lst_sel_fkdat-sign   = 'I'.
      lst_sel_fkdat-option = 'BT'.
      lst_sel_fkdat-low    = wa_low_date.
      lst_sel_fkdat-high   = wa_high_date.
      APPEND lst_sel_fkdat TO lt_sel_fkdat.
      lst_sel_clmty-sign   = 'E'.
      lst_sel_clmty-option = 'EQ'.
      lst_sel_clmty-low    = 'ZSBC'.
      APPEND lst_sel_clmty TO lt_sel_clmty.
      lt_sel_v_parnr[] = s_vend[].
      lt_sel_clmgrp[]  = s_clgrp[].
      CALL FUNCTION 'PVSDBWTY_CLAIM_SELECT'
        EXPORTING
          it_sel_fkdat     = lt_sel_fkdat
          it_sel_clmgrp    = lt_sel_clmgrp
          it_sel_v_parnr   = lt_sel_v_parnr
          it_sel_clmty     = lt_sel_clmty
    *      it_sel_clmno     = lt_claim
        IMPORTING
          et_pnwtyh_dia    = lt_pnwtyh_dia
          et_pnwtyv_dia    = lt_pnwtyv_dia
          et_pvwty_dia     = lt_pvwty_dia
        EXCEPTIONS
          no_entry_found   = 1
          authority_failed = 2
          OTHERS           = 3.
      IF sy-subrc = 3 .
        MESSAGE e309(wty) .
      ENDIF .
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
       EXPORTING
    *    PERCENTAGE       = 0
         text             =  text-m03. "Extracting claim
      LOOP AT lt_pvwty_dia
           ASSIGNING <fs_pvwty_dia>
           WHERE poskt_cust = 'MAT'.
        INSERT <fs_pvwty_dia> INTO TABLE lt_pvwty_dia_mat.
      ENDLOOP.
      it_pvwty_dia_all[] = lt_pvwty_dia[].
      SORT lt_pnwtyh_dia     BY pnguid.
      SORT lt_pvwty_dia      BY version_guid z_wty_posnr_hier.
      SORT lt_pvwty_dia_mat  BY version_guid.
      SORT it_pvwty_dia_all  BY version_guid posnr.
    * Keep Version record OC or IV in a separate table for later use
      LOOP AT lt_pnwtyv_dia
              ASSIGNING <lfs_pnwtyv_dia>.
        it_submit_records-header_guid  = <lfs_pnwtyv_dia>-header_guid.
        it_submit_records-versn        = <lfs_pnwtyv_dia>-versn.
        it_submit_records-prev_version = <lfs_pnwtyv_dia>-prev_version.
        it_submit_records-kateg        = <lfs_pnwtyv_dia>-kateg.
        it_submit_records-aktiv        = <lfs_pnwtyv_dia>-aktiv.
        it_submit_records-knumv        = <lfs_pnwtyv_dia>-knumv.
        it_submit_records-pnguid       = <lfs_pnwtyv_dia>-pnguid.
        INSERT TABLE it_submit_records.
      ENDLOOP.
    * =============
    * Process Claim
    * =============
      LOOP AT lt_pnwtyv_dia
              ASSIGNING <lfs_pnwtyv_dia>
              WHERE aktiv        EQ true   "Active version only
                AND kateg        EQ 'IV'   "Category
                AND fi_doc_exist EQ 'X'.
        CLEAR: t_detail_info, t_summary_alv.
    *   Read Header detail
        READ TABLE lt_pnwtyh_dia
             WITH KEY pnguid = <lfs_pnwtyv_dia>-header_guid
             ASSIGNING <lfs_pnwtyh_dia>
             BINARY SEARCH.
    *   Claim must be without error -----------------------------
        IF sy-subrc                      NE 0      OR
           <lfs_pnwtyh_dia>-z_wty_error   = true   OR
           <lfs_pnwtyh_dia>-z_wty_convflg = true.
          CONTINUE. "Rejected this Claim
        ENDIF.
    *   Check Model
        IF <lfs_pnwtyh_dia>-z_wty_model IN s_model.
        ELSE.
          CONTINUE. "Rejected this Claim
        ENDIF.
    *   Read first "MAT" Item information ------------------
        READ TABLE lt_pvwty_dia_mat
             WITH KEY version_guid = <lfs_pnwtyv_dia>-pnguid
             ASSIGNING <lfs_pvwty_dia_mat>
             BINARY SEARCH.
        wa_index_mat = sy-tabix.
        IF sy-subrc NE 0.
          CONTINUE. "Rejected this Claim
        ENDIF.
    *   ====================================================
    *   Process all item "MAT" linked to the current version
    *   ====================================================
        WHILE sy-subrc                     = 0
              AND
              <lfs_pvwty_dia_mat>-version_guid = <lfs_pnwtyv_dia>-pnguid.
          IF <lfs_pvwty_dia_mat>-matnr IN s_matnr.
    *       ======================================
    *       Process Items linked to the "MAT" Item
    *       ======================================
            READ TABLE lt_pvwty_dia
                 WITH KEY version_guid     = <lfs_pnwtyv_dia>-pnguid
                          z_wty_posnr_hier = <lfs_pvwty_dia_mat>-posnr
                 ASSIGNING <lfs_pvwty_dia_es2>
                 BINARY SEARCH.
            wa_index_link = sy-tabix.
            DO. "Execute only ONCE (to process all items linked to the)
              "MAT Item
              IF sy-subrc NE 0.
                EXIT.  "Exit the DO loop
              ENDIF.
              WHILE sy-subrc                     = 0
                    AND
                   <lfs_pvwty_dia_es2>-version_guid =
                           <lfs_pnwtyv_dia>-pnguid
                    AND
                   <lfs_pvwty_dia_es2>-z_wty_posnr_hier =
                           <lfs_pvwty_dia_mat>-posnr.
                IF <lfs_pvwty_dia_es2>-valiv EQ c_zero.
                ELSE.
    *             Initialize the detail information to display ---------
                  CLEAR: t_detail_info.
                  t_detail_info-v_parnr    = <lfs_pnwtyv_dia>-v_parnr.
                  t_detail_info-matnr      = <lfs_pvwty_dia_mat>-matnr.
                  t_detail_info-item_type  = <lfs_pvwty_dia_es2>-poskt_cust.
                  t_detail_info-iv_versn   = <lfs_pnwtyv_dia>-versn.
                  t_detail_info-clmno      = <lfs_pnwtyh_dia>-clmno.
                  t_detail_info-crncy      = <lfs_pnwtyv_dia>-v_crncy.
                  t_detail_info-iv_meinh   = <lfs_pvwty_dia_es2>-meinh.
                  t_detail_info-z_wty_model = <lfs_pnwtyh_dia>-z_wty_model.
                  ADD  <lfs_pvwty_dia_es2>-quant TO
                                                 t_detail_info-iv_appr_qty.
                  SELECT SINGLE kbetr
                         INTO   t_detail_info-iv_appr_rate
                         FROM   konv
                         WHERE  knumv  = <lfs_pnwtyv_dia>-knumv
                           AND  kposn  = <lfs_pvwty_dia_es2>-posnr
                           AND  kschl  = 'ZVAP'
                           AND  kinak  = space.
    *              t_detail_info-flat_indic   = <lfs_pnwtyh_dia>-z_wty_model
    *             t_detail_info-pric_indic   = <lfs_pnwtyh_dia>-z_wty_serno
                  PERFORM get_the_submit_record
                          USING <lfs_pnwtyv_dia>-header_guid
                                <lfs_pnwtyv_dia>-prev_version
                                <lfs_pnwtyh_dia>-clmno
                                <lfs_pvwty_dia_es2>-posnr.
                ENDIF.
    *           =====================
    *           Read next Linked item
    *           =====================
                PERFORM read_next_item  TABLES   lt_pvwty_dia
                                        CHANGING wa_index_link.
                IF sy-subrc = 0.
                  ASSIGN <fs_pvwty_dia> TO <lfs_pvwty_dia_es2>.
                ENDIF.
              ENDWHILE.
              EXIT.  "Exit the DO loop
            ENDDO.
          ENDIF.
    *     ====================
    *     Read next "MAT" item
    *     ====================
          PERFORM read_next_item  TABLES   lt_pvwty_dia_mat
                                  CHANGING wa_index_mat.
          IF sy-subrc = 0.
            ASSIGN <fs_pvwty_dia> TO <lfs_pvwty_dia_mat>.
          ENDIF.
        ENDWHILE.
      ENDLOOP.
    * ========================
    * Get the description text
    * ========================
      LOOP AT t_detail_info
           ASSIGNING <fs_detail_info>.
    *   Get the model text -------------------------------------
        SELECT SINGLE mfrpn
               INTO   <fs_detail_info>-z_wty_model
               FROM   mara
               WHERE  matnr = <fs_detail_info>-z_wty_model.
    *   Set Node name to regroup later by group -----------------
        SELECT SINGLE name1
               INTO   <fs_detail_info>-name
               FROM   lfa1
               WHERE  lifnr = <fs_detail_info>-v_parnr.
    *   Set Node name to regroup later by group -----------------
        SELECT SINGLE maktx
               INTO   <fs_detail_info>-maktx
               FROM   makt
               WHERE  matnr = <fs_detail_info>-matnr
                 AND  spras = sy-langu.
        MOVE-CORRESPONDING <fs_detail_info> TO t_summary_alv.
        t_summary_alv-claim_nb = 1.
        COLLECT t_summary_alv.
      ENDLOOP.
    * ===========================================
    * Calculate the average of the summary report
    * ===========================================
      LOOP AT t_summary_alv
           ASSIGNING <fs_summary_alv>.
        DIVIDE <fs_summary_alv>-ov_prop_qty   BY <fs_summary_alv>-claim_nb.
        DIVIDE <fs_summary_alv>-ov_prop_rate  BY <fs_summary_alv>-claim_nb.
        DIVIDE <fs_summary_alv>-ov_submit_qty  BY <fs_summary_alv>-claim_nb.
        DIVIDE <fs_summary_alv>-ov_submit_rate BY <fs_summary_alv>-claim_nb.
        DIVIDE <fs_summary_alv>-iv_appr_qty    BY <fs_summary_alv>-claim_nb.
        DIVIDE <fs_summary_alv>-iv_appr_rate   BY <fs_summary_alv>-claim_nb.
      ENDLOOP.
      DELETE t_summary_alv WHERE v_parnr NOT IN s_vend.
    ENDFORM.                    " select_claim_to_process
    *&      Form  SET_HOT_SPOT
    *       text
    *      -->P_0287   text
    FORM set_hot_spot  TABLES   p_fieldcat     TYPE slis_t_fieldcat_alv
                       USING    value(p_field).
      FIELD-SYMBOLS: <lfs_field_cat> LIKE LINE OF gt_fieldcat_sum.
      READ TABLE p_fieldcat WITH KEY fieldname  = p_field
           ASSIGNING <lfs_field_cat>.
      IF sy-subrc = 0.
        <lfs_field_cat>-hotspot = 'X'.
        <lfs_field_cat>-key     = 'X'.
      ENDIF.
    ENDFORM.                    " SET_HOT_SPOT
    *&      Form  set_screen_text
    *       text
    *      -->P_0997   text
    FORM set_screen_text  USING    p_label
                                   p_text.
      MOVE p_label TO :gtw_fieldcat-seltext_l,
                       gtw_fieldcat-seltext_m,
                       gtw_fieldcat-seltext_s,
                       gtw_fieldcat-reptext_ddic.
      IF p_text NE space.
        gtw_fieldcat-ddictxt = p_text.
      ENDIF.
    ENDFORM.                    " set_screen_text
    *&      Form  set_default_variant
    *       text
    *      -->P_0822   text
    *      <--P_GS_VARIANT1  text
    FORM set_default_variant  CHANGING p_variant     TYPE disvariant
                                       p_disvar      TYPE slis_vari.
    * Get default variant
      CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
        EXPORTING
          i_save     = c_save
        CHANGING
          cs_variant = p_variant
        EXCEPTIONS
          not_found  = 2.
      IF sy-subrc = 0.
        p_disvar =  p_variant-variant.
      ENDIF.
    ENDFORM.                    " set_default_variant
    *&      Form  validate_vendor
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM validate_vendor.
      DATA: l_lifnr LIKE lfa1-lifnr.
      IF s_vend[] IS INITIAL.
      ELSE.
        SELECT SINGLE lifnr
               INTO   l_lifnr
               FROM   lfa1
               WHERE  lifnr IN s_vend.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH text-e01.
        ENDIF.
      ENDIF.
    ENDFORM.                    " validate_vendor
    *&      Form  inform_claim_error
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM inform_claim_error USING value(p_claim_no)
                                  value(p_version).
      DATA: l_text1(50),
            l_text2(50).
      CONCATENATE text-301
                  p_claim_no
                  INTO l_text1 SEPARATED BY space.
      CONCATENATE text-302
                  p_version
                  text-303
                  INTO l_text2 SEPARATED BY space.
      CALL FUNCTION 'POPUP_TO_INFORM'
        EXPORTING
          titel = text-200
          txt1  = l_text1
          txt2  = l_text2
          txt3  = ' '
          txt4  = text-304.
    ENDFORM.                    " inform_claim_error
    *&      Form  validate_posting_parameter
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM validate_posting_parameter .
      DATA: l_low_date  TYPE d,
            l_high_date TYPE d.
      CLEAR: wa_low_date, wa_high_date.
    * Posting parameters must be entered
      IF s_cpudt[] IS INITIAL AND s_postdt[] IS INITIAL.
        MESSAGE e000 WITH text-e04.
      ENDIF.
    * Posting paramters can't be intered at the same time
      IF s_cpudt[] IS INITIAL OR s_postdt[] IS INITIAL.
      ELSE.
        MESSAGE e000 WITH text-e03.
      ENDIF.
    * Validate posting period ---------------------------------------------
      IF s_postdt[] IS INITIAL.
        READ TABLE s_cpudt INDEX 1.
        IF s_cpudt-low IS INITIAL.
          MESSAGE e000 WITH text-e03.
        ENDIF.
        PERFORM validate_period USING    s_cpudt-low
                                CHANGING l_low_date
                                         l_high_date.
        wa_low_date  = l_low_date.
        wa_high_date = l_high_date.
        IF s_cpudt-high IS INITIAL.
        ELSE.
          PERFORM validate_period USING    s_cpudt-high
                                  CHANGING l_low_date
                                           l_high_date.
          IF s_cpudt-high LT s_cpudt-low.
            MESSAGE ID 'DB' TYPE 'E' NUMBER '650' .
          ENDIF.
          wa_high_date = l_high_date.
        ENDIF.
      ELSE.
    *   Validate posting date --------------------------------------------
        READ TABLE s_postdt INDEX 1.
        wa_low_date  = s_postdt-low.
        IF s_postdt-high IS INITIAL.
          wa_high_date = wa_low_date.
        ELSE.
          wa_high_date = s_postdt-high.
        ENDIF.
      ENDIF.
    ENDFORM.                    " validate_posting_parameter
    *&      Form  get_fin_period
    *       Get the financial period from 1960 to 9999
    *  -->  p1        text
    *  <--  p2        text
    FORM get_fin_period USING value(p_year_low)
                              value(p_year_high).
      DATA : BEGIN OF fp_table OCCURS 0,
                   periv LIKE t009b-periv, "FINANCIAL YEAR VARIANT
                   bdatj LIKE t009b-bdatj, "CALENDAR YEAR
                   bumon LIKE t009b-bumon, "MONTH
                   butag LIKE t009b-butag, "DAY OF MONTH
                   poper LIKE t009b-poper, "COST PERIOD
                   reljr LIKE t009b-reljr, "YEAR SHIFT
             END OF fp_table.
      DATA: l_fin_bdatj       LIKE t009b-bdatj,
            l_period_start    TYPE d,
            l_period_end      TYPE d,
            l_prev_period_end TYPE d,
            l_prev_fin_bdatj  LIKE t009b-bdatj,
            l_prev_poper      LIKE t009b-poper,
            l_count           TYPE n.
    * Get the Fiscal year variant periods
      SELECT periv bdatj bumon butag poper reljr
             INTO  TABLE fp_table
             FROM  t009b
             WHERE periv = 'ZB'.
      LOOP AT fp_table.
        IF l_prev_period_end NE '00000000'.
          l_period_start = l_prev_period_end + 1.
        ENDIF.
        CONCATENATE fp_table-bdatj fp_table-bumon fp_table-butag
                    INTO l_period_end.
        l_prev_period_end = l_period_end.
        l_fin_bdatj       = fp_table-bdatj + fp_table-reljr.
        IF c_year_low NE ''      AND l_fin_bdatj LT p_year_low.
          CONTINUE.
        ELSEIF p_year_high NE '' AND l_fin_bdatj GT p_year_high.
          CONTINUE.
        ELSEIF p_year_low NE '' AND p_year_high EQ '' AND
               l_fin_bdatj  GT c_year_low.
          CONTINUE.
        ENDIF.
        IF l_prev_fin_bdatj EQ l_fin_bdatj         AND
           l_prev_poper     EQ fp_table-poper.
          it_period-end    = l_period_end.
          MODIFY it_period TRANSPORTING  end
                 WHERE year  = it_period-year
                   AND poper = it_period-poper.
        ELSE.
          it_period-year   = l_fin_bdatj.
          it_period-poper  = fp_table-poper+1.
          it_period-start  = l_period_start.
          it_period-end    = l_period_end.
          INSERT TABLE it_period.
        ENDIF.
        l_prev_fin_bdatj = l_fin_bdatj.
        l_prev_poper     = fp_table-poper.
        IF l_count EQ 0.
          l_count = l_count + 1.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " get_fin_period
    *&      Form  set_period_to_analyse
    *       Find the fiscal period for a specific date
    *  -->  p1        text
    *  <--  p2        text
    FORM set_period_to_analyse.
      LOOP AT it_period
           ASSIGNING <fs_it_period>
           WHERE start LE sy-datum
             AND end   GE sy-datum.
        CONCATENATE <fs_it_period>-year
                    <fs_it_period>-poper
                    INTO s_cpudt-low.
        s_cpudt-sign   = 'I'.
        s_cpudt-option = 'EQ'.
        APPEND s_cpudt.
        EXIT.
      ENDLOOP.
    ENDFORM.                    " set_period_to_analyse
    *&      Form  validate_material
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM validate_material .
      DATA: l_matnr LIKE mara-matnr.
      IF s_matnr[] IS INITIAL.
      ELSE.
        SELECT SINGLE matnr
               INTO   l_matnr
               FROM   mara
               WHERE  matnr IN s_matnr.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH text-e02.
        ENDIF.
      ENDIF.
    ENDFORM.                    " validate_material
    *&      Form  validate_claim_group
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM validate_claim_group .
      DATA: l_clmgrp LIKE cwty006-clmgrp.
      IF s_clgrp[] IS INITIAL.
      ELSE.
        SELECT SINGLE clmgrp
               INTO   l_clmgrp
               FROM   cwty006
               WHERE  clmgrp IN s_clgrp.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH text-e06.
        ENDIF.
      ENDIF.
    ENDFORM.                    " validate_claim_group
    *&      Form  set_alv_field_desc
    *       text
    *      -->P_LTW_FIELDCATALOG  text
    *      <--P_GTW_FIELDCAT  text
    FORM set_alv_field_desc USING value(p_fieldcat) TYPE lvc_s_fcat
                                  value(p_level).
      gtw_fieldcat-seltext_l    = p_fieldcat-scrtext_l.
      gtw_fieldcat-seltext_m    = p_fieldcat-scrtext_m.
      gtw_fieldcat-seltext_s    = p_fieldcat-scrtext_s.
      gtw_fieldcat-reptext_ddic = p_fieldcat-reptext.
      CASE p_fieldcat-fieldname.
        WHEN 'NAME'.
          PERFORM set_screen_text USING 'Vendor Name'           'L'.
        WHEN 'MAKTX'.
          PERFORM set_screen_text USING 'Material Description'  'L'.
        WHEN 'CLAIM_NB'.
          PERFORM set_screen_text USING '#Claims'               'L'.
        WHEN 'IV_MEINH'.
          PERFORM set_screen_text USING 'IV UoM'                'L'.
        WHEN 'OV_MEINH'.
          PERFORM set_screen_text USING 'OV UoM'                'L'.
        WHEN 'FLAT_INDIC'.
          PERFORM set_screen_text USING 'Flat Rate Ind.'        'L'.
        WHEN 'PRIC_INDIC'.
          PERFORM set_screen_text USING 'Price Ind.'            'L'.
        WHEN 'OV_PROP_QTY'.
          IF p_level = 1. "Summary report
    *BEGIN OF TR#D03K935718
    *        PERFORM set_screen_text USING 'OV avg. Prop. Qty'    'L'.
             PERFORM set_screen_text USING 'Avg Prop Qty Sub'    'L'.  "RFC2917
    *END OF TR#D03K935718
          ELSE.
            PERFORM set_screen_text USING 'OV Prop. Qty'         'L'.
          ENDIF.
        WHEN 'OV_PROP_RATE'.
          IF p_level = 1. "Summary report
    *BEGIN OF TR#D03K935718
    *        PERFORM set_screen_text USING 'OV avg. Prop. Rate $'  'L'.
             PERFORM set_screen_text USING 'Avg Prop Rate Sub'  'L'.    "RFC2917
    *END OF TR#D03K935718
          ELSE.
            PERFORM set_screen_text USING 'OV Prop. Rate $'       'L'.
          ENDIF.
        WHEN 'OV_SUBMIT_QTY'.
          IF p_level = 1. "Summary report
    *BEGIN OF TR#D03K935718
    *        PERFORM set_screen_text USING 'OV avg. Submit Qty'    'L'.
             PERFORM set_screen_text USING 'Avg Qty Sub'    'L'.          "RFC2917
    *END OF TR#D03K935718
          ELSE.
            PERFORM set_screen_text USING 'OV Submit Qty'         'L'.
          ENDIF.
        WHEN 'OV_SUBMIT_RATE'.
          IF p_level = 1. "Summary report
    *BEGIN OF TR#D03K935718
    *        PERFORM set_screen_text USING 'OV avg. Submit Rate $' 'L'.
            PERFORM set_screen_text USING 'Avg Rate Sub' 'L'.        "RFC2917
    *END OF TR#D03K935718
          ELSE.
            PERFORM set_screen_text USING 'OV Submit Rate $'      'L'.
          ENDIF.
        WHEN 'IV_APPR_QTY'.
          IF p_level = 1. "Summary report
    *BEGIN OF TR#D03K935718
    *        PERFORM set_screen_text USING 'IV Avg. Appr. Qty'     'L'.
            PERFORM set_screen_text USING 'Avg Qty Pd'     'L'.     "RFC2917
    *END OF TR#D03K935718
          ELSE.
            PERFORM set_screen_text USING 'IV Appr. Qty'          'L'.
          ENDIF.
        WHEN 'IV_APPR_RATE'.
          IF p_level = 1. "Summary report
    *BEGIN OF TR#D03K935718
    *        PERFORM set_screen_text USING 'IV Avg. Appr. Rate $'  'L'.
            PERFORM set_screen_text USING 'Avg Rate Pd'  'L'.   "RFC2917
    *END OF TR#D03K935718
          ELSE.
            PERFORM set_screen_text USING 'IV Appr. Rate $'       'L'.
          ENDIF.
        WHEN 'OV_VERSN'.
          PERFORM set_screen_text USING 'OV Versn.'               'L'.
        WHEN 'IV_VERSN'.
          PERFORM set_screen_text USING 'IV Versn.'               'L'.
        WHEN OTHERS.
          gtw_fieldcat-ddictxt      = p_fieldcat-selddictxt.
      ENDCASE.
    *   Initialisation des Labels des entetes de colonne -------------------
      gtw_fieldcat-no_out       = p_fieldcat-no_out.
      gtw_fieldcat-emphasize    = p_fieldcat-emphasize.
      gtw_fieldcat-fix_column   = p_fieldcat-fix_column.
      gtw_fieldcat-icon         = p_fieldcat-icon.
      gtw_fieldcat-no_zero      = 'X'.
      gtw_fieldcat-do_sum       = p_fieldcat-do_sum.
    ENDFORM.                    " set_alv_field_desc
    *&      Form  validate_period
    *       text
    *      -->P_S_CPUDT_LOW  text
    FORM validate_period  USING value(p_period)
                          CHANGING p_low_date    TYPE d
                                   p_high_date   TYPE d.
      DATA: l_year(4),
            l_poper(2).
      l_year  = p_period(4).
      l_poper = p_period+4(2).
      READ TABLE it_period WITH KEY year  = l_year
                                    poper = l_poper
                 ASSIGNING <fs_it_period>.
      IF sy-subrc NE 0.
        MESSAGE e000 WITH text-e04.
      ENDIF.
      p_low_date  = <fs_it_period>-start.
      p_high_date = <fs_it_period>-end.
    ENDFORM.                    " validate_period
    *&      Form  read_next_item
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM read_next_item  TABLES pt_pvwty_dia     STRUCTURE wty_pvwty_dia
                         CHANGING p_index TYPE i.
      p_index = p_index + 1.
    *     Read next Item information ------------------------------
      READ TABLE pt_pvwty_dia INDEX p_index
           ASSIGNING <fs_pvwty_dia>.
    ENDFORM.                    " read_next_item
    *&      Form  get_the_submit_record
    *       text
    *      -->P_<LFS_PNWTYV_DIA>_HEADER_GUID  text
    *      -->P_<LFS_PNWTYV_DIA>_PREV_VERSION  text
    FORM get_the_submit_record  USING    p_header_guid
                                         p_prev_version
                                         p_claim_no
                                         p_posnr.
      DATA: l_nb_while       TYPE i,
            l_zaehk          LIKE konv-zaehk,
            l_submit_found(1).
    * ... USD1092841 - Add Start
      FIELD-SYMBOLS: <fs_submit_rec_vs3> TYPE tp_submit_records.
    * ... USD1092841 - Add End
      CLEAR: l_submit_found, l_nb_while.
      READ TABLE it_submit_records
           WITH KEY header_guid  = p_header_guid
                    versn        = p_prev_version
           ASSIGNING <fs_submit_rec_vs2>.
      WHILE sy-subrc = 0 .
        ADD 1 TO l_nb_while.
    *   if more than 30 loop(endless loop), it means som

    Hi Siddarth
    As per query, if you want to display sums automatically when you report is displayed for the first time, you'll have to modify your field catalog a bit.
    To acheive this, you need to identify the field for which the totals are calculated ex- for every new material num, or for every new documnet number etc.
    once you have this info, you identify the field that has to be totaled.
    then while building your fieldcatalog, set this parameter :
    l_wa_fieldcat-do_sum     =  'X' for the field that has to be totaled.
    and when you build a sort table then set this parameter:
    l_t_sort           TYPE slis_t_sortinfo_alv.
    l_s_sort-subtot    = 'X'. for the field for which totals are calculated.
    Hope this helps.
    Cheers
    Ravish
    Reward if helpful

  • Average of the column in ALV report

    Hi,
      I am working on an ALV report and for one of the column, i am calculating the average with fieldcatalog property do_sum = 'C'.
    I am sorting the output table for 2 fields and whenever I am expanding/compressing the sorted fields the average of the column is changing. Please let me know how do I get this average calculated constant. It should not change when the user collapses/expands on the sorted field.
    Regards
    Rashmi

    The same question has been asked in this thread:
    Compute average of a report column
    I have offered a solution but as I've said it's not great but it may meet your needs.
    Or another forum user may review and be able to suggest a better solution.
    Does the average need to be part of the report?
    Could you calculate it and display it within a page item below the report instead?

  • Summing up a Column in ALV report

    Hi All,
    I have developed an ALV Report which will display Invoices and other details.
    Now i need to display the sum of NETWR column, if user wish to select that column and click the "SUM" icon.
    As of now, if i select the NETWR column and click 'SUM" column, i am getting Runtime error.
    How to resolve this issue?
    Regards
    Pavan

    Hi Pavan,
    ALV GRID CONTROL:
    This task is performed by the SAP Control Framework.
    The R/3 System allows you to create custom controls using ABAP Objects. The application server is the Automation Client, which drives the custom controls (automation server) at the front end.
    If custom controls are to be included on the frontend, then the SAPGUI acts as a container for them.
    Custom controls can be ActiveX Controls or JavaBeans.
    The system has to use a Remote Function Call (RFC) to transfer methods for creating and using a control to the front end.
    ABAP objects are used to implement the controls in programs.
    An SAP Container can contain other controls (for example, SAP ALV Grid Control, Tree Control, SAP Picture Control, SAP Splitter Control, and so on). It administers these controls logically in one collection and provides a physical area for the display.
    Every control exists in a container. Since containers are themselves controls, they can be nested within one another. The container becomes the parent of its control. SAP containers are divided into five groups:
    SAP custom container: Displays within an area defined in Screen Painter on screens or sub screens.
    Class: CL_GUI_CUSTOM_CONTAINER
    SAP dialog box container: Displays in a modeless dialog box or as a full screen. Class:
    CL_GUI_DIALOGBOX_CONTAINER
    SAP docking container: Displays as docked, resizable sub-window with the option of displaying it as a modeless dialog box. Class: CL_GUI_DOCKING_CONTAINER
    SAP splitter container: Displays and groups several controls in one area - that is, splits the area into cells Class: CL_GUI_SPLITTER_CONTAINER
    SAP easy splitter container: Displays controls in two cells, which the user can resize using a split bar. Class: CL_GUI_EASY_SPLITTER_CONTAINER.
    In the control, you can adjust the column width by dragging, or use the 'Optimum width' function to adjust the column width to the data currently displayed. You can also change the column sequence by selecting a column and dragging it to a new position.
    Standard functions are available in the control toolbar. The details display displays the fields in the line on which the cursor is positioned in a modal dialog box.
    The sort function in the ALV Control is available for as many columns as required. You can set complex sort criteria and sort columns in either ascending or descending order.
    You can use the 'Search' function to search for a string (generic search without *) within a selected area by line or column.
    You can use the 'Sum' function to create totals for one or more numeric columns. You can then use the "Subtotals" function to set up control level lists: You can use the 'Subtotal' function to structure control level lists: select the columns (non-numeric columns only) that you want to use and the corresponding control level totals are displayed.
    For 'Print' and 'Download' the whole list is always processed, not just the sections displayed on the screen.
    You can define display variants to meet your own specific requirements. For information on saving variants, see 'Advanced Techniques'.
    The ALV grid control is a generic tool for displaying lists in screens. The control offers standard functions such as sorting by any column, adding numeric columns, and fixed lead columns .
    Data collection is performed in the program (with SELECT statements, for example) or by using a logical database. The data records are saved in an internal table and passed on to the ALV control along with a field description.
    The field description contains information about the characteristics of each column, such as the column header and output length. This information can defined either globally in the Dictionary (structure in the Dictionary) or in the field catalog in the program itself. You can also merge both techniques.
    The ALV link is a standard function of Query and QuickViewer. If multiline queries or Quick View lists have been defined, they will automatically be compressed to a single line and output in the ALV control as a long, single line list.
    Use Screen Painter to create a sub screen container for the ALV grid control. The control requires an area where it can be displayed in the screen. You have to create a container control that determines this area.
    Use the corresponding icon in the Screen Painter layout to create the container control. The size of area "MY_CONTROL_AREA" determines the subsequent size of the ALV control.
    The valid GUI status must be set at the PBO event in the flow logic of the ALV subscreen container.
    The OK_CODE processing for the cancel functions must be programmed at the PAI event.
    The reference variables for the custom container and the ALV grid control must be declared.
    To create reference variables, use ABAP statement TYPE REF TO .
    The global classes you need to do this are called cl_gui_custom_container (for the custom container control) and cl_gui_alv_grid (for the ALV grid control).
    The global classes are defined in the Class Builder. You can use the Class Builder to display information for the methods, their parameters, exceptions, and so on.
    Use ABAP statement CREATE OBJECT to create the objects for the container and the ALV control. Objects Are instances of a class.
    When an object is created (CREATE), method CONSTRUCTOR of the corresponding class is executed. The parameters of method CONSTRUCTOR determine which parameters have to be supplied with data when the object is created. In the above example, object alv_grid is given the name of the container control (g_custom_container) in exporting parameter i_parent, which links the two controls. For information on which parameters method CONSTRUCTOR possesses and which of these parameters are required, see the Class Builder.
    Objects should only be created once during the program. To ensure that this is the case, enclose the CREATE OBJECT statement(s) in an IF IS INITIAL. ... ENDIF clause. The objects must be generated before the control is displayed for the first time - that is, during the PBO event of the ALV subscreen container.
    To display the requested dataset in the ALV control, the data must be passed on to the control as an internal table, and a field description must exist indicating the order in which the columns will be output.
    In the simplest case, the field description can use a structure from the Dictionary. The Dictionary also determines the technical field attributes like type and length, as well as the semantic attributes like short and long texts. The ALV control uses this information to determine the column widths and headers. The column sequence is determined by the field sequence in the structure.
    If no suitable structure is active in the Dictionary, or you want to output internal program fields in the control, then you will have to define information like the output length and column header in the field catalog.
    In a typical program run, the dataset is read first (SELECT ....), the internal table is filled with the data to display (... INTO TABLE ...), and ABAP statement CALL SCREEN is then used to call the ALV sub screen container.
    The data transfer to the ALV control takes place during the call of method
    set_table_for_first_display from class cl_gui_alv_grid. The method call must be programmed at the PBO event of the ALV subscreen container.
    The name of the Dictionary structure that supplies the field description is specified in exporting parameter i_structure_name. The name of the internal table that contains the data records to display is specified in changing parameter it_outtab.
    The field description for the ALV control can be ta ken from an active Dictionary structure (fully automatic), by passing a field catalog (manual), or through a mixture of the two options (merge).
    The field catalog is in internal table with type lvc_t_fcat. This type is defined globally in the Dictionary.
    Each line in the field catalog table corresponds to a column in the ALV control.
    The field characteristics (= column characteristics) are defined in the field catalog. The field catalog is in internal table with type lvc_t_fcat. Each line that is explicitly described in the ALV control corresponds to a column in the field catalog table.
    The link to the data records to output that are saved in internal table is established through field name . This name must be specified in column "fieldname" in the field catalog.
    This field can be classified through a Dictionary reference (ref_table and ref_field) or by specifying an ABAP data type (inttype).
    Column headers and field names in the detail view of an ALV control line can be determined in the field catalog in coltext and seltext, respectively.
    The position of a field during output can be determined with col_pos in the field catalog.
    If you want to hide a column, fill field no_out with an "X" in the field catalog. Hidden fields can be displayed again in a user display variant.
    Icons can be displayed in the ALV control. If you want a column to be interpreted as an icon, then the icon name must be known to the program (include .) and icon = "X" must be specified for this column in the field catalog.
    The above example shows a semi-automatic field description: Part of the field description comes from the Dictionary structure (sflight), while another part is explicitly defined in the field catalog (gt_fieldcat).
    The field catalog (internal table) is filled in the program and is passed on together with the name of the Dictionary structure during the method call. The information is merged accordingly in method set_table_for_first_display.
    For a user to save display variants, parameters is_variant and i_save must be passed on during method call set_table_for_first_screen. To assign display variants uniquely to a program, at least the program name must be supplied in the transferred structure (gs_variant).
    Program names can be up to 30 characters long.
    If you only pass on the current parameters for is_variant, then existing variants can be loaded, but no new ones can be saved. If you use parameter i_save, you must pass on a variant structure with is_variant.
    I_SAVE = SPACE No variants can be saved.
    I_SAVE = 'U' The user can only save user-specific variants.
    I_SAVE = 'X' The user can only save general (shared) variants.
    I_SAVE = 'A' The user can save both user-specific and general (shared) variants.
    You can use parameter is_layout of method set_table_for_first_display, for example, to define the header in the ALV control and the detail display.
    To do this, define a query area in the program in accordance with Dictionary structure lvc_s_layo, and pass on the text to display in field -grid_title or -detailtitl.
    If you want to create print lists with zebra stripes, set field -zebra to "X". You can display a print preview for print lists by requesting standard function "Print".
    All parameters of method SET_TABLE_FOR_FIRST_DISPLAY from global class
    CL_GUI_ALV_GRID are defined in the Class Builder.
    Events are defined in global class cl_gui_alv_grid; you can use these events to implement user interaction within the program. To respond to a double -click on a table line, you must respond to event DOUBLE_CLICK.
    You receive control in the program, allowing you to implement interactive reporting - such as a full screen details list. The events for cl_gui_alv_grid are located in the Class Builder.
    To define an implement a local class in the program, you use a handler method. In this handler method, you program the functionality to trigger by a double -click in the output table.
    To activate a handler method at runtime, a class or an object from that class registers itself with an event using command SET HANDLER. The names of the IMPORTING parameters in the handler method correspond to the names of the EXPORTING parameters of the related event.
    In the above example, the local class is LCL_ILS and the handler method is ON_DBLCLICK. An object - ALV_DBLCLICK - is created and registers itself for event DOUBLE_CLICK.
    You can query parameter e_row-index to determine which output line was requested by the double -click. This parameter corresponds to the line number of the output table (internal table with the data records to output). If you need information for the selected line, you have to read it with READ TABLE itab INDEX e_row-index.
    This subsequent read in the output table generally corresponds to the HIDE area in conventional reporting. You first have to make sure that the user has double -clicked a line in the output table (similar to the valid line selection with the HIDE technique).
    A field group can contain global data objects, but not data objects that have been defined locally in a subroutine or function module.
    You can use INSERT to specify both fields and field symbols. This makes it possible to dynamically insert a data object referred to by a field symbol into a field group at runtime. Any field symbols that have not been assigned are ignored, which means no new field is inserted into the field group.
    The EXTRACT statement writes all the fields of a field group as one record to a sequential dataset (transport takes place with similarly named fields). If a HEADER field group is defined, then its fields are placed ahead of each record as sort keys. You can then sort the dataset with SORT and process it with LOOP ...ENDLOOP. In this case, no further EXTRACT is possible.
    The INSERT statement is not a declarative statement: This means field groups can also be expanded in the program flow section.
    As soon as the first dataset of a field group has been extracted with EXTRACT, that field group can no longer be expanded with INSERT. In particular, the HEADER field group cannot be expanded after the first EXTRACT (regardless of the field group).
    When the GET events are processed, the logical database automatically writes hexadecimal zeros in all the fields of a node when it returns to an upper-level node in the hierarchy. Since the HEADER normally contains sort fields for all field groups, these hexadecimal zeros in the HEADER serve as a type of hierarchy key: The more zeros there are, the further up in the control level hierarchy you go.
    &#61550;&#61472;The SORT statement sorts the extract dataset in accordance with the defined field sequence in field group HEADER. The addition BY ... sets a new sort key.
    Each must be either a field of field group HEADER or a field group that consists only of fields of the field group HEADER. You can use the additions ASCENDING and DESCENDING to determine whether the fields are sorted in ascending (default) or descending order.
    Fields containing X'00' in the logical databases are always displayed before all other values during a SORT.
    Processing of an extract dataset always takes places within a LOOP. The contents of the extract dataset field are placed in program fields with the same names.
    The group change always involves the fields of the HEADER. Single record processing for extract datasets is performed using language element AT ( = field group).
    CNT() is not a statement, but instead a field that is automatically create d and filled when is a non-numeric field from field group HEADER and is part of the sort key. At the end of the group, CNT() contains the number of different values that the field recorded in this group level.
    SUM() is not a statement, but instead a field that is automatically created and filled when is a numeric field of an extract dataset. At the end of the group, SUM() contains the control total of field .
    *** and CNT are only available at the end of the group level or at AT LAST.
    Single record processing for extract datasets AT WITH is only performed when field group is immediately followed by field group in the temporary dataset.
    Loops over an extract dataset cannot be nested. However, several contiguous loops are permitted.
    The sequence of the control level changes within the LOOP must correspond to the sort sequence.
    Totals can only be calculated within control footer processing.
    Extracts allow only appends (EXTRACT), sorting (SORT) and sequential processing (LOOP).
    Once a SORT or LOOP has occurred, the intermediate dataset is frozen and cannot be expanded with EXTRACT. Operations that insert into or delete from EXTRACT datasets are not supported.
    Extracts allow for several record types (FIELD-GROUPS) with fields that can be set dynamically (INSERT is not a declarative statement!). Internal tables have a single, statically-defined line type.
    Internal tables use the sequence of table fields according to the declaration for the hierarchy of the control leve l. The control level structure for internal tables is therefore static, and is independent of which criteria were used to sort the internal table.
    Extracts do not depend on the field sequence for control level processing: a re-sort or a completely different control level process can take place. The control level structure for extract datasets is therefore dynamic. It corresponds exactly to the sort key of the extract dataset. The sort key is the sequence of fields from the field group HEADER, and is used to sort the extract dataset.
    Extracts rely on the compiler to determine which combinations of group levels and a cumulating field the control level totals desire. The desired control level totals are determined by the processing of LOOP ... ENDLOOP blocks. Internal tables build the control level total with the SUM statement.
    This procedure leads to high resource depletion for totaling control levels in internal tables.
    Regards,
    Chandru

  • Decimals upto 2 in alv report

    Hi to all abapers,
    I have to show only upto 2 decimals in the field of an alv report but it is of type p and decimals 4.I dont want to change its type to 2 decimals due to some calculations.So can we show upto 2 decimals in the report?
    Thanks in Advance,
    Salish

    Hi,
    Here is the code
    <b>Here act_pckeff is of type p decimals 4 and i want it upto 2 decimals in the output.</b>
    PERFORM fldcat  USING i_fieldcat 'ACT_PCKEFF'       'DEC'       'Actual Efficiency "Packed"'    ''."13
    FORM fldcat USING p_ifieldcat TYPE lvc_t_fcat
                          value(p_name)
                          value(p_type)
                          value(p_desc)
                          value(p_key).
      DATA: w_fldcat TYPE LINE OF lvc_t_fcat.
      CLEAR w_fldcat.
      w_fldcat-fieldname = p_name.
      w_fldcat-datatype = p_type.
      w_fldcat-reptext = p_desc.
      w_fldcat-key     = p_key.
      IF w_fldcat-fieldname = 'AUFNR'.
        w_fldcat-no_zero = 'X'.
      ENDIF.
      IF p_type = 'CURR' OR p_type = 'QUAN'..
        w_fldcat-do_sum = 'X'.
      ENDIF.
      <b>IF p_name = 'ACT_PCKEFF'.
        w_fldcat-decimals = 2.
        w_fldcat-do_sum = 'C'.
      ENDIF</b>.
      APPEND w_fldcat TO p_ifieldcat.
    ENDFORM.                    " fldcat
    Regards,
    Salish.

  • Add a row after Total row in ALV report

    Hi Experts,
    I have a report is displayed by  ALV format(not use function module to display it but use Class cl_gui_custom_container),I want to add a row after the total row. for example,
    Customer   amount1    amount2    amount3 
    10000         1,234        1,000         2,000
    10001         4,000        2,000         1,000
    10002         1,300        1,000         3,000
    11000         1,200        4,000         3,000
         Total:     7,734        8,000         9,000
    Ratio%        31.27       32.34          36.39
    the row of 'Total' is calculated by fieldcat-do_sum = 'X' But after the Total row we need a Ratio row to display the ratio. Yes we can calculate the total amout and ratio and then append it into the output itab, but we don't like this solution.We want to keep the total function in the ALV report.Any experts can poit me a direction. Thanks in advance.
    Joe

    Djoe,
    First you need to handle the user command,in order to capture the button action. For this you need to implment a class, i  am attaching sample codes here
    In top include write the following code
    CLASS lcl_event_handler DEFINITION .
      PUBLIC SECTION .
        METHODS:
         handle_toolbar  FOR EVENT toolbar                   " To add new functional buttons to the ALV toolbar
                         OF        cl_gui_alv_grid
                         IMPORTING e_object,
         handle_user_command FOR EVENT user_command          " To implement user commands
                            OF cl_gui_alv_grid
                            IMPORTING e_ucomm .
      PRIVATE SECTION.
    ENDCLASS.                                               " Lcl_event_handler DEFINITION
    Now   <b>Class implementation</b>
    CLASS lcl_event_handler IMPLEMENTATION .
      METHOD handle_toolbar.                                " Handle Toolbar
        PERFORM f9500_handle_toolbar USING e_object.
    ENDMETHOD .                                            " Handle_toolbar
      METHOD handle_user_command .                          " Handle User Command
        PERFORM f9600_handle_user_command USING e_ucomm .
      ENDMETHOD.
    ENDCLASS .                                              " lcl_event_handler IMPLEMENTATION
    FORM f9600_handle_user_command USING p_e_ucomm TYPE sy-ucomm.
      CONSTANTS:c_newl(4) TYPE c
                          VALUE 'NEWL',               " New line
                c_copy(4) TYPE c
                          VALUE 'COPY',               " Copy
                c_corr(4) TYPE c
                          VALUE 'CORR'.               " Correction
      CASE p_e_ucomm .
        WHEN c_newl.
    Create a new line
          PERFORM f9610_insert_new_line.
    ENDFORM.                                          " f9600_handle_user_command
    FORM f9610_insert_new_line .
    *Data Declarations
      DATA: lt_rows     TYPE lvc_t_row,                 " Itab for row property
            ls_rows     TYPE lvc_s_row,                 " Work area for row
            lv_cntid    TYPE i.                         " Counter
      DATA: gv_index TYPE sy-index.
      CLEAR gs_last.
      CALL METHOD gr_alvgrid->get_selected_rows
        IMPORTING
          et_index_rows = lt_rows.
      READ TABLE lt_rows INTO ls_rows INDEX 1.
      IF sy-subrc EQ 0.
        gv_index = ls_rows-index + 1.
      ELSE.
        gv_index = 1.
      ENDIF.
      DESCRIBE TABLE gt_last LINES lv_cntid.
      lv_cntid = lv_cntid + 1.
      gs_last-cntid = lv_cntid.
      INSERT gs_last INTO gt_last INDEX gv_index.
      LOOP AT gt_last INTO gs_last FROM gv_index TO gv_index.
    Make the new line editable
        PERFORM f9611_style.
      ENDLOOP.
      CALL METHOD gr_alvgrid->refresh_table_display
        EXCEPTIONS
          finished = 1
          OTHERS   = 2.
    ENDFORM.                    " f9610_insert_new_line
    You can ask questions doubts if any!
    regards
    Antony Thomas

  • Percentage in alv report

    Hi Expert,
                In alv report percentage calculation.Here we have a problem, In total column it will adding  the fields
           in percentage column, but i want to calculate the percentage in run time.
                Example:   
                              A               B                       %*100
                             10               20                      20%
                             20               40                      20%
         TOTAL:         30               60                      40 -
    >it is a total but not percentage 
    Thank you,
    Dinesh.

    Hi,
    1. In the ALV output tab add extra fields that are the same as those on which you are sorting and contain the same values.
    2. In the Field Catalog you must add these fields but they must be hidden i.e. no_out = 'X'.
    3. These fields must be included in the Sort Catalog with subtot = 'X'.
    4. In order to handle the final total line in your layout for the ALV you must set field no_totalline'X' because you are going to be taking this over as well.
    5. Create a form called SUBTOTAL_TEXT or similar structured as follows:
    form subtotal_text using ep_subtot_line like output_tabes_subtottxt type slis_subtot_text.
    In this form you will do the percentage calculation again at total level. The structure ep_subtot_line
    will contain a field for each of the fields in your output_tab i.e. ep_subtot_line-sales,
    ep_subtot_line-cost and ep_subtot_line-margin. Put the margin calculation into ep_subtot_line-margin.
    6. In the eventtab that you pass to the ALV_GRID function module you must create a record with the
    field name = 'SUBTOTAL_TEXT' and the field form = the name of the form you created in step 5 above.

  • How to display subtotals in separate column in alv report?

    hi,
    I am displayed the subtotals  for QUantity field BDMNG in Reuse_alv_grid_display  in the same column.
    but I want to display subtotal in separate column.
    How to display subtotals in separate column in alv report?
    thanks&regards.
    samba.k

    Hi
    As far as i know you can't do this,the option you have is to create one more column (subtotal) and populate it by manual calculation at every subtotal (not alv subtotal but yours) .
    Best Regards
    Yossi

  • Add buttons in ALV Report output

    Dear Friends,
    I am developing one ALV report in PP moule for calculating Shelf Life. The output is coming properly in ALV.
      But my additional requirement is ADD coustomise buttons in ALV Reports.
    Please give me an idea how can I insert buttons in my alv report?
    Thanks & Regards
    Vasu

    Hi vasu,
    consider the code given below.
          FORM F4200_PF_STATUS_SET                                      *
    FORM f4200_pf_status_set USING i_extab TYPE slis_t_extab.
      REFRESH i_extab.
      PERFORM f4210_exclude_fcodes CHANGING i_extab.
    The PF status is an exact copy of the PF status 'STANDARD' of program
    SAPLSALV but with command 'CHNG' added to it.
      SET PF-STATUS 'ZSOM_STANDARD' EXCLUDING i_extab.
    ENDFORM.
    *&      Form  f4210_exclude_fcodes
    FORM f4210_exclude_fcodes USING i_extab TYPE slis_t_extab.
      DATA: ws_fcode TYPE slis_extab.
      CLEAR ws_fcode.
      ws_fcode = '&EB9'.            " Call up Report.
      APPEND ws_fcode TO i_extab.
      ws_fcode = '&ABC'.            " ABC Analysis.
      APPEND ws_fcode TO i_extab.
      ws_fcode = '&NFO'.            " Info Select.
      APPEND ws_fcode TO i_extab.
      ws_fcode = '&LFO'.            " Information.
      APPEND ws_fcode TO i_extab.
    ENDFORM.                    " f4210_exclude_fcodes
    *&      Form  f4300_user_command
    FORM f4300_user_command USING ucomm LIKE sy-ucomm
                                             selfield TYPE slis_selfield.
      CASE ucomm.
        WHEN '&IC1'.                              "Double Click line Item
          READ TABLE i_data INDEX selfield-tabindex.
          IF i_data-qmnum NE space.
            SET PARAMETER ID 'IQM' FIELD i_data-qmnum.
            CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN.
            CLEAR ucomm.
          ENDIF.
        WHEN 'CHNG'.                          " Change Notification Icon
          READ TABLE i_data INDEX selfield-tabindex.
          IF i_data-qmnum NE space.
            SET PARAMETER ID 'IQM' FIELD i_data-qmnum.
            CALL TRANSACTION 'IW52' AND SKIP FIRST SCREEN.
          CLEAR ucomm.
          ENDIF.
      ENDCASE.
      CLEAR ucomm.
    ENDFORM.                    " f4300_user_command
    EXPLANATION
    In this program, first we created a PF status (ZSOM_STANDARD), which was an exact copy of STANDARD of program SAPLSALV through transaction SE41 (Menu Painter). Then we added another button to it,with a new fcode called ‘CHNG’.  After this this we set this PF status instead of STANADRD.
    We initialize a third event USER_COMMAND and associate a form with it. In this form we can capture the function codes and write any functionality under it. If we write functionality for an existing fcode, then this gets precedence over the default functionality that might be associated with it.
    In this example, we capture a standard fcode ‘&IC1’ that is nothing but double clicking a line of the report.  We are capturing the notification number of that line and calling transaction IW52 with it. We are also doing the same when a user clicks on the new ‘Change Notification’ button.
    When the user clicks the “Back’ button in IW52, it comes back to the report.
    Please reward for the same.
    Message was edited by: Prakhar Saxena

  • HOW TO ADD NEW VARIABLE DATAS ON ALV REPORT

    Hi gurus,
               I have cretaed one alv report using
    REUSE_ALV_GRID_DISPLAY.
    I HAVE CALCULATED SOME TOTALS AND STORED ON
    ONE VARIABLE .
    that variable name is 'toterror'.
    now i want to add  this variable on first line OF ALV REPORT.
    that is i should get LIKE THIS.
    PERNR   TEXT     ACTION  [ TITLES OF FIELDS ].THEN
    TOTAL ERROR RECORDS  '900'.
    THEN THE CORRESPONDING FIELDS DATA SHOULD BE DISPLAYED.
    HELP ME.
    THANKS IN ADVANCE.

    Hi
    Thanks Ajeet.
    The scenario is that I have to create a formula (contract end date-current date) and have to display the result using exeption to highlight the contracts ending in 30-60 days.
    The problem is that the info provider does not have any infoobject for date(only valid to and validity start date)
    I have created a formula variable on valid to date using replacement path. But dont have any variable to use for current date.
    The only time char in the cube is Fiscal yera variant.
    How should I go futher creating such formula? Shall I user customer exit variable? But I dont have any date char to create on.
    Can you shed some light on this problem
    Thanks

  • Authorization on ALV Report

    Hello everyone,
    I have an ALV report with a radiobutton in the selection screen. This radiobutton has 4 options(for example): Office A, Office B, Office C, Office D.
    When i choose Office C, the ALV will report data concerning only to this Office (all fields in the table are common to all Offices).
    But besides this, i would like to check at the beginning if the user trying to access the ALV report is from Office A,B, C or D. If he is from Office B, he should only have access to ALV with radiobutton chosen to Office B.
    Can anyone help me with a suggestion ?
    I read something about authorization groups. Is this an option here ?

    Here is a sample code with similar functionality... Using this to develop your logic....
    Type pools Declaration..............................................*
    TYPE-POOLS SLIS.                       " Global types
    Range tables........................................................*
    RANGES R_LIFEX FOR LIKP-LIFEX.         " External Identification of
                                           " Delivery note
    selection screen elememts...........................................*
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-009.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS:
       P_OPEN RADIOBUTTON GROUP R1 DEFAULT 'X'.
                                           " Open orders
    SELECTION-SCREEN COMMENT (20) TEXT-001 FOR FIELD P_OPEN.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS:
       P_PREPAY RADIOBUTTON GROUP R1.      " Prepay orders
    SELECTION-SCREEN COMMENT (20) TEXT-002 FOR FIELD P_PREPAY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK B1.
    Constants variables.................................................*
    CONSTANTS:
       C_L        TYPE C VALUE 'L',        " SD document object
       C_J        TYPE C VALUE 'J',        " SD document category
       C_A        TYPE C VALUE 'A',        " Status of Not yet processed
       C_B        TYPE C VALUE 'B',        " Status of Partially processed
       C_LF(2)    TYPE C VALUE 'LF',       " Delivery Type
       C_E        TYPE C VALUE 'E',        " Language
       C_TON(3)   TYPE C VALUE 'TON',      " Material unit
       C_TO(2)    TYPE C VALUE 'TO',       " Material unit
       C_X        TYPE C VALUE 'X',        " Parameter value
       C_I        TYPE C VALUE 'I',        " Sign
       C_CP(2)    TYPE C VALUE 'CP',       " Option
       C_PP1(3)   TYPE C VALUE 'PP*',      " Prepay order
       C_PP2(3)   TYPE C VALUE 'pP*',      " Prepay order
       C_PP3(3)   TYPE C VALUE 'pp*',      " Prepay order
       C_PP4(3)   TYPE C VALUE 'Pp*',      " Prepay order
       C_0        TYPE C VALUE  '0',       " Zero
       C_UREA(40) TYPE C VALUE 'UREA(GRANULAR)',
                                           " Material name
       C_30%(3)   TYPE C VALUE '30%',      " Material name
       C_32%(3)   TYPE C VALUE '32%',      " Material name
       C_28%(3)   TYPE C VALUE '28%',      " Material name
       C_NH3(3)   TYPE C VALUE 'NH3',      " Material name
       C_AN(3)    TYPE C VALUE 'AN',       " Material name
       C_UAN(3)   TYPE C VALUE 'UAN',      " Material name
       C_30(2)    TYPE C VALUE '30',       " Output length
       C_20(2)    TYPE C VALUE '20',       " Output length
       C_1_102311 TYPE P DECIMALS 6    VALUE '1.102311',
                                           " Conversion factor
    Begin of Deletion CS1K931253
      C_METHANOL(40)           TYPE C VALUE 'METHANOL',
                                          " Material name
    End of Deletion CS1K931253
       C_TOP_OF_PAGE(15)        TYPE C VALUE 'TOP_OF_PAGE',
                                           " Top of page event
       C_BEFORE_LINE_OUTPUT(25) TYPE C VALUE 'BEFORE_LINE_OUTPUT',
                                           " Before line output event
       C_END_OF_LIST(15)        TYPE C VALUE 'END_OF_LIST',
                                           " End of list
    Begin of Insertion CS1K931253
       C_OPEN(4)                TYPE C VALUE 'OPEN',
                                           " Open orders
       C_PREPAY(6)              TYPE C VALUE 'PREPAY'.
                                           " Prepay orders
    End of Insertion CS1K931253
    Working Variable declarations                                        *
    DATA:
      W_NUMBER    TYPE I,                  " Plant number
      W_INDEX     TYPE SY-TABIX VALUE '1', " Table Index
      W_MATNR     TYPE LIPS-MATNR,         " Material Number
    Begin of Deletion - CS1K931253
    W_LFIMG     TYPE LIPS-LFIMG,         " Actual quantity delivered
    W_TOTAL32   TYPE LIPS-LFIMG,         " Actual quantity delivered
    End of Deletion - CS1K931253
      W_LFIMG     TYPE P DECIMALS 3,       " Actual quantity delivered
      W_TOTAL32   TYPE P DECIMALS 3,       " Actual quantity delivered
      W_INCR      TYPE I VALUE 5,          " Increment variable
      W_PRDCT(40) TYPE C,                  " Product Name
    Field string Declarations                                            *
    *Field string to hold open delivery quantities
      BEGIN OF FS_OPEN_DEL,
        VTEXT     TYPE TVSTT-VTEXT,        " Plant name
        MAT_NUM   TYPE I,                  " Plant Number
        PRDCT(40) TYPE C,                  " Product Name
        QTYA      TYPE LIPS-LFIMG,         " Quantity moved by Truck
        QTYB      TYPE LIPS-LFIMG,         " Quantity moved by Rail
        QTYC      TYPE LIPS-LFIMG,         " Quantity moved by Barge
        QTYD      TYPE LIPS-LFIMG,         " Quantity moved by Pipe
        QTYE      TYPE LIPS-LFIMG,         " Quantity moved by Vessel
        QTYT      TYPE LIPS-LFIMG,         " Total Quantity moved
        QTYG      TYPE LIPS-LFIMG,         " Quantity moved by
        VRKME     TYPE LIPS-VRKME,         " Sales unit
      END OF FS_OPEN_DEL,
    *Field string to hold open deliveries
      BEGIN OF FS_LIKPUK,
        VBELN TYPE LIKP-VBELN,             " Delivery
      END OF FS_LIKPUK,
    *Field string to hold Ship point description
      BEGIN OF FS_TVSTT,
        VSTEL TYPE LIKP-VSTEL,             " Plant
        VTEXT TYPE TVSTT-VTEXT,            " Plant Name
      END OF FS_TVSTT,
    *Field string to hold delivery item documents data
      BEGIN OF FS_LIPS,
        VBELN TYPE LIKP-VBELN,             " Delivery
        POSNR TYPE LIPS-POSNR,             " Item
        MATNR TYPE LIPS-MATNR,             " Material Number
        LFIMG TYPE LIPS-LFIMG,             " Quantity delivered
        VRKME TYPE LIPS-VRKME,             " Sales unit
      END OF FS_LIPS,
    *Field string to hold delivery header documents data
      BEGIN OF FS_LIKP,
        VBELN TYPE LIKP-VBELN,             " Delivery
        VSTEL TYPE LIKP-VSTEL,             " Plant
        VSBED TYPE LIKP-VSBED,             " Shipping Condition
      END OF FS_LIKP,
    Field string to hold Plants and its delivered quantities
      BEGIN OF FS_DEL_QUAN,
        PRODNAME(40),                      " Product Name
        VTEXT TYPE TVSTT-VTEXT,            " Plant
        VSBED TYPE LIKP-VSBED,             " Shipping Condition
        LFIMG TYPE LIPS-LFIMG,             " Delivered quantity
        VRKME TYPE LIPS-VRKME,             " Sales unit
      END OF FS_DEL_QUAN,
    Field String to hold material text
      BEGIN OF FS_MAKT,
        MATNR TYPE MAKT-MATNR,             " Material Number
        MAKTX TYPE MAKT-MAKTX,             " Material text
      END OF FS_MAKT,
      FS_FIELDCAT TYPE LINE OF SLIS_T_FIELDCAT_ALV,
      FS_EVENTS   TYPE LINE OF SLIS_T_EVENT.
    Internal Table Declarations                                          *
    DATA:
    Table to hold open delivery quantities
      T_OPEN_DEL LIKE STANDARD TABLE
                   OF FS_OPEN_DEL,
    Table to hold open deliveries
      T_LIKPUK LIKE STANDARD TABLE
                 OF FS_LIKPUK,
    Table to hold Ship point description
      T_TVSTT LIKE STANDARD TABLE
                OF FS_TVSTT,
    Table to hold delivery item documents data
      T_LIPS LIKE STANDARD TABLE
               OF FS_LIPS,
    Table to hold delivery item documents data
      T_LIPS2 LIKE STANDARD TABLE
               OF FS_LIPS,
    Table to hold delivery header documents data
      T_LIKP LIKE STANDARD TABLE
               OF FS_LIKP,
    Table to hold delivery header documents data
      T_LIKP2 LIKE STANDARD TABLE
               OF FS_LIKP,
    Table to hold Plants and its delivered quantities
      T_DEL_QUAN LIKE STANDARD TABLE
                OF FS_DEL_QUAN,
    Table to hold Material text
      T_MAKTX LIKE STANDARD TABLE
                OF FS_MAKT,
    Field catalog...
      T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    Events...
      T_EVENTS   TYPE SLIS_T_EVENT.
    START-OF-SELECTION                                                  *
    START-OF-SELECTION.
    Retrives Open deliveries
      PERFORM GET_DELS.
    Retrives Open delivery data
      PERFORM GET_ORDER_DATA.
    Retrives Delivery item data
      PERFORM GET_ITEM_DATA.
    Gets Plant description
      PERFORM GET_SHIPPOINT_TEXT.
    Fetch Material description.
      PERFORM GET_MATTEXT.
    Connects Plant and products delivered by it
      PERFORM CONNECT_PLANT_PRODUCT_DATA.
    Sums up quantities based on Shipping condition
      PERFORM COLLECT_DATA_BY_SHIPTYPE.
    Changing UAN 28% to UAN 32%
      PERFORM CHANGE_UAN.
    END-OF-SELECTION                                                    *
    END-OF-SELECTION.
    Displays the data
      PERFORM DISPLAY_DATA.
    Form  GET_DELS
    This subroutine gets all open deliveries
    No Parameter interface
    FORM GET_DELS.
    *Get all open deliveries
       SELECT VBELN                        " Delivery
    APPENDING TABLE T_LIKPUK
         FROM VBUK
      PACKAGE SIZE 5000
        WHERE ( WBSTK = C_A OR WBSTK = C_B )
          AND VBTYP = C_J
          AND VBOBJ = C_L.
      ENDSELECT.
      IF SY-SUBRC NE 0.
        MESSAGE I280(LF).
        STOP.
      ENDIF.                               " IF SY-SUBRC NE 0.
    ENDFORM.                               " GET_DELS
    Form  GET_ORDER_DATA
    This subroutine gets delivery header data
    No Parameter interface
    FORM GET_ORDER_DATA .
      IF  P_PREPAY EQ C_X.
    Fill the Pattern required as pp, any case.
        REFRESH R_LIFEX.
        R_LIFEX-SIGN = C_I.
        R_LIFEX-OPTION = C_CP.
        R_LIFEX-LOW = C_PP1.
        APPEND R_LIFEX.
        R_LIFEX-LOW = C_PP2.
        APPEND R_LIFEX.
        R_LIFEX-LOW = C_PP3.
        APPEND R_LIFEX.
        R_LIFEX-LOW = C_PP4.
        APPEND R_LIFEX.
    Get delivery information.
        IF T_LIKPUK IS NOT INITIAL.
          SELECT VBELN                     " Delivery
                 VSTEL                     " Plant
                 VSBED                     " Shipping condition
            FROM LIKP
            INTO TABLE T_LIKP
             FOR ALL ENTRIES IN T_LIKPUK
           WHERE VBELN = T_LIKPUK-VBELN
             AND LFART = C_LF
             AND LIFEX IN R_LIFEX
             AND LIFSK EQ SPACE.
          IF SY-SUBRC NE 0.
            MESSAGE I280(LF).
            STOP.
          ENDIF.                           " IF SY-SUBRC NE 0.
        ENDIF.                             " IF T_LIKPUK IS NOT INITIAL
       ELSE.
        IF T_LIKPUK IS NOT INITIAL.
          SELECT VBELN                     " Delivery
                 VSTEL                     " Plant
                 VSBED                     " Shipping condition
            FROM LIKP
            INTO TABLE T_LIKP
             FOR ALL ENTRIES IN T_LIKPUK
           WHERE VBELN = T_LIKPUK-VBELN
             AND LFART = C_LF
             AND LIFSK EQ SPACE.
          IF SY-SUBRC NE 0.
            MESSAGE I280(LF).
            STOP.
          ENDIF.                           " IF SY-SUBRC NE 0.
        ENDIF.                             " IF T_LIKPUK IS NOT INITIAL
      ENDIF.                               " IF P_PREPAY EQ C_X.
      T_LIKP2 = T_LIKP.
      REFRESH T_LIKPUK.
    ENDFORM.                               " GET_ORDER_DATA
    Form  GET_ITEM_DATA
    This subroutine gets delivery item data
    No Parameter interface
    FORM GET_ITEM_DATA .
    Get delivery item information.
      IF T_LIKP IS NOT INITIAL.
        SELECT VBELN                       " Delivery
               POSNR                       " Item
               MATNR                       " Material Number
               LFIMG                       " Delivered Quantity
               VRKME                       " Sales Unit
          FROM LIPS
          INTO TABLE T_LIPS
           FOR ALL ENTRIES IN T_LIKP
         WHERE VBELN = T_LIKP-VBELN
           AND LFIMG NE 0.
        IF SY-SUBRC NE 0.
          STOP.
        ENDIF.                             " IF SY-SUBRC NE 0.
      ENDIF.                               " IF T_LIKP IS NOT INITIAL.
    Begin of Insertion CS1K931253
      SORT T_LIPS BY VBELN POSNR.
      DELETE ADJACENT DUPLICATES FROM T_LIPS COMPARING VBELN.
    End of Insertion  CS1K931253
      T_LIPS2 = T_LIPS.
    ENDFORM.                               " GET_ITEM_DATA
    Form  GET_SHIPPOINT_TEXT
    This subroutine gets Shipping point text
    No Parameter interface
    FORM GET_SHIPPOINT_TEXT .
    Retrieve Shipping point texts, for unique shipping points.
      SORT T_LIKP2 BY VSTEL.
      DELETE ADJACENT DUPLICATES FROM T_LIKP2 COMPARING VSTEL.
      IF T_LIKP2 IS NOT INITIAL.
        SELECT VSTEL                       " Plant
               VTEXT                       " Plant description
          FROM TVSTT
          INTO TABLE T_TVSTT
           FOR ALL ENTRIES IN T_LIKP2
         WHERE SPRAS = C_E
           AND VSTEL = T_LIKP2-VSTEL.
        IF SY-SUBRC NE 0.
    Sy-subrc check not required
        ENDIF.                             " IF SY-SUBRC NE 0
      ENDIF.                               " IF T_LIKP2 IS NOT INITIAL.
    ENDFORM.                               " GET_SHIPPOINT_TEXT
    *& Form  GET_MATTEXT
    This subroutine fetches Material description
    No Parameter interface
    FORM GET_MATTEXT .
      SORT T_LIPS2 BY MATNR.
      DELETE ADJACENT DUPLICATES FROM T_LIPS2 COMPARING MATNR.
    Fetch Matrial text
      IF T_LIPS2 IS NOT INITIAL.
        SELECT MATNR                       " Material Number
               MAKTX                       " Material text
          INTO TABLE T_MAKTX
          FROM MAKT
       FOR ALL ENTRIES IN T_LIPS2
         WHERE MATNR EQ T_LIPS2-MATNR
    Begin of insertion CS1K931253
           AND MATNR NE '000000000000030014'
    End of insertion CS1K931253
           AND SPRAS = SY-LANGU.
        IF SY-SUBRC NE 0.
    Sy-subrc check not required
        ENDIF.                             " IF SY-SUBRC NE 0
      ENDIF.                               " IF T_LIPS2 IS NOT INITIAL.
    ENDFORM.                               " GET_MATTEXT
    Form  CONNECT_PLANT_PRODUCT_DATA
    This subroutine Connects Plant and quantity delivered by it
    No Parameter interface
    FORM CONNECT_PLANT_PRODUCT_DATA.
      SORT T_LIKP  BY VBELN.
      SORT T_TVSTT BY VSTEL.
      SORT T_MAKTX BY MATNR.
      LOOP AT T_LIPS INTO FS_LIPS.
    Getting Plant Name
        READ TABLE T_LIKP  INTO FS_LIKP  WITH KEY VBELN = FS_LIPS-VBELN
                                         BINARY SEARCH.
        IF SY-SUBRC EQ 0.
          READ TABLE T_TVSTT INTO FS_TVSTT WITH KEY VSTEL = FS_LIKP-VSTEL
                                           BINARY SEARCH.
          IF SY-SUBRC EQ 0.
            FS_DEL_QUAN-VTEXT = FS_TVSTT-VTEXT.
          ENDIF.                           " IF SY-SUBRC EQ 0
        ENDIF.                             " IF SY-SUBRC EQ 0
    Getting Ship Type.
        FS_DEL_QUAN-VSBED = FS_LIKP-VSBED.
    Getting Quantity.
        IF FS_LIPS-VRKME EQ C_TO.
    Begin of Deletion - CS1K931174
         PERFORM CONVERT_UNIT.
    End of Deletion - CS1K931174
    Begin of Insertion - CS1K931174
           FS_DEL_QUAN-VRKME = C_TON.
           FS_DEL_QUAN-LFIMG = FS_LIPS-LFIMG * C_1_102311.
    End of Insertion - CS1K931174
        ELSE.
          FS_DEL_QUAN-LFIMG = FS_LIPS-LFIMG.
          FS_DEL_QUAN-VRKME = FS_LIPS-VRKME.
        ENDIF.                             " IF FS_LIPS-VRKME EQ C_TO
    Getting Product Name
        W_MATNR   = FS_LIPS-MATNR.
        SHIFT W_MATNR LEFT DELETING LEADING C_0.
        CASE W_MATNR.
    Begin of Deletion - CS1K931174
        WHEN '10023'.
          FS_DEL_QUAN-PRODNAME = C_METHANOL.
    End of Deletion - CS1K931174
          WHEN '10024'.
            FS_DEL_QUAN-PRODNAME = C_UREA.
          WHEN '10026'.
            FS_DEL_QUAN-PRODNAME = C_30%.
          WHEN '10027'.
            FS_DEL_QUAN-PRODNAME = C_32%.
          WHEN '10030'.
            FS_DEL_QUAN-PRODNAME = C_NH3.
          WHEN '10031'.
            FS_DEL_QUAN-PRODNAME = C_28%.
          WHEN '36052'.
            FS_DEL_QUAN-PRODNAME = C_AN.
          WHEN OTHERS.
            READ TABLE T_MAKTX INTO FS_MAKT WITH KEY MATNR = FS_LIPS-MATNR
                                            BINARY SEARCH.
            IF SY-SUBRC EQ 0.
              FS_DEL_QUAN-PRODNAME = W_MATNR.
            ENDIF.                         " IF SY-SUBRC NE 0
        ENDCASE.                           " CASE FS_MATNR
    Begin of Insertion - CS1K931174
        IF W_MATNR NE '10023'.
    End of Insertion - CS1K931174
          APPEND FS_DEL_QUAN TO T_DEL_QUAN.
    Begin of Insertion - CS1K931174
        ENDIF.                             " IF W_MATNR NE '10023'.
    End of Insertion - CS1K931174
        CLEAR:
          FS_DEL_QUAN,
          FS_LIKP,
          FS_LIPS,
          FS_TVSTT,
          FS_MAKT.
      ENDLOOP.                             " LOOP AT T_LIPS INTO FS_LIPS
      REFRESH:
        T_LIKP,
        T_LIPS.
      CLEAR:
        FS_LIKP,
        FS_LIPS.
    ENDFORM.                               " CONNECT_PLANT_PRODUCT_DATA
    Form  COLLECT_DATA_BY_SHIPTYPE
    This subroutine adds quantity based on shipping condition
    No Parameter interface
    FORM COLLECT_DATA_BY_SHIPTYPE .
      SORT T_DEL_QUAN BY PRODNAME VTEXT VSBED.
      LOOP AT T_DEL_QUAN INTO FS_DEL_QUAN.
    Adding delivered quantites based on Shiiping condition
        CASE FS_DEL_QUAN-VSBED.
          WHEN '01'.
            FS_OPEN_DEL-QTYA = FS_OPEN_DEL-QTYA + FS_DEL_QUAN-LFIMG.
          WHEN '02'.
            FS_OPEN_DEL-QTYB = FS_OPEN_DEL-QTYB + FS_DEL_QUAN-LFIMG.
          WHEN '03'.
            FS_OPEN_DEL-QTYC = FS_OPEN_DEL-QTYC + FS_DEL_QUAN-LFIMG.
          WHEN '04'.
            FS_OPEN_DEL-QTYD = FS_OPEN_DEL-QTYD + FS_DEL_QUAN-LFIMG.
          WHEN '05'.
            FS_OPEN_DEL-QTYE = FS_OPEN_DEL-QTYE + FS_DEL_QUAN-LFIMG.
        ENDCASE.                           " CASE FS_DEL_QUAN-VSBED
        FS_OPEN_DEL-VRKME = FS_DEL_QUAN-VRKME.
        AT END OF VTEXT.
          FS_OPEN_DEL-VTEXT = FS_DEL_QUAN-VTEXT.
          FS_OPEN_DEL-PRDCT = FS_DEL_QUAN-PRODNAME.
          FS_OPEN_DEL-QTYT  = FS_OPEN_DEL-QTYA + FS_OPEN_DEL-QTYB +
                              FS_OPEN_DEL-QTYC + FS_OPEN_DEL-QTYD +
                              FS_OPEN_DEL-QTYE.
          CASE FS_OPEN_DEL-PRDCT.
    Begin of Deletion - CS1K931174
           WHEN C_METHANOL.
             FS_OPEN_DEL-MAT_NUM = 1.
    End of Deletion - CS1K931174
            WHEN C_UREA.
              FS_OPEN_DEL-MAT_NUM = 2.
            WHEN C_30%.
              FS_OPEN_DEL-MAT_NUM = 3.
            WHEN C_32%.
              FS_OPEN_DEL-MAT_NUM = 3.
            WHEN C_28%.
              FS_OPEN_DEL-MAT_NUM = 3.
            WHEN C_NH3.
              FS_OPEN_DEL-MAT_NUM = 4.
            WHEN C_AN.
              FS_OPEN_DEL-MAT_NUM = 5.
            WHEN OTHERS.
              IF FS_OPEN_DEL-PRDCT NE W_PRDCT.
                W_INCR = W_INCR + 1.
              ENDIF.                       " IF FS_OPEN_DEL-PRDCT...
              W_PRDCT = FS_OPEN_DEL-PRDCT.
              FS_OPEN_DEL-MAT_NUM = W_INCR.
          ENDCASE.                         " CASE FS_OPEN_DEL-PRDCT
          APPEND FS_OPEN_DEL TO T_OPEN_DEL.
          CLEAR FS_OPEN_DEL.
        ENDAT.                             " AT END OF VTEXT.
      ENDLOOP.                             " LOOP AT T_DEL_QUAN INTO ...
      REFRESH T_DEL_QUAN.
    ENDFORM.                               " COLLECT_DATA_BY_SHIPTYPE
    Form  CHANGE_UAN
    This subroutine to convert 28%UAN to 32%UAN
    No Parameter interface
    FORM CHANGE_UAN .
    DATA LFS_OPEN_DEL2 LIKE FS_OPEN_DEL.
      SORT T_OPEN_DEL BY VTEXT PRDCT.
    Converting 28% UAN to 32% UAN
      LOOP AT T_OPEN_DEL INTO FS_OPEN_DEL.
        IF FS_OPEN_DEL-MAT_NUM = 3.
          CASE FS_OPEN_DEL-PRDCT.
            WHEN C_32%.
              READ TABLE T_OPEN_DEL INTO LFS_OPEN_DEL2 WITH KEY
                                         VTEXT = FS_OPEN_DEL-VTEXT
                                         PRDCT = C_28% BINARY SEARCH.
              IF SY-SUBRC EQ 0.
                 FS_OPEN_DEL-QTYG = FS_OPEN_DEL-QTYT + ( LFS_OPEN_DEL2-QTYT
    ( 875 / 1000 ) ).
              ELSE.
                FS_OPEN_DEL-QTYG = FS_OPEN_DEL-QTYT.
              ENDIF.                       " IF SY-SUBRC EQ 0 .
              W_TOTAL32 = W_TOTAL32 + FS_OPEN_DEL-QTYG.
              MODIFY TABLE T_OPEN_DEL FROM FS_OPEN_DEL TRANSPORTING QTYG.
            WHEN C_28%.
              READ TABLE T_OPEN_DEL INTO LFS_OPEN_DEL2 WITH KEY
                                         VTEXT = FS_OPEN_DEL-VTEXT
                                         PRDCT = C_32% BINARY SEARCH.
              IF SY-SUBRC NE 0.
                FS_OPEN_DEL-QTYG = ( FS_OPEN_DEL-QTYT * ( 875 / 1000 ) ).
                W_TOTAL32 = W_TOTAL32 + FS_OPEN_DEL-QTYG.
                MODIFY TABLE T_OPEN_DEL FROM FS_OPEN_DEL TRANSPORTING QTYG.
              ENDIF.                       " IF SY-SUBRC NE 0.
            WHEN  C_30%.
               FS_OPEN_DEL-QTYG = ( FS_OPEN_DEL-QTYT * ( 9375 / 10000 ) ).
               W_TOTAL32 = W_TOTAL32 + FS_OPEN_DEL-QTYG.
               MODIFY TABLE T_OPEN_DEL FROM FS_OPEN_DEL TRANSPORTING QTYG.
          ENDCASE.                         " CASE FS_OPEN_DEL-PRDCT
        ENDIF.                             " IF FS_OPEN_DEL-MAT_NUM = 3
      ENDLOOP.                             " LOOP AT T_OPEN_DEL INTO WA...
    ENDFORM.                               " CHANGE_UAN
    Form  DISPLAY_DATA
    This subroutine displays data
    No Parameter interface
    FORM DISPLAY_DATA.
      IF T_OPEN_DEL IS NOT INITIAL.
    Adding events to table T_EVENTS
        PERFORM ADD_EVENTS.
    Generating Fieldcatlog
        PERFORM ADD_FIELDCATLOG.
        SORT T_OPEN_DEL BY MAT_NUM VTEXT PRDCT.
        CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
         EXPORTING
          I_INTERFACE_CHECK              = ' '
          I_BYPASSING_BUFFER             =
          I_BUFFER_ACTIVE                = ' '
           I_CALLBACK_PROGRAM             = SY-REPID
          I_CALLBACK_PF_STATUS_SET       = ' '
          I_CALLBACK_USER_COMMAND        = ' '
          I_STRUCTURE_NAME               =
          IS_LAYOUT                      =
           IT_FIELDCAT                    = T_FIELDCAT
          IT_EXCLUDING                   =
          IT_SPECIAL_GROUPS              =
          IT_SORT                        =
          IT_FILTER                      =
          IS_SEL_HIDE                    =
          I_DEFAULT                      = 'X'
          I_SAVE                         = ' '
          IS_VARIANT                     =
           IT_EVENTS                      = T_EVENTS
          IT_EVENT_EXIT                  =
          IS_PRINT                       =
          IS_REPREP_ID                   =
          I_SCREEN_START_COLUMN          = 0
          I_SCREEN_START_LINE            = 0
          I_SCREEN_END_COLUMN            = 0
          I_SCREEN_END_LINE              = 0
        IMPORTING
          E_EXIT_CAUSED_BY_CALLER        =
          ES_EXIT_CAUSED_BY_USER         =
          TABLES
            T_OUTTAB                       = T_OPEN_DEL
         EXCEPTIONS
           PROGRAM_ERROR                  = 1
           OTHERS                         = 2
        IF SY-SUBRC NE 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.                             " IF SY-SUBRC NE 0.
      ENDIF.                               " IF T_OPEN_DEL IS NOT INITIAL.
    ENDFORM.                               " DISPLAY_DATA
    FORM TOP_OF_PAGE.
    This subroutine displays product name in top of page
    No Parameter interface
    FORM TOP_OF_PAGE.
      CLEAR FS_OPEN_DEL.
      READ TABLE T_OPEN_DEL INDEX W_INDEX INTO FS_OPEN_DEL.
      IF SY-SUBRC EQ 0.
    Display Product name in Top of page.
        IF  FS_OPEN_DEL-PRDCT EQ C_28% OR
            FS_OPEN_DEL-PRDCT EQ C_32%.
          FS_OPEN_DEL-PRDCT = C_UAN.
        ENDIF.                             " IF  FS_OPEN_DEL-PRDCT EQ C_28..
      ENDIF.                               " IF SY-SUBRC EQ 0
    Begin of Deletion - CS1K931253
    WRITE:
       40 'OPEN'(003),
          FS_OPEN_DEL-PRDCT.
    Begin of Deletion - CS1K931253
    Begin of Insertion - CS1K931253
    IF P_OPEN EQ 'X'.
      WRITE:
        40 C_OPEN,
           FS_OPEN_DEL-PRDCT.
    ELSE.
      WRITE:
        40 C_PREPAY,
           FS_OPEN_DEL-PRDCT.
    ENDIF.                                 " IF P_OPEN EQ 'X'
    Begin of Insertion - CS1K931253
    ENDFORM.                               " TOP_OF_PAGE
    FORM BEFORE_LINE_OUTPUT
    This subroutine displays total quantity for each product
    No Parameter interface
    FORM BEFORE_LINE_OUTPUT USING RS_LINEINFO TYPE SLIS_LINEINFO.
      CLEAR FS_OPEN_DEL.
      READ TABLE T_OPEN_DEL INDEX RS_LINEINFO-TABINDEX INTO FS_OPEN_DEL.
    Calculating Total quantity delivered based for each product
      IF FS_OPEN_DEL-MAT_NUM  NE W_NUMBER AND
         RS_LINEINFO-TABINDEX NE 1.
        W_INDEX = RS_LINEINFO-TABINDEX.
        ULINE.
    Begin of Deletion - CS1K931253
       WRITE:'Total quantity delivered:'(004),
              W_LFIMG UNIT FS_OPEN_DEL-VRKME .
    End of Deletion - CS1K931253
    Begin of Insertion - CS1K931253
        WRITE:'Total quantity delivered:'(004),
               W_LFIMG.
    End of Insertion - CS1K931253
        IF W_NUMBER EQ '3'.
    Begin of Deletion - CS1K931253
        WRITE:/ 'Total 32%:'(005),
                  W_TOTAL32  UNIT FS_OPEN_DEL-VRKME .
    End of Deletion - CS1K931253
    Begin of Insertion - CS1K931253
          WRITE:/ 'Total 32%:'(005),
                   W_TOTAL32.
    End of Insertion - CS1K931253
        ENDIF.                             " IF FS_NUMBER EQ '3'.
        NEW-PAGE.
        CLEAR W_LFIMG.
      ENDIF.                               " FS_OPEN_DEL-MAT_NUM NE...
      W_NUMBER = FS_OPEN_DEL-MAT_NUM.
      W_LFIMG = W_LFIMG + FS_OPEN_DEL-QTYT.
    ENDFORM.                               " BEFORE_LINE_OUTPUT
    FORM END_OF_LIST.
    This subroutine to display End of List
    No Parameter interface
    FORM END_OF_LIST.
      FORMAT COLOR 2.
    Begin of Deletion - CS1K931253
    WRITE: /'Total quantity delivered:'(004),
            W_LFIMG UNIT FS_OPEN_DEL-VRKME .
    End of Deletion - CS1K931253
    Begin of Insertion - CS1K931253
      WRITE: /'Total quantity delivered:'(004),
             W_LFIMG.
    End of Insertion - CS1K931253
      FORMAT COLOR OFF.
    ENDFORM.                               " END_OF_LIST
    Form  ADD_EVENTS
    This subroutine to append events to ALV
    No Parameter interface
    FORM ADD_EVENTS.
      CLEAR FS_EVENTS.
      FS_EVENTS-NAME = C_TOP_OF_PAGE.
      FS_EVENTS-FORM = C_TOP_OF_PAGE.
      APPEND FS_EVENTS TO T_EVENTS.
      CLEAR FS_EVENTS.
      FS_EVENTS-NAME = C_BEFORE_LINE_OUTPUT.
      FS_EVENTS-FORM = C_BEFORE_LINE_OUTPUT.
      APPEND FS_EVENTS TO T_EVENTS.
      CLEAR FS_EVENTS.
      FS_EVENTS-NAME = C_END_OF_LIST.
      FS_EVENTS-FORM = C_END_OF_LIST.
      APPEND FS_EVENTS TO T_EVENTS.
    ENDFORM.                               " ADD_EVENTS
    Form  ADD_FIELDCATLOG
    This subroutine to append fields to field catlog
    No Parameter interface
    FORM ADD_FIELDCATLOG.
      FS_FIELDCAT-FIELDNAME = 'VTEXT'(006).
      FS_FIELDCAT-SELTEXT_L = 'PLANT'(007).
      FS_FIELDCAT-OUTPUTLEN = C_30.
      FS_FIELDCAT-SELTEXT_M = 'PLANT'(007).
      FS_FIELDCAT-SELTEXT_S = 'PLANT'(007).
      FS_FIELDCAT-KEY       = 'X'.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'PRDCT'(008).
      FS_FIELDCAT-SELTEXT_L = 'PRODUCT'(009).
      FS_FIELDCAT-SELTEXT_M = 'PRODUCT'(009).
      FS_FIELDCAT-SELTEXT_S = 'PRODUCT'(009).
      FS_FIELDCAT-OUTPUTLEN = C_20.
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYA'(010).
      FS_FIELDCAT-SELTEXT_L = 'TRUCK'(011).
      FS_FIELDCAT-SELTEXT_M = 'TRUCK'(011).
      FS_FIELDCAT-SELTEXT_S = 'TRUCK'(011).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYB'(012).
      FS_FIELDCAT-SELTEXT_L = 'RAIL'(013).
      FS_FIELDCAT-SELTEXT_M = 'RAIL'(013).
      FS_FIELDCAT-SELTEXT_S = 'RAIL'(013).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYC'(014).
      FS_FIELDCAT-SELTEXT_L = 'BARGE'(015).
      FS_FIELDCAT-SELTEXT_M = 'BARGE'(015).
      FS_FIELDCAT-SELTEXT_S = 'BARGE'(015).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYD'(016).
      FS_FIELDCAT-SELTEXT_L = 'PIPE'(017).
      FS_FIELDCAT-SELTEXT_M = 'PIPE'(017).
      FS_FIELDCAT-SELTEXT_S = 'PIPE'(017).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYE'(018).
      FS_FIELDCAT-SELTEXT_L = 'VESSEL'(019).
      FS_FIELDCAT-SELTEXT_M = 'VESSEL'(019).
      FS_FIELDCAT-SELTEXT_S = 'VESSEL'(019).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYT'(020).
      FS_FIELDCAT-SELTEXT_L = 'TOTAL'(021).
      FS_FIELDCAT-SELTEXT_M = 'TOTAL'(021).
      FS_FIELDCAT-SELTEXT_S = 'TOTAL'(021).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'QTYG'(022).
      FS_FIELDCAT-SELTEXT_L = '32%TOTAL'(023).
      FS_FIELDCAT-SELTEXT_M = '32%TOTAL'(023).
      FS_FIELDCAT-SELTEXT_S = '32%TOTAL'(023).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
      FS_FIELDCAT-FIELDNAME = 'VRKME'(024).
      FS_FIELDCAT-SELTEXT_L = 'UNITS'(025).
      FS_FIELDCAT-SELTEXT_M = 'UNITS'(025).
      FS_FIELDCAT-SELTEXT_S = 'UNITS'(025).
      APPEND FS_FIELDCAT TO T_FIELDCAT.
      CLEAR FS_FIELDCAT.
    ENDFORM.                               " ADD_FIELDCATLOG
    Regards,
    Pavan

Maybe you are looking for