08-13-2008 12:44 PM
hi guyz,
my requirement is to compare the length of the field in database table to the length given by the selection screen.how can i do that?...plz advise..
thanks
08-13-2008 12:45 PM
08-13-2008 12:49 PM
08-13-2008 12:53 PM
Hi
I hope this is what you want
DATA :
w_len TYPE i,
w_len1 TYPE i.
DATA :
BEGIN OF fs_itab,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
END OF fs_itab.
DATA :
itab LIKE
STANDARD TABLE
OF fs_itab.
PARAMETERS :
p_name(30) TYPE c.
SELECT
kunnr
name1
INTO fs_itab
FROM kna1
UP TO 2 ROWS.
ENDSELECT.
w_len = strlen( fs_itab-kunnr ).
w_len1 = strlen( p_name ).
WRITE :
/ w_len , w_len1.
if not can you be more clear on this
Regards
pavan
08-13-2008 12:58 PM
HI ,
Use the following code,
select LENG
from dd03l
into var1
where tabname = <Your table name>
and fieldname = <you field name>.
With this u will get length of the field in the data base table.
for the field in the selection screen ,
use strlen ( p_var ) .
compare both the values.
08-13-2008 1:21 PM
I think you meant something like this.
I used field VBELN from VBAK as an example.
ls_components is a table that contains all the components from the structure you provide it with, in the example below, VBAK.
The division by two is something I didn't quite understand why but after a couple of checks a friend suggested that the internal length (what is actually filled in lv_abap_comp-length) is always the double of the actual table field length (maybe this has something to do with Unicode issues...)
Change the VBELN field below to other fields from VBAK as a test and see if that's what you meant.
TYPE-POOLS: abap.
TABLES: VBAK.
DATA: length TYPE i,
ls_components TYPE abap_compdescr_tab,
lo_strucdescr TYPE REF TO cl_abap_structdescr,
lv_abap_comp TYPE abap_compdescr. "work area for the ls_components table, that provides the name of the field, as one of the components.
SELECT-OPTIONS s_vbeln FOR length NO INTERVALS.
" Example using VBAK table structure
lo_strucdescr ?= cl_abap_typedescr=>describe_by_data( VBAK ).
ls_components = lo_strucdescr->components.
READ TABLE ls_components INTO lv_abap_comp WITH KEY name = 'VBELN'.
*BREAK-POINT.
lv_abap_comp-length = lv_abap_comp-length / 2.
IF lv_abap_comp-length IN s_vbeln.
WRITE 'Length provided for VBELN field equals the DDIC''s definition'.
ELSE.
WRITE 'Wrong length for VBELN field.'.
ENDIF.
Avraham
08-13-2008 1:21 PM
I think you meant something like this.
I used field VBELN from VBAK as an example.
ls_components is a table that contains all the components from the structure you provide it with, in the example below, VBAK.
The division by two is something I didn't quite understand why but after a couple of checks a friend suggested that the internal length (what is actually filled in lv_abap_comp-length) is always the double of the actual table field length (maybe this has something to do with Unicode issues...)
Change the VBELN field below to other fields from VBAK as a test and see if that's what you meant.
TYPE-POOLS: abap.
TABLES: VBAK.
DATA: length TYPE i,
ls_components TYPE abap_compdescr_tab,
lo_strucdescr TYPE REF TO cl_abap_structdescr,
lv_abap_comp TYPE abap_compdescr. "work area for the ls_components table, that provides the name of the field, as one of the components.
SELECT-OPTIONS s_vbeln FOR length NO INTERVALS.
" Example using VBAK table structure
lo_strucdescr ?= cl_abap_typedescr=>describe_by_data( VBAK ).
ls_components = lo_strucdescr->components.
READ TABLE ls_components INTO lv_abap_comp WITH KEY name = 'VBELN'.
*BREAK-POINT.
lv_abap_comp-length = lv_abap_comp-length / 2.
IF lv_abap_comp-length IN s_vbeln.
WRITE 'Length provided for VBELN field equals the DDIC''s definition'.
ELSE.
WRITE 'Wrong length for VBELN field.'.
ENDIF.
Avraham
08-13-2008 4:03 PM