Sort itab stable

Hi,
can you please  explain me diffrence between Sort itab stable and sort itab using simple example.
Regards,
Suresh.

1  3
2  2
1  3
1  2
2  3
SORT ITAB STABLE always gives the output same
1  2
1  3
1  3
2  2
2  3
but SORT ITAB gives
1  2
1  3
1  3
2  2
2  3
or
1  3
1  3
1  2
2  2
2  3
or
1  3
1  2
1  3
2  3
2  2

Similar Messages

  • SORT ITAB BY VARIABLE_NAME

    hi,
    i want to sort the int table with variable parameters, like VKBUR, BUDAT, VKORG, MATNR, etc.
    for that ive created a char variable of 5 length (say CRIT) and assigned value based on selection criteria by the user.
    Then, im using SORT ITAB BY CRIT. Its not getting sorted properly.
    Any suggestions,
    Regards,
    Naveen

    You can easily achieve it by using filed symbols.
    Assign the field (upon which you require sorting) to field symbol<Fs> and then sort the table with (<Fs>)reference.
    Sample code is given below for your help.
    DATA: BEGIN OF x1 OCCURS 0,
            t1 TYPE string,
            t2 TYPE string,
            t3 TYPE string,
           END OF x1.
    FIELD-SYMBOLS: <fs> TYPE ANY.
    x1-t1 = 'B'.
    x1-t2 = 'D'.
    x1-t3 = '9'.
    APPEND x1.
    x1-t1 = 'C'.
    x1-t2 = 'X'.
    x1-t3 = '4'.
    APPEND x1.
    x1-t1 = 'F'.
    x1-t2 = 'Y'.
    x1-t3 = '6'.
    APPEND x1.
    LOOP AT x1.
      WRITE: / x1-t1, '    ', x1-t2, '    ', x1-t3.
    ENDLOOP.
    SKIP 2.
    * Sort by field T1
    ASSIGN 't1' TO <fs>.
    SORT x1 BY (<fs>).
    LOOP AT x1.
      WRITE: / x1-t1, '    ', x1-t2, '    ', x1-t3.
    ENDLOOP.
    skip 2.
    * Sort by field T3
    ASSIGN 't3' TO <fs>.
    SORT x1 BY (<fs>).
    LOOP AT x1.
      WRITE: / x1-t1, '    ', x1-t2, '    ', x1-t3.
    ENDLOOP.

  • Sort  itab by using field symbol

    All,
    I have a field symbol  that pointing to a field value in work area of an internal table i_sort ( For example work area that contains the field name having a value MATNR' ( this decides only at runtime) )
    My requirement is i need to sort another table for example i_tab (structure same as records in i_sort) using this field symbol.
    Any Info?

    Hi,
    Check the below report sorting table VBAP based on field VBELN dynamically.
    Let me know if u need any clarification.
    REPORT  ZTEST1.
    tables: dd03l.
    field-symbols: <fs1> type any,
                   <fs2> type any.
    data:
       wa_1 type vbak,
       w_index type sy-index.
    data:
      itab like standard table of vbap,
      ftab like standard table of dd03l.
      select * from vbap into table itab
               up to 10 rows.
    select single * from vbak into wa_1 where vbeln ne space.
    assign wa_1-vbeln to : <fs1>,
                           <fs2>.
    do.
      assign component sy-index of structure wa_1 to <fs1>.
      if <fs1> = <fs2>.
        w_index = sy-index.
        exit.
      endif.
    enddo.
    select *
      from DD03L
      into table ftab
    where TABNAME eq 'VBAK'.
    sort ftab by position.
    read table ftab with key position = w_index into dd03l.
    sort itab by (dd03l-FIELDNAME).
    Thanks,
    - Ram

  • Sort itab by select-options

    Hi,
    i have this code:
    SELECT-OPTIONS:   S_MATNR   FOR MARA-MATNR.
      SELECT  * FROM MARA WHERE MATNR IN S_MATNR.
        CLEAR: WA_ITAB.
        WA_ITAB-MATNR = MARA-MATNR.
        WA_ITAB-MTART = MARA-MTART.
        WA_ITAB-MATKL = MARA-MATKL.
        APPEND WA_ITAB TO IT_ITAB.
      ENDSELECT.
    now i want to sort the it_itab by the given select-options. Is this possible?
    ( select-options can have single valuse, ranges, meta characters)
    Or is it possible to use select from table mara in order by select-options?
    Regards, Dieter

    Hi,
    First of all please avoid such a select statement. It causes a lot of performance problem.
    Code like this
    SELECT  *  FROM MARA
    INTO CORRESPONDING FIELDS OF TABLE IT_ITAB
    WHERE MATNR IN S_MATNR.
    Secondly what do you mean by SORT ITAB by SELECT_OPTIONS S_MATNR.
    You yourself have said that the select-option can contain single values or multiple values or ranges.
    So how should the SORT be?
    Kinldy check with the requirment. It seems a little weird.
    Regards,
    Ankur Parab

  • Ways of building sort itabs

    eg. is this way of doing correct for building sorted table?
    will this lose the binary properties for quick access?
    sort standard_itab by a b c.
    sorteditab[] = standard_itab[]
    or should it be this way? using insert?
    loop at standard_itab into wa.
      insert wa into sorteditab.
    endloop.

    Hi Charles,
    This link: http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb34d0358411d1829f0000e829fbfe/content.htm
    soesn't specify anything about the type of tables when assigning.
    So, your first code looks ok.
    This code works fine for me:
    REPORT ZTEST.
    DATA: ftab TYPE SORTED TABLE OF f
               WITH NON-UNIQUE KEY table_line,
          itab TYPE standard TABLE OF i ,
          fl   TYPE f.
      DO 3 TIMES.
      INSERT sy-index INTO TABLE itab.
      ENDDO.
    sort itab.
    LOOP AT itab INTO fl.
      WRITE: / fl.
    ENDLOOP.
    ftab[] = itab[].
    LOOP AT ftab INTO fl.
      WRITE: / fl.
    ENDLOOP.
    Regards,
    Ravi
    Message was edited by:
            Ravi Kanth Talagana

  • Sort itab by another itab?

    Hi,
    i have 2 itabs: itab0 with matnr and lgpbe. itab1 with matnr matkl brgew.
    it sort itab0 by lgpbe.
    Is it possiple to sort itab1 like itab0 without having lgpbe and without changing
    the entries of itab1?
    i look for any like "sort itab1 by itab0-matnr"???
    Regards, Dieter

    HI,
      you cannot use sort statement like this..
      how ever.. just do this way.
       loop at itab0.
       loop at itab1 where matnr  = itab0=matnr.
       itab2 = itab1.
       append itab2.
       endloop.
       endloop.
    at end of this itab2 will have ur sorted data.

  • Runtime error in sorted itab

    Q2]]  A runtime error occurs if you violate the sort order of a sorted table by appending to it -
    WHY?

    Hi,
    First of all you should try and understand the meaning of Append and Insert.
    Append always adds a new line to the end of the internal table.If the table is empty,then it would add it as the first line.
    Insert always inserts the row according to the sorting or if you have given any condition then accordingly.
    Modify can play the role of either the Append or Insert depending on the type of the table.
    Hence,if you try to use Append in a sorted table, it adds a new row at the end of the table and disturbs the sorting.Insert on the other hand includes the row at a place according to the sorting.
    In case you have any further clarifications,do let me know.
    Regards,
    Puneet Jhari.

  • Standard and sorted itab

    what is the diff between standard and sorted itab

    Hi Abhay,
    check the following explanation.
    <b>Standard tables</b>
    This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPENDstatement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option (BINARY) with key access, the response time is logarithmically proportional to the number of table entries.
    <b>Sorted tables</b>
    This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERTstatement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHEREcondition.
    Hope this helps.
    Regards,
    kinshuk

  • Sort Itab - Ignoring Case

    Hi,
    I need to sort an Internal Table by name field by ignoring the CASE.
    One way is: Convert the Name into Upper or Lower case and do the sorting.
    However, is there any other way we could handle this?  Do we have SORT which can ignore the case?
    Thanks for the reply.
    Thanks,
    Sandeep

    Hi Sandeep,
    I think that is the way to do that. Make that as either upper /lower case and do sorting. Normally when we sort upper case will come first & lower case will come next.
    refer this thread:
    http://scn.sap.com/thread/1309978
    Regards,
    Poornima

  • Sort itab

    I need to do the following sort:
    SORT it_header BY lifnr xblnr belnr ASCENDING.
    Only I also want it sorted by CHECF descending.  Basically, I need it to be ascending except I want all records, with a blank CHECF, last (within it's own vendor, lifnr, section). 
    Example:
    LIFNR  XBLNR  BELNR  CHECF
    00001  001000  000100 
    00002 012000   000111 
    00002 012340   012300  000034
    00001  001100  000110  000001
    Would be, after all sorts:
    LIFNR  XBLNR  BELNR  CHECF
    00001  001100  000100  000001
    00001  001000  000100 
    00002 012340   012300  000034
    00002 012000   000111                "If no CHECF then it should be the last entry for the vendor, no matter the other fields.
    Is there a way to do this without looping through the table?

    Davis,
    I have question .
    i used as you suggested by your last reply. but i am thinking the output is not coming as per your first reply
    Here is code
    report zaRs.
    data : begin of it_header occurs 0,
           field1(5) type c,
           field2(6) type c,
           field3(6) type c,
           field4(6) type c.
    data : end of it_header.
    move '00001001000000100' to it_header. append it_header.
    move '00002012000000111' to it_header. append it_header.
    move '00002012340012300000034' to it_header. append it_header.
    move '00001001100000110000001' to it_header. append it_header.
    sort it_header by field1 ascending field4 descending field2 field3 ascending.
    loop at it_header.
      write :/ it_header.
    endloop.
    After running this report i got the output like the following
    00001001100000110000001
    00001001000000100
    00002012340012300000034
    00002012000000111

  • How to check internal table sorted or not

    Hi all
    I need to check internal table sorted or not which is without header line and having only one field and six values. please let me know how to check it is sorted or not because i need to display message if it is not sorted.
    thanks,
    Minal

    Hi Minal,
    Go through  this info.
    Sorted tables
    This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.
    Stable sort
    The option
    SORT <itab> ... STABLE.
    allows you to perform a stable sort, that is, the relative sequence of lines that are unchanged by the sort is not changed. If you do not use the STABLE option, the sort sequence is not preserved. If you sort a table several times by the same key, the sequence of the table entries will change in each sort. However, a stable sort takes longer than an unstable sort.
    Examples
    DATA: BEGIN OF LINE,
            LAND(3)  TYPE C,
            NAME(10) TYPE C,
            AGE      TYPE I,
            WEIGHT   TYPE P DECIMALS 2,
          END OF LINE.
    DATA ITAB LIKE STANDARD TABLE OF LINE WITH NON-UNIQUE KEY LAND.
    LINE-LAND = 'G'.   LINE-NAME   = 'Hans'.
    LINE-AGE  = 20.    LINE-WEIGHT = '80.00'.
    APPEND LINE TO ITAB.
    LINE-LAND = 'USA'. LINE-NAME   = 'Nancy'.
    LINE-AGE  = 35.    LINE-WEIGHT = '45.00'.
    APPEND LINE TO ITAB.
    LINE-LAND = 'USA'. LINE-NAME   = 'Howard'.
    LINE-AGE  = 40.    LINE-WEIGHT = '95.00'.
    APPEND LINE TO ITAB.
    LINE-LAND = 'GB'.  LINE-NAME   = 'Jenny'.
    LINE-AGE  = 18.    LINE-WEIGHT = '50.00'.
    APPEND LINE TO ITAB.
    LINE-LAND = 'F'.   LINE-NAME   = 'Michele'.
    LINE-AGE  = 30.    LINE-WEIGHT = '60.00'.
    APPEND LINE TO ITAB.
    LINE-LAND = 'G'.   LINE-NAME   = 'Karl'.
    LINE-AGE  = 60.    LINE-WEIGHT = '75.00'.
    APPEND LINE TO ITAB.
    PERFORM LOOP_AT_ITAB.
    SORT ITAB.
    PERFORM LOOP_AT_ITAB.
    SORT ITAB.
    PERFORM LOOP_AT_ITAB.
    SORT ITAB STABLE.
    PERFORM LOOP_AT_ITAB.
    SORT ITAB DESCENDING BY LAND WEIGHT ASCENDING.
    PERFORM LOOP_AT_ITAB.
    FORM LOOP_AT_ITAB.
      LOOP AT ITAB INTO LINE.
        WRITE: / LINE-LAND, LINE-NAME, LINE-AGE, LINE-WEIGHT.
      ENDLOOP.
      SKIP.
    ENDFORM.
    ************rewords some points if it is helpful.
    Rgds,
    P.Naganjana Reddy

  • How To delete the Chosen line from the Table Control

    Hi Friends,
      i am new to Module Pool Programming , i developed a Table Control in input mode and i am getting data also into that table control. my requirement is that i want to delete the current chosen line from that table control. please help me out.

    HI
    GOOD
    GO THROUGH THIS REPORT
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF flights-cols,
    lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
          TABLES demo_conn.
    SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
      cols-screen-input = '0'.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
    DESCRIBE TABLE itab LINES lines.
    flights-lines = lines.
    ENDMODULE.
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
      MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'TOGGLE'.
          LOOP AT flights-cols INTO cols WHERE index GT 2.
            IF  cols-screen-input = '0'.
              cols-screen-input = '1'.
            ELSEIF  cols-screen-input = '1'.
              cols-screen-input = '0'.
          ENDIF.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
        WHEN 'SORT_UP'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
            cols-selected = ' '.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'SORT_DOWN'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
            cols-selected = ' '.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'DELETE'.
          READ TABLE flights-cols INTO cols
                                  WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              DELETE itab.
    ENDLOOP.
          ENDIF.
    ENDCASE.
    ENDMODULE.
    CHANGE THE CODE AS PER THIS LIGIC.
    THANKS
    MRUTYUN

  • How to use PF status in Table Control?

    I have made 1 table control. Now I need to use three buttons like SELECT, DESELECT, DELETE the rows of table control using PF STATUS.  Can you plz help with the Code.

    Hi.
    Refer this code.
    The following example processes a table control with LOOP with parallel loop using an internal table. By using function codes you can sort columns and delete rows from the internal table. The ready for input status of the table control fields is controlled using a function code.
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF flights-cols,
          lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
          TABLES demo_conn.
    SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
      cols-screen-input = '0'.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
      DESCRIBE TABLE itab LINES lines.
      flights-lines = lines.
    ENDMODULE.
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
      MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'TOGGLE'.
          LOOP AT flights-cols INTO cols WHERE index GT 2.
            IF  cols-screen-input = '0'.
              cols-screen-input = '1'.
            ELSEIF  cols-screen-input = '1'.
              cols-screen-input = '0'.
            ENDIF.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDLOOP.
        WHEN 'SORT_UP'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
            cols-selected = ' '.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'SORT_DOWN'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
            cols-selected = ' '.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'DELETE'.
          READ TABLE flights-cols INTO cols
                                  WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              DELETE itab.
            ENDLOOP.
          ENDIF.
      ENDCASE.
    ENDMODULE.
    Reward all helpfull answers.
    Regards.
    Jay

  • How to clear data from Table-Control

    Hi all,
    I am working on table control. I have some data on the table control.
    When I press the 'Cancel' button, I require that the table-control should be cleared.
    I tried using REFRESH CONTROL TC01 USING SCREEN 1001. But, the data doesn't get cleared.
    Please advise.
    Regards,
    Saurabh Buksh.

    hi
    good
    try this example
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF flights-cols,
          lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
          TABLES demo_conn.
    SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
      cols-screen-input = '0'.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
      DESCRIBE TABLE itab LINES lines.
      flights-lines = lines.
    ENDMODULE.
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
      MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'TOGGLE'.
          LOOP AT flights-cols INTO cols WHERE index GT 2.
            IF  cols-screen-input = '0'.
              cols-screen-input = '1'.
            ELSEIF  cols-screen-input = '1'.
              cols-screen-input = '0'.
            ENDIF.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDLOOP.
        WHEN 'SORT_UP'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
            cols-selected = ' '.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'SORT_DOWN'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
            cols-selected = ' '.
            MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'DELETE'.
          READ TABLE flights-cols INTO cols
                                  WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              DELETE itab.
            ENDLOOP.
          ENDIF.
      ENDCASE.
    ENDMODULE.
    thanks
    mrutyun^

  • How to move the selected rows from a  table control in dialog programming

    hiiiiiiii Every1
    I have to update some fields for a slected row in table control on click of a button and save it in database.
    Regards
    Sachin Dhingra

    see below example, I have added INSERT option after DELETE option, you can use same table or you can use differnt table by populating into that table and insert into the db table. If you want to use same internal table then use below code
    LOOP AT itab INTO demo_conn WHERE mark = 'X'.
    insert into table from itab.
    ENDLOOP.
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA cols LIKE LINE OF flights-cols.
    DATA: ok_code TYPE sy-ucomm,
    save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
    TABLES demo_conn.
    SELECT * FROM spfli INTO TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
    cols-screen-input = '0'.
    MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
    SET PF-STATUS 'SCREEN_100'.
    ENDMODULE.
    MODULE cancel INPUT.
    LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
    MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
    save_ok = ok_code.
    CLEAR ok_code.
    CASE save_ok.
    WHEN 'TOGGLE'.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
    IF cols-screen-input = '0'.
    cols-screen-input = '1'.
    ELSEIF cols-screen-input = '1'.
    cols-screen-input = '0'.
    ENDIF.
    MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    WHEN 'SORT_UP'.
    READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
    IF sy-subrc = 0.
    SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
    cols-selected = ' '.
    MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDIF.
    WHEN 'SORT_DOWN'.
    READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
    IF sy-subrc = 0.
    SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
    cols-selected = ' '.
    MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDIF.
    WHEN 'DELETE'.
    READ TABLE flights-cols INTO cols WITH KEY screen-input = '1'.
    IF sy-subrc = 0.
    LOOP AT itab INTO demo_conn WHERE mark = 'X'.
    DELETE itab.
    ENDLOOP.
    ENDIF.
    WHEN 'INSERT'.
    READ TABLE flights-cols INTO cols WITH KEY screen-input = '1'.
    IF sy-subrc = 0.
    LOOP AT itab INTO demo_conn WHERE mark = 'X'.
    itab1 = itab.
    modify itab1.
    ENDLOOP.
    ENDIF.
    if not itab1 is initial.
    INSERT dbtab FROM TABLE itab1.
    endif.
    ENDCASE.
    ENDMODULE.

Maybe you are looking for