cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Amount in SAPSCRIPTS

Former Member
0 Kudos

Hi Frens

I have a requirement , where i am printing the amount in a script called from a standard SAP program.

My requirement is to sum these amounts and print it in the footer. I am using a subroutine in a Z program to do the needful.

The code in script is :

/: PERFORM CALC_TOTAL IN PROGRAM ZAHFR_F150_DUNN01

/: USING &MHND-DMSHB&

/: ENDPERFORM

In the Z program i have defined a variable gv_amount

DATA: gv_amount TYPE mhnd-dmshb.

FORM calc_total TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy. "#EC CALLED

DATA: lv_amount TYPE mhnd-dmshb.

*-- Retrieve data for Current Item Amount

READ TABLE in_tab WITH KEY name = 'MHND-DMSHB' .

IF sy-subrc = 0 .

  • lv_amount = in_tab-value.

SHIFT in_tab-value LEFT DELETING LEADING space.

MOVE in_tab-value TO lv_amount.

gv_amount = gv_amount + lv_amount .

ENDIF.

ENDFORM. " CALC_TOT

The above code gives a dump as it is not able to interpret the value in in_tab-value

as a number.

Could you please suggest a way how to pass the amount field to the called subroutine and then sum it there.

Any pointers on the same would be of great help.

Thanks

Pankaj

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member196280
Active Contributor
0 Kudos

Yes, understood the reason for dump.. I guess the dump occurs if the values greater then 1000. Since in_tab-value is character format..Ok, solution to avoid the dump.

Write the following code it will avoid dump.

SHIFT in_tab-value LEFT DELETING LEADING space.

<b>Do.

REPLACE ',' WITH ' ' INTO in_tab-value.

IF SY-SUBRC <> 0.

CONDENSE in_tab-value NO-GAPS.

EXIT.

ENDIF

ENDDO.</b>

MOVE in_tab-value TO lv_amount.

gv_amount = gv_amount + lv_amount .

Close the thread once your question is answered.

Regards,

SaiRam

Former Member
0 Kudos

HI,

Just check the variable declarations u r using. u r moving a char field to a curr field.do proper conversions.this will definately solve ur prob.

reward if helpful.

~Kamal

SuhaSaha
Advisor
Advisor
0 Kudos

Hi Pankaj,

Are you trying to display <i>gv_amount</i> in the SAPscript?

Then i fear it must be giving the short dump.


/: DEFINE GV_TOT
/: PERFORM CALC_TOTAL IN PROGRAM ZAHFR_F150_DUNN01
/: USING &MHND-DMSHB&
/: CHANGING &V_TOT&
/: ENDPERFORM

READ TABLE in_tab WITH KEY name = 'MHND-DMSHB' .
IF sy-subrc = 0 .
* lv_amount = in_tab-value.
SHIFT in_tab-value LEFT DELETING LEADING space.
MOVE in_tab-value TO lv_amount.
gv_amount = gv_amount + lv_amount .
ENDIF.

READ TABLE out_tab WITH KEY name = 'V_TOT' .
IF sy-subrc = 0 .
 out_tab-value = gv_amount.
MODIFY out_tab.
ENDIF.

Then display the value of V_TOT in the total field. This should solve the problem.

Please reward some points.

Reagrds,

Suhas

Former Member
0 Kudos

Hi Suhas

Thanks for your reply.

but , the problem is that the value in_tab-value is an amount eg"300.00".

It does not interpret it as amount, and the MOVE statement gives an error.

I am not trying to print gv_amount in the scripts, but i am trying to add this value toin the subroutine.

Any further pointer would be of help.

Thanks

Pankaj

Former Member
0 Kudos

HI,

try by changing the lv_amount type to type N, coz u r moving a char variable into currency variable and so u r getting the error.

Reward if helpful.

~Kamal