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

type conversion

Former Member
0 Likes
914

hi,

in internal table i_filedata one field is type c, that field is 4 amount.

ex. amount(27),

when it is assigned to a varible v_amt type bapiwrbtr, dump occurs.

v_amt = amount.

hw to rectify that type mismatch.

amount should be c or t or string or d.

thanks in advance,

8 REPLIES 8
Read only

Former Member
0 Likes
882

Hi for amount type declare the type as PACK

ex:

data: v_amt type P dec 2.

Regs

Manas.

Read only

Former Member
0 Likes
882

Hi i wrote this code..

it is working fine. i checked in ECC5 as well as ECC6

data:

amount(27).

data: v_amt type bapiwrbtr.

amount = 123.

v_amt = amount.

write: v_amt.

Read only

0 Likes
882

hi

ur coding is is wrking fine when we give numbers, but if u give alphanumeric, then dump occurs. If the enduser wrongly type amount as alphanumeric, that error should be handled, hw to handle that error.

thanks

Read only

0 Likes
882

Than change your field declaration for AMOUNT to type P.

PARAMETERS: P_AMT TYPE BSEG-DMBTR.

Regards,

Naimesh Patel

Read only

0 Likes
882

hi

amount should be in type C or D or T or N or string.

since amount is taken from flatfile.

thanks

Read only

0 Likes
882

You can do it like this:

DATA: C_AMOUNT(30),
P_AMOUNT TYPE BSEG-DMBTR.

C_VALUE = '-12,345,678.90'.
replace ',' in c_value  with ' '.
replace ',' in c_value  with ' '.
replace ',' in c_value  with ' '.
replace ',' in c_value  with ' '.
condense c_value NO-GAPS.
IF C_VALUE CA SY-ABCDE.
  message e398(00) with 'Error in data'.
ENDIF.
move c_vALUE to P_AMOUNT.

Regards,

Naimesh Patel

Read only

0 Likes
882

Hi,

Try this code and change it according to your requirement

DATA digit(11) VALUE ' 0123456789'.

PARAMETERS: text(16) DEFAULT 'A20,000.00'.

DATA c_text(16).

DATA amount TYPE p DECIMALS 2.

DATA n TYPE n.

DATA i TYPE i.

c_text = text.

CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.

MOVE c_text TO amount.

ENDCATCH.

IF sy-subrc EQ 1.

CALL FUNCTION 'PREPARE_STRING'

EXPORTING

i_valid_chars = digit

i_xvalid_check = 'X'

i_xchar_repl = 'X'

i_xtoupper = 'X'

CHANGING

c_string = c_text.

CONDENSE c_text NO-GAPS.

DESCRIBE FIELD amount DECIMALS n.

i = 10 ** n.

amount = c_text / i.

ENDIF.

WRITE:/ text, 50 amount.

Regards,

AMit

Read only

0 Likes
882

hi

thank u . it is wrking fine.

regards

prabhu