2013 Nov 13 9:05 AM
Hi experts,
Actually my first question is, how can i get data with a function. Than i want to get dynamically fields and tables for my query in a function.
I have a database and i want to get data use function. Everything ok. I created a function than i used in program but it is giving me type error.
How did i it?
I created ZP_VERI_GETIR function like below.
function's source code
One more problem : Imported parameter name is 'TABLO' but i have never used it
SELECT * FROM ZPMAK INTO CORRESPONDING FIELDS OF
TABLE gt_itab.
IF SY-SUBRC EQ 0.
MESSAGE 'VERİLER ALINDI' TYPE 'I'.
ENDIF.
ENDFUNCTION.
I called my function in program.
DATA itab like zpmak occurs 0.
CALL FUNCTION 'ZP_VERI_GETIR'
EXPORTING
tablo = zpmak
IMPORTING
gt_itab = itab.
But i am getting type error. How can i solve it.
2013 Nov 13 9:34 AM
hi, guy
you can write at table tab as parameter, or changing tab.
Hi experts,
Actually my first question is, how can i get data with a function. Than i want to get dynamically fields and tables for my query in a function.
I have a database and i want to get data use function. Everything ok. I created a function than i used in program but it is giving me type error.
How did i it?
I created ZP_VERI_GETIR function like below.
function's source code
One more problem : Imported parameter name is 'TABLO' but i have never used it
SELECT * FROM ZPMAK INTO CORRESPONDING FIELDS OF
TABLE gt_itab.
IF SY-SUBRC EQ 0.
MESSAGE 'VERİLER ALINDI' TYPE 'I'.
ENDIF.
ENDFUNCTION.
I called my function in program.
DATA itab like zpmak occurs 0.
CALL FUNCTION 'ZP_VERI_GETIR'
EXPORTING
tablo = zpmak
IMPORTING
gt_itab = itab.
But i am getting type error. How can i solve it.
2013 Nov 13 9:11 AM
Hi Omer,
it's hard to see in the image because of the quality. Please check your import/export parameters and the type again. There must be a difference somewhere otherwise you won't get the type error
Regards,
Ioan.
2013 Nov 13 9:16 AM
Thanks for your answer.
Pls Click on image than you can see easily
2013 Nov 13 9:27 AM
Ok, try to declare your variables like this: DATA: itab type z_table,
z_zpmak type z_table.
CALL FUNCTION 'ZP_VERI_GETIR'
EXPORTING
tablo = z_zpmak
IMPORTING
gt_itab = itab.
2013 Nov 13 9:33 AM
Bingoo! it is working
Also i want to learn how can i get dynamically field and table name with function. Can you tell me how can i do it?
Thanks for your help.
2013 Nov 13 9:34 AM
Hello Omar,
Some changes are required in your Function Module;
1) Import Parameter
TABLO TYPE DBOBJ_NAME
2) Export Parameter is Ok
3) In Source Code;
SELECT * FROM (TABLO) INTO CORRESPONDING FIELDS OF
TABLE gt_itab.
4)
CALL FUNCTION 'ZP_VERI_GETIR'
EXPORTING
tablo = 'ZPMAK'
IMPORTING
gt_itab = itab.
We are trying to Pass the Tablename, "ZPMAK". In the function module we would query the table name dynamically.
2013 Nov 13 9:39 AM
Thanks for your answer.
I have to use table type. Thats ok.
Next question is How can i get dynamically field and table name with function?
2013 Nov 13 9:44 AM
Hi Omer,
the dynamic stuff is pretty complicated and I don't understand your question. You have to be more explicit about what you want to know.
Regards,
Ioan.
2013 Nov 13 9:34 AM
hi, guy
you can write at table tab as parameter, or changing tab.
2013 Nov 13 9:41 AM
2013 Nov 13 9:51 AM
Hi Omer
What exactly do you mean by field and table name..? Can you please elaborate. I do understdan you pass table name and it fetches the data for the passed table name
Nabheet
2013 Nov 13 10:02 AM
I want to 2 parameter on selection screen. I can choose table name and field names. When i clicked button i want to see my selected table and field data's on write screen.
I hope u have understood me.
2013 Nov 13 10:09 AM
hi, guy , I want to show you this screen spot. but I dont konw what is this web site suport pic format?
you can write table parameter name in tables tab, tying is LIKE, and Associated Type is a structure for table type. When you actived your function completed, you can user Ctrl + F6 to selected your just finished function in code edit, and then you can find the table parameter auto-displayed.
2013 Nov 13 10:13 AM
you can do as follow
create two parameters as importing one in Function module
One for table name which you already have and another for field name.
and one for table parameter which will return you data.
In field name you can concatenatte all field names like
concatenate 'BUKRS' 'MANDT' into IM_FIELDNAME (you can have n number of field)
Select (im_fieldname) from (im_tablename) into table IT_TAB.
2013 Nov 13 10:16 AM
Hi Omer,
Please try this
Parameters: TABLE_NAME like DCOBJDEF-NAME. "Enter the table Name
DATA: data_refe1 TYPE REF TO data,
data_refe2 TYPE REF TO data ,
tab_fldcat TYPE TABLE OF lvc_s_fcat,
wa_fldcat LIKE LINE OF tab_fldcat.
DATA: BEGIN OF table_dtls OCCURS 0.
INCLUDE STRUCTURE dntab.
DATA: END OF table_dtls.
REFRESH table_dtls.
CALL FUNCTION 'NAMETAB_GET'
EXPORTING
langu = sy-langu
tabname = table_name
TABLES
nametab = table_dtls
EXCEPTIONS
no_texts_found = 1.
LOOP AT table_dtls .
wa_fldcat-fieldname = table_dtls-fieldname.
wa_fldcat-ref_table = table_name.
wa_fldcat-ref_field = table_dtls-fieldname.
APPEND wa_fldcat TO tab_fldcat.
ENDLOOP.
* Build the internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = tab_fldcat
IMPORTING
ep_table = data_refe1.
ASSIGN data_refe1->* TO <fs>.
SELECT * FROM (table_name)
INTO CORRESPONDING FIELDS OF TABLE <fs>.
2013 Nov 13 10:29 AM
2013 Nov 13 10:36 AM
FUNCTION ZP_DINAMIK_DATA.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(TABLE) TYPE CHAR20
*" EXPORTING
*" REFERENCE(GT_ITAB) TYPE DATA
*"----------------------------------------------------------------------
field-symbols: <f1> type any table.
create data gt_itab type (TABLE).
assign gt_itab->* to <f1>.
SELECT * FROM (TABLE) INTO CORRESPONDING FIELDS OF
TABLE <f1>.
IF SY-SUBRC EQ 0.
MESSAGE 'VERİLER ALINDI' TYPE 'I'.
ENDIF.
ENDFUNCTION.
PROGRAM'S CODE
*&---------------------------------------------------------------------*
*& Report ZP_DINAMIK_DATA
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZP_DINAMIK_DATA.
SELECTION-SCREEN BEGIN OF BLOCK blok1 WITH FRAME TITLE bilgi1.
PARAMETERS p_table TYPE char30.
"PARAMETERS p_field TYPE char30.
SELECTION-SCREEN END OF BLOCK blok1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (60) getdy USER-COMMAND btn5.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
getdy = 'get data'.
start-of-selection.
DATA: itab like p_table occurs 0.
CASE SY-UCOMM.
WHEN 'BTN5'.
CALL FUNCTION 'ZP_DINAMIK_DATA'
EXPORTING
table = p_table
IMPORTING
GT_ITAB = itab
.
ENDCASE.
not working and no errors.
2013 Nov 13 10:38 AM
2013 Nov 13 11:08 AM
REPORT ZP_DINAMIK_DATA.
SELECTION-SCREEN BEGIN OF BLOCK blok1 WITH FRAME TITLE bilgi1.
PARAMETERS p_table TYPE char30.
"PARAMETERS p_field TYPE char30.
SELECTION-SCREEN END OF BLOCK blok1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (60) getdy USER-COMMAND btn5.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
getdy = 'get data'.
at selection-screen.
DATA: itab like p_table occurs 0.
CASE SY-UCOMM.
WHEN 'BTN5'.
CALL FUNCTION 'ZP_DINAMIK_DATA'
EXPORTING
table = p_table
IMPORTING
GT_ITAB = itab
.
ENDCASE.
i am getting type error....
2013 Nov 13 11:19 AM
You can do as follow. Use data ref to in tables parameter.
Program
DATA gr_ref TYPE REF TO DATA
FIELD-SYMBOLS <fs_data> TYPE STANDARD TABLE.
CALL FUNCTION ''ZP_DINAMIK_DATA'
IMPORTING
IT_DATA = gr_ref
ASSIGN gr_ref->* TO <lt_table>.
In function module ZP_DINAMIK_DATA
DATA lr_ref TYPE REF TO DATA
Create dynamic internal table as told in earlier post by anriban. Then fill the data using select * and proceed.
IT_DATA = lr_ref
2013 Nov 13 12:21 PM
Thanks for your help.
function module ZP_DINAMIK_DATA
field-symbols: <f1> type table .
DATA lr_ref TYPE REF TO DATA.
create data IT_DATA type table of (TABLE).
assign IT_DATA->* to <f1>.
SELECT * FROM (TABLE) INTO CORRESPONDING FIELDS OF table
<f1>.
IF SY-SUBRC EQ 0.
MESSAGE 'VERİLER ALINDI' TYPE 'I'.
ENDIF.
Program
CALL FUNCTION 'ZP_DINAMIK_DATA'
EXPORTING
table = p_table
IMPORTING
* GT_ITAB = itab
IT_DATA = gr_ref
.
ASSIGN gr_ref->* TO <lt_table>.
Regards,
Omer.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |