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

Calculating hash total

Former Member
0 Likes
2,828

Hello everyone!

I am required to produced a CSV file and the last record should have a "hash total" which works like this:

For example, we have 3 records:

Record_1: 100.02

Record_2: 101.01

Record_3: 200.15

The hash total would be calculated like this:

10002 + 10101 + 20015 = 40118

The hash total is 40118 which should be outputted as: "000000000040118"

I already tried saving the numbers into a TYPE N variable but it rounds off the decimals.

Any help will be greatly appreciated! Thanks a lot!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,792

Hi

decalare a varaible

data: v_num (10) type c.

first calculate the sum.

and move that sum to this field v_num.

and use the conversion fun modules

CONVERSION_EXIT_ALPHA_OUTPUT

CONVERSION_EXIT_ALPHA_INPUT

pass the same number as input and output you will get the output as '0000040118'.

Reward points if useful

Regards

Anji

Hello everyone!

I am required to produced a CSV file and the last record should have a "hash total" which works like this:

For example, we have 3 records:

Record_1: 100.02

Record_2: 101.01

Record_3: 200.15

The hash total would be calculated like this:

10002 + 10101 + 20015 = 40118

The hash total is 40118 which should be outputted as: "000000000040118"

I already tried saving the numbers into a TYPE N variable but it rounds off the decimals.

Any help will be greatly appreciated! Thanks a lot!

7 REPLIES 7
Read only

Former Member
0 Likes
1,792

Hi,

Create a dataelement with type C, and domain with conversion exit(ALPHA) with required length.

Use this reference as calculated hash value.and passthis value to converion_exit_alpha_ input.you will get the leading zeros and value will not be rounded.

Hope this helps you

Regards,

Read only

Former Member
0 Likes
1,793

Hi

decalare a varaible

data: v_num (10) type c.

first calculate the sum.

and move that sum to this field v_num.

and use the conversion fun modules

CONVERSION_EXIT_ALPHA_OUTPUT

CONVERSION_EXIT_ALPHA_INPUT

pass the same number as input and output you will get the output as '0000040118'.

Reward points if useful

Regards

Anji

Read only

0 Likes
1,792

Hi, Anji!

Thanks for the reply.

However, I am relatively new in ABAP so I do not know what do I need to include and how to include it to access CONVERSION_EXIT_ALPHA_OUTPUT and CONVERSION_EXIT_ALPHA_INPUT ...

Thanks for the help! _

Read only

Former Member
0 Likes
1,792

data : begin of itab occurs 0,
       val(10),
       end of itab.
data : total(15).
itab-val = '100.02'.
append itab.
itab-val = '101.01'.
append itab.

itab-val = '200.15'.
append itab.

loop at itab.
replace all occurrences of '.' in itab-val with ''.
condense itab-val.
total = total + itab-val.
*modify itab.
endloop.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    INPUT         = total
 IMPORTING
   OUTPUT        = total
          .

          write : / total.

regards

shiba dutta

Read only

0 Likes
1,792

Thanks a lot for your help!

I also tried another method:


  hash_total = amt_total.
  REPLACE '.' WITH '' INTO hash_total.
  CONDENSE hash_total NO-GAPS.

Where has_total is type string.

It also produces the same output I need.

Which you think is better or more efficient? Thanks!

Read only

0 Likes
1,792

in my reply i used the addition between two characters field but if you can avoid it then it will be better .. i think you can use your method it will be good enough...

regards

shiba dutta

Read only

0 Likes
1,792

Thank you very much for the attention! _