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

Getting Error While using WRITE TO STATEMENT

Former Member
0 Likes
2,336

Hi Everyone,

I am facing an issue when ever i am writing a WRITE TO statement. my requirement is as follows.

4563 JPY will be stored in the database table BSEG as 45.63. But when this values is displayed on the screen (like FB03), system will internally convert back and display 4,563 JPY.  in one of my subroutine of the program while populating the output amount value(WRBTR) is being fetched from BSEG table and moved to output internal table based on currency(PSWSL).

WRITE wa_bseg-wrbtr TO wa_output-amount CURRENCY wa_bseg=pswsl.

the WRITE TO statement with CURRENCY is being written so that the system will internally convert back and shown in proper format in FB03.

after PPV reclassification, the amount 324 JPY is posted as 3 under one GL account. I need to implement the same WRITE TO CURRENCY to display in proper format. i tried to write in as follow.

WRITE wa_bseg-wrbtr TO wa_currentamount-amt_doccur CURRENCY wa_bseg-pswsl.

but it is throwing an error saying amt_doccur should be of type I,C,N

details of field amt_doccur(data type : DEC, no of char: 23, decimal:4, total length: 30) where as details of field wa_bseg-wrbtr is (data type: CURR, no of char:13, decimal : 2 total length : 16). how to avoid this error. or is there any function module which can convert the data type from CURR to DEC.

Kindly suggest some solution.

Thanks & Regards

PRN

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,537

It's really very basic.

WRITE wa_bseg-wrbtr TO wa_currentamount-amt_doccur CURRENCY wa_bseg-pswsl.

wa_currentamount-amt_doccurr is not of type C, N nor I. So to make your statement work, you must do a conversion. Exactly what the error says. So you could do:_

DATA doccurr type i.

WRITE wa_bseg-wrbtr TO doccurr CURRENCY wa_bseg-pswsl.

wa_currentamount-amt_doccur = doccurr

Or, possibly in 7.4+ (I've not tried it). WRITE wa_bseg-wrbtr TO CONV #(wa_currentamount-amt_doccur ) CURRENCY wa_bseg-pswsl.

However, and MORE IMPORTANTLY, why are you wanting to store the converted value in your internal table. That's a very odd thing to do. Normally you only do the conversion at output. I think you're doing something wrong.

5 REPLIES 5
Read only

Clemenss
Active Contributor
0 Likes
1,537

Hi Ranjan,

WRITE TO always expects a character-like target. What you can see on screen or printed list and what you can type using the keyboard are characters. The WRITE (TO) statement implicitly uses the conversion exit of the written data converting any interbal format to character output.

JPY is defined in the currency table as a value with zero decimals, so the 2 decimals you can see in the BSEG currency field are ignored when writing this value to a (char-like) output using the currency addition.

Note: Only use WRITE when you want to create a readable character output, otherwise use MOVE.

The best you can do is describe your task in more detail, what is the expected output.

Regards Clemens

Read only

jitendra_it
Active Contributor
0 Likes
1,537

Hello Ranjan,

What is the data type of field wa_output-amount which is used in first statement ?

You can also check this FM CURRENCY_AMOUNT_SAP_TO_DISPLAY.

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,537

WRITE wa_bseg-wrbtr TO wa_currentamount-amt_doccur CURRENCY wa_bseg-pswsl.

but it is throwing an error saying amt_doccur should be of type I,C,N

Just a remark, no, it may only be a character-like data object (I (Integer) is impossible)


details of field amt_doccur(data type : DEC, no of char: 23, decimal:4, total length: 30) where as details of field wa_bseg-wrbtr is (data type: CURR, no of char:13, decimal : 2 total length : 16). how to avoid this error. or is there any function module which can convert the data type from CURR to DEC.

Your question also applies to conversion from CURR to CURR when the number of decimals of the two data objects is different. Probably (maybe I'm wrong please verify it) amt_doccur should have its value amount right aligned as for any currency amount, exactly as with BSEG-WRBTR. To make this possible, you may use the ASSIGN statement for ignoring the decimals:

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS copy_curr_field 
        IMPORTING source TYPE p 
        EXPORTING target TYPE p.
ENDCLASS."
CLASS lcl_app IMPLEMENTATION.
  METHOD copy_curr_field.
    FIELD-SYMBOLS <source> TYPE x.
    FIELD-SYMBOLS <target> TYPE x.
    DATA soff TYPE i.
    DATA toff TYPE i.
    ASSIGN target TO <target> CASTING.
    ASSIGN source TO <source> CASTING.
    IF xstrlen( <target> ) < xstrlen( <source> ).
      "SSSSS to TTT -> soff=2 and toff=0
      soff = xstrlen( <source> ) - xstrlen( <target> ).
      toff = 0.
    ELSE.
      "SSS to TTTTT -> soff=0 and toff=2
      soff = 0.
      toff = xstrlen( <target> ) - xstrlen( <source> ).
    ENDIF.
    <target>+toff = <source>+soff.
  ENDMETHOD."
ENDCLASS."
START-OF-SELECTION.
DATA target TYPE p DECIMALS 4.
DATA source TYPE p DECIMALS 2.
source = '45.63'.
lcl_app=>copy_curr_field( EXPORTING source = source IMPORTING target = target ). 

The amount of 4563 JPY is stored 45.63 in source field, and 0.4563 in target field.

Maybe the amount of 4563 JPY should be stored 45.6300 in your amt_doccur field, in that case you may simply use: wa_currentamount-amt_doccur = wa_bseg-wrbtr.


after PPV reclassification, the amount 324 JPY is posted as 3 under one GL account. I need to implement the same WRITE TO CURRENCY to display in proper format.

I don't get what you exactly mean with "is posted as 3". Where do you see that? Is it the result of your code?

Read only

matt
Active Contributor
0 Likes
1,539

It's really very basic.

WRITE wa_bseg-wrbtr TO wa_currentamount-amt_doccur CURRENCY wa_bseg-pswsl.

wa_currentamount-amt_doccurr is not of type C, N nor I. So to make your statement work, you must do a conversion. Exactly what the error says. So you could do:_

DATA doccurr type i.

WRITE wa_bseg-wrbtr TO doccurr CURRENCY wa_bseg-pswsl.

wa_currentamount-amt_doccur = doccurr

Or, possibly in 7.4+ (I've not tried it). WRITE wa_bseg-wrbtr TO CONV #(wa_currentamount-amt_doccur ) CURRENCY wa_bseg-pswsl.

However, and MORE IMPORTANTLY, why are you wanting to store the converted value in your internal table. That's a very odd thing to do. Normally you only do the conversion at output. I think you're doing something wrong.

Read only

Former Member
0 Likes
1,537

Hi Clemens, Jitendra, Sandra, Matthew,

Thank you very much for your reply. Sorry for late reply as i was travelling. Issue resolved.

Thanks Very much

Ranjan Nayak