cancel
Showing results for 
Search instead for 
Did you mean: 

delete record in the ALV report and at the same time it reflects file in AL11 directory

Junaidshaik284
Participant
0 Kudos

HI everyone,

my requirement is to upload data from excel to AL11 and to display alv report. when I try to click delete button to delete select entry in the displayed in alv and update the same in AL11 and please guide how to update delete record in al11(csv file ) and I wrote code to display and delete record in alv. Guide me to delete record in al11(csv file) also.

lt_rows = lo_selections->get_selected_rows( ).<br>    LOOP AT lt_rows ASSIGNING FIELD-SYMBOL(<fs_rows>).<br>      READ TABLE t_emp ASSIGNING FIELD-SYMBOL(<fs_emp>) INDEX <fs_rows>.<br>      IF sy-subrc EQ 0.<br>        CLEAR <fs_emp>.<br>      ENDIF.<br>    ENDLOOP.<br>    DELETE t_emp WHERE name IS INITIAL.<br>    o_alv->refresh( ).
raymond_giuseppi
Active Contributor
0 Kudos

Paste the code without formatting in the code area

Junaidshaik284
Participant
0 Kudos

CLASS lcl_file_alv IMPLEMENTATION.


METHOD md_int.

lo_alv = NEW lcl_file_alv( ).

ENDMETHOD.

METHOD md_f4help_ps.

CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file1.

ENDMETHOD.

METHOD md_f4help_as.
CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
directory = w_directory
IMPORTING
serverfile = p_file2
EXCEPTIONS
canceled_by_user = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'Error Message' TYPE 'I'.
ENDIF.
ENDMETHOD.

METHOD md_fetchdata.



IF r1 = 'X'.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = t_trux
i_filename = p_file1
* I_STEP = 1
TABLES
i_tab_converted_data = t_emp[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CONCATENATE w_path sy-datum sy-uzeit w_text INTO w_path1 IN CHARACTER MODE.

OPEN DATASET w_path1 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
LOOP AT t_emp ASSIGNING FIELD-SYMBOL(<fs_emp>).
CONCATENATE <fs_emp>-name <fs_emp>-address <fs_emp>-age <fs_emp>-gender INTO w_string SEPARATED BY ','.
TRANSFER w_string TO w_path1.
ENDLOOP.
CLOSE DATASET w_path1.
ELSE.
MESSAGE 'error' TYPE 'E'.
ENDIF.

*
* CALL METHOD cl_salv_table=>factory
* IMPORTING
* r_salv_table = o_alv
* CHANGING
* t_table = t_emp.
*
* CALL METHOD o_alv->display.


ELSEIF r2 = 'X'.


CLEAR t_emp.
OPEN DATASET p_file2 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
DO.
READ DATASET p_file2 INTO w_string.
IF sy-subrc = 0.
SPLIT w_string AT ',' INTO wa_emp-name wa_emp-address wa_emp-age wa_emp-gender.
APPEND wa_emp TO t_emp.
CLEAR wa_emp.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
ENDIF.
ENDMETHOD.

METHOD md_display_alv.


CONSTANTS: gc_true TYPE sap_bool VALUE 'X'.
TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* r_container = gr_container
* container_name = 'CONTAINER'
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = t_emp.


CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.

lo_selections = o_alv->get_selections( ).
lo_selections->set_selection_mode( if_salv_c_selection_mode=>multiple ).


o_alv->set_screen_status(
pfstatus = 'ZDLT'
report = syst-repid
set_functions = o_alv->c_functions_all ).

lo_layout_settings = o_alv->get_layout( ).
lo_layout_settings->set_save_restriction( if_salv_c_layout=>restrict_none ). "ALV LAYOUT

lo_columns = o_alv->get_columns( ). "ALV COLUMN SIZE
lo_columns->set_optimize( ).

lo_display_settings = o_alv->get_display_settings( ). "ZEBRA LINES DISPLAY
lo_display_settings->set_striped_pattern( if_salv_c_bool_sap=>true ).

lo_display_settings->set_list_header( 'ALV REPORT' ). "ALV HEADER TITILE

o_events = o_alv->get_event( ).
SET HANDLER : lo_alv->md_double_click FOR o_events,
lo_alv->md_link_click FOR o_events,
lo_alv->md_user_command FOR o_events.


CALL METHOD o_alv->display.


ENDMETHOD.

METHOD md_double_click.


BREAK-POINT.

ENDMETHOD.

METHOD md_link_click.
BREAK-POINT.
ENDMETHOD.

METHOD md_user_command.
lt_rows = lo_selections->get_selected_rows( ).
LOOP AT lt_rows ASSIGNING FIELD-SYMBOL(<fs_rows>).
READ TABLE t_emp ASSIGNING FIELD-SYMBOL(<fs_emp>) INDEX <fs_rows>.
IF sy-subrc EQ 0.
CLEAR <fs_emp>.
ENDIF.
ENDLOOP.
DELETE t_emp WHERE name IS INITIAL.
o_alv->refresh( ).
ENDMETHOD.
ENDCLASS.
Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert

There is no such thing as a "file in AL11"! You mean a "file in the file system of the application server".

AL11 is only a UI that displays the file system of the current application server. Similar to how "Windows Explorer" displays the file system of your notebook / desktop PC. And nobody would say, that a file exists "in Windows Explorer".

Junaidshaik284
Participant
0 Kudos

Yes, file in application server

Sandra_Rossi
Active Contributor

As you are an SAP employee, you will be interested to beautify your answer by using the [CODE] button, e.g.:

REPORT z_delete_record_csv_alv.
TABLES: your_data_table. " Replace with the name of your data table
TYPES: BEGIN OF ty_your_data_table,
         field1 TYPE c LENGTH 10, " Replace with the structure of your data table
         field2 TYPE i,
       END OF ty_your_data_table.
DATA: it_your_data_table TYPE TABLE OF ty_your_data_table,
      wa_your_data_table TYPE ty_your_data_table,
      it_deleted_records TYPE TABLE OF ty_your_data_table,
      wa_deleted_record  TYPE ty_your_data_table.
DATA: lo_alv       TYPE REF TO cl_salv_table,
      lo_functions TYPE REF TO cl_salv_functions_list.

START-OF-SELECTION.
  " Populate your_data_table with data from the CSV file in AL11
  SELECT *
  INTO TABLE it_your_data_table
  FROM your_data_table. " Replace with the name of your data table
  " Create ALV and enable deletion
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = lo_alv
    CHANGING
      t_table      = it_your_data_table.
  lo_functions = lo_alv->get_functions( ).
  lo_functions->set_all( abap_true ).
  " Event handler for deletion
  SET HANDLER delete_record FOR lo_functions.
  " Display ALV
  lo_alv->display( ).
  " Event handler method for deletion
  METHOD delete_record.
    DATA: lv_index TYPE i.
    " Get the selected rows for deletion
    DATA(lt_selected_rows) = lo_alv->get_selected_rows( ).
    IF lt_selected_rows IS INITIAL.
      RETURN.
    ENDIF.
    " Store the deleted records in a separate internal table
    LOOP AT lt_selected_rows INTO lv_index.
      READ TABLE it_your_data_table INTO wa_your_data_table INDEX lv_index.
      IF sy-subrc = 0.
        APPEND wa_your_data_table TO it_deleted_records.
        DELETE it_your_data_table INDEX lv_index.
      ENDIF.
    ENDLOOP.
    " Update the CSV file in AL11 directory
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename = 'AL11_DIRECTORY/your_file.csv' " Replace with the actual path and file name
        filetype = 'ASC'
      TABLES
        data_tab = it_your_data_table.
    " Process the deleted records as required
    LOOP AT it_deleted_records INTO wa_deleted_record.
      " Your logic for processing deleted records
      WRITE: / 'Deleted record:', wa_deleted_record-field1, wa_deleted_record-field2.
    ENDLOOP.
    " Display updated ALV
    lo_alv->display( ).
  ENDMETHOD.
Sandra_Rossi
Active Contributor

Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

If you want to target someone, if this person has posted an Answer, use the button COMMENT, if this person is the Original Poster of the question he/she will be automatically informed, otherwise copy/paste their hyperlinked name so that the person receives a warning (NB: @ doesn't work/but typing this character will suggest hyperlinked names).

VXLozano
Active Contributor
0 Kudos

If the logic is that straight:

  1. upload the data
  2. present the ALV to the user
  3. download the data

You don't need to delete record in the file. Just follow those three steps in your program. Do not save the file until the user tells your program to do it (accepting their modifications).

Split your requirement into those three "problems", solve each one, put all the solutions toguether, and serve your program with a pinch of salt.

Junaidshaik284
Participant
0 Kudos

Thank you so much for understanding but i want to delete multiple records based on user's interaction in alv report and you wrote the logic that it is deleting record based on index and suppose we have 5 rows, user selected 4,5 rows and the loop delete first 4th record then we have 4 records in internal table it is just checking 5th index so i think that it does not work properly and can you frame code to delete multiple records what user selected and tell me that logic.


LOOP AT lt_selected_rows INTO lv_index.
      READ TABLE it_your_data_table INTO wa_your_data_table INDEX lv_index.
      IF sy-subrc = 0.
        APPEND wa_your_data_table TO it_deleted_records.
        DELETE it_your_data_table INDEX lv_index.
      ENDIF.
Junaidshaik284
Participant
0 Kudos

thank you for understanding me vicen.lozano.

Junaidshaik284
Participant
0 Kudos

Hi ulrich.schmidt

thanks for understanding me

Accepted Solutions (0)

Answers (0)