‎2007 Mar 22 9:04 AM
Hello,
I have to construct a dynamic where clause and I am stuck with a problem. I don't know what fields I will have in my where clause, so I have to decide where to put quotes for the character values and where not to put values for numaric values. I have the dynamic fields in a table type DFIES. There, I have a field DATATYPE. I found out the following list of predefined datatypes in ABAP Dictionary, I hope it is complete. So, I thought to check the datatype field and to decide whether I need quotes or not.
But I am not shure for what data types I need quotes. I wrote bellow what I know, and maybe you can complete what I don't know.
Type Permitted Places m Meaning ABAP Type
ACCP 6 Accounting period n(6) -> ???
CHAR 1-255 Character string c(m) -> QUOTES
CLNT 3 Client c(3) -> QUOTES
CUKY 5 Currency key c(5) -> QUOTES
CURR 1-17 Currency field p((m+1)/2) -> ???
DATS 8 Date d -> ???
DEC 1-31, in tables: 1-17 Calculation/amount field p((m+1)/2) -> ???
FLTP 16 Floating point number f(8) -> ???
INT1 3 1 byte integer b -> NO QUOTES
INT2 5 2 byte integer s -> NO QUOTES
INT4 10 4 byte integer i -> NO QUOTES
LANG 1 Language c(1) -> QUOTES
LCHR 256-... Long character string c(m) -> QUOTES
LRAW 256-... Long byte string x(m) -> ???
NUMC 1-255 Numeric text n(m) -> ???
PREC 2 Accuracy s -> ???
QUAN 1-17 Quantity p((m+1)/2) -> ???
RAW 1-255 Byte sequence x(m) -> ???
RAWSTRING 256-... Byte sequence xstring -> ???
SSTRING 1-255 Character string string -> QUOTES
STRING 256-... Character string string -> QUOTES
TIMS 6 Time t -> ???
UNIT 2-3 Unit c(m) -> ????
If someone knows another way to find out if I need quotes for a field value in a dynamic where clause please let me know.
Thank you!
‎2007 Mar 22 9:08 AM
Hi,
This is the sample report for DYNAMIC ALV report.
Kindly go through it.
REPORT YMS_DYNAMICALV.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.
start-of-selection.
build the dynamic internal table
perform build_dyn_itab.
write 5 records to the alv grid
do 5 times.
perform build_report.
enddo.
call the alv grid.
perform call_alv.
************************************************************************
Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
Create fields .
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
enddo.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*********************************************************************
Form build_report
*********************************************************************
form build_report.
data: fieldname(20) type c.
data: fieldvalue(5) type c.
data: index(3) type c.
field-symbols: <fs1>.
do p_flds times.
index = sy-index.
Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
<b> assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.</b>
enddo.
Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.
************************************************************************
CALL_ALV
************************************************************************
form call_alv.
data: wa_cat like line of alv_fldcat.
do p_flds times.
clear wa_cat.
wa_cat-fieldname = sy-index.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '5'.
append wa_cat to alv_fldcat.
enddo.
Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = alv_fldcat
tables
t_outtab = <dyn_table>.
endform.
Thanks,
Shankar
‎2007 Mar 22 9:13 AM
Hi,
Pls go through this dynamic alv sample report.
REPORT YMS_DYNAMICALV.
TYPE-POOLS: SLIS.
FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
<DYN_WA>.
DATA: ALV_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FLDCAT TYPE LVC_T_FCAT.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FLDS(5) TYPE C.
SELECTION-SCREEN END OF BLOCK B1.
START-OF-SELECTION.
build the dynamic internal table
PERFORM BUILD_DYN_ITAB.
write 5 records to the alv grid
DO 5 TIMES.
PERFORM BUILD_REPORT.
ENDDO.
call the alv grid.
PERFORM CALL_ALV.
************************************************************************
Build_dyn_itab
************************************************************************
FORM BUILD_DYN_ITAB.
DATA: NEW_TABLE TYPE REF TO DATA,
NEW_LINE TYPE REF TO DATA,
WA_IT_FLDCAT TYPE LVC_S_FCAT.
Create fields .
DO P_FLDS TIMES.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = SY-INDEX.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-INTLEN = 5.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
ENDDO.
Create dynamic internal table and assign to FS
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT
IMPORTING
EP_TABLE = NEW_TABLE.
ASSIGN NEW_TABLE->* TO <DYN_TABLE>.
Create dynamic work area and assign to FS
CREATE DATA NEW_LINE LIKE LINE OF <DYN_TABLE>.
ASSIGN NEW_LINE->* TO <DYN_WA>.
ENDFORM. "build_dyn_itab
*********************************************************************
Form build_report
*********************************************************************
FORM BUILD_REPORT.
DATA: FIELDNAME(20) TYPE C.
DATA: FIELDVALUE(5) TYPE C.
DATA: INDEX(3) TYPE C.
FIELD-SYMBOLS: <FS1>.
DO P_FLDS TIMES.
INDEX = SY-INDEX.
Set up fieldvalue
CONCATENATE 'FLD' INDEX INTO
FIELDVALUE.
CONDENSE FIELDVALUE NO-GAPS.
<b> assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.</b>
ENDDO.
Append to the dynamic internal table
APPEND <DYN_WA> TO <DYN_TABLE>.
ENDFORM. "build_report
************************************************************************
CALL_ALV
************************************************************************
FORM CALL_ALV.
DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.
DO P_FLDS TIMES.
CLEAR WA_CAT.
WA_CAT-FIELDNAME = SY-INDEX.
WA_CAT-SELTEXT_S = SY-INDEX.
WA_CAT-OUTPUTLEN = '5'.
APPEND WA_CAT TO ALV_FLDCAT.
ENDDO.
Call ABAP List Viewer (ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = ALV_FLDCAT
TABLES
T_OUTTAB = <DYN_TABLE>.
ENDFORM. "call_alv
Thanks,
Shankar
‎2007 Mar 22 9:59 AM
After some documentation I reached to the following conclusion:
ACCP n(6) Character data type
CHAR c(m) Character data type
CLNT c(3) Character data type
CUKY c(5) Character data type
DATS d Character data type
LANG c(1) Character data type
LCHR c(m) Character data type
LRAW x(m) Character data type
NUMC n(m) Character data type
RAW x(m) Character data type
RAWSTRING xstring Character data type
SSTRING string Character data type
STRING string Character data type
TIMS t Character data type
UNIT c(m) Character data type
CURR p((m+1)/2) Numeric data type
DEC p((m+1)/2) Numeric data type
FLTP f(8) Numeric data type
INT1 b Numeric data type
INT2 s Numeric data type
INT4 i Numeric data type
PREC s Numeric data type
QUAN p((m+1)/2) Numeric data type