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

Rounding / TYPE N / TYPE P?

Former Member
0 Likes
2,449

Hi Experts,

data : my_zbd1p LIKE bseg-zbd1p.

As I am manually calculationg the my_zbd1p, am getting the values like,

1.886,

2.849,

2.507 etc.

But, I wanna display them in the report with rounding.

So,

1) If I declare as DATA : my_zbd1p(11) TYPE N, Will I get rounding?

<b>2) My main doubts is that, How the system will consider for rounding? I mean, What r the limits, Is it like, >5 & <5?</b>

3) After rounding, Wht r the values for,

1.886,

2.849,

2.507 ?

thanq.

Message was edited by:

Srikhar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,415

Use Packed data type to get rounding..

21 REPLIES 21
Read only

Former Member
0 Likes
2,416

Use Packed data type to get rounding..

Read only

0 Likes
2,415

ThanQ Sheshu,

Pls. culd u clarify in bit details, U mean TYPE P?

thanq.

Read only

0 Likes
2,415

If you want to round the value ,the best method is declare variable type p,

suppose you have value 10.99

if you use type p,value would be 11.00 ...

Read only

0 Likes
2,415

Hi Sheshu,

I hv very prog. this prog. shuld b in such a way that, from BAPi / from SElection screen user inputs - both shuld work.

Changing the location of START-OF-SELECTION is working fine for BAPi/SUBMIT.

But, if the user comes from SELECTION SCREEN by giving some input, then, the output ALV is not coming!

I mean, the prog. shuld b in such a way that, both shuld work.

If ur time permits, pls. let me know that, so that , I will send my code, and <u><b>let me know the correct location of START-OF-SELECTION.</b></u>

1) bapi_flag = 'X' tells the prog. that, the control come from BAPi/SUBMIT.

2) This location is working for ALV output , go for CNTRL+F for following

*selection-screen online report location

START-OF-SELECTION.

3) This location is working fine for BAPi/SUBMIT , go for CNTRL+F for following

*bapi report location for SOS

*START-OF-SELECTION.

Pls. help me.

Thank you,

Read only

0 Likes
2,415

Yes SRikhar,

send me the program and i am not clear abt ur req ,could u please explian little bit more

Read only

0 Likes
2,415

ThanQ.

Pls. go thru Yahoo ID - vtkapoor2000

Password is--->

subject - ALV and BAPi - Program

Attachment - MS word attachment

Requiremet is,

This is prog. shuld work for both requiremets, i.e.

1 - from selection screen by user input yielding ALV

2- from BAPi, shuld get data in output TABLEs

So, problem is with START-OF-SELECTION location in the prog.! i.e.

1) bapi_flag = 'X' tells the prog. that, the control is come from BAPi/SUBMIT.

2) This following location (for start-of-selection) is working for ALV output(i.e. if control comes from SELECTION SCREEN) , so, go for CNTRL+F for following statement/comment in the prog.

*selection-screen online report location

START-OF-SELECTION.

2) This following location (for start-of-selection) is working for BAPi / SUBMIT output(i.e. if control comes from BAPi) , so, go for CNTRL+F for following statement/comment ,

*bapi report location for SOS

*START-OF-SELECTION.

thanq,

Message was edited by:

Srikhar

Read only

0 Likes
2,415

Pls. let me know, after U downloaded/got the prog.

thanq.

Read only

0 Likes
2,415

Hello Srikhar,

I saw your code and one can not understand .

1. you written at selection-screen on value-request on layout after end-of-selection ( Can you keep above start-of-seklection).

2nd point is

IF bapi_flag IS INITIAL.

do the alv output

else.

do bapi function module operation since ztables are available in your program ,so i can not execute and see the results.

endif.

Let me know if you need

If you explain one by one it is easy to explain.

Read only

0 Likes
2,415

ThanQ:

U mean like,

1- S...-S.... ON VALUE REQUEST

2 - START-OF-SELECTION

3- END-OF-SELECTION

???

thanq.

Read only

0 Likes
2,415

yes,keep the at selection-screen event before start-of-selection

Read only

0 Likes
2,415

Hi Shehsu,

I can understand that, its very difficult to undesratnd my prog. code.

So, reagarding the my problem & ur suggestion of changing location of START-OF-SELECTIOn, its working with F8 i.e. clock symbol(again if I comment the PERFORM chk_if_F8),

but not working with Push Button i.e. sscrefield-ucomm = 'STA'

later added notes:

So, I got one idea that,

As its ur suggestion is working with clock symbol i.e. F8, i.e. sy-ucomm = 'ONLI', so I am explicitly writing the code like,

sscrfiled-ucomm = 'ONLI' under AT SELECTION SCREEN and pressing the Push button, so, even though the push button is carrying the UCOMM as STA, its over writing with ONLI (I hv written explicitly), then working for both i.e. BAPi and selection-screen.

So, Now,

The requirement is,

1) If user press, F8, shuld come warning message,

2)If user press Push button, shuld get ALV - thing thing am achieving now?

So, the issue is with F8?

so, any clue?

thanq.

Message was edited by:

Srikhar

Read only

0 Likes
2,415

what is F8 Function code ?

Sekhar,

in start-of-selection

write the code like

case sy-ucomm.

when 'ALV Push button'. use function code

use alv logic here

when 'F8" .. use function code

use logic.

endcase

Read only

0 Likes
2,415

Thanq SHESHU,

Some how, now, its working, after changing the location of START-OF-SELECTION & sy-ucomm VALUES!

I hope u deleted the prog. from ur end? Thanq for understanding.

ThaQ,

Message was edited by:

Srikhar

Read only

Former Member
0 Likes
2,415

Declare as Type I for rounding it to the nearest integer.

Then you would get the values

2,3 and 3

Regards,

Ravi

Read only

0 Likes
2,415

ThanQ Ravi,

Pls. clarify,

2) My main doubts is that, How the system will consider for rounding? I mean, What r the limits, Is it like, >5 & <5?

Coz, If 2.507 wuld round to 3!, my totals wuld bcom wrong i.e. wrong report!!

So, wht is alternative? Shuld I use some logic manually?

thanq.

Message was edited by:

Srikhar

Read only

0 Likes
2,415

Yes.

It will round based on the halfway mark.

anything more than .5 it will round to the next number and antthing less than .5 it will round to the number below it.

If you want to round it irrespective of the value after the decimal, then you can use the function

floor.

data: val type i.

val = floor( V_deci ). "Val will have 1 if v_deci has 1.56 or 1.36

If you want to round it the next interger irrespective of the value after the decimal, then you can use the function

ceil.

data: val type i.

val = ceil( V_deci ). "Val will have 2 if v_deci has 1.56 or 1.36

Regards,

Ravi

Read only

0 Likes
2,415

ThanQ Ravi for ur tips,

I observed that, in my case, Rounding is always not advisable! So, instead of manually calculation of Discount, I wanna to fetch directly from DB.

Actually, I am looking to pull the data of,

VF03-----> Header Level Cash Discount - Amount i.e. say, 3%

So, Where Can I get the Header level i.e. from which source/DB/tbl I can retrieve this data?,

Cash Discount Amount data e.g. 3%

Thank you,

Read only

0 Likes
2,415

Hi Ravi,

Isuue: I put a break-point in SMARTFORM and after its purpose get solved, I deleted it. But, still, its coming, while am issuing the output from VA23 transaction! actually, i deleted it.

So, i tried,

re activation, system restart

no use!

So, I hv a idea:

In SMARTFORM debug mode, I noted down the line # and FM/Prog. name, and I went to SE38>given prog. name->displayed, and there I found the Break-point (acive)syntax. So, I wanna delete/commment it,if I do it, but am getting the message as,

<i><b>The object in a name space that is reserved for generated objects. Falg object as generated?</b></i>

So,

1 - Shuld I say OK or CANCEL to the above message? (actually, as I dont know, I clicked CANCEL/NO, then am getting the following message,

<i><b>Object does not have an object directory entry</b></i>

2- Actually, Wht does it mean?

Pls clarify

thanq.

Message was edited by:

Srikhar

Message was edited by:

Srikhar

Read only

Former Member
0 Likes
2,415

Hi,

You can Type P. Check the following example;

DATA pack TYPE p VALUE '123.456'

DECIMALS 3.

WRITE pack DECIMALS 2.

WRITE: / pack ROUND -2,

/ pack ROUND -1,

/ pack ROUND 1,

/ pack ROUND 2.

Ourpur:

123,46

12.345,600

1.234,560

12,346

1,235

Regards,

Bhaskar

Read only

0 Likes
2,415

Thank you,

So, Is there any syntax for the following requirement (Other than SPLIT, CONCATENATE opertaions),

my_discount = 123.456,

I wanna display = 123.45

thanq.

Read only

Former Member
0 Likes
2,415

.