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

split not working

Former Member
0 Likes
660

i have converted the packed decimal to char format .

i want split the numeric and decimal ..not able to do it the sy-subrc value is zero

DATA: lv_menge(2),
        lv_Dec(2).
  CLEAR lv_menge.
  LOOP AT  it_data INTO wa_data.
    SORT it_btext.
    READ TABLE it_btext INTO wa_btext
       WITH KEY bwart = wa_data-bwart BINARY SEARCH.
    IF sy-subrc EQ 0.
      wa_output-btext = wa_btext-btext.
    ENDIF.

    READ TABLE it_maktx INTO wa_maktx
      WITH KEY matnr = wa_data-matnr BINARY SEARCH.
    IF sy-subrc EQ 0.
      wa_output-maktx = wa_maktx-maktx.
    ENDIF.

    *WRITE: wa_data-menge TO wa_output-menge1  .*
    *SPLIT wa_output-menge1 AT '.' INTO lv_menge lv_dec.*

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
636

Hello Mozam,

I think you donot need to use the SPLIT function here. You can use the FRAC & TRUNC functions:

Try this code:

DATA: 
lv_menge TYPE i,
lv_Dec TYPE i.

  CLEAR lv_menge.
  LOOP AT  it_data INTO wa_data.
    SORT it_btext.
    READ TABLE it_btext INTO wa_btext
       WITH KEY bwart = wa_data-bwart BINARY SEARCH.
    IF sy-subrc EQ 0.
      wa_output-btext = wa_btext-btext.
    ENDIF.
 
    READ TABLE it_maktx INTO wa_maktx
      WITH KEY matnr = wa_data-matnr BINARY SEARCH.
    IF sy-subrc EQ 0.
      wa_output-maktx = wa_maktx-maktx.
    ENDIF.

    lv_menge = TRUNC( wa_data-menge ). "Integer part
    
    lv_dec = FRAC( wa_data-menge ). "Decimals Part
 
    *WRITE: wa_data-menge TO wa_output-menge1  .
    *SPLIT wa_output-menge1 AT '.' INTO lv_menge lv_dec.

Hope this helps.

BR,

Suhas

PS: Additional advantage of these functions is that it does not depend on the decimals separator, whereas SPLIT will be dependent on the decimal separator

Edited by: Suhas Saha on Feb 27, 2009 12:40 PM

5 REPLIES 5
Read only

former_member242255
Active Contributor
0 Likes
636

wa_output-menge1 shouild be char type..

Read only

Former Member
0 Likes
636

It depends on the user settings, if your user settings are in the format 1.22,33 it wont work.

I think lv_menge declaration is wrong, lenght is 2? or more.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
637

Hello Mozam,

I think you donot need to use the SPLIT function here. You can use the FRAC & TRUNC functions:

Try this code:

DATA: 
lv_menge TYPE i,
lv_Dec TYPE i.

  CLEAR lv_menge.
  LOOP AT  it_data INTO wa_data.
    SORT it_btext.
    READ TABLE it_btext INTO wa_btext
       WITH KEY bwart = wa_data-bwart BINARY SEARCH.
    IF sy-subrc EQ 0.
      wa_output-btext = wa_btext-btext.
    ENDIF.
 
    READ TABLE it_maktx INTO wa_maktx
      WITH KEY matnr = wa_data-matnr BINARY SEARCH.
    IF sy-subrc EQ 0.
      wa_output-maktx = wa_maktx-maktx.
    ENDIF.

    lv_menge = TRUNC( wa_data-menge ). "Integer part
    
    lv_dec = FRAC( wa_data-menge ). "Decimals Part
 
    *WRITE: wa_data-menge TO wa_output-menge1  .
    *SPLIT wa_output-menge1 AT '.' INTO lv_menge lv_dec.

Hope this helps.

BR,

Suhas

PS: Additional advantage of these functions is that it does not depend on the decimals separator, whereas SPLIT will be dependent on the decimal separator

Edited by: Suhas Saha on Feb 27, 2009 12:40 PM

Read only

Former Member
0 Likes
636

great saha

Read only

Former Member
0 Likes
636

Hi,

SPLIT only work with char type variables, so variable that need to be split and variables in which final result need to be stored shloud be all char type so make sure all the variables in command

SPLIT wa_output-menge1 AT '.' INTO lv_menge lv_dec. are all char type.

Pooja