‎2010 Apr 26 7:57 AM
Hi Experts,
how to code below requirement.
last 2 digits are considered as decimals
If the salary for the employee is SR 11148.00 then the decoded value for PART-D is
(First the 11148.00 has to be converted as 9 digit number as 001114800)
(09)+ (08)+ + (17)+ (16)+ (15)+ (44)+ (83)+ (02)+ (0*1) = 58
Thanls in advance,
Vishal.
‎2010 Apr 26 8:15 AM
Hello,
Welcome to SDN.
Try something like below
data sal type p decimals 2 value '11148.00'.
data tmp(9) type n.
data code type i.
data n type i value 0.
data val type i value 9.
tmp = sal * 100.
write tmp.
do val times.
code = code + ( val * tmp+n(1) ).
n = n + 1.
val = val - 1.
if val = 0.
exit.
endif.
enddo.
write code.
Hope this helps
Regards,
Sachin
‎2010 Apr 26 8:15 AM
Hello,
Welcome to SDN.
Try something like below
data sal type p decimals 2 value '11148.00'.
data tmp(9) type n.
data code type i.
data n type i value 0.
data val type i value 9.
tmp = sal * 100.
write tmp.
do val times.
code = code + ( val * tmp+n(1) ).
n = n + 1.
val = val - 1.
if val = 0.
exit.
endif.
enddo.
write code.
Hope this helps
Regards,
Sachin
‎2010 Apr 26 8:34 AM
Hi,
Try this code,
(If the length restricted to 9 )
data : w_sal type p decimals 2 value '11148.00',
w_temp type string,
w_amt type p,
w_count type i value 9,
w_req_sal(10) type n.
w_temp = w_sal.
replace '.' in w_temp with space.
condense w_temp.
w_req_sal = w_temp.
do 9 times.
w_amt = w_amt + ( w_req_sal+sy-index(1) ) * w_count.
subtract 1 from w_count.
enddo.
write w_amt.
Regards,
Raghava Channooru
‎2010 Apr 26 8:58 AM
Try this
data:lv_char type char09.
data:lv_offset type sy-fdpos.
write value into lv_char.
replace '.' in lv_car with ' '.
condense lv_char no-gaps.
len = strlen( lv_char ).
do.
if sy-index = strlen( lv_char ).
exit.
endif.
lv_offset = lv_offset + 1.
lv_sum = lv_sum + ( lv_char+lv_offset(1) * lv_len ).
lv_len = lv_len - 1.
enddo.
write lv_sum.
‎2010 Apr 26 9:31 AM
thanks all for your replies....
cant we do it using constant value..
for example ..say we are taking value from selection scree..
Thanks in advance.
vishal.
‎2010 Apr 26 9:37 AM
Hello,
Do you mean that the value is being input from a selection screen ?
If so, simply replace the data statement defining sal type p decimals2 by
parameter sal type p decimals 2 default '11184.00'.
If you change the value on execution on the selection screen, then that would be used in the calculations
Regards
Sachin
‎2010 Apr 26 10:02 AM
Hi vishal ,
The below piece of code should solve your problem..
data : fsalary type float.
data : isalary type i.
data : iresult type i.
data : fsal type f.
data : isal type i.
data : count type i.
data : len type i.
data : addlen type i.
data : sal type string.
data : fssal type string.
data : zero type c value '0'.
count = 1.
fsalary = '11148.00' .
isalary = fsalary .
sal = isalary.
len = strlen( sal ).
addlen = 9 - len + 1.
while addlen GT 0.
concatenate zero fssal into fssal .
addlen = addlen - 1.
endwhile.
concatenate fssal sal into fssal .
condense fssal no-gaps.
write fssal.
while isalary GT 0.
if count LT 10.
isal = isalary mod 10.
iresult = iresult + ( isal * count ).
fsal = isalary / 10.
isal = floor( fsal ).
isalary = isal.
count = count + 1.
endif.
endwhile.
write iresult.
*******************
fssal and iresult gives you the required values.
fssal --- the final string of 9 characters.
iresult -- the decoded value..
Please revert back in case of any issues....
‎2010 Apr 26 11:07 AM
Hi vishal,
In the above piece of code i have mentioned you can take the value of fsalary from selection screen as :--
parameter fsalary type p decimals 2.
and please do not forget to comment the lines
data : fsalary type float.
fsalary = '11148.00' .
‎2010 Apr 26 1:40 PM
Thanks a lot for your replies...
If their no amount specified...then how the calculation should go on ..considering their should be only 9.
For example..if the amount field is 56565 i.e 5 we need to add 4 zeroes in froint of 56565 i,e 000056565
if it is 56565.00 we need to bring it as 005656500
Thanks in advance.
Regards,
Vishal
‎2010 Apr 27 7:54 AM
Hi Vishal,
you mean to say that you need different decode values for 56565 and 56565.00 ?????????????
if its yes.. then it can bring ambuigity in your decoded values as it will be the same for 56565.00 and 5656500...
Please see to this matter and reply.....