Monday, December 20, 2010
This program illustrates how to create dynamic sorted table with the help of class CL_ABAP_TABLEDESCR and method CREATE.

REPORT ztest_program.
*&--------------------------------------------------------------------------*
* Declarations
*&--------------------------------------------------------------------------*
DATA:
      lineType  TYPE REF TO cl_abap_structdescr,
      tableType TYPE REF TO cl_abap_tabledescr,
      key       TYPE abap_keydescr_tab,
      lt_table  TYPE REF TO data.
DATA:
      gv_dref   TYPE REF TO data.
FIELD-SYMBOLS:
     <lt_table>   type ANY TABLE,
     <lt_std_tab> TYPE STANDARD TABLE.
*&--------------------------------------------------------------------------*
* Selection Screen
*&--------------------------------------------------------------------------*
PARAMETERS:
     p_table   TYPE rsrd1-tbma_val.


*&--------------------------------------------------------------------------*
* Start of selection
*&--------------------------------------------------------------------------*
START-OF-SELECTION.

lineType ?= cl_abap_typedescr=>describe_by_name( p_table ).

APPEND 'CARRID' TO key.
APPEND 'CONNID' TO key.

tableType = cl_abap_tabledescr=>create( p_line_type  = lineType
                                        p_table_kind = cl_abap_tabledescr=>tablekind_sorted
                                        p_unique     = abap_true
                                        p_key        = key ).

CREATE DATA lt_table TYPE HANDLE tableType.
ASSIGN lt_table->* TO <lt_table>.

SELECT * FROM (p_table) INTO TABLE <lt_table> UP TO 10 ROWS.

  CREATE DATA gv_dref TYPE TABLE OF (p_table).
  ASSIGN gv_dref->* TO <lt_std_tab>.
<lt_std_tab> = <lt_table>.
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename              = 'C:\temp\test.txt'
    filetype              = 'ASC'
    WRITE_FIELD_SEPARATOR = 'X'
  TABLES
    data_tab              = <lt_std_tab>.
IF sy-subrc = 0.
  WRITE 'successfully downloaded'.
ENDIF.

1 comment:



  1. That's really cool buddy.....Obviously the lady was logical.





    SAP Consultants in London

    ReplyDelete

Your useful comments, suggestions are appreciated.Your comments are moderated.

Online Training

Online Training

Follow by Email

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.