Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sorting in Table Control

Former Member
0 Likes
12,736

Hello All,

I have table control & I added sort button with code ..

in top program ..

data:  fld_list   LIKE  TBL_CTRL-cols,

wa_fld_list LIKE LINE OF fld_list.

in PAI..

  when 'SORTU'.

       READ TABLE TBL_CTRL-cols INTO wa_fld_list WITH KEY selected = 'X'.

       IF sy-subrc = 0.

       SORT  IT_ZPRODUCT_T STABLE BY (wa_fld_list-SCREEN-name+14) ASCENDING. "

          wa_fld_list-selected = ' '.

         MODIFY TBL_CTRL-cols FROM wa_fld_list INDEX sy-tabix.

        ENDIF.

I am facing this problem :

when i select any column and click on sort  button nothing happen..... why ?! 

regards ,

zakyaih

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
11,144

I use  if statement  ...because after sort execute the program execute STATUS_3000 again

if it_ZPRODUCTS_T is INITIAL.

     SELECT * FROM  ZPRODUCTS_T

       INTO CORRESPONDING FIELDS OF TABLE it_ZPRODUCTS_T up to 100 rows .

   ENDif.

29 REPLIES 29
Read only

Arun_Prabhu_K
Active Contributor
0 Likes
11,144

Hello Zakyiah Tuwaylib.

     Code seems to be correct.

     Check if the data is already sorted or not?

     Try with DESCENDING sort option.

Regards.

Read only

0 Likes
11,143

thanks for response

i tried both way DESCENDING and ASCENDING

same issue

Read only

0 Likes
11,143

Zakyiah Tuwaylib,

     Just debug and see.

     TYPE /h in the command prompt and then click SORT button.

     It will help you understand how program execution takes place.

Regards.

Read only

0 Likes
11,142
Re: Sorting in Table Control

K.Arun Prabhu

many thanks for help

i get  this

Read only

0 Likes
11,141

sorry .. i get this

even in  internal table no data sorted

Read only

0 Likes
11,141

Have you mentioned the correct table control name?


READ TABLE TBL_CTRL-cols INTO wa_fld_list WITH KEY selected = 'X'.


MODIFY TBL_CTRL-cols FROM wa_fld_list INDEX sy-tabix.

What is the sy-tabix value before this statement gets executed?

What is the sy-subrc value after this statement's execution?

Read only

0 Likes
11,141

yes,

before

0

8

after

0

8

I will print screen what i did from the scratch .

Read only

Former Member
0 Likes
11,141

Hi,

Just try like standard way!

when 'SORTU'.

data: fldname(100),help(100).

READ TABLE TBL_CTRL-cols INTO wa_fld_list WITH KEY selected = 'X'.

if sy-subrc = 0.

read table table_control-cols into col with key selected = 'X'.
       split col-screen-name at '-' into help fldname.
       sort
  IT_ZPRODUCT_T by (fldname) DESCENDING ( field names).

   wa_cols-selected = ' '.

MODIFY TBL_CTRL-cols FROM wa_fld_list INDEX sy-tabix.
Read only

0 Likes
11,140

thanks for response

i tried standard way same issue

regards,

zakyiah

Read only

0 Likes
11,140

Hi

If you put a break point at sort statement do you see your internal table getting sorted in debugging if yes then check in debugging whether ypu are doing some data selection again which may be overwritting this sort. Please paste your PBO sample code

Nabheet

Read only

0 Likes
11,140

HI,

i am not friendly with breakpoints

where i should but it ?

Read only

0 Likes
11,140

Being an ABAPER if you want to you should be. Put a break point in PAI on sort and then in PBO

Read only

0 Likes
11,140

yes i am beginner .. i am working with  ABAP  just from 1 month

where is it exactly ?

Read only

0 Likes
11,140

Hi zakyiah Tuwaylib

Then see this demo program DEMO_DYNPRO_TABCONT_LOOP_AT.

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.

Read only

0 Likes
11,140

i think that same as i did

thank you

Read only

0 Likes
11,139

even in  internal table no data sorted 

Read only

0 Likes
11,139

Hi,

Can you pls let me know how you arrived at offset - 14 in your below code ?

SORT  IT_ZPRODUCT_T STABLE BY (wa_fld_list-SCREEN-name+14) ASCENDING.

This should be dependent of your screen field. Just double click in screen painter on any of the field of table control and check the name .Lets us say your 1st screen field name is WA_PRODUCT-PRODUCT_ID. Then if you want to sort it via PRODUCT_ID then you should choose offset 11 (count number of chars till '-', count characters in string WA_PRODUCT-, which is 11 ) and write as follows:

SORT  IT_ZPRODUCT_T STABLE BY (wa_fld_list-SCREEN-name+11) ASCENDING. I hope it helps.

So, just find correct offset.

Regards

Nishant

Read only

0 Likes
11,139

hi ,

thanks for helping  me

yea ,, my internal table is IT_ZPRODUCT_T (13)+  ( - ) = 14

AMMMMM

EVEN WHEN I USE THIS CODE SAME RESULT

data: fldname(100),help(100).

     READ TABLE TBL_CTRL-cols INTO wa_fld_list WITH KEY selected = 'X'.

     if sy-subrc = 0.

         read table TBL_CTRL-cols INTO wa_fld_list with key selected = 'X'.

        split wa_fld_list-screen-name at '-' into help fldname.

        sort   IT_ZPRODUCT_T by (fldname) ASCENDING .

         wa_fld_list-selected = ' '.

        MODIFY TBL_CTRL-cols FROM wa_fld_list INDEX sy-tabix.

        endif.

I will print screen what i did from the scratch .

Read only

Former Member
0 Likes
11,139

Hi,

You can seach SAP examples on table control in SE38. Search with DEMO*DYNPRO*TAB* and press F4. There is one demo program by SAP which explain sorting functionality as well. Also you may find  example in ABAPDOCU transaction.

Regards

Nishant.

Read only

AniketB
Explorer
0 Likes
11,139

Hi  Zakiyah,

I am sure you must have gone through this link.

Table Controls: Examples with Modifications (SAP Library - ABAP Programming (BC-ABA))

The screen field name seems to be the issue.Can you share the screen shot of the flow logic of the screen?Also just check whether the number of characters before the screen field name are correct, in your case they are '14'.

Regards,

AB

Read only

Former Member
0 Likes
11,138

I will print screen what i did from the scratch .

Read only

Former Member
0 Likes
11,138

hi ,

my code

At Top Include :

tables : ZPRODUCTS_T

TYPES :BEGIN OF itab,

          mark TYPE c .

          INCLUDE STRUCTURE ZPRODUCTS_T.

TYPES: END OF itab .

DATA:  wa_ZPRODUCTS_T TYPE itab,

           it_ZPRODUCTS_T TYPE STANDARD TABLE OF itab WITH HEADER LINE .

CONTROLS: TBL_CTRL_PRODUCT TYPE tableview USING screen 100.

DATAT:  cols LIKE LINE OF TBL_CTRL_PRODUCT-cols,

PROCESS BEFORE OUTPUT.

  MODULE STATUS_1007.

 

  LOOP AT it_ZPRODUCT_T into wa_ZPRODUCT_T with control TBL_CTRL_PRODUCT

     CURSOR TBL_CTRL_PRODUCT-CURRENT_LINE.

  ENDLOOP.

MODULE STATUS_1007 OUTPUT.

   SELECT * FROM  ZPRODUCTS_T INTO CORRESPONDING FIELDS OF TABLE it_ZPRODUCTS_T up to 100 rows .

END MODULE.

PROCESS AFTER INPUT.

  LOOP AT it_ZPRODUCTS_T .

  ENDLOOP.

MODULE USER_COMMAND_1007.

MODULE USER_COMMAND_1007 INPUT.

READ TABLE   it_ZPRODUCTS_T INTO  wa_ZPRODUCTS_T.

CASE SY-UCOMM .

   when 'SORTD'.

   

       read table TBL_CTRL_PRODUCT -cols into cols with key selected = 'X'.

       if sy-subrc = 0.

         sort IT_ZPRODUCTS_T stable by (cols-screen-name+15) descending.

         cols-selected = ' '.

         modify TBL_CTRL_PRODUCT -cols from cols index sy-tabix.

       endif.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_1007  INPUT

?! what is the problem

Read only

0 Likes
11,138

Hi Zakiyah,

Thanks for the screen shots.

I can see that you have used two Table controls and i can see from the flow logic that you have not used the first one in the PBO i.e. you have not Looped it, may be that is the issue...what you can do is declare the first table control followed by your second table control. Same should be the case when you are in PAI i.e. for example

PROCESS BEFORE OUTPUT.

Loop at Tcontol1.

Endloop.

Loop at Tcontol2.(Table control which is giving issues)

Endloop.

PROCESS AFTER INPUT.

Loop at Tcontol1.

Endloop.

Loop at Tcontol2.(Table control which is giving issues)

Endloop.

The flow of the table control processing is Top Left to Bottom Right, this might be affecting the flow.

Regards,

AB.

Read only

0 Likes
11,138

many thanks

oh no ..  I already deleted the table control 1

i just rewrite my steps again with another table control and another master table to make sure

everything is ok .. 

but I faced same issue

when I printed screen maybe before I delete it

"The flow of the table control processing is Top Left to Bottom Right, this might be affecting the flow."

?!

Message was edited by: zakyiah Tuwaylib

Read only

0 Likes
11,138

Hi Zakiyah,

I was referring to the case when there are multiple table controls on the same screen then "The flow of the table control processing is Top Left to Bottom Right".


From here i would say you should try the following:

Put a break point just after the sort statement in the PAI and check in the debugger whether the table is sorting or not.

If it is getting sorted then i can also see from your code that there is a module 'MODULE STATUS_1007' in the PBO where you are fetching data from the database into the internal table which is used in the table control, so every time after the PAI call the data you are sorting is getting overwritten.


I would suggest to put some condition in the PBO Module like if the Internal Table is initial then only fill it.


Regards,

AB



Read only

0 Likes
11,138

yea in debugging mode internal table is sort ...but how can i do that with table control

Read only

Former Member
0 Likes
11,138

many thanks all i answered by myself

Read only

0 Likes
11,138

Hi Zakyiah

Since eveyone has contributed to this thread it will be good if you can share how were you able to solve the issue.

Nabheet

Read only

Former Member
0 Likes
11,145

I use  if statement  ...because after sort execute the program execute STATUS_3000 again

if it_ZPRODUCTS_T is INITIAL.

     SELECT * FROM  ZPRODUCTS_T

       INTO CORRESPONDING FIELDS OF TABLE it_ZPRODUCTS_T up to 100 rows .

   ENDif.