Thursday, April 4, 2019

Modify screen based on check box



There are two buttons on screen
Rad1
Rad2


Both buttons are in same block and same group.

PARAMETERS      p_opt1   RADIOBUTTON GROUP gr1 DEFAULT 'X' USER-COMMAND a.
PARAMETERS :    p_opt2 RADIOBUTTON GROUP gr1.


This code will populate the variant field based on radio button selected.
 LOOP AT SCREEN.
    IF p_opt2 gc_x.
      CLEAR p_var.
      p_var '/EXCEL'(025).
      IF screen-name 'P_MATNR'.       " Input parameter
        CLEAR p_matnr.
        screen-input '0'.
        MODIFY SCREEN.
      ENDIF.
    ELSEIF p_opt1 gc_x.
      CLEAR p_file.
      p_var '/DEFAULT'(026).
    ENDIF.

Wednesday, April 3, 2019

Fetch data from excel file into Internal table

 DATAlt_itab  TYPE STANDARD TABLE OF alsmex_tabline INITIAL SIZE 0.
  DATAlk_itab  TYPE alsmex_tabline,
              lk_excel TYPE ty_excel.

  DATA  lt_excel TYPE STANDARD TABLE OF ty_excel.
  DATA  lv_ivnum(10TYPE n.

  FIELD-SYMBOLS<itab_xls> TYPE any,
                 <fk_excel> TYPE ty_excel.
*read file from presentation Layer for XL file upload
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                p_file
      i_begin_col             '1'
      i_begin_row             '2'
      i_end_col               '200'
      i_end_row               '9999'
    TABLES
      intern                  lt_itab
    EXCEPTIONS
      inconsistent_parameters 1
      upload_ole              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.
* Sort table by rows and colums
  SORT lt_itab BY row col ASCENDING.

  IF NOT lt_itab IS INITIAL.
* Populate it_data_read with the data read from excel file
    LOOP AT lt_itab INTO lk_itab.
      ASSIGN COMPONENT lk_itab-col OF STRUCTURE lk_excel
            TO <itab_xls>.
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.

      <itab_xls> lk_itab-value.

      AT END OF row.
        APPEND lk_excel TO gt_excel.
        CLEARlk_itablk_excel.
      ENDAT.
    ENDLOOP.
  ENDIF.

Populte filepath on selection screen

  DATAlt_filetab   TYPE filetable,
              lk_filetab  TYPE file_table,
              lc_title      TYPE string,
              lk_rc         TYPE i.

  lc_title 'Select local file'(004).

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            lc_title
      file_filter             ',*.*,*.*.'
      initial_directory       ': '
    CHANGING
      file_table              lt_filetab
      rc                      lk_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 sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    READ TABLE lt_filetab INTO lk_filetab INDEX 1.
    IF sy-subrc EQ 0.
      p_filepath lk_filetab-filename.
    ENDIF.
  ENDIF.

Refresh ALV Grid on user action



DATA ref_grid TYPE REF TO cl_gui_alv_grid.

* to reflect the data changed into internal table
      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->refresh_table_display.
      ENDIF.

******************************************************
Option -2.

* to reflect the data changed into internal table
      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.
* refresh the ALV Grid output from internal table
      l_selfield-refresh gc_x.