2011 Feb 10 1:38 PM
Hi Expert,
I am trying to create a FM like RFC_READ_TABLE. In this table we put table name and the field name for which we write a query and option for query we get the out put only for that field in this case.
My requirement is very similar to this. But here i want to enter any table name and in option i want to write dynamic sql query for any filed of table then i want data based on this so that it will display the entire table entries.
Like TABNAMELIKE EKKO
OTHERCON bukrs_k = 3000.
Based on this selection it has to show the entire table fields.
To make this easy to understand i made a custom FM which are getting data from table or view and i select any field and put query it will show the result.
FUNCTION ZDYNSQL_EKKO_EKPO.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(ERNAMLIKE) TYPE CHAR15 OPTIONAL
*" VALUE(OTHERCON) TYPE CHAR50 OPTIONAL
*" TABLES
*" VALUE STRUCTURE V_EKKO_EKPO
*"----
*TABLES : V_EKKO_EKPO, EKKO, EKPO.
DATA: STR_WHERE TYPE TABLE OF EDPLINE.
DATA: STR_LINE TYPE EDPLINE.
*CONCATENATE 'EBELN LIKE''' EBELNLIKE '%''' INTO STR_LINE.
CONCATENATE 'ERNAM LIKE ''' ERNAMLIKE '%''' INTO STR_LINE.
IF OTHERCON <> ' '.
CONCATENATE STR_LINE 'AND' OTHERCON ' ' INTO STR_LINE SEPARATED BY SPACE.
ENDIF.
APPEND STR_LINE TO STR_WHERE.
SELECT * FROM V_EKKO_EKPO INTO CORRESPONDING FIELDS OF TABLE VALUE WHERE (STR_WHERE).
ENDFUNCTION.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Now here is sample code of exact requirement.
FUNCTION ZDYNSQL_TABLE_READ.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(TABNAMELIKE) TYPE DD02L-TABNAME
*" VALUE(OTHERCON) TYPE CHAR80 OPTIONAL
*" TABLES
*" VALUE STRUCTURE DD02L
*"----
DATA: STR_WHERE TYPE TABLE OF EDPLINE.
DATA: STR_LINE TYPE STRING.
CONCATENATE 'TABNAME LIKE ''' TABNAMELIKE '%' 'DD02L' 'TABNAME' INTO STR_LINE.
IF OTHERCON <> ' '.
CONCATENATE STR_LINE 'AND' OTHERCON ' ' INTO STR_LINE SEPARATED BY SPACE.
ENDIF.
APPEND STR_LINE TO STR_WHERE.
SELECT * FROM DD02L INTO CORRESPONDING FIELDS OF TABLE VALUE WHERE (STR_WHERE).
ENDFUNCTION.
In this i put table name as EKKO and put sql query as bukrs_k = 3000 it provide a short dump.
How can i solve this problem. Please provide some input or modification
Thanks And Regards
Ranjeet Singh
Hi Expert,
I am trying to create a FM like RFC_READ_TABLE. In this table we put table name and the field name for which we write a query and option for query we get the out put only for that field in this case.
My requirement is very similar to this. But here i want to enter any table name and in option i want to write dynamic sql query for any filed of table then i want data based on this so that it will display the entire table entries.
Like TABNAMELIKE EKKO
OTHERCON bukrs_k = 3000.
Based on this selection it has to show the entire table fields.
To make this easy to understand i made a custom FM which are getting data from table or view and i select any field and put query it will show the result.
FUNCTION ZDYNSQL_EKKO_EKPO.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(ERNAMLIKE) TYPE CHAR15 OPTIONAL
*" VALUE(OTHERCON) TYPE CHAR50 OPTIONAL
*" TABLES
*" VALUE STRUCTURE V_EKKO_EKPO
*"----
*TABLES : V_EKKO_EKPO, EKKO, EKPO.
DATA: STR_WHERE TYPE TABLE OF EDPLINE.
DATA: STR_LINE TYPE EDPLINE.
*CONCATENATE 'EBELN LIKE''' EBELNLIKE '%''' INTO STR_LINE.
CONCATENATE 'ERNAM LIKE ''' ERNAMLIKE '%''' INTO STR_LINE.
IF OTHERCON <> ' '.
CONCATENATE STR_LINE 'AND' OTHERCON ' ' INTO STR_LINE SEPARATED BY SPACE.
ENDIF.
APPEND STR_LINE TO STR_WHERE.
SELECT * FROM V_EKKO_EKPO INTO CORRESPONDING FIELDS OF TABLE VALUE WHERE (STR_WHERE).
ENDFUNCTION.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Now here is sample code of exact requirement.
FUNCTION ZDYNSQL_TABLE_READ.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(TABNAMELIKE) TYPE DD02L-TABNAME
*" VALUE(OTHERCON) TYPE CHAR80 OPTIONAL
*" TABLES
*" VALUE STRUCTURE DD02L
*"----
DATA: STR_WHERE TYPE TABLE OF EDPLINE.
DATA: STR_LINE TYPE STRING.
CONCATENATE 'TABNAME LIKE ''' TABNAMELIKE '%' 'DD02L' 'TABNAME' INTO STR_LINE.
IF OTHERCON <> ' '.
CONCATENATE STR_LINE 'AND' OTHERCON ' ' INTO STR_LINE SEPARATED BY SPACE.
ENDIF.
APPEND STR_LINE TO STR_WHERE.
SELECT * FROM DD02L INTO CORRESPONDING FIELDS OF TABLE VALUE WHERE (STR_WHERE).
ENDFUNCTION.
In this i put table name as EKKO and put sql query as bukrs_k = 3000 it provide a short dump.
How can i solve this problem. Please provide some input or modification
Thanks And Regards
Ranjeet Singh
2011 Feb 10 5:11 PM
Hi Ranjeet,
There are multiple threads in SDN for dynamic query.. Please check out the following wiki code gallery to see if it would suit your requirement,
http://wiki.sdn.sap.com/wiki/display/Snippets/DynamicCreationandDisplayofSQLQueries
2011 Feb 15 8:52 AM
Hi Kris,
I tried to make sample using that link you provide to me. How can i declare Global Interface in FM and in import parameter references like "REFERENCE(I_INTERFACE_CHECK) DEFAULT SPACE".
Also it uses a function-pool.
Let me tell you about my exact requirement about FM.
I want in import parameter input as any SAP Table name like
TABNAME TYPE EKKO
OPTIONS TYPE CHAR80
I want my output to be stored in TABLES attributes as per the table name entered in import parameter. In import parameter Table name can be any one of SAP tables and Option based on that particular table. Like if i go with table EKKO and put OPTIONS as
ebelp = 4 then TABLES attributes Tab contains all the relevant data for input.
Is there any way with the help of that i can put my data into internal tables. I tried to put in TABLES as VALUE LIKE ANY but it shows that generic are not allowed. Can you provide some sample on this.
I also getting exceptions like CX_SY_DYNAMIC_OSQL_SEMANTICS, SAPSQL_INVALID_FIELDNAME.
Waiting for your valuable reply.
Thanks And Regards
Ranjeet Singh
2011 Mar 03 5:03 AM
Hi Kris,
Now the requirement is more clear like this. We need to give input as complete Select query. Like below are examples.
1) Select * from ekko into table it_data where bukrs = 3000. or
2) select fld1 fld2 fld3 from tablename into it_data up to 10 rows where fld4 = XXXXX.
We want to pass only such query as input and want result according to them. User can put any table name, can chose any table fields, also he can use inner join group by statement.
parameters: option type string.
In Option we need to wright that select query.
Regards
Ranjeet Singh
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |