Application Development and Automation 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: 
Read only

Length

Former Member
0 Likes
1,364

I am entereing a number whose length is 9 characters longs... The system should proceed only if the length is equal to 9 characters.. How could i check that...

15 REPLIES 15
Read only

Former Member
0 Likes
1,328

I think the syntax is

data w_length(10).

data w_field(9).

w_field = '12345678'.

w_length = STRLEN( w_field )

Anyway the command is STRLEN.

Read only

Former Member
0 Likes
1,328

strlen

<b>Report zex33.

parameter : str(9).

data : len type i.

len = STRLEN( str ).

if len eq 9.

write : / str.

else.

write : / 'String length is not equal to 9'.

endif.</b>

Read only

0 Likes
1,328

Let's say the user enters SERNR

What would be the statement to check whether is it 9 characters or not....

Read only

Former Member
0 Likes
1,328

Hi alexander,

you can store the inpur number in a field defined as string

then you can use STRLEN keyword to get the length

hope this helps

Read only

Former Member
0 Likes
1,328

Hi,

Use <b>STRLEN</b> to get lenth of the field.

Regards,

Balavardhan.K

Read only

suresh_datti
Active Contributor
0 Likes
1,328

use the DESCRIBE statetment to get the length of the field..

~Suresh

Read only

Former Member
0 Likes
1,328

Hi,

Assign the value to string & calculate the length of string (strlen). if it is less than 9 then throw an error message.

Ashvender

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,328

Try something like this.

data: len type i.
parameters: p_fld(9) type c.


at selection-screen.

   len = strlen( p_fld ).
    if len <> 9.
      message e001(00) with 'Value does not have a length of 9'.
    endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,328

check V1 = <b>strlen(field).</b>

if V1 = 9.

do the processing.

endif.

Read only

0 Likes
1,328

Here is the code... I have to make sure that I_SERNR then it has to process the code... How can i do that...

DATA: I_EQUI LIKE EQUI.

DATA: I_SERNR LIKE EQUI-SERNR.

I_SERNR = SERNR.

SHIFT I_SERNR LEFT DELETING LEADING '0'.

  • DATA: SERNR LIKE EQUI-SERNR.

  • DATA: MATNR TYPE MATNR.

IF SY-TCODE = 'MB31'.

SELECT SINGLE * FROM EQUI INTO I_EQUI

WHERE EQTYP = 'S'

AND MATNR = MATNR

AND SERNR = SERNR.

IF SY-SUBRC EQ 0.

MESSAGE E398(00) WITH 'SERIAL NUMBER ALREADY EXISTS'.

ELSE.

IF I_SERNR0(1) = '2' OR I_SERNR0(1) = '3' OR I_SERNR+0(1) = '6'.

IF I_SERNR1(2) = SY-DATUM2(2).

IF I_SERNR3(2) LE SY-DATUM4(2).

IF I_SERNR5(4) GT '0000' AND I_SERNR5(4) LT '9999'.

ELSE.

MESSAGE E398(00) WITH 'PLEASE ENTER RANGE WITHIN 0000 AND 9999'.

ENDIF.

ELSE.

MESSAGE E398(00) WITH 'PLEASE ENTER A DATE IN THE PAST'.

ENDIF.

ELSE.

IF I_SERNR1(2) LT SY-DATUM2(2).

IF I_SERNR5(4) GT '0000' AND I_SERNR5(4) LT '9999'.

ELSE.

MESSAGE E398(00) WITH 'PLEASE ENTER RANGE WITHIN 0000 AND 9999'.

ENDIF.

ELSE.

MESSAGE E398(00) WITH 'PLEASE ENTER A DATE IN THE PAST'.

ENDIF.

ENDIF.

ELSE.

MESSAGE E398(00) WITH 'INVALID MANUFACTURING SITE'.

ENDIF.

ENDIF.

ELSE.

SELECT SINGLE * FROM EQUI INTO I_EQUI

WHERE EQTYP = 'S'

AND MATNR = MATNR

AND SERNR = SERNR.

IF SY-SUBRC NE 0.

MESSAGE E398(00) WITH 'PLEASE ENTER A VALID SERIAL NUMBER'.

ENDIF.

ENDIF.

Read only

0 Likes
1,328

I_SERNR has to be 9 characters long..How can do that..

Read only

0 Likes
1,328

Hi,

Do like this:

data: length type i.

data: v_string type string.

v_string = I_SERNR.

Write this code before IF statement(SY-TCODE = 'MB31').

length = strlen( v_string ).

if length <> 9.

message e000(0) with 'Value length is not = 9'.

endif.

Ashvender

Read only

0 Likes
1,328
DATA: I_EQUI LIKE EQUI.
DATA: I_SERNR LIKE EQUI-SERNR.
I_SERNR = SERNR.
SHIFT I_SERNR LEFT DELETING LEADING '0'.

* DATA: SERNR LIKE EQUI-SERNR.
* DATA: MATNR TYPE MATNR.

<b>

data: len type i.
len = strlen( i_sernr ).
if len <> 9.
message e001(00) with 'SERNR value not = 9'.
endif.

</b>


IF SY-TCODE = 'MB31'.

SELECT SINGLE * FROM EQUI INTO I_EQUI
WHERE EQTYP = 'S'
AND MATNR = MATNR
AND SERNR = SERNR.
IF SY-SUBRC EQ 0.
MESSAGE E398(00) WITH 'SERIAL NUMBER ALREADY EXISTS'.
ELSE.
........

Regards,

Rich Heilman

Read only

0 Likes
1,328

In this current the serial number 2,3 digits are validated against year, 4,5 digits are validated against month. When I enter 13 for the month it is accepting and validating. Also I have to make to sure the valid years are current year and past year, valid months are current month and past month... how to achieve it .....

Read only

Former Member
0 Likes
1,328

Hi,

I hope following code will solve your problem.

DATA : v_len TYPE i.

PARAMETERS : p_num(9) TYPE n.

AT SELECTION-SCREEN ON p_num.

v_len = STRLEN( p_num ).

IF v_len <> 9.

IF v_len < 9.

MESSAGE 'Length of p_num is Less Than 9' TYPE 'E'.

ELSE.

MESSAGE 'Length of p_num is Greater Than 9' TYPE 'E'.

ENDIF.

ENDIF.

Reward points if the answer is helpful.

Regards,

Mukul