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

casting sorted table to standard table

Former Member
0 Likes
4,134

Hello guys,

i use the method go_alv_grid->set_table_for_first_display

the table going to be passed to that function needs to be type of standard table.

Now, i have a table of type sorted table, and that leads to a type conflict.

is there a way to cast my sorted table to a standard table ?

thanks for help,

sven

1 ACCEPTED SOLUTION
Read only

tushar_shukla
Active Participant
2,333

Create a standard table with same type and pass the sorted table to standard internal table.e.g.


data : itab_sort type SORTED TABLE OF mara WITH UNIQUE KEY matnr,
          itab_std type TABLE OF mara .

........................................

itab_std = itab_sort. 

Hello guys,

i use the method go_alv_grid->set_table_for_first_display

the table going to be passed to that function needs to be type of standard table.

Now, i have a table of type sorted table, and that leads to a type conflict.

is there a way to cast my sorted table to a standard table ?

thanks for help,

sven

7 REPLIES 7
Read only

tushar_shukla
Active Participant
2,334

Create a standard table with same type and pass the sorted table to standard internal table.e.g.


data : itab_sort type SORTED TABLE OF mara WITH UNIQUE KEY matnr,
          itab_std type TABLE OF mara .

........................................

itab_std = itab_sort. 

Read only

0 Likes
2,333

oh i forgot to say, i'm using field symbols, and my table is dynamic

i tried:

FIELD-SYMBOLS:

<FS_1> TYPE SORTED TABLE,

<FS_1a> type STANDARD TABLE,...

<FS_1> = <FS_1a>.

CALL METHOD go_alv_grid->set_table_for_first_display

EXPORTING

is_layout = layout

CHANGING

it_outtab = <FS_1a>

it_fieldcatalog = LT_FIELDCATALOG.

+

it does not work , i still get a exception

Read only

0 Likes
2,333

Hi Sven,

Say your sorted table is assigned to <TSORT>, then I would do

field-symbols:
  <rec>     type any.
  <TSTD> type table.
data:
  lr_data type ref to data.
* read any record of sorted table
read table <tsort> assigning <rec> index 1.
* make surte table isn't empty
check sy-subrc = 0.
* create standard table of this structure
create data lr_data like table of <rec>.
* assign to field-symbol
assign lr_data->* to <TSTD>.
* move sorted to standard table
<TSTD> = <TSORT>.
* free unuesed memory (optional)
free <TSORT>.
* grid display <TSTD>

Regards,

Clemens

Read only

matt
Active Contributor
2,333

If you need the standard table to be defined even if the sorted table is empty, use:

DATA: lr_data TYPE REF TO DATA.

FIELD-SYMBOLS: <ls_record> TYPE ANY,
             <lt_standard> TYPE STANDARD TABLE.

CREATE DATA lr_data LIKE LINE OF <sorted_table>.
ASSIGN lr_data->* TO <ls_record>:

CREATE DATA lr_data LIKE STANDARD TABLE OF <ls_record>.
ASSIGN lr_data->* TO <lt_standard>.

<lt_standard> = <lt_sorted>.

If you ever go the other way - from a standard table to a sorted or hashed, or a hashed to a sorted, or sorted to a hashed, or a sorted/hashed table with a different key, use

INSERT LINES OF <source_table> INTO TABLE <destination_table>.

matt

Read only

Former Member
0 Likes
2,333

hey man..

do this::


    data gt_sorted type sorted table of mara with unique key matnr.
    data gt_standard type standard table of mara.

.

.

.


    gt_standard[] = gt_sorted[].

    CALL METHOD go_alv_grid->set_table_for_first_display
    EXPORTING
       is_layout = layout
   CHANGING
      it_outtab = gt_standard[]
      it_fieldcatalog = LT_FIELDCATALOG.

if doesnt work try with gt_standard without [] in the set_table_for_first_display method..

Hope it works!

Read only

0 Likes
2,333

Your brackets are redundant in that statement based on the definition and it doesn't solve the requirement to be dynamic.

To the OP, you didn't mention the exception type but you haven't shown very much code or how your field symbols get assigned. At some point, order to get the code to compile or execute dynamically without exception, you need to provide a named external or internal type in order to use a data reference or the RTTS classes to make that move. Without some link back to the line type and sort key (whether it's 'default' or not), it's not going to work.

Read only

Former Member
0 Likes
2,333

This message was moderated.