10-09-2008 11:30 AM
Hi Guruz,
here is my question
i gotto pull data from 3 tables based on the case statement but im passing same values to retrieve the data .now how can i use 1 perform statement so it can pull the data from table based on case.
( at the moment im using 3 performz)
plz advise..
regards
Edited by: BrightSide on Oct 9, 2008 11:56 AM
10-09-2008 12:02 PM
perform fetch using XXXXXX XXXXX XXXXXX.
where 'XXXXXX'are your fields.
10-09-2008 12:08 PM
Hi,
Pass all parameters to a suborutine and inside subroutine do a case statement or condtional if and depending of the condtion result do your processing on desired table.
FORM case_form using var1 type var2 type c var3 type c
tables tab1 tab2 tab3.
if var1 eq 'X'.
"processing of tab1
elseif var2 eq 'X'.
"processing of tab2
elseif va3 eq 'X'.
"processing of tab3
endif.
ENDFORM.
"Then just call your subroitune only once.
PERFORM case_form using...
Is that what you meant?
10-09-2008 12:08 PM
Hi Bright,
Can you please explain in brief about your requirement.
Whether you want to fetch the data from one table depending upon the case statement condition or from three tables in each
case statement condition.
1) If you want to fecth the data from 3 tables in every case statement then, its is easy create the the subroutine.
just call the subroutine with respective parameters ans define the logic to fetch the data.
2) If you want to fecth the data from selective table depending on the condition of the case statement, then
pass the parametet of the subroutine as the table name.
and use the dynamic table name in the select statement.
This might solve the problem. If not please let us know your
requirement in brief.
Regards,
Dinakar.
10-09-2008 12:28 PM
Hello all,
thanks for ur replies,
I want to fecth the data from selective table depending on the condition of the case statement, then
pass the parametet of the subroutine as the table name.
and use the dynamic table name in the select statement.
plz advise..
Edited by: BrightSide on Oct 9, 2008 12:28 PM
10-09-2008 12:41 PM
Where you want the case statement to be, inside or outside soubroutine?
To pass table_name dynamically to routine use:
FORM sub USING table_name type c.
select * from (table) into ...
ENDFORM.
"then call it like this
PERFORM sub USING 'TABLE1'.
Regards
Marcin
10-09-2008 12:42 PM
IF XXXXXX = 'X'.
tablename = 'ekko'
Peform fetch tables gt_output
using tablename fieldname fieldname1 fieldname2 fieldname3.
elseif YYYYYY = 'Y'.
tablename = 'ekpo'.
Peform fetch tables gt_output
using tablename fieldname fieldname1 fieldname2 fieldname3.
else.
tablename = 'XXXXX'.
Peform fetch tables gt_output
using tablename fieldname fieldname1 fieldname2 fieldname3.
Endif.
Form .
Select ebeln ........ from tablename
into gt_output
= >into corresponding gt_output ( If selected fields are different for three tables)
where XXXXX = fieldname and
XXXXX = fieldname1 and
XXXXX = fieldname2.
Endform.
10-09-2008 12:17 PM
case.
when 1. " retrieve data from table 1.
perform get_data using common_fields '1'.
when 2. " retrieve data from table 2.
perform get_data using common_fields '2'.
when 3 . " retrieve data from table 3.
perform get_data using common_fields '3'.
endcase.
form get_data using fields tablenumber.
if tablenumber = '1'.
assign table 1.
if tablenumber = '2'.
assign table 2.
if tablenumber = '3'.
assign table 3.
<< get data from table >>
endform
10-09-2008 12:59 PM
data:
it_kna1 type table of kna1,
wa_kna1 type kna1,
it_vbak type table of vbak,
wa_vbak type vbak.
perform fill_tab using 'KNA1'
'IT_KNA1[]'.
perform fill_tab using 'VBAK'
'IT_VBAK[]'.
*&---------------------------------------------------------------------*
*& Form FILL_TAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0026 text
* -->P_0027 text
*----------------------------------------------------------------------*
form FILL_TAB using value(p_dbtab)
value(p_itab).
field-symbols: <fs_itab> type any table.
assign (p_itab) to <fs_itab>.
if sy-subrc eq 0,
select * from (p_dbtab)
into table <fs_itab>.
* where ....
endif.
endform. " FILL_TAB
As for the WHERE clause: guess you'll be able to find out yourself how to do that