Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*&---------------------------------------------------------------------*
*& Report  ZPM_WO
*&---------------------------------------------------------------------*
*& Author        : Tarun Gambhir
*& Description   : To generate an ALV report display to track
*&                 damage-type work orders and pending completion status
*&                 whose order status is PM01 or PM02 in order to ensure
*&                 timely completions.
*&---------------------------------------------------------------------*
*&  Display records in first screen in ALV Grid Display with checkboxes
*&  appended with each record and perform an user action to display the
*&  selected records into another ALV Gird
*&  or user can use their own code as per their requirements
*&---------------------------------------------------------------------*

REPORT  zpm_wo NO STANDARD PAGE HEADING MESSAGE-ID zmsg_wo.

*&---------------------------------------------------------------------*
*          TYPE POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS : slis. " used for ALV output

*&---------------------------------------------------------------------*
*          TYPE DECLARATION
*&---------------------------------------------------------------------*
TYPES :
* for table aufk (work order details)
        BEGIN OF t_aufk,
          aufnr TYPE aufk-aufnr, " order number
          ktext TYPE aufk-ktext, " description
          objnr TYPE aufk-objnr, " object number
        END OF t_aufk,

* for table jest (object status details)
        BEGIN OF t_jest,
          objnr TYPE jest-objnr, " object number
        END OF t_jest,

* for table afko (basic finish date details)
        BEGIN OF t_afko,
          aufnr TYPE afko-aufnr, " order number
          gltrp TYPE afko-gltrp, "basic finish date
        END OF t_afko,

* for table qmel (notification number details)
        BEGIN OF t_qmel,
          aufnr TYPE qmel-aufnr, " order number
          qmnum TYPE qmel-qmnum, " notification number
        END OF t_qmel,

* final table from which the records need to be displayed
        BEGIN OF t_final,
          aufnr TYPE aufk-aufnr, " order number
          ktext TYPE aufk-ktext, " description
          qmnum TYPE qmel-qmnum, " notification number
          flag(1), " for selection of records
        END OF t_final,

* table which contains the selected records to be processed
        BEGIN OF t_process,
          aufnr TYPE aufk-aufnr, " order number
          ktext TYPE aufk-ktext, " description
          qmnum TYPE qmel-qmnum, " notification number
        END OF t_process,

* table for messages
        BEGIN OF t_message,
          aufnr TYPE aufk-aufnr, "order number
          msg(200), "message text
        END OF t_message.

*&---------------------------------------------------------------------*
*          CONTANTS DECLARATION
*&---------------------------------------------------------------------*
CONSTANTS : c_check(1VALUE 'X',    " value used to set X for a field
            c_langu(1VALUE 'E',    " language used
            c_ustat(4VALUE 'TECO'" object status description

*&---------------------------------------------------------------------*
*          RANGES DECLARATION
*&---------------------------------------------------------------------*
*          RANGE VALUE TO BE USED FOR THE ORDER TYPE
*&---------------------------------------------------------------------*
RANGES : r_auart FOR aufk-auart. "for order type

*&---------------------------------------------------------------------*
*          PARAMETERS FOR SELECTION-SCREEN
*&---------------------------------------------------------------------*
*          SELECTION SCREEN BLOCK FOR THE VARIANT NAME
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_var TYPE disvariant-variant. " variant parameter
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
*          VARIABLE DECLARATIONS
*&---------------------------------------------------------------------*
DATA : v_rep_id TYPE sy-repid,   " report id
       v_istat TYPE tj02t-istat, " order status
       v_cdate TYPE sy-datum,    " current system date
       v_line_count TYPE i,      " number of lines in final internal table
       v_filename TYPE string.   " path for download error log

*&---------------------------------------------------------------------*
*          INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* TYPE OF T_AUFK
* internal table to select records for damaged order types
DATA : it_aufk TYPE STANDARD TABLE OF t_aufk,
* work area for damaged order types
       wa_aufk TYPE t_aufk.

* TYPE OF T_JEST
* internal table to select object number based upon user status
DATA : it_jest TYPE STANDARD TABLE OF t_jest,
* work area to select object number based upon user status
       wa_jest TYPE t_jest.

* TYPE OF T_AFKO
* internal table to select the basic finish date corresopnding to work order
DATA : it_afko TYPE STANDARD TABLE OF t_afko,
* work area to select the basic finish date corresopnding to work order
       wa_afko TYPE t_afko.

* TYPE OF T_QMEL
* internal table to select the notification number corresopnding to object number
DATA : it_qmel TYPE STANDARD TABLE OF t_qmel,
* work area to select the notification number corresopnding to object number
       wa_qmel TYPE t_qmel.

* TYPE OF T_FINAL
* final internal table to select final records to be displayed
DATA : it_final TYPE STANDARD TABLE OF t_final,
* final work area to select final records to be displayed
       wa_final TYPE t_final.

* TYPE OF T_PROCESS
* final internal table to select final records to be displayed
DATA : it_process TYPE STANDARD TABLE OF t_process,
* final work area to select final records to be displayed
       wa_process TYPE t_process.

* FOR VARIANT
DATA : wa_variant TYPE disvariant.
* FOR VARIANT IMPORT
DATA : wa_i_variant TYPE disvariant.

*&---------------------------------------------------------------------*
*          ALV INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv, "internal table for field catalog
       wa_field TYPE slis_fieldcat_alv. "work area for field catalog

* SORTING INFO
DATA : it_sort TYPE slis_t_sortinfo_alv, "internal table for sorting field
       wa_sort TYPE slis_sortinfo_alv. "work area for sorting field

* FOR LAYOUT OF ALV GRID
DATA : wa_layout TYPE slis_layout_alv. "work area for layout design

*&---------------------------------------------------------------------*
*          ALV INTERNAL TABLE & WORK AREA DECLARATIONS
*&---------------------------------------------------------------------*
* FIELD CATALOG
DATA : it_field1 TYPE slis_t_fieldcat_alv, "internal table for field catalog
       wa_field1 TYPE slis_fieldcat_alv. "work area for field catalog

* SORTING INFO
DATA : it_sort1 TYPE slis_t_sortinfo_alv, "internal table for sorting field
       wa_sort1 TYPE slis_sortinfo_alv. "work area for sorting field

* FOR LAYOUT OF ALV GRID
DATA : wa_layout1 TYPE slis_layout_alv. "work area for layout design

*&---------------------------------------------------------------------*
*          INITIALIZATION
*&---------------------------------------------------------------------*
*          TO INITIALIZE ALL THE VARIABLES TO BE USED
*          IN THE PROGRAM
*&---------------------------------------------------------------------*
INITIALIZATION.
  v_rep_id = sy-repid.            " report id
  r_auart-sign = 'I'.             " for inclusive
  r_auart-option = 'BT'.          " for between operator
  r_auart-low = 'PM01'.           " order type(low value)
  r_auart-high = 'PM02'.          " order type(high value)
  APPEND r_auart.                 " append values for range
  v_cdate = sy-datum - 7.         " take date 7 days before current date
  wa_variant-report = v_rep_id.   " report for using variants

*&---------------------------------------------------------------------*
*          AT SELECTION-SCREEN OUTPUT
*&---------------------------------------------------------------------*
*          TO CLEAR THE VALUE OF THE VARIANT PARAMETER WHEN USER
*          RETURNS FROM THE OUTPUT SCREEN TO THE SELECTION SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
  CLEAR p_var. "clear variant value

*&---------------------------------------------------------------------*
*          AT-SELECTION SCREEN ON VALUE REQUEST
*&---------------------------------------------------------------------*
*          TO GET THE F4 HELP FOR EXISTING VARIANTS
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
  PERFORM f4_variant_help USING p_var.

*&---------------------------------------------------------------------*
*          AT-SELECTION SCREEN
*&---------------------------------------------------------------------*
*          TO PASS THE DEFAULT VALUE OF THE VARIANT IF THE PARAMETER
*          FOR VARIANT IS LEFT AS BLANK
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*&---------------------------------------------------------------------*
*         IF THE USER DOESN'T ENTERS ANY VALUE FOR VARIANT
*         THEN THE DEFAULT VARIANT SHOULD BE USED TO DISPLAY
*&---------------------------------------------------------------------*
  IF p_var EQ ' '.
    PERFORM get_default_variant USING p_var.

*&---------------------------------------------------------------------*
*         IF THE USER ENTERS SOME VARIANT NAME FOR THE SELECTION
*         SCREEN WHICH NEED TO BE VALIDATED AGAINST THE EXISTING
*         VARIANTS
*&---------------------------------------------------------------------*
  ELSE.
    PERFORM check_variant_existence USING p_var.

  ENDIF.

*&---------------------------------------------------------------------*
*          START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*&---------------------------------------------------------------------*
*          CLEAR ALL THE CONTENTS OF ALL INTERBAL TABLES
*&---------------------------------------------------------------------*
  REFRESH it_jest.
  REFRESH it_aufk.
  REFRESH it_afko.
  REFRESH it_qmel.
  REFRESH it_final.
*&---------------------------------------------------------------------*
*          select user status from TJ02T for TXT04(status of an object)
*          into variable V_ISTAT
*&---------------------------------------------------------------------*
  SELECT SINGLE
    istat
  FROM tj02t
  INTO (v_istat)
  WHERE
    txt04 EQ c_ustat AND
    spras EQ c_langu.

*&---------------------------------------------------------------------*
*          select object number based upon the user status selected
*&---------------------------------------------------------------------*
  SELECT
    objnr
  FROM jest
  INTO TABLE it_jest
  WHERE
    stat EQ v_istat.
  IF sy-subrc <> 0.
    MESSAGE e003.
  ELSE.
*&---------------------------------------------------------------------*
*         select into it_aufk table: object number, description and
*         object number based on object number selected and order type
*         in PM01 and PM02
*&---------------------------------------------------------------------*
    SELECT
      aufnr
      ktext
      objnr
    FROM aufk
    INTO TABLE it_aufk
    FOR ALL ENTRIES IN it_jest
    WHERE
      objnr EQ it_jest-objnr AND
      auart IN r_auart.

    IF sy-subrc <> 0.
      MESSAGE e002.
    ELSE.
*&---------------------------------------------------------------------*
*         select into it_afko table: order number and basic finish date
*         based upon order number selected and basic finish date as
*         v_cdate variable
*&---------------------------------------------------------------------*
      SELECT
        aufnr
        gltrp
      FROM afko
      INTO TABLE it_afko
      FOR ALL ENTRIES IN it_aufk
      WHERE
        aufnr EQ it_aufk-aufnr AND
        gltrp LE v_cdate.
*&---------------------------------------------------------------------*
*         select into it_qmel table: order number and notification
*         number based on the order number selected
*&---------------------------------------------------------------------*
      SELECT
        aufnr
        qmnum
      FROM qmel
      INTO TABLE it_qmel
      FOR ALL ENTRIES IN it_aufk
      WHERE
        aufnr EQ it_aufk-aufnr.
    ENDIF.
  ENDIF.

*&---------------------------------------------------------------------*
*          READ THE RECORDS FOMR THE ABOVE POPULATED INTERNAL TABLE
*          INTO WORK AREA AND THEN POPULATE THE FINAL INTERNAL
*          TABLE
*&---------------------------------------------------------------------*
* read internal table it_jest into work area wa_jest
  LOOP AT it_jest INTO wa_jest.

* read it_aufk based on object number from wa_jest
    READ TABLE it_aufk INTO wa_aufk WITH KEY objnr = wa_jest-objnr.
* if records found
    IF sy-subrc EQ 0.
* read it_afko for order number and description based on order number
      READ TABLE it_afko INTO wa_afko WITH KEY aufnr = wa_aufk-aufnr.
* if records found
      IF sy-subrc EQ 0.
        wa_final-aufnr = wa_afko-aufnr. "move order number to it_final
        wa_final-ktext = wa_aufk-ktext. "move description to it_final
      ELSE.
* if no record found then move to next loop pass
        CONTINUE.
      ENDIF.
    ELSE.
* if no record found then move to next loop pass
      CONTINUE.
    ENDIF.

* read it_qmel for description based on the order number selected above
    READ TABLE it_qmel INTO wa_qmel WITH KEY aufnr = wa_final-aufnr.
* if records found
    IF sy-subrc EQ 0.
      wa_final-qmnum = wa_qmel-qmnum. "move notification number to it_final
    ENDIF.

* finally append the records into the final internal table
    APPEND wa_final TO it_final. "append wa_final into it_final
    CLEAR wa_final. "clear work area
    CLEAR wa_aufk.  "clear work area
    CLEAR wa_qmel.  "clear work area

  ENDLOOP.

*&---------------------------------------------------------------------*
*          TO COUNT THE NUMBER OF RECORDS IN THE FINAL INTERNAL
*          TABLE AND RETURN TO SELECTION SCREEN
*          IF NO RECORDS EXISTS THEN AN INFORMATION MESSGE IS DISPLAYED
*&---------------------------------------------------------------------*
  DESCRIBE TABLE it_final
  LINES v_line_count.
  IF ( v_line_count EQ 0 ).
    MESSAGE i002. "error message
    EXIT.
  ENDIF.

*&---------------------------------------------------------------------*
*          END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*          FIELD CATALOG FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
  PERFORM field_catalog.

*&---------------------------------------------------------------------*
*          SORT W.R.T. WORK ORDER NUMBER FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
  PERFORM sort_field.

*&---------------------------------------------------------------------*
*          FOR LAYOUT FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
  PERFORM set_layout.

*&---------------------------------------------------------------------*
*          DISPLAY RECORDS IN ALV GRID FOR FIRST GRID DISPLAY
*&---------------------------------------------------------------------*
  PERFORM alv_display.

*&---------------------------------------------------------------------*
*&      SUBROUTINE DEFINITIONS
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------*
*       SUB-ROUTINE FIELD_CATALOG USED TO SET THE COLUMNS FOR
*       THE ALV GRID (OUTPUT FORMAT)
*       SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog .

  wa_field-fieldname = 'FLAG'.   " name of field from internal table
  wa_field-tabname = 'IT_FINAL'" internal table name
  wa_field-outputlen = 2.        " output length on screen
  wa_field-checkbox = c_check.   " print as checkbox
  wa_field-edit = c_check.       " make field open for input
  wa_field-seltext_l = ' '.      " header information
  APPEND wa_field TO it_field.   " append field catalog internal table
  CLEAR wa_field.                " clear field catalog work area

  wa_field-fieldname = 'AUFNR'.  " name of field from internal table
  wa_field-tabname = 'IT_FINAL'" internal table name
  wa_field-outputlen = 20.       " output length on screen
  wa_field-seltext_l = text-003" header information
  APPEND wa_field TO it_field.   " append field catalog internal table
  CLEAR wa_field.                " clear field catalog work area

  wa_field-fieldname = 'KTEXT'.  " name of field from internal table
  wa_field-tabname = 'IT_FINAL'" internal table name
  wa_field-outputlen = 45.       " output length on screen
  wa_field-seltext_l = text-004" header information
  APPEND wa_field TO it_field.   " append field catalog internal table
  CLEAR wa_field.                " clear field catalog work area

  wa_field-fieldname = 'QMNUM'.  " name of field from internal table
  wa_field-tabname = 'IT_FINAL'" internal table name
  wa_field-outputlen = 22.       " output length on screen
  wa_field-seltext_l = text-005" header information
  APPEND wa_field TO it_field.   " append field catalog internal table
  CLEAR wa_field.                " clear field catalog work area

ENDFORM.                    " FIELD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  SORT_FIELD
*&---------------------------------------------------------------------*
*       SUB-ROUTINE SORT_FIELD IS USED TO SORT THE RECORDS IN THE
*       INTERNAL TABLE BASED ON THE GIVEN FIELD AND NATURE OF
*       SORTING TO BE DONE (ASCENDING OR DESCENDING)
*----------------------------------------------------------------------*
FORM sort_field .

  wa_sort-spos = 1.             " sort priority
  wa_sort-fieldname = 'AUFNR'.  " field on which records sorted
  wa_sort-tabname = 'IT_FINAL'" internal table name
  wa_sort-up = c_check.         " sort ascending
  APPEND wa_sort TO it_sort.    " append sort info internal table
  CLEAR wa_sort.                " clear sort info work area

ENDFORM.                    " SORT_FIELD
*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT
*&---------------------------------------------------------------------*
*       SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
*       ALV GRID LINES IN ALTERNATIVE COLOURS
*----------------------------------------------------------------------*
FORM set_layout .

  wa_layout-zebra = c_check.    " so set colors of line alternatively

ENDFORM.                    " SET_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  ALV_DISPLAY
*&---------------------------------------------------------------------*
*       SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
*       FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
*       AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
*       DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
     i_callback_program                = v_rep_id       " report id
     i_callback_pf_status_set          = 'PF'           " for PF-STATUS
     i_callback_user_command           = 'USER_COMMAND' " for 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                      =
*     I_GRID_SETTINGS                   =
     is_layout                         = wa_layout      " for layout
     it_fieldcat                       = it_field       " field catalog
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
     it_sort                           = it_sort        " sort info
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
*     i_save                            = 'A'
*     is_variant                        = wa_variant     " variant name
*     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                          = it_final      " internal table
   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.                    " ALV_DISPLAY

*&---------------------------------------------------------------------*
*&      Form  pf
*&---------------------------------------------------------------------*
*       SUB-ROUTINE PF IS USED TO SET THE PF-STATUS OF THE SCREEN
*       ON WHICH THE ALV GRID IS DISPLAYED
*----------------------------------------------------------------------*
*       -->RT_EXTAB
*----------------------------------------------------------------------*
FORM pf USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZTG_STAT'.
ENDFORM.                    "pf

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
*       AND EXECUTE THE APPROPIATE CODE
*----------------------------------------------------------------------*
*      -->LV_OKCODE   used to capture the function code
*                     of the user-defined push-buttons
*      -->L_SELFIELD   text
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.

* assign the function code to variable v_okcode
  lv_okcode = sy-ucomm.

* handle the code execution based on the function code encountered
  CASE lv_okcode.

* when the function code is EXECUTE then process the selected records
    WHEN 'EXECUTE'.

* refresh it_process when user processes selected records
      REFRESH it_process.

* to reflect the data changed into internal table
      DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new

      IF ref_grid IS INITIAL.
        CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
          IMPORTING
            e_grid = ref_grid.
      ENDIF.

      IF NOT ref_grid IS INITIAL.
        CALL METHOD ref_grid->check_changed_data.
      ENDIF.

*----------------------------------------------------------------------*
* sort the internal table by flag descending so that the selected
* records are appended at the beginning of internal table
*----------------------------------------------------------------------*
      SORT it_final BY flag DESCENDING.

*----------------------------------------------------------------------*
* move the selected records from final internal table into another
* internal table so that they can be processed
*----------------------------------------------------------------------*
      LOOP AT it_final INTO wa_final WHERE flag = 'X'.
        wa_process-aufnr = wa_final-aufnr.
        wa_process-ktext = wa_final-ktext.
        wa_process-qmnum = wa_final-qmnum.
        APPEND wa_process TO it_process.
      ENDLOOP.

* refresh the ALV Grid output from internal table
      l_selfield-refresh = c_check.

* now all the selected records by the user at run-time are appended into
* into a new internal table which can now be used to processed as per the
* user requirements
      DATA : line_count1 TYPE i.

      DESCRIBE TABLE it_process
      LINES line_count1.
      IF line_count1 GE 1.
        PERFORM user_action.
      ELSE.
        MESSAGE e002.
      ENDIF.

    WHEN 'SEL_ALL'.
* to select all the records displayed in ALV Grid
      LOOP AT it_final INTO wa_final.
        wa_final-flag = 'X'.
        MODIFY it_final FROM wa_final.
      ENDLOOP.
* refresh the ALV Grid output from internal table
      l_selfield-refresh = c_check.

    WHEN 'DESEL_ALL'.
* to deselect all the records displayed in ALV Grid
      LOOP AT it_final INTO wa_final.
        wa_final-flag = ' '.
        MODIFY it_final FROM wa_final.
      ENDLOOP.
* refresh the ALV Grid output from internal table
      l_selfield-refresh = c_check.

  ENDCASE.

ENDFORM.                    "USER_COMMAND
*&---------------------------------------------------------------------*
*&      Form  F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*       SUB-ROUTINE f4_variant_help TO GET A F4 HELP FOR VARIANT
*       SELECTION AND DISPLAY DATA ACCORDINGLY
*----------------------------------------------------------------------*
*      <--P_P_VAR  text
*----------------------------------------------------------------------*
FORM f4_variant_help USING p_p_var.

  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
      EXPORTING
        is_variant                = wa_variant  " export variant
*   I_TABNAME_HEADER          =
*   I_TABNAME_ITEM            =
*   IT_DEFAULT_FIELDCAT       =
       i_save                    = 'A'          " layout for all users
       i_display_via_grid        = 'X'          " grid view of variants
     IMPORTING
*   E_EXIT                    =
       es_variant                = wa_i_variant " import variant
     EXCEPTIONS
       not_found                 = 1
       program_error             = 2
       OTHERS                    = 3.
  IF sy-subrc = 0.
* PASS THE SELECTED VARIANT TO THE SELECTION SCREEN FIELD
    p_p_var = wa_i_variant-variant.
  ELSEIF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    " F4_VARIANT_HELP
*&---------------------------------------------------------------------*
*&      Form  GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*       SUB-ROUTINE GET_DEFAULT_VARIANT TO PASS THE DEFAULT VARIANT
*       IF USER DOESN'T ENTERS ANY VALUE FOR THE VARIANT
*----------------------------------------------------------------------*
*      <--P_P_VAR  variant name
*----------------------------------------------------------------------*
FORM get_default_variant USING l_p_var.

  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = wa_variant "variant name
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
* IF DEFAULT VARIANT FOUND
  IF sy-subrc = 0.
* PASS THE DEFAULT VARIANT TO THE SELECTION SCREEN FIELD
    l_p_var = wa_variant-variant.
  ELSEIF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    " GET_DEFAULT_VARIANT
*&---------------------------------------------------------------------*
*&      Form  CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
*       SUB-ROUTINE CHECK_VARIANT_EXISTENCE TO VALIDATE THE VARIANT
*       NAME ENTERED BY THE USER
*       IF VARIANT FOUND THEN EXECUTE
*       ELSE DISPLAY ERROR MESSAGE
*----------------------------------------------------------------------*
*      <--P_P_VAR  variant name
*----------------------------------------------------------------------*
FORM check_variant_existence USING l_p_var.

*&---------------------------------------------------------------------*
*          ASSIGN THE VALUE OF THE VARIANT ENTERED BY USER TO THE
*          WORK AREA FIELD AND CHECK FOR ITS EXISTENCE
*&---------------------------------------------------------------------*
  wa_variant-variant = l_p_var.
*&---------------------------------------------------------------------*
*          TO CHECK THE EXISTENCE FOR VARIANT CORRESPONDING TO
*          EXISTING VARIANT IF THE USER ENTERS SOME VALUE FOR
*          THE PARAMETER
*&---------------------------------------------------------------------*
  CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
    EXPORTING
      i_save        = 'A'
    CHANGING
      cs_variant    = wa_variant " variant name
    EXCEPTIONS
      wrong_input   = 1
      not_found     = 2
      program_error = 3
      OTHERS        = 4.
  IF sy-subrc <> 0.
    MESSAGE e001.
  ENDIF.

ENDFORM.                    " CHECK_VARIANT_EXISTENCE
*&---------------------------------------------------------------------*
*&      Form  USER_ACTION
*&---------------------------------------------------------------------*
*       SUB-ROUTINE USER_ACTION CAN BE USED AS PER THE USER REQUIREMENT
*       TO PROCESS THE SELECTED RECORDS IN ALV GRID DISPLAY
*----------------------------------------------------------------------*
FORM user_action.
*       user code to process selected records in internal table
*       it_process

*&---------------------------------------------------------------------*
*          FIELD CATALOG FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
  PERFORM field_catalog1.

*&---------------------------------------------------------------------*
*          SORT W.R.T. WORK ORDER NUMBER FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
  PERFORM sort_field1.

*&---------------------------------------------------------------------*
*          FOR LAYOUT FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
  PERFORM set_layout1.

*&---------------------------------------------------------------------*
*          DISPLAY RECORDS IN ALV GRID FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
  PERFORM alv_display1.

ENDFORM.                    " F4_FILE_REQUEST
*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
*       SUB-ROUTINE FIELD_CATALOG USED TO SET THE COLUMNS FOR
*       THE ALV GRID (OUTPUT FORMAT)
*       SETS THE COLUMN NAME AND THE OUTPUT LENGTH FOR THE FIELDS
*----------------------------------------------------------------------*
FORM field_catalog1 .

  REFRESH it_field1.
  CLEAR wa_field1.

  wa_field1-fieldname = 'AUFNR'.    " name of field from internal table
  wa_field1-tabname = 'IT_PROCESS'" internal table name
  wa_field1-outputlen = 20.         " output length on screen
  wa_field1-seltext_l = text-003.   " header information
  APPEND wa_field1 TO it_field1.    " append field catalog internal table
  CLEAR wa_field1.                  " clear field catalog work area

  wa_field1-fieldname = 'KTEXT'.    " name of field from internal table
  wa_field1-tabname = 'IT_PROCESS'" internal table name
  wa_field1-outputlen = 45.         " output length on screen
  wa_field1-seltext_l = text-004.   " header information
  APPEND wa_field1 TO it_field1.    " append field catalog internal table
  CLEAR wa_field1.                  " clear field catalog work area

  wa_field1-fieldname = 'QMNUM'.    " name of field from internal table
  wa_field1-tabname = 'IT_PROCESS'" internal table name
  wa_field1-outputlen = 22.         " output length on screen
  wa_field1-seltext_l = text-005.   " header information
  APPEND wa_field1 TO it_field1.    " append field catalog internal table
  CLEAR wa_field1.                  " clear field catalog work area

ENDFORM.                    " FIELD_CATALOG1
*&---------------------------------------------------------------------*
*&      Form  SORT_FIELD1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
*       SUB-ROUTINE SORT_FIELD IS USED TO SORT THE RECORDS IN THE
*       INTERNAL TABLE BASED ON THE GIVEN FIELD AND NATURE OF
*       SORTING TO BE DONE (ASCENDING OR DESCENDING)
*----------------------------------------------------------------------*
FORM sort_field1.

  wa_sort1-spos = 1.               " sort priority
  wa_sort1-fieldname = 'AUFNR'.    " field on which records sorted
  wa_sort1-tabname = 'IT_PROCESS'" internal table name
  wa_sort1-up = c_check.           " sort ascending
  APPEND wa_sort1 TO it_sort1.     " append sort info internal table
  CLEAR wa_sort1.                  " clear sort info work area

ENDFORM.                    " SORT_FIELD1
*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
*       SUB-ROUTINE SET_LAYOUT IS USED TO SET THE DISPLAY OF THE
*       ALV GRID LINES IN ALTERNATIVE COLOURS
*----------------------------------------------------------------------*
FORM set_layout1 .

  wa_layout1-zebra = c_check.    " so set colors of line alternatively

ENDFORM.                    " SET_LAYOUT1
*&---------------------------------------------------------------------*
*&      Form  ALV_DISPLAY1 FOR SELECTED RECORDS
*&---------------------------------------------------------------------*
*       SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
*       FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
*       AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
*       DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display1.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
     i_callback_program                = v_rep_id        " report id
*     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                      =
*     I_GRID_SETTINGS                   =
     is_layout                         = wa_layout1      " for layout
     it_fieldcat                       = it_field1       " field catalog
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
     it_sort                           = it_sort1        " sort info
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
*     i_save                            = ' '
*     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                          = it_process     " internal table
   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.                    " ALV_DISPLAY1

Output Display Screen-shots:- 

Selection screen for variant selection:-

F4 help provided for variant selection.

If no input for variant selection, then DEFAULT variant used.

Report based on the variant used:-

If no records selected and user click EXECUTE button, error message 'NO RECORDS SELECTED' displayed

Else If records selected and EXECUTE button is pressed, the seleected records to be displayed in another ALV Grid.

These selected records can also be processed as per user requirements. 

  • No labels

3 Comments

  1. Hi..

      my requirement also same like this, but in 1st column of grid i displayed all the checkboxes and in 2nd column i have order number.

    when order number repeates i don't have to print check box in 1st column. how can i do it any idea..

  2. HI,

    you could try to merge the cells - there is a coding example on http://www.tricktresor.de/content/index.php?navID=523&aID=464 (sorry it's on german)

    Ivo

  3. An error in FORM fieldcatalog for the field "flag". Have to be

      wa_field-input = c_check.       " make field open for input


    Regards

    Sergii