Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Hello Folks,


       I am sharing a code for CA01 Routing creation through
BAPI_ROUTING_CREATE. Earlier i used to create a BDC for this, which was not flexible and development efforts are also more as compared to this.


REPORT  zcc002_routing_bapi.

**********************************************************************
* Table Declaration
**********************************************************************
*TABLES :
**********************************************************************
*  Type Pool Declarations
**********************************************************************
* Type Pool Used for ALV Log Display

TYPE-POOLS : slis.

**********************************************************************
* Types Declarations
**********************************************************************
* Structure to Load Data from the Text File

TYPES : BEGIN OF ty_routing,
           material  LIKE  bapi1012_mtk_c-material,
           plant LIKE  bapi1012_tsk_c-plant,
           tsk_desc LIKE  bapi1012_tsk_c-description,
           task_list_usage LIKE  bapi1012_tsk_c-task_list_usage,
           task_list_status  LIKE  bapi1012_tsk_c-task_list_status,
           ident_key         LIKE  bapi1012_tsk_c-ident_key,
     "Identification for the Inspection Point Field Combination
*          lot_size_from         LIKE  bapi1012_tsk_c-lot_size_from,
*          lot_size_to         LIKE  bapi1012_tsk_c-lot_size_to,
*          task_measure_unit LIKE  bapi1012_tsk_c-task_measure_unit,
           op_activity         LIKE  bapi1012_opr_c-activity,
*     planning_work_center  LIKE  bapi1012_tsk_c-planning_work_center,
           control_key         LIKE  bapi1012_opr_c-control_key,
           work_cntr         LIKE  bapi1012_opr_c-work_cntr,
           op_description  LIKE  bapi1012_opr_c-description,
* operation_measure_unit  LIKE  bapi1012_opr_c-operation_measure_unit,
           std_value_01 LIKE bapi1012_opr_c-std_value_01,
           std_value_02 LIKE bapi1012_opr_c-std_value_02,
           std_value_03 LIKE bapi1012_opr_c-std_value_03,
           std_value_04 LIKE bapi1012_opr_c-std_value_04,
           std_value_05 LIKE bapi1012_opr_c-std_value_05,
           std_value_06 LIKE bapi1012_opr_c-std_value_06,
*          ins_activity         LIKE bapi1012_cha_c-activity,
*          inspchar         LIKE bapi1012_cha_c-inspchar,
*          quantitative_ind  LIKE  bapi1012_cha_c-quantitative_ind,
           mstr_char         LIKE  bapi1012_cha_c-mstr_char,
           quantitative_ind  LIKE  bapi1012_cha_c-quantitative_ind,
* cha_master_import_modus LIKE bapi1012_cha_c-cha_master_import_modus,
*          char_descr         LIKE bapi1012_cha_c-char_descr,
           method  LIKE  bapi1012_cha_c-method,
           smpl_procedure  LIKE  bapi1012_cha_c-smpl_procedure,
*          smpl_unit         LIKE  bapi1012_cha_c-smpl_unit,
*          smpl_quant         LIKE bapi1012_cha_c-smpl_quant,
*          formula_ind        LIKE bapi1012_cha_c-formula_ind,
*          lsl_ind        LIKE bapi1012_cha_c-lw_tol_lmt_ind,
*          usl_ind        LIKE bapi1012_cha_c-up_tol_lmt_ind,
*          tgt_ind        LIKE bapi1012_cha_c-target_val_check_ind,
           summ_rec(1) TYPE c,
           sing_rec(1) TYPE c,
           target_val         LIKE bapi1012_cha_c-target_val,
           lw_tol_lmt         LIKE bapi1012_cha_c-lw_tol_lmt,
           up_tol_lmt         LIKE bapi1012_cha_c-up_tol_lmt,
           formula1         LIKE bapi1012_cha_c-formula_field_1,
           formula2         LIKE bapi1012_cha_c-formula_field_1,
         END OF ty_routing.

**********************************************************************
*                Constants Declarations
**********************************************************************

**********************************************************************
* Global variables
**********************************************************************
DATA : v_exit TYPE c.
DATA: gv_test_run    TYPE bapiflag,
       gv_group       TYPE bapi1012_tsk_c-task_list_group,
       gv_gr_counter  TYPE  bapi1012_tsk_c-group_counter,
       gv_file TYPE localfile,
       gv_row TYPE n,
       gv_plant LIKE bapi1012_tsk_c-plant,
       gv_lines TYPE i,
       gv_per TYPE p,
       gv_txt(50) TYPE c.

**********************************************************************
*                Internal Table Declarations
**********************************************************************
* Data Declarations for import internal table parameters to BAPI

DATA : it_task TYPE TABLE OF bapi1012_tsk_c WITH HEADER LINE,
        it_mat_task_allo TYPE TABLE OF bapi1012_mtk_c WITH HEADER LINE,
        it_inspchar TYPE TABLE OF bapi1012_cha_c  WITH HEADER LINE,
        it_op TYPE TABLE OF bapi1012_opr_c  WITH HEADER LINE,
        it_ret TYPE TABLE OF bapiret2 WITH HEADER LINE.

* Declare Internal table for Message Header for ALV Display

DATA: BEGIN OF it_loghead  OCCURS 0,
         material LIKE bapi1012_mtk_c-material,
         plant LIKE bapi1012_tsk_c-plant,
         msgtype LIKE bapiret2-type,
         msg(100) TYPE c,
         expand TYPE c,
       END OF it_loghead .

* Declare Internal table for Message Details for ALV Display

DATA: BEGIN OF it_logdetail OCCURS 0,
         material LIKE bapi1012_mtk_c-material,
         plant LIKE bapi1012_tsk_c-plant,
         msgtype LIKE bapiret2-type,
         msg(100) TYPE c,
       END OF it_logdetail.

* Internal Table to Load and Hold Data from the Text File

DATA : it_routing TYPE TABLE OF ty_routing WITH HEADER LINE.


**********************************************************************
*                Work Area Declarations
**********************************************************************
DATA : wa_routing TYPE ty_routing.

**********************************************************************
*            Selection Screen
**********************************************************************

*SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*PARAMETERS     :
*SELECTION-SCREEN END OF BLOCK b1.

**********************************************************************
*                At Selection Screen
**********************************************************************

**********************************************************************
*                Start-of-selection
**********************************************************************

START-OF-SELECTION.
* Clear Internal Tables holding Messages

   CLEAR it_loghead[].
   CLEAR it_logdetail[].

* Call Subroutine to Show File Dialog
   PERFORM choose_data_file.

* Call Subroutine to Load data into Internal table from text file
   PERFORM load_data_from_file.

* Determine the number of records in the internal table
   DESCRIBE TABLE it_routing LINES gv_lines.
   IF gv_lines <> 0.
     PERFORM populate_bapi_tables.
   ENDIF.

   IF it_task IS NOT INITIAL.
*   Call Subroutine to upload last routing details
     PERFORM call_bapi_and_commit.
   ENDIF.

*   Call Subroutine to Display Log in ALV
   PERFORM display_log_list.

**********************************************************************
*                End-of-selection
**********************************************************************
END-OF-SELECTION.

**********************************************************************
*                Forms and subroutines
**********************************************************************

*&--------------------------------------------------------------------

*&      Form  CHOOSE_DATA_FILE

*&--------------------------------------------------------------------

*  Subroutine to Show File Dialog and select file from the PC

*---------------------------------------------------------------------

FORM choose_data_file .



   DATA: lt_filetable TYPE filetable,
         lf_rc TYPE i,
         lv_fname(50) TYPE c,
         lv_fext(3) TYPE c.
   DATA: lw_file TYPE file_table.



* Function module to show File open Dialog

   CALL METHOD cl_gui_frontend_services=>file_open_dialog
     EXPORTING
       window_title            = 'Select Routing Data File'
       file_filter             = '*.txt'
       multiselection          = abap_false
     CHANGING
       file_table              = lt_filetable
       rc                      = lf_rc
     EXCEPTIONS
       file_open_dialog_failed = 1
       cntl_error              = 2
       error_no_gui            = 3
       not_supported_by_gui    = 4
       OTHERS                  = 5.

   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                DISPLAY LIKE 'E'
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     EXIT.
   ENDIF.

* Number of selected filed must be equal to one.

   CHECK lf_rc = 1.

* Access selected file




   READ TABLE lt_filetable INTO lw_file INDEX 1.
   CHECK sy-subrc = 0.
   gv_file = lw_file-filename.
   SPLIT gv_file AT '.' INTO lv_fname lv_fext.

* Check if Text file is Selected
   IF lv_fext NE 'txt'.
     MESSAGE 'Invalid File Type !' TYPE 'I'.
*    SUBMIT z_bapi_qp01.
   ENDIF.

ENDFORM.                    " CHOOSE_DATA_FILE



*&--------------------------------------------------------------------

*&      Form  LOAD_DATA_FROM_FILE

*&--------------------------------------------------------------------

* Subroutine to Load data into Internal table from text file

*---------------------------------------------------------------------

FORM load_data_from_file .
   DATA:  lv_file_name   TYPE  string.

   lv_file_name = gv_file.
* Call Function module to load data from Text File
   CALL FUNCTION 'GUI_UPLOAD'
     EXPORTING
       filename                = lv_file_name
       filetype                = 'ASC'
       has_field_separator     = 'X'
     TABLES
       data_tab                = it_routing
     EXCEPTIONS                                              "#EC *
       file_open_error         = 1
       file_read_error         = 2
       no_batch                = 3
       gui_refuse_filetransfer = 4
       invalid_type            = 5
       no_authority            = 6
       unknown_error           = 7
       bad_data_format         = 8
       header_not_allowed      = 9
       separator_not_allowed   = 10
       header_too_long         = 11
       unknown_dp_error        = 12
       access_denied           = 13
       dp_out_of_memory        = 14
       disk_full               = 15
       dp_timeout              = 16
       OTHERS                  = 17.
   IF sy-subrc <> 0.                                         "#EC NEEDED
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   LOOP AT it_routing WHERE material IS NOT INITIAL.
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
       EXPORTING
         input  = it_routing-material
       IMPORTING
         output = it_routing-material.
     MODIFY it_routing TRANSPORTING material.
   ENDLOOP.
ENDFORM.                    " LOAD_DATA_FROM_FILE




*&--------------------------------------------------------------------

*&      Form  CLEAR_INTERNAL_TABLES

*&--------------------------------------------------------------------

* Subroutine to Clear Internal Tables

*---------------------------------------------------------------------

FORM clear_internal_tables .

   CLEAR it_mat_task_allo[].

   CLEAR it_task[].

   CLEAR it_op[].

   CLEAR it_inspchar[].

   CLEAR it_ret[].

ENDFORM.                    " CLEAR_INTERNAL_TABLES


*&--------------------------------------------------------------------
*&      Form  POPULATE_BAPI_TABLES
*&--------------------------------------------------------------------
FORM populate_bapi_tables .
   DATA : lv_act(4) TYPE n,
          lv_opr(4) TYPE n.
* Loop at internal table to load all data

   LOOP AT it_routing.
*   Call Subroutine to Display the Progress
     PERFORM display_progress_timer.
     ON CHANGE OF it_routing-material.
*    IF it_routing-ins_activity IS INITIAL AND it_task IS NOT INITIAL.
       IF it_routing-material IS NOT INITIAL AND it_task IS NOT INITIAL.
*   Call Subroutine to Load the routing
         PERFORM call_bapi_and_commit.

*   Re-initialise the internal tables
         PERFORM clear_internal_tables.
       ENDIF.

       IF it_routing-plant IS NOT INITIAL.
         gv_plant = it_routing-plant.
       ENDIF.

     ENDON.

     IF it_routing-op_activity IS NOT INITIAL.
       lv_opr = it_routing-op_activity.
       CLEAR lv_act.
     ENDIF.

     IF it_routing-plant NE space.
       CLEAR : lv_act,
               it_mat_task_allo.
*   Moving Corresponding fields to Material internal table
       it_mat_task_allo-material = it_routing-material.
       it_mat_task_allo-plant = gv_plant.
       it_mat_task_allo-valid_from = sy-datum.
       APPEND it_mat_task_allo.

*   Moving Corresponding fields to task internal table
       CLEAR it_task.
       it_task-valid_from = sy-datum.
       it_task-description = it_routing-tsk_desc.
       it_task-task_list_usage = it_routing-task_list_usage.
       it_task-task_list_status = it_routing-task_list_status.
*      it_task-lot_size_from = it_routing-lot_size_from.
*      it_task-lot_size_to = it_routing-lot_size_to.
       it_task-lot_size_to = '99999999'.
*      it_task-planning_work_center = it_routing-planning_work_center.
       it_task-plant = gv_plant.
*      it_task-task_measure_unit = it_routing-task_measure_unit.
       SELECT SINGLE meins FROM mara INTO it_task-task_measure_unit
         WHERE matnr = it_routing-material.
       it_task-ident_key = it_routing-ident_key.
       APPEND it_task.

* Moving Corresponding fields to Operation internal table
       CLEAR it_op.
       it_op-valid_from = sy-datum.
       it_op-activity = lv_opr.
       it_op-plant = gv_plant.
       it_op-control_key = it_routing-control_key.
       it_op-work_cntr =  it_routing-work_cntr.
       it_op-description = it_routing-op_description.
*  it_op-operation_measure_unit   = it_routing-operation_measure_unit.
       it_op-operation_measure_unit   = it_task-task_measure_unit.
       it_op-denominator  = '1'.
       it_op-nominator    = '1'.
       it_op-base_quantity = '1.000'.
*      it_op-insp_point_complt_flow_variant = '3'.
       it_op-free_grid ='X'.
       it_op-std_value_01 = it_routing-std_value_01.
       it_op-std_value_02 = it_routing-std_value_02.
       it_op-std_value_03 = it_routing-std_value_03.
       it_op-std_value_04 = it_routing-std_value_04.
       it_op-std_value_05 = it_routing-std_value_05.
       it_op-std_value_06 = it_routing-std_value_06.
       APPEND it_op.
     ELSE.
       IF it_routing-op_activity IS NOT INITIAL.
*   Moving Corresponding fields to Operation internal table
         CLEAR it_op.
         it_op-valid_from = sy-datum.
         it_op-activity = lv_opr.
         it_op-plant = gv_plant.
         it_op-control_key = it_routing-control_key.
         it_op-work_cntr =  it_routing-work_cntr.
         it_op-description = it_routing-op_description.
*  it_op-operation_measure_unit   = it_routing-operation_measure_unit.
         it_op-operation_measure_unit   = it_task-task_measure_unit.
         it_op-denominator  = '1'.
         it_op-nominator    = '1'.
         it_op-base_quantity = '1.000'.
         it_op-insp_point_complt_flow_variant = '3'.
         it_op-std_value_01 = it_routing-std_value_01.
         it_op-std_value_02 = it_routing-std_value_02.
         it_op-std_value_03 = it_routing-std_value_03.
         it_op-std_value_04 = it_routing-std_value_04.
         it_op-std_value_05 = it_routing-std_value_05.
         it_op-std_value_06 = it_routing-std_value_06.
         APPEND it_op.
       ELSE.

         lv_act = lv_act + 10.
*Moving Corresponding fields to Inspection Characteris internal table
         CLEAR it_inspchar.
*        it_inspchar-activity = it_routing-ins_activity.
         it_inspchar-activity = lv_opr.
         it_inspchar-inspchar = lv_act.
         it_inspchar-valid_from  = sy-datum.
         it_inspchar-mstr_char = it_routing-mstr_char.
         it_inspchar-pmstr_char = gv_plant.
         it_inspchar-method = it_routing-method.
         it_inspchar-pmethod = gv_plant.
* Measured Values Must Be Recorded
         it_inspchar-meas_value_confirm_ind = 'X'.
         IF it_routing-smpl_procedure IS NOT INITIAL.
           it_inspchar-sampling_procedure_ind = 'X'.
           it_inspchar-smpl_procedure  = it_routing-smpl_procedure.
           it_inspchar-smpl_unit = it_task-task_measure_unit.
           it_inspchar-smpl_quant = 1. "it_routing-smpl_quant.
         ENDIF.
*        it_inspchar-dec_places = 2.
         it_inspchar-cha_master_import_modus = 'N'.
* Get Characteristic Description and decimal places
         SELECT SINGLE sortfeld stellen FROM qpmk
           INTO (it_inspchar-char_descr, it_inspchar-dec_places)
           WHERE zaehler = gv_plant
             AND mkmnr = it_routing-mstr_char.
         it_inspchar-quantitative_ind = it_routing-quantitative_ind.
         IF it_routing-quantitative_ind IS INITIAL.
           it_inspchar-attribute_required_ind = 'X'.
           SELECT SINGLE auswmenge1 FROM qpmz
             INTO it_inspchar-sel_set1
             WHERE zaehler = gv_plant
               AND mkmnr = it_routing-mstr_char.
           it_inspchar-psel_set1 = gv_plant.
         ENDIF.
         IF it_routing-target_val IS NOT INITIAL.
           it_inspchar-target_val_check_ind = 'X'.
           it_inspchar-meas_value_confirm_ind = 'X'.
         ENDIF.
         IF it_routing-up_tol_lmt IS NOT INITIAL.
           it_inspchar-up_tol_lmt_ind = 'X'.
           it_inspchar-meas_value_confirm_ind = 'X'.
         ENDIF.
         IF it_routing-lw_tol_lmt IS NOT INITIAL.
           it_inspchar-lw_tol_lmt_ind = 'X'.
           it_inspchar-meas_value_confirm_ind = 'X'.
         ENDIF.
         IF ( it_routing-formula1 IS NOT INITIAL OR
              it_routing-formula2 IS NOT INITIAL ).
           it_inspchar-formula_ind = 'X'.
           it_inspchar-meas_value_confirm_ind = 'X'.
           it_inspchar-formula_check_by_sap = 'X'.
         ENDIF.
         IF it_routing-summ_rec = 'X'.
           it_inspchar-result_recording_type = ' '.
         ELSE.
           it_inspchar-result_recording_type = '+'.
         ENDIF.
         it_inspchar-target_val = it_routing-target_val.
         it_inspchar-up_tol_lmt = it_routing-up_tol_lmt.
         it_inspchar-lw_tol_lmt = it_routing-lw_tol_lmt.
         it_inspchar-formula_field_1 = it_routing-formula1.
         it_inspchar-formula_field_2 = it_routing-formula2.
         it_inspchar-meas_unit = '%'.
         APPEND it_inspchar.
       ENDIF.
     ENDIF.

   ENDLOOP.

ENDFORM.                    " POPULATE_BAPI_TABLES

*&--------------------------------------------------------------------
*&      Form  Display_Progress_timer
*&--------------------------------------------------------------------
* Subroutine to show Progress at Status Bar
*---------------------------------------------------------------------

FORM display_progress_timer .
   gv_per = sy-tabix / gv_lines * 100.
   WRITE gv_per TO gv_txt.
   CONDENSE gv_txt.
   CONCATENATE gv_txt '% of Routings Completed...'
    INTO gv_txt SEPARATED BY space.

   CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
     EXPORTING
       percentage = gv_per
       text       = gv_txt.

ENDFORM.                    " Display_Progress_timer

*&--------------------------------------------------------------------
*&      Form  CALL_BAPI_AND_COMMIT
*&--------------------------------------------------------------------
* Subroutine to Load the Routings
*---------------------------------------------------------------------

FORM call_bapi_and_commit .

* Initialise internal table

   REFRESH it_ret.

* Call Function to Create Routing
   CALL FUNCTION 'BAPI_ROUTING_CREATE'
*   EXPORTING
*     TESTRUN                      = ' '
*     PROFILE                      =
*     BOMUSAGE                     =
*     APPLICATION                  =
     IMPORTING
       group                        = gv_group
       groupcounter                 = gv_gr_counter
     TABLES
       task                         = it_task
       materialtaskallocation       = it_mat_task_allo
*     SEQUENCE                     =
       operation                    = it_op
*     SUBOPERATION                 =
*     REFERENCEOPERATION           =
*     WORKCENTERREFERENCE          =
*     COMPONENTALLOCATION          =
*     PRODUCTIONRESOURCE           =
       inspcharacteristic           = it_inspchar
*     TEXTALLOCATION               =
*     TEXT                         =
       return                       = it_ret
             .

   READ TABLE it_ret INDEX 1.
   DESCRIBE TABLE it_ret.

* Check for success message and then Commit, otherwise dont commit
   IF it_ret-type EQ 'S' AND sy-tfill EQ 1.
     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
*     IMPORTING
*       RETURN        =
               .

* Populate Success message in internal table for ALV Log display
     it_loghead-plant = gv_plant.
     it_loghead-material = it_mat_task_allo-material.
     it_loghead-msgtype = 'S'.
     CONCATENATE 'Routing Created Successfully' gv_group
       INTO it_loghead-msg SEPARATED BY space.
     APPEND it_loghead.

   ELSE.
* Populate Error message in internal table for ALV Log display
     it_loghead-plant = gv_plant.
     it_loghead-material = it_mat_task_allo-material.
     it_loghead-msgtype = 'E'.
     it_loghead-msg = 'Routing Not Created'.
     APPEND it_loghead.
* Retrieve and populate Error Details for Log Display
     CLEAR it_ret.
     LOOP AT it_ret.
       it_logdetail-plant = gv_plant.
       it_logdetail-material = it_mat_task_allo-material.
       it_logdetail-msgtype = it_ret-type.
       it_logdetail-msg = it_ret-message.
       IF it_ret-parameter IS NOT INITIAL.
         CONCATENATE it_logdetail-msg '- Error in parameter'
         it_ret-parameter INTO it_logdetail-msg SEPARATED BY space.
         IF it_ret-row IS NOT INITIAL.
           gv_row = it_ret-row.
           CONCATENATE it_logdetail-msg '- In Row' gv_row
           INTO it_logdetail-msg SEPARATED BY space.
         ENDIF.
       ENDIF.
       APPEND it_logdetail.
     ENDLOOP.

     REFRESH it_ret.
   ENDIF.
ENDFORM.                    " CALL_BAPI_AND_COMMIT

*&--------------------------------------------------------------------
*&      Form  DISPLAY_LOG_LIST
*&--------------------------------------------------------------------
* Subroutine to Display Log
*---------------------------------------------------------------------

FORM display_log_list .
   DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
   wa_fieldcat TYPE LINE OF slis_t_fieldcat_alv,
   wa_layout TYPE slis_layout_alv,
   it_keyinfo TYPE TABLE OF slis_keyinfo_alv WITH HEADER LINE.
   DATA lv_repid LIKE sy-repid.

* Store report name
   lv_repid = sy-repid.
* Create FieldCatalog for ALV
   CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
       i_program_name         = lv_repid
       i_internal_tabname     = 'IT_LOGHEAD'
       i_inclname             = lv_repid
     CHANGING
       ct_fieldcat            = it_fieldcat
     EXCEPTIONS
       inconsistent_interface = 1
       program_error          = 2
       OTHERS                 = 3.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
       i_program_name         = lv_repid
       i_internal_tabname     = 'IT_LOGDETAIL'
       i_inclname             = lv_repid
     CHANGING
       ct_fieldcat            = it_fieldcat
     EXCEPTIONS
       inconsistent_interface = 1
       program_error          = 2
       OTHERS                 = 3.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   LOOP AT it_fieldcat INTO wa_fieldcat WHERE fieldname = 'MSG'.
     wa_fieldcat-seltext_l = 'Message'.
     wa_fieldcat-seltext_m = 'Message'.
     wa_fieldcat-seltext_s = 'Message'.
     MODIFY it_fieldcat FROM wa_fieldcat.
   ENDLOOP.

   it_keyinfo-header01 = 'PLANT'.
   it_keyinfo-header02 = 'MATERIAL'.
   it_keyinfo-item01 = 'PLANT'.
   it_keyinfo-item02 = 'MATERIAL'.
   APPEND it_keyinfo.

   wa_layout-expand_fieldname = 'EXPAND'.
   wa_layout-def_status = ' '.
   SORT it_logdetail BY plant material msg.
   DELETE ADJACENT DUPLICATES FROM it_logdetail COMPARING
                            plant material msg.

* Call function to display ALV LOG
   CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
     EXPORTING
       i_callback_program    = sy-repid
       it_fieldcat           = it_fieldcat
       is_layout             = wa_layout
       i_default             = 'X'
       i_save                = 'A'
       i_tabname_header      = 'IT_LOGHEAD'
       i_tabname_item        = 'IT_LOGDETAIL'
       is_keyinfo            = it_keyinfo
       i_bypassing_buffer    = 'X'
       i_suppress_empty_data = abap_true
     TABLES
       t_outtab_header       = it_loghead
       t_outtab_item         = it_logdetail
     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_LOG_LIST

Regards

Animesh Sundriyal