Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

length of the field on the slection screen

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

Hi

use strlen.

regards

vivek

Former Member
0 Kudos

hi,

Can you elaborate your requirement?

Regards

Sumit Agarwal

bpawanchand
Active Contributor
0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

**THREAD IS CLOSED**