Sunday, April 7, 2013

Understanding RICEFW - Reports

Learning RICEFW is essentially learning the technical part of SAP.

R ->  Reports
I  ->  Interfaces
C ->  Conversions
E ->  Extensions
F ->  Forms
W-> Workflows
 
Important concepts of each of these 6 categories.
 
Reports:
Reporting is used so that large amount of consolidated data which is essentially stored in multiple tables can be viewed in one go based on any selection criteria one might need.
Reports are executable programs, meaning in SE38 when you are creating a program,  
select the program type as Executable program.
 
SAP provides as basic as the write statements letting one program their own reports to as advanced as direct function modules which when fed by the respective input internal table will display the report.
 
The various function modules that we have for reporting are
- REUSE_ALV_LIST_DISPLAY - This displays the output in the format of an ALV LIST
- REUSE_ALV_GRID_DISPLAY - This displays the output in the format of an ALV GRID
- REUSE_ALV_GRID_DIPLAY_TREE - For when information is needed to be displayed in the form of tree.
 
The same can be done in OOPS, where in there are many methods to perform the same functionalities like the SET_TABLE_FOR_FIRST_DISPLAY in the class CL_GUI_ALV_GRID.
 
SAP also supports interactive reporting, where in navigation can be done between the report output and its details screen (Details screen meaning, if the user clicks on a particular line of the report a new report opens up with the respective details as per requirement. Ex: Consider in a particular report user clicks on the field sold-to-party on a row, then another screen appears giving details about all the sales orders of this sold-to-party's name).
 
REPORT EVENTS:
 
Reports are event driven. And the different events in-sequence that a report execution encounters are as below -

1. LOAD-OF-PROGRAM -
As the name says this event is used to load the module pool, function module, subroutine pool programs into the executable program. This event occurs only once during a particular execution. And this program is pretty much something like a constructor of a class.

2. INITIALIZATION -
This event is executed before the selection screen is displayed, and this provides an opportunity to initialize values on selection screen.

3. AT SELECTION-SCREEN -
This event is processed after the initialization, and it is primarily used to validate the selection screen values. In other words, as soon as the user enters values in the selection screen and executes this event is processed which validates the values entered by the user and displays any error message if the values entered are not appropriate.

The types of selection screen events are -
  • At Selection-Screen Output.
  • At Selection-Screen On Value Request For <Field>.
  • At Selection-Screen On Help Request For <Field>.
  • At Selection-Screen On <field- select-options>.
  • At Selection-Screen On <field-Parameter>.
  • At Selection-Screen On Block <blockname>.
  • At Selection-Screen On Radiobutton Group <groupname>.
  • At Selection-Screen.
  •  
    AT SELECTION SCREEN OUTPUT -
    Actually this event occurs in between INITIALIZATION and AT SELECTION-SCREEN. This event is used to dynamically change the properties of the selection screen. In other words, this event allows us to modify the selection screen even before it is displayed for the first time. For ex: When the selection screen first appears the user wants to see few fields intensified ON and few intensified OFF, this can be achieved by this event.
     
    AT SELECTION SCREEN ON VALUE REQUEST FOR <FIELD> -
    This event gets triggered when the F4 option is pressed on a field. This is particularly useful if you have your own set of data that you want to display when user presses F4.
    Note: If this F4 is for select option, It needs to be mentioned twice once for low and other for the high.
    Ex: Prepare a table with all the values you want to display when the user presses F4.
    Say the table is gt_kna1,
    AT SELECTION SCREEN ON VALUE REQUEST FOR s_kunnr-low.
     
    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
    retfield = 'KUNNR'
    dynprofield = 'S_KUNNR'
    dynpprog = sy-prog
    dynpnr = sy-dynnr
    value_org = 'S'
    TABLES
    value_tab = gt_kna1.
    Similarly for the high field that is s_kunnr-high.
     
    AT SELECTION SCREEN ON HELP REQUEST FOR <FIELD> -
    This is very similar to the above value request, except that a help documentation is provided when the user presses F1.
    Note: In both cases, because the selection screen parameters are of the data type the corresponding data element the default F4 and F1 help appear. If these events are used the standard F1 and F4 helps are overwritten.
     
    Now prepare the Help table with attributes -

    gt_help-tabname = ''.
    gt_help-fieldname = ''.
    gt_help-keyword = ''.
    gt_help-length = ''.
    gt_help-value = ''
    APPEND gt_help.
     
    CALL FUNCTION 'HELP_GET_VALUES'
    EXPORTING
    popup_title = ''
    TABLES
    fields = gt_help
    EXCEPTIONS
    no_entries = 1
    OTHERS = 2.
     
    AT SELECTION-SCREEN ON -
    This is pretty much same like the AT SELECTION-SCREEN used to validate the selection screen values, except that the AT SELECTION-SCREEN validates all the values but the AT SELECTION-SCREEN ON validates only the field it is used on -
    Ex:
    AT SELECTION-SCREEN ON s_kunnr.
    If s_kunnr is initial.
    MESSAGE 'Please enter the sold-to-party value', TYPE 'E'.
    Endif.
     
    4. START-OF-SELECTION -
        Data selection from the data base tables is done here.

    5. END-OF-SELECTION -
        From the start-of-selection one output table which is a consolidation of all the data
        (the final internal table) is prepared and at the end-of-selection this output is written
        to display.

    6. AT LINE-SELECTION -
        This event is specific to interactive reporting. On the primary screen of an output, if
        the user clicks on a row or a field and expects an event to happen, code for this can be
        written under this event. The AT LINE-SELECTION populates few system fields which
        will help capturing the row or the field that has been selected.
        SY-LSIND is tone such system field which holds the number of the detail list.
        For Basic or primary list SY-LSIND is zero, for first detail list SY-LSIND = 1.
        A particular report can have 0 to 22 details screens.
        GET CURSOR FIELD fname value fval - this give the value on which the user has clicked.
        HIDE - Hide is a keyword which stores values of specific key fields in the memory along 
        with the sy-linno system field.
        This statement is used within a loop while displaying that is in END-OF-SELECTION. All  
        the fields that you think you might use can be displayed using this keyword, and can
        be used to display the interactive report.
        Interactive reporting can as well be done using the I_CALLBACK_USER_COMMAND of the
        reuse_alv function module.
       
             Unlike the topics discussed earlier, there are other process control events that can be used to extract data and prepare the final internal table.
    AT FIRST - Beginning of the loop
    AT NEW - At every new occurrence of the field
    AT END OF - At the end of a particular occurrence
    AT LAST - At the end of the loop.
    All these events are to used within a loop.

    TOP-OF-PAGE -
    This event is triggered when the first write statement is seen. When the controller sees the first write statement, it will go and check if top-of-page event is present, If yes it will execute whatever is present in there like the title, column headings etc.
    Ex:
    TOP-OF-PAGE
    FORMAT COLOR 1.
    WRITE: ' Customer Details'.
    FORMAT COLOR 1 OFF.
    ULINE.

    TOP_OF_PAGE DURING LINE_SELECTION -
    This keyword lets us provide TOP-OF-PAGE for secondary lists
    Ex:
    TOP_OF_PAGE DURING LINE_SELECTION
    If sy-lsind = 1. (First detail list)


    Endif.

    Few important notes to remember about reporting -
     
    1. Report  <ZMNS_CUSTOMER_ORDERS> This is the first line of any report.
     
    2. KEYWORDS to format the report layout -
    • To avoid heading - NO STANDARD PAGE HEADING is the keyword  
              Syntax: Report  <ZMNS_CUSTOMER_ORDERS> NO STANDARD PAGE HEADING
     
    • To specify the length of the column in a report - LINE-SIZE
             Syntax: Report  <ZMNS_CUSTOMER_ORDERS> LINE-SIZE 40
             The system field sy-linsz is set with this keyword.
    • To specify the length of the page in a report - LINE-COUNT page_lines(footer_lines)
             Syntax: Report  <ZMNS_CUSTOMER_ORDERS>  LINE-COUNT 0(2)
             The page_lines if mentioned 0 is by default set to 60000 by the system and the 2 
             meaning 2 lines are reserved for the footer. Note, a footer cannot be set for the
             detail list.
             The system field sy-linct is set with this keyword.
             The footer must be set under END_OF_PAGE keyword.
    • NEW-PAGE - If all the above settings, like the count, title, header and all need to be valid only for the first page, new settings for the next individual page can be set using the NEW-PAGE keyword.
    • Syntax: NEW-PAGE <NO-TITLE> <NO-HEADING>
     
    Selection screen:
     
    Syntax:
    Selection screen begin of screen <>
     
    Selection screen end of screen <>
     
    Selection screen parameters can be either PARAMETERS or SELECT-OPTIONS.
     
    PARAMETERS are single valued entries:
    Ex: PARAMETER  pa_kunnr type kunnr DEFAULT '108183'. 
    The default keyword is optional, in case you want to run the report for the same value always.

    PARAMETER as checkbox:
    Ex: PARAMETER pa_c AS CHECKBOX DEFAULT 'X'.
     
    PARAMETER as radio button:
    Ex: PARAMETER: pa_rb1 radio button group rad1 DEFAULT 'X'
                             pa_rb2 radio button group rad1.
     
    SELECT_OPTIONS :
    Ex: s_vbeln for vbak-vbeln.
    Used when range of values are to be used.
     
    LAYOUT TIPS :
    - For color use syntax - FORMAT COLOR n, n is the number of the color.

    - HOTSPOT - If the requirement is to call a detail screen when the user clicks on a specific
      field, and to indicate this, a hand symbol can be made to appear when the mouse is
      hovered over that field, this can be achieved by the above keyword.
     
    - The layout of the grid can also be set by setting some values in the field catalog like -
      output length, hotspot on, sel_text etc.
     
    - Also the layout exporting parameter can also be used to perform layout settings like  
      no_toolbar, grid_title etc. See CL_GUI_ALVGRID class for the structure of any of these 
      fields.
     
    - Its worth noting about a variable IT_EXCLUDING in the function module  
      REUSE_ALV_GRID_DISPLAY which can be used in cases when the requirement is to display
      only certain buttons on alv grid. Obtain the function codes of the button that are needed
      to be displayed, and add the function codes of those buttons to the it_excluding
      table and pass it on to the function module.
     
    Interactive reporting using OOPS:
    The concept of interactive reporting is pretty much same either using the Standard function module approach or the OOPS approach. In OOPS we have  a method SET_TABLE_FOR_FIRST_DISPLAY to display the report in ALV grid.

    Syntax:

    ** Declare an event class with double click handling method which is of type double_click 
       of CL_GUI_ALV_GRID.

    CLASS event_class DEFINITION.
    PUBLIC SECTION.
       METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
                       IMPORTING e_row .
    ENDCLASS.

    As can be seen above this method is for the event DOUBLE_CLICK in the class CL_GUI_ALV_GRID, and e_row is the parameter which will give information about
    the row selected. Once the class is declared, write the respective code under this method that you want to see happen when the user double clicks.

    EX: CLASS event_class IMPLEMENTATION.
           METHOD handle_double_click.
              READ TABLE gt_kunnr INDEX e_row-index INTO gw_kunnr.
              SELECT * FROM kna1
              INTO CORRESPONDING FIELDS OF TABLE gw_kna1
              WHERE kunnr EQ gw_kunnr-kunnr.
              CALL SCREEN 101.
           ENDMETHOD.
         ENDCLASS.

    Now that the method is ready, calling the method is remaining. This will happen after the SET_TABLE_FOR_FIRST_DISPLAY method is called.

    Event_receiver TYPE REF TO event_class.

    CREATE OBJECT event_receiver.

    SET HANDLER Event_receiver->handle_double_click FOR c_alv1.

    This should take care of the interactive reporting. 
     
     
     
     
     
     
     
     
     
     
     
     
     
     


    No comments:

    Post a Comment

    Note: Only a member of this blog may post a comment.