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 the Smartform Table at Run time

0 Likes
764

Hi All ,

I have a requirement wherein I see that when we print the form, the sequence of the orders is fixed.

The ALV screen information can be sorted, we are looking that when we re-sort in the screen, the printied form doesn't change in the order. We are looking for the sorting criteria to be applied also at the moment of printing (besides the workcenter that we mentioned before).

Is there a way where we can apply Sorting on Table in Smartform at run-time on user screen ?

Is it feasible?

Hi All ,

I have a requirement wherein I see that when we print the form, the sequence of the orders is fixed.

The ALV screen information can be sorted, we are looking that when we re-sort in the screen, the printied form doesn't change in the order. We are looking for the sorting criteria to be applied also at the moment of printing (besides the workcenter that we mentioned before).

Is there a way where we can apply Sorting on Table in Smartform at run-time on user screen ?

Is it feasible?

1 REPLY 1
Read only

rosenberg_eitan
Active Contributor
0 Likes
458

Hi , 

See code.  

regards.

FORM table_sort_1
  TABLES
    rt_outtab
    rt_sort TYPE lvc_t_sort .

* Based on code from function K_KKB_OUTTAB_SORT

  DATA: a01 TYPE lvc_fname ,
        a02 TYPE lvc_fname ,
        a03 TYPE lvc_fname ,
        a04 TYPE lvc_fname ,
        a05 TYPE lvc_fname ,
        a06 TYPE lvc_fname ,
        a07 TYPE lvc_fname ,
        a08 TYPE lvc_fname ,
        a09 TYPE lvc_fname ,
        a10 TYPE lvc_fname ,
        a11 TYPE lvc_fname ,
        a12 TYPE lvc_fname ,
        a13 TYPE lvc_fname ,
        a14 TYPE lvc_fname ,
        a15 TYPE lvc_fname .

  DATA: d01 TYPE lvc_fname ,
        d02 TYPE lvc_fname ,
        d03 TYPE lvc_fname ,
        d04 TYPE lvc_fname ,
        d05 TYPE lvc_fname ,
        d06 TYPE lvc_fname ,
        d07 TYPE lvc_fname ,
        d08 TYPE lvc_fname ,
        d09 TYPE lvc_fname ,
        d10 TYPE lvc_fname ,
        d11 TYPE lvc_fname ,
        d12 TYPE lvc_fname ,
        d13 TYPE lvc_fname ,
        d14 TYPE lvc_fname ,
        d15 TYPE lvc_fname .

  CHECK rt_sort[] IS NOT INITIAL .

  DATA: l_pos    TYPE n LENGTH 2 .
  DATA: l_field  TYPE lvc_fname .
  FIELD-SYMBOLS:  TYPE lvc_fname .

  SORT rt_sort BY spos.
  CLEAR l_pos.

  LOOP AT rt_sort.

    l_pos = l_pos + 1.

    IF rt_sort-up = abap_true .
      CONCATENATE 'A' l_pos INTO l_field.
    ELSE.
      CONCATENATE 'D' l_pos INTO l_field.
    ENDIF.

    ASSIGN (l_field) TO .
     = rt_sort-fieldname.

  ENDLOOP.

  IF sy-subrc NE 0.
    RAISE sortfield_not_found.
  ENDIF .

  SORT rt_outtab STABLE
    BY
      (a01) ASCENDING
      (d01) DESCENDING
      (a02) ASCENDING
      (d02) DESCENDING
      (a03) ASCENDING
      (d03) DESCENDING
      (a04) ASCENDING
      (d04) DESCENDING
      (a05) ASCENDING
      (d05) DESCENDING
      (a06) ASCENDING
      (d06) DESCENDING
      (a07) ASCENDING
      (d07) DESCENDING
      (a08) ASCENDING
      (d08) DESCENDING
      (a09) ASCENDING
      (d09) DESCENDING
      (a10) ASCENDING
      (d10) DESCENDING
      (a11) ASCENDING
      (d11) DESCENDING
      (a12) ASCENDING
      (d12) DESCENDING
      (a13) ASCENDING
      (d13) DESCENDING
      (a14) ASCENDING
      (d14) DESCENDING
      (a15) ASCENDING
      (d15) DESCENDING  .

ENDFORM .                    "table_sort_1