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

Ideas To Dynamic Programming.

Former Member
0 Likes
722

Dear Friends,

In my requirement...

1. I will be recieving a string of source code in a RFC input parameter. Then Using this Source code we have to execute the

query and return Data....either as a return parameter or otherwise i can download the report to a folder in application server.

Please guide me.

Regards,

jeevan.

1 ACCEPTED SOLUTION
Read only

mvoros
Active Contributor
0 Likes
679

Hi,

I guess if you search on this forum or SAP documentation you will find examples how to achieve your goal.

I have just one comment. This creates a security risk. You have to be very careful and validate your input ontherwise your FM can be ugly misused. Good luck.

Cheers

4 REPLIES 4
Read only

mvoros
Active Contributor
0 Likes
680

Hi,

I guess if you search on this forum or SAP documentation you will find examples how to achieve your goal.

I have just one comment. This creates a security risk. You have to be very careful and validate your input ontherwise your FM can be ugly misused. Good luck.

Cheers

Read only

Former Member
0 Likes
679

hello martin ,

Thanks for your reply....And i will takecare of the security issues.

Please help me solving the below problem...

I am experimenting with the below code but i am getting

"the type component table is unknown." i am on 4.7

please suggest me a alternative to this........

code:-

*&---------------------------------------------------------------------*
*& Report  ZDYNAMIC3                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZDYNAMIC3                               .
 PARAMETER : p_tabnam TYPE tabname DEFAULT 'SFLIGHT',
             p_selfl1 TYPE edpline DEFAULT 'CARRID',            
             p_selfl2 TYPE edpline DEFAULT 'CONNID',
             p_selfl3 TYPE edpline DEFAULT 'FLDATE',            
             p_selfl4 TYPE edpline DEFAULT 'PRICE',
             p_selfl5 TYPE edpline DEFAULT 'CURRENCY',
             p_where1 TYPE edpline DEFAULT 'PRICE > 300',            
             p_where2 TYPE edpline DEFAULT 'AND CURRENCY = ''EUR'''.
             
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE, 
               <ls_outtab> TYPE ANY,
               <l_fld> TYPE ANY.

DATA: lt_where    TYPE TABLE OF edpline,
      lt_sel_list TYPE TABLE OF edpline,
      lt_group    TYPE TABLE OF edpline,
      l_having    TYPE string,
      l_wa_name   TYPE string,
      l_sel_list  TYPE edpline,
      dref        TYPE REF TO data,
      itab_type   TYPE REF TO cl_abap_tabledescr,
      struct_type TYPE REF TO cl_abap_structdescr,
      elem_type   TYPE REF TO cl_abap_elemdescr,
      comp_tab    TYPE cl_abap_structdescr=>component_table,
      comp_fld    TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
* Creation of the output table including a non standard field, f_count* 
*see ABAP FAQ #14 for more information on this topic
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type   ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
* We remove the unnecessary fields
LOOP AT comp_tab INTO comp_fld.
   IF comp_fld-name <> p_selfl1
       AND   comp_fld-name <> p_selfl2
       AND      comp_fld-name <> p_selfl3 
       AND      comp_fld-name <> p_selfl4
       AND      comp_fld-name <> p_selfl5.
    DELETE TABLE comp_tab WITH TABLE KEY name = comp_fld-name.
    ENDIF.
    ENDLOOP.
    comp_fld-name = 'F_COUNT'.
    comp_fld-type = elem_type.
    APPEND comp_fld TO comp_tab.
    struct_type = cl_abap_structdescr=>create( comp_tab ).
    itab_type   = cl_abap_tabledescr=>create( struct_type ).
    l_wa_name = 'l_WA'.
    CREATE DATA dref TYPE HANDLE itab_type.
    ASSIGN dref->* TO <lt_outtab>.
    CREATE DATA dref TYPE HANDLE struct_type.
    ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields and the "group by" clause
APPEND p_selfl1 TO lt_sel_list.
APPEND p_selfl1 TO lt_group.
APPEND p_selfl2 TO lt_sel_list.
APPEND p_selfl2 TO lt_group.
APPEND p_selfl3 TO lt_sel_list.
APPEND p_selfl3 TO lt_group.
APPEND p_selfl4 TO lt_sel_list.
APPEND p_selfl4 TO lt_group.
APPEND p_selfl5 TO lt_sel_list.
APPEND p_selfl5 TO lt_group.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list. 
* creation of the "where" clause
APPEND p_where1 TO lt_where.
APPEND p_where2 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT        (lt_sel_list)
     FROM     (p_tabnam)
     INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
     WHERE    (lt_where)       GROUP BY (lt_group)
     HAVING   (l_having)       ORDER BY (lt_group).
* display of the results
LOOP AT <lt_outtab> ASSIGNING <ls_outtab>.
LOOP AT comp_tab INTO comp_fld.
    ASSIGN COMPONENT comp_fld-name OF STRUCTURE <ls_outtab> TO <l_fld>.      WRITE: <l_fld>.   
     ENDLOOP.   
     SKIP.
     ENDLOOP.

Regards,

jeevan.

Read only

mvoros
Active Contributor
0 Likes
679

Hi,

what line is giving you this error? I checked it on ECC6 system and it works.

Cheers

Read only

0 Likes
679

it looks like that class does not exist in 4.7. Use SE24 and try to view class cl_abap_structdescr....if it's not there then that's why you're getting the syntax error.