Skip to Content
avatar image
Former Member

Remove initial 0 values and find the first number

Hi ,

I have different numbers in my records, they vary from 1 digit to 9 digit . I also have some letters in these records . Relevant field is 10 character length and if it fills initial free spaces with '0' to make record 10 digit. I want to find first digit after '0' values.

For example I have records like :

000123456S I want to find '1'

0000000081 I want to find '8'

Thanks for your helps

Erkan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 09, 2007 at 07:56 PM

    Hi ,

    I forgot one additional requirement . I also want to check if the letter I found is a letter or a number .

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      U can either use this function module also

      CONVERSION_EXIT_ALPHA_OUTPUT

      or

      SHIFT <yourField> LEFT DELETING LEADING '0'

      or

      try NO-ZERO option of WRITE statement

      or

      Another way is to create another variable of type I and assign the value into it

      example:

      DATA: L_NUMC(08) TYPE N.

      DATA: L_INT TYPE I.

      L_NUMC = '00000018'.

      L_INT = L_NUMC.

      Result will be = 18.

      Hope this helps

  • avatar image
    Former Member
    Oct 09, 2007 at 08:05 PM

    Try:

    DATA: f1(10) VALUE '0001234567'.
    
    IF f1 CN '0'.
      WRITE: /001 f1+3(1).
    ENDIF.

    Rob

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 08:22 PM

    I think this will be the complete solution ...

    SHIFT varibale LEFT DELETING LEADING '0'.

    then

    tempvar = variable(1)

    then check the value of tempvar

    ====================

    if tempvar co '0123456789'.

    write : 'Numericals'.

    else.

    write : 'ALPHA numericals'.

    endif.

    ====================

    Reward Points if it is helpful.

    Thanks & Regards

    ilesh 24x7

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 08:30 PM

    Hi Erkan,

    here the full code.

    I found a error when the value is '0000000000', its solved here:

    data: text(10) value '0000A00000',

    cont(2),

    num_lett.

    while text+cont(1) = '0' <b>and cont < 9.</b>

    cont = cont + 1.

    endwhile.

    write: / text+cont(1).

    num_lett = 'A'.

    case text+cont(1).

    when '0' or '1' or '2' or '3' or '4' or

    '5' or '6' or '7' or '8' or '9'.

    num_lett = 'N'.

    endcase.

    if num_lett = 'A'.

    write: / 'ALPHA numeric'.

    else.

    write: / 'numeric'.

    endif.

    Regards

    Allan Cristian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 08:04 PM

    Hi Erkan,

    try it to ur first post.

    data: text(10) value '000123456S',

    cont(2).

    while text+cont(1) = '0'.

    cont = cont + 1.

    endwhile.

    write: / text+cont(1).

    Regards,

    Allan Cristian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 08:10 PM

    SHIFT varibale LEFT DELETING LEADING '0'.

    then

    tempvar = variable(1)

    then check the value of tempvar

    use the below logic to check for numerical or char filed...

    test(5) type c.

    test = '12345'.

    if test co '0123456789 ' and test NE ' '.

    write : 'only numericals'.

    ELSEif test = SPACE.

    write : 'SPACE'.

    elseIF NOT TEST = SPACE.

    write : 'ALPHA numericals'.

    else.

    write : 'Other'.

    endif.

    ENDIF.

    <b>Reward Points if it is helpful.</b>

    Thanks & Regards

    ilesh 24x7

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 08:33 PM

    Thanks for all answers

    Add comment
    10|10000 characters needed characters exceeded