‎2008 Dec 24 7:59 AM
Hi,
i had a requirement where i need to fetch number of records from table given in the selection screen, by considering other secletion screen input details. can any one please help.
Thanks.
venkat.
‎2008 Dec 24 8:03 AM
Hi Venkat,
The better way is use
SY-DBCNT. ------> DB operations, number of table lines processed
Thanks,
Chidanand
‎2008 Dec 24 8:05 AM
Hi,,,,,,
Your question is not clear, By other selection screen means Other Report selection screen, if this is the case then you can use "SUBMIT" statement. check the syntax with SAP Help.
Thanks
Saurabh
‎2008 Dec 24 8:07 AM
My question is how to select data from table which is given as input in the selection screen
‎2008 Dec 24 8:13 AM
copy the value of selection screen to some string variable say table_name
then write select query like
select * from (table_name) upto 100 rows.
you can also write like upto n row's
‎2008 Dec 24 8:44 AM
Hi Venkat,
You have to use Field symbols in order to fetch the records at run time or dynamically.
Please, go through it.
‎2008 Dec 24 8:11 AM
Hi,
have a look at this code.
parameter p_table type tabname.
select *
from (p_table)
into table itab.
regards,
Santosh Thorat
‎2008 Dec 24 8:14 AM
Hi.
parameters: table type tabname.
select *
from (table)
into table itab.
Thanks
Saurabh
‎2008 Dec 24 8:15 AM
Hello Guys,
May i know what is the DATA declaration for ITAB.
BR,
Suhas
‎2008 Dec 24 8:18 AM
Thanks santosh, but if i need to use where condition, how to compare the table fields which we do not know until runtime, can you please help in this case.
‎2008 Dec 24 8:26 AM
HI
Refer this code.
initialization.
**Selection screen for Input screen.
selection-screen begin of block b with frame title text-001.
select-options: s_werks for aufm-werks obligatory, "Plant
selection-screen end of block b.
if s_werks is not initial and s_budat is not initial.
Fetch the Order Number from table AUFNR.
select mblnr
mjahr
zeile
werks
aufnr
from aufm
into table it_aufm
where werks in s_werks
and budat in s_budat
and aufnr in s_aufnr.
if sy-subrc <> 0.
message 'Value is not avalibale as per you INPUT' type 'E'.
endif.
else.
message 'Plant and Posting date both are mandatory' type 'E'.
endif.
Regards.
jay
‎2008 Dec 24 8:32 AM
Hi santosh/Akash,
can you please help me how to fetch data using the where condition of the fields which we do not know until runtime.
Thanks & regards.
venkat
‎2008 Dec 24 8:34 AM
hI,
You can find the table fields in table DD03L.
regards,
Santosh
‎2008 Dec 24 8:38 AM
Hello Venkat,
Do you think this is a logical requirement?
You can get the fieldnames of the table from DD03L, but you need to have values to use against these fields. How to you intend to do this @ runtime? (Santosh your comments on this issues)
Can you plz elaborate what's ur actual requirement is ?
BR,
Suhas
Edited by: Suhas Saha on Dec 24, 2008 9:39 AM
‎2008 Dec 24 9:18 AM
Hi Venkat,
You can give your conditions dynamically with dynamic table name as below,
TABLES: vbak.
DATA: t_vbak TYPE STANDARD TABLE OF vbak,
wa_vbak LIKE LINE OF t_vbak.
TYPES: ty_field(50) TYPE c,
ty_cond TYPE TABLE OF ty_field.
DATA: t_cond TYPE ty_cond, "Internal table to store conditions
wa_cond TYPE ty_field.
DATA: w_tab TYPE tabname VALUE 'VBAK'.
SELECT-OPTIONS: so_vbeln FOR vbak-vbeln. "Input selection screen
wa_cond = 'VBELN IN SO_VBELN '. "Giving the condition
APPEND wa_cond TO t_cond.
SELECT * FROM (w_tab)
INTO TABLE t_vbak
WHERE (t_cond). "<=This is same as 'WHERE VBELN IN SO_VBELN'
WRITE: / 'Number of records : ' , sy-dbcnt.
WRITE: / 'VBELN'.
LOOP AT t_vbak INTO wa_vbak.
WRITE: / wa_vbak-vbeln.
ENDLOOP.Regards,
Manoj Kumar P
‎2008 Dec 24 9:32 AM
Hi Venkat,
For fetching the data from the table given at selection screen, you can use the following code.
*& Report Z_DYNAMIC_ITAB_TEST
Description : USING FIELD SYMBOLS TO DISPLAY TABLE FIELDS OF A TABLE
ENTERED BY USER AT THE SELECTION SCREEN.
SELECTION SCREEN CONTAINS :
DB TABLE NAME :--------
SELECTION FIELDS :--------
*----
!
report z_dynamic_itab_test .
include z_table_fs_top.
include z_table_fs_forms.
initialization.
perform clear_fields.
start-of-selection.
perform fetch_data.
end-of-selection.
&----
*& Include Z_TABLE_FS_TOP
&----
----
Type Pools *
----
type-pools: slis,
rsds.
----
Tables *
----
tables :sscrfields, "Fields on selection screens
dd03l. "Table Fields
----
Types *
----
types: begin of t_dd03l,
tabname like dd03l-tabname, "Table Name
fieldname like dd03l-fieldname, "Field Name
keyflag like dd03l-keyflag, "Key Flag
rollname like dd03l-rollname, "Roll Name
position like dd03l-position, "Position
ddtext(30), "Description
end of t_dd03l.
types : begin of t_fname, "To hold the field names
fld like dd03l-fieldname,
end of t_fname.
----
Internal Tables *
----
data : it_dd03l type table of t_dd03l, "To hold the field names of dd03l.
it_flds type table of rsdsfields, "To hold the field names
it_fields type table of dd03l, "To hold the field names
it_cat type table of lvc_s_fcat, "To hold Field Catalog
it_fname type table of t_fname.
----
Work areas *
----
data: wa_dd03l like line of it_dd03l, "Workarea for IT_DD03L
wa_flds like line of it_flds, "Workarea for IT_FLDS
wa_fields like line of it_fields, "Workarea for IT_FIELDS
wa_cat like line of it_cat , "Workarea for IT_CAT
wa_fname like line of it_fname. "Workarea for IT_FNAME
*----
!
*SELECTION SCREEN WITH BLOCK DEFINITION.
selection-screen begin of block b2 with frame title text-004.
parameters: p_tbname type dd03l-tabname.
select-options: s_field for dd03l-fieldname no intervals.
selection-screen end of block b2.
*----
!
----
Variables *
----
data : lv_where type string,
lv_cnt type i value '1',
v_records type i.
data : gv_where_cl(100) type c. "Variable to hold Where clause
data: wa_flname(5) type c.
data: wa_fldcat type lvc_s_fcat.
data: it_fldcat type lvc_t_fcat.
data: it type ref to data.
DECLARATION OF FIELD SYMBOLS :
field-symbols: <fs_table> type table.
field-symbols: <fs_temp> type any,
<fs_final> type any.
&----
*& Include Z_TABLE_FS_FORMS
&----
&----
*& Form clear_fields
&----
To clear all work areas and refresh all internal tables.
----
form clear_fields .
clear wa_dd03l.
clear wa_flds.
clear wa_fields.
clear wa_cat.
clear wa_fname.
refresh it_dd03l.
refresh it_flds.
refresh it_fields.
refresh it_cat.
refresh it_fname.
endform. " clear_fields
&----
*& Form FETCH_DATA
&----
Fetch data from different tables
----
form fetch_data .
describe table s_field lines v_records.
Populate it_flds from s_field, to hold the fields to be Selected.
if s_field is not initial.
loop at s_field.
wa_flname = s_field-low.
write: s_field-low.
BUILD FIELD CATALOG FOR ALL FIELDS.
wa_flds-fieldname = wa_flname.
append wa_flds to it_flds.
endloop.
endif.
Populate the Where clause as a string.
if s_where[] is not initial.
loop at s_where.
concatenate lv_where s_where-low into lv_where separated by space.
endloop.
endif.
Populate it_dd03l, to hold the field names from DD03L.
select tabname
fieldname
keyflag
rollname
position
from dd03l
into table it_dd03l
where tabname eq p_tbname
and fieldname ne 'MANDT'.
if sy-subrc = 0.
sort it_dd03l by position.
delete it_dd03l where fieldname cp '.INCLU*'. ""CP = Covers Pattern
endif.
Populate it_fname, with fields which have to be selected (entered in selection).
loop at it_dd03l into wa_dd03l.
Read table it_flds.
read table it_flds into wa_flds with key fieldname = wa_dd03l-fieldname.
if sy-subrc = 0.
Move data from it_dd03l to it_fname
wa_fname-fld = wa_dd03l-fieldname.
append wa_fname to it_fname.
clear wa_fname.
endif.
endloop.
*TO CHECK IF TABLE EXISTS.
call function 'SCPR_DB_TABLE_EXIST'
exporting
tabname = p_tbname
exceptions
tab_dont_exist = 1
others = 2.
if sy-subrc <> 0.
if sy-subrc = 1.
GIVE A POP UP.
call function 'POPUP_TO_DECIDE_INFO'
exporting
textline1 = 'Table Does Not Exist !'
titel = 'Invalid Table Name'
start_column = 25
start_row = 6.
endif.
endif.
SELECT ALL RECORDS FROM DD03L.
select *
into table it_fields
from dd03l
where tabname = p_tbname.
if sy-subrc = 0.
sort it_fields by position.
delete it_fields where fieldname cp '.INCLU*'. "CP = Covers Pattern.
endif.
Populate IT_CAT with fields which are REQUIRED.
Display upto 150 fields only.
loop at it_fields into wa_fields to 150.
Read table it_fname
read table it_fname into wa_fname with key fld = wa_fields-fieldname.
if sy-subrc = 0.
Move data from it_fields
wa_cat-tabname = p_tbname.
wa_cat-fieldname = wa_fields-fieldname.
wa_cat-col_pos = lv_cnt.
wa_cat-inttype = wa_fields-inttype.
wa_cat-datatype = wa_fields-datatype.
wa_cat-intlen = wa_fields-intlen.
wa_cat-seltext = wa_fields-fieldname.
wa_cat-decimals = wa_fields-decimals.
wa_cat-ref_field = wa_fields-fieldname.
wa_cat-ref_table = p_tbname.
append wa_cat to it_cat.
clear wa_cat.
lv_cnt = lv_cnt + 1.
endif.
endloop.
CREATE A DYNAMIC INTERNAL TABLE.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_cat
importing
ep_table = it.
ASSIGN IT TO <FS>.
assign it->* to <fs_table>.
*Select the data from the table given as input and populate
it into the dynamic internal table created based on the where
condition.
select (it_fname)
from (p_tbname)
into table <fs_table>
where (lv_where).
if sy-subrc <> 0.
message 'No data found' type 'I'.
endif.
*Displaying dynamic internal table .
loop at <fs_table> assigning <fs_temp>.
write:/ <fs_temp> quickinfo 'CONTENTS'.
endloop.
endform. " FETCH_DATA
‎2008 Dec 24 10:35 AM
Hi Venkat,
example for data selection based on the input field:
here Inpit value is Purchase requisition number(BANFN)
selection criteria
select * from EBAN in to table itab
where BANFN EQ P_BANFN.
p_banfn is input value.
or provide me your selection criteria.
Regards
Hameed