01-21-2007 11:38 AM
Hello, there.
I want to define a dynamic select statment: Only the selection fields are suppose to be dynamic, meaning "select var_dynfld1 var_dynfld2 from kna1 where kunnr = 222".
Does anyone can send me the exact syntax ?
Thanks in advance,
Rebeka
01-21-2007 12:24 PM
Hey again.
Let me be more exact & specific:
I have an internal table which I want to read from.
The problem is that I want to set my key fields according to some dynamic conditions.
DATA:
BEGIN OF ITAB OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
MATNR LIKE MARA-MATNR,
SUM LIKE BSEG-WRBTR,
END OF ITAB.
At first time I want to write READ TABLE ITAB WITH KEY KUNNR = 2
and after that: READ TABLE ITAB WITH KEY MATNR = 2.
I want the KUNNR and MATNR to be defined as variables.
01-21-2007 11:54 AM
code sample
REPORT YDYNSEL
NO STANDARD PAGE HEADING.
data: itab type standard table of sflight .
TYPE-POOLS RSFS.
DATA SELECT_FIELDS TYPE RSFS_FIELDS.
data: FIELDLISTS TYPE RSFS_TAB_FIELDS,
FLAG_READ.
IF FLAG_READ = SPACE.
FIELDLISTS-TABLENAME = 'SFLIGHT'.
READ TABLE SELECT_FIELDS WITH KEY FIELDLISTS-TABLENAME
INTO FIELDLISTS.
append 'CARRID' to FIELDLISTS-fields .
append 'CONNID' to FIELDLISTS-fields .
FLAG_READ = 'X'.
ENDIF.
SELECT (FIELDLISTS-FIELDS)
up to 10 rows from sflight into corresponding fields of table itab .
Regards
Raja
01-21-2007 11:57 AM
Hi,
How to write dynamic where condition you can find in documentation:
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3990358411d1829f0000e829fbfe/content.htm
in section "Specifying Columns Dynamically"
There is also small example there...
regards
Krzys
01-21-2007 12:02 PM
Hi Rebeka,
Check the below mentioned code is the same requirement you are looking for. If not the Explain your requirement in details.
If you are using parameters statements instead of select-options then you need to use Where condition like this in select statement(WHERE kunnr = s_kunnr).
DATA: Begin of itab occurs10,
kunnr type kunnr,
land1 type land1_gp,
ort01 type ort01_gp,
pstlz type pstlz,
end of itab.
select-options: s_kunnr for kna1-kunnr.
start-of-selection.
SELECT kunnr land1 ort01 pstlz
FROM kna1
INTO TABLE itab
WHERE kunnr in s_kunnr.
Ashven
01-21-2007 12:09 PM
Hi,
If the question is answered, can you mark the thread as answered.
raja
01-21-2007 12:24 PM
Hey again.
Let me be more exact & specific:
I have an internal table which I want to read from.
The problem is that I want to set my key fields according to some dynamic conditions.
DATA:
BEGIN OF ITAB OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
MATNR LIKE MARA-MATNR,
SUM LIKE BSEG-WRBTR,
END OF ITAB.
At first time I want to write READ TABLE ITAB WITH KEY KUNNR = 2
and after that: READ TABLE ITAB WITH KEY MATNR = 2.
I want the KUNNR and MATNR to be defined as variables.
01-21-2007 12:27 PM
data: fnam(40) .
move: 'KUNNR' to fnam .
read table itab with key (fnam) = 2 .
clear fnam .
move: 'MATNR' to fnam .
read table itab with key (fnam) = 2 .
Regards
Raja