Function to calculate string
Hi,
I am looking for a function that you can insert: '5+(8*3)-2' and it will give you the value.
something like a calculator function but for a text string.
Did any of you guys have seen something like this before?
thanks,
Itay
Hi,
You have to do it dynamically, the input parameters are values (for example in your case
( 5, 8, 3, 2) operation (* + / -) are formulas...
R001 = 5, R002 = 8, R003 = 3, R004 = 2
1. Create parameter 100 char length.
2. Get the formula from the user (for example 5+ ( 8 * 3 ) - 2 into the parameter field {like (R001 + (R002 * R003 ) - R004}
3. Use Key word "SPLIT" amd move the values into a internal table (each value will be in a row...
4. Now get the value of R001,R002,R003,R004 & operators....
5. Create a progam dynamically (take the help of dynamic program)
6. Create variables in the program (these variables should be created based on the values in SPLIT commanded used internal table.... with one addition variable for the RESULT, all the varibales declared should be of data type "F".
7. use the SYNTAX-CHECK FOR <program> to check the program syntax is correct.
8. if subrc eq 0 then Submit the dynamic program
9. WRITE the result....
You will get the result...take the below code help
DATA: BEGIN OF fm_split_formula OCCURS 0,
text(10) TYPE c,
END OF fm_split_formula,
BEGIN OF fm_repo OCCURS 0,
line(72),
END OF fm_repo.
DATA: fm_f_check(240),
fm_h_check(72) ,
fm_g_check TYPE i,
fm_offset1 TYPE i,
fm_offset2 TYPE i,
fm_subrc LIKE sy-subrc,
fm_mtext1.
DATA: BEGIN OF fm_func,
f1(7) VALUE 'STRLEN(',
f2(7) VALUE 'SQRT( ',
f3(7) VALUE 'MOD ',
f4(7) VALUE 'DIV ',
f5(7) VALUE 'COS( ',
f6(7) VALUE 'SIN( ',
f7(7) VALUE 'LOG( ',
f8(7) VALUE 'EXP( ',
END OF fm_func.
DATA: fm_loc_index LIKE sy-index,
fm_repo_cnt TYPE i,
fm_cnt_lp TYPE i,
fm_name(10) VALUE 'FORMEL'.
CONSTANTS: fm_operand(8) VALUE ' =()+-*/',
fm_numbers(12) VALUE ' 1234567890.',
fm_result(4) VALUE 'R1 =',
*- Start of insert for # DR1K900907 by Prabhu Rajesh
fm_result1(3) VALUE 'R =',
*- End of insert for # DR1K900907 by Prabhu Rajesh
fm_res(1) VALUE 'R'.
CLEAR : fm_split_formula, fm_repo,fm_repo_cnt.
REFRESH: fm_split_formula, fm_repo.
SPLIT fm_formula AT ' ' INTO TABLE fm_split_formula.
LOOP AT fm_split_formula.
IF NOT ( fm_split_formula-text = fm_func-f1 OR
fm_split_formula-text = fm_func-f2 OR
fm_split_formula-text = fm_func-f3 OR
fm_split_formula-text = fm_func-f4 OR
fm_split_formula-text = fm_func-f5 OR
fm_split_formula-text = fm_func-f6 OR
fm_split_formula-text = fm_func-f7 OR
fm_split_formula-text = fm_func-f8 OR
fm_split_formula-text CO fm_numbers OR
fm_split_formula-text CO fm_operand ).
fm_repo = fm_split_formula-text.
APPEND fm_repo.
ENDIF.
ENDLOOP.
If the hint is useful
Say thanks by reward
.
Regards,
Prabhu Rajesh
Similar Messages
-
Need a function to calculate employee attendance data for a given period
need a function to calculate employee attendance data for a given period
as
Working days,
CL ,
SL,
PL,
LWP
regards,
Gaurav Sood.Issue resolved
-
Function Type Calculate Inventory in BPS SEM 6.0
Hi,
Do anybody have idea about function type Calculate Inventory .
We are in SEM 6.0 sp SAPKGS6006. I'm not getting any documentation on this particulat function type.
Please revert if you have any knowledge on this.
Thanks
PratyushHi Marc,
Yes, this looks like a standard function. The number is 31.
PLNTP CALCF SPFIE REFF TIMF FB_METHOD FB_PARAM FB_EXEC TECHF TEXT
31 UPB_Y_TMCHA UPS UPS UPS UPB_YS_TECHF_S Calculate Inventory
Thanks
Pratyush -
Function to calculate Page size in XML RTF template
Hi All,
For one of my requirments, I need to find out the page size of my output.
And from a given point of the output, i should know the size till bottom of the page.
My program has an RTF and will generate output in PDF format.
Please let me know how to do this. This is very important for me.
Thanks in advance.
Edited by: DharV on Nov 17, 2011 12:18 AMNo, the actual requirment is in this thread
Re: Need to drag the table down the end of page
I could not get the solution for this, so just checking if I have a function to calculate the horizantal size of the output page, and i can apply some logic.
Let me know if iam not clear
Thanks
Edited by: DharV on Dec 6, 2011 1:14 AM -
REPALCE() function issue. String getting truncated.
Hi,
I am using ORACLE DATABASE 11g. I am facing a very strange problem. I have a string in an variable when i print that sting i can see that the string is correct but after applying a replace function on to it when i print the string the string is incomplete.
Details are as follows :- In the code i am getting some DDL statement (alter table ) , this is the difference between the 2 compared tables. Then I want to place ';' at the last of each line and keyword 'BEGIN' at start and 'END;' at the last. I tried to do this with replace() function but the output string is shot than needed. Please follow the code :-
dbms_output.put_line('V_TAB_DIFF_ALTER:=' || V_TAB_DIFF_ALTER); -- Print the original string. Variable datatype used varchar2(32767)/CLOB
dbms_output.put_line('SOURCE Size := '||Length(V_TAB_DIFF_ALTER)); -- Size of the original string.
V_TAB_DIFF_ALTER_REP :=V_TAB_DIFF_ALTER; -- Placed the sting in new variable.
V_TAB_DIFF_ALTER_REP := 'BEGIN '||replace(V_TAB_DIFF_ALTER_REP,CHR(10),';') || ' END;'; -- Used the replace function and concatenate string.
-- EXECUTE IMMEDIATE V_TAB_DIFF_ALTER_REP;
dbms_output.put_line('After replace := '||V_TAB_DIFF_ALTER_REP); -- Now again printing the sting but this time its not proper.The output is as follows :-
V_TAB_DIFF_ALTER:=ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("BENEFICIARY_ACCOUNT_ID" VARCHAR2(32))
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("HAS_OFFSET_ACCOUNT" CHAR(1) DEFAULT 'N')
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("MARKET_ENTITY" VARCHAR2(40))
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("FUTURE_PREVIOUS_STATUS" VARCHAR2(50))
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("PREVIOUS_STATUS" VARCHAR2(50))
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("FUTURE_AS_OF_COUNTER" NUMBER)
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("FUTURE_AS_OF_DATE" DATE)
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("STMT_CYCLE_DAY" NUMBER)
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("PREVENT_EXCESS_FLAG" CHAR(1))
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("TEMP_EXCESS_START_DATE" DATE)
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("TEMP_EXCESS_EXPIRY_DATE" DATE)
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("TEMP_EXCESS_SANCTIONED_AMT" NUMBER)
SOURCE Size := 1830 -- Length of original string.
After replace := BEGIN ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("BENEFICIARY_ACCOUNT_ID" VARCHAR2(32));
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("HAS_OFFSET_ACCOUNT" CHAR(1) DEFAULT 'N');
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("MARKET_ENTITY" VARCHAR2(40));
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("FUTURE_PREVIOUS_STATUS" VARCHAR2(50));
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("PREVIOUS_STATUS" VARCHAR2(50));
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("FUTURE_AS_OF_COUNTER" NUMBER);
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("FUTURE_AS_OF_DATE" DATE);
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("STMT_CYCLE_DAY" NUMBER);
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("PREVENT_EXCESS_FLAG" CHAR(1));
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("TEMP_EXCESS_START_DATE" DATE);
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("TEMP_EXCESS_EXPIRY_DATE" DATE);
ALTER TABLE "NGPR2ST"."FLX_DD_ACCOUNTS_B" ADD ("TEMP_EXCESS_SANCTIONE ------ Here the remaining string is missing.
NEW Var. Length :- 1862 -- Length of the new string but still the printed string is not the perfect one. It only prints 1830 characters, rest are not printed.
{code}
Here you can see that the sting in after replace in actually short and will give error when trying to execute. As you can also see that length of new string is more i.e. 1862 but its reading and writing only 1830 characters => which is the actual size of original string.
Variable datatypes used varchar2(32767) and CLOB. Faced issues in both the cases.
Its very obvious that when i am trying to replace a few things then I can add a bit more to it. Why is it only reading or writing only the 1830 character string not the whole 1862 string ??? How can i get the size as 1862 but not the whole string ??
Let me know any solution on this ...
Thanks in advance.
Edited by: VIRU on Nov 17, 2011 10:24 PMThanks William for your reply.
I have tried with increasing the buffer size by
exec dnms_output.enable(40000000);but still no improvements.
I was able to successful print long strings than this one but when it comes to format it with replace i am facing this scenario.
Let me know if you have any idea. -
Use Planning Function to calculate new value
Hi All,
I have what seems to be a simple problem, but no success in resolving.
I have 3 planning keyfigures:
-Units
-Price
-Value
The price field is populated from another planning sheet.
The unit field is entered by the user.
The value should be calculated by planning function when button pushed.
I have tried just basic "Value=Units*Price", but always comes back zero.
I have also tried more complex "{Value, CharA, CharB, CharC} = {Units, CharA, CharB...." for each characteristic. Still zero.
It must be multipling by zero, but not sure how to avoid.
If I put "Value=Price", it works. If I put "Value=Units", it works. If I put "Value=Units+Price", it works.
Please help.
Terrence
Here is the details.
In the infoprovider the data is like this:
Country/ Product/ Unit Sales/ Price/ Value
DE/ Shirt/ 50/ 0/ 0
DE/ Shirt/ 0/ 100.00/ 0
The query is display:
Country/ Product/ Unit Sales/ Price/ Value
DE/ Shirt/ 50/ 100.00/ 0
I have tried the following 2 formulas:
Formula 1:
= {Unit Sales} *
Formula 2:
FOREACH Country, Product.
{Value, Country, Product} = {Unit Sales, Country, Product} * {Price, Country, Product}
ENDFOR.
Both return zero for values.
Thanks,
Terrence
Here is the details.
In the infoprovider the data is like this:
Country/ Product/ Unit Sales/ Price/ Value
DE/ Shirt/ 50/ 0/ 0
DE/ Shirt/ 0/ 100.00/ 0
The query is display:
Country/ Product/ Unit Sales/ Price/ Value
DE/ Shirt/ 50/ 100.00/ 0
I have tried the following 2 formulas:
Formula 1:
= {Unit Sales} *
Formula 2:
FOREACH Country, Product.
{Value, Country, Product} = {Unit Sales, Country, Product} * {Price, Country, Product}
ENDFOR.
Both return zero for values.
Thanks,
Terrence
How to use case when function to calculate time ?
Dear All,
May i know how to use case when function to calculate the time ?
for the example , if the First_EP_scan_time is 12.30, then must minus 30 min.
CASE WHEN FIRSTSCAN.EP_SHIFT <> 'R1' AND FIRSTSCAN.EP_SHIFT <> 'R2'
THEN ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF((CASE WHEN SHIFTCAL.EP_SHIFT = 'N1'
THEN CONVERT(VARCHAR(8),DATEADD(DAY,+1,LEFT(FIRSTSCAN.EP_SCAN_DATE ,8)),112) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','')
ELSE LEFT(FIRSTSCAN.EP_SCAN_DATE ,8) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','') END),12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0 - 0.25) AS FLOAT),2)
ELSE ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF(FIRSTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0) AS FLOAT),2) END AS OTWORK_HOUR
Do not use computations in a declarative language. This is SQL and not COBOL.
Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton.
CREATE TABLE Timeslots
(slot_start_time TIME(1) NOT NULL PRIMARY KEY,
slot_end_time TIME(1) NOT NULL,
CHECK (start_time < end_time));
INSERT INTO Timeslots --15 min intervals
VALUES ('00:00:00.0', '00:14:59.9'),
('00:15:00.0', '00:29:59.9'),
('00:30:00.0', '00:44:59.9'),
('00:45:00.0', '01:00:59.9'),
('23:45:00.0', '23:59:59.9');
Here is the basic query for rounding down to a time slot.
SELECT CAST (@in_timestamp AS DATE), T.start_time
FROM Timeslots AS T
WHERE CAST (@in_timestamp AS TIME)
BETWEEN T.slot_start_time
AND T.slot_end_time;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL
Problem with user-defined functions in XQuery String
hello
i've a problem with user-defined functions in XQuery String
details are here (the code is not Human-readable via forum's embedded editor ?? strange)
http://docs.google.com/Doc?id=ddqwddsr_21c96d9x
thanks !!
See
michaels> select xmlquery('declare function local:test_function($namecmp as xs:string?, $inputtype as xs:string?) as xs:string?
return {$inputtype}
local:test_function("1","2")' returning content) o from dual
Error at line 5
ORA-19114: error during parsing the XQuery expression:
LPX-00801: XQuery syntax error at '{'
3 return {$inputtype}
- ^
michaels> select xmlquery('declare function local:test_function($namecmp as xs:string?, $inputtype as xs:string?) as xs:string?
$inputtype
local:test_function("1","2")' returning content) o from dual
O
2
1 row selected.
Any function to calculate actual work hours (deduct the break hours)
Hi expert,
I have defined the daily work schedule & break schedule. Work center is assigned with the daily work schedule. Now I want to calculate each work center actual work hours. I have a table where the start & finish time of working is keep.
for eg.
first break hr 10:00am to 10:15am
second break hr 13:00pm to 14:00pm
The work center might start work from 10:05 and finished at 14:30 or any other case.
I need to deduct the break hrs & get the actual hr worked
Is there any function to calculate the actual work hours base on the daily work schedule & break schedule ?
Thanks
Hello,
Try the below FM's
HR_PERSONAL_WORK_SCHEDULE
WORKING_HOURS = 'X' " you will get the actual work hours
HR_BE_WORKING_SCHEDULE
Try the below class
CL_PT_TIME_EV_WORK_SCHED_UTIL
Regards,
Krishna
Message was edited by:
Krishnakumar
Java function to calculate timezone
HI
I have a specific requirement to create one java function to calculate the timezone based on the date
for mapping.
Like input(date)->Java Func->Timezone(Output).
As i am not very much conversant with java it will be very helpful for me if anybody who has done the code send me.
Thanks
Debraj Roy
Hi Debraj,
Hope these links provide the required information
Re: CurrentDate function?
Date Calculation
http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/frameset.htm
http://java.sun.com/docs/books/tutorial/i18n/format/simpleDateFormat.html
http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html
Regards
Vishnu
why this query
select [Measures].[F Events Count] on 0,
Filter([D Actor Player].[Actor].children,
([Measures].[F Events Count],
{([D Date].[Hierarchy].[Season].[2012 - 2013]),([D Date].[Hierarchy].[Season].[2013 - 2014])},
[D Result].[Result].&[Goal])
>=5) on 1
from [FBA Cube]
gives this error:
Query (3, 3) The >= function expects a string or numeric expression for the 1 argument. A tuple set expression was used.
while the following query works fine
select [Measures].[F Events Count] on 0,
Filter([D Actor Player].[Actor].children,
([Measures].[F Events Count],
[D Date].[Hierarchy].[Season].[2012 - 2013],
[D Result].[Result].&[Goal])
>=5) on 1
from [FBA Cube]
why having set inside Filter's boolean expression generates that error? how can we
keep the set inside the Filter's boolean expression but
solve the problem? please explain the reason and solution
Hi Butmah ,
I think you should use an aggregation function with the set and the tuple ... adding an AdventureWorks snippet :
select [Measures].[Order Count] on 0,
Filter([Product].[Category].children,
SUM({[Date].[Fiscal].[Fiscal Year].&[2011],[Date].[Fiscal].[Fiscal Year].&[2009]}
,([Measures].[Order Count],[Geography].[Geography].[Country].&[United States])
>=5) on 1
from [Adventure Works]
Regards, David .
Calculate string CPI (length of string in pixel)
Word-wrap position is at the moment done in SAP via length of string (count of letters) via function u201CRKD_WORD_WRAPu201D. But this is counting number of char, this give the problem that different font type and size give different word-wrap position ! -> We need to calculate if possible the word-wrap position via the relative length of text u2013 I tried to find some on SDN and Internet, the only thing I can find is some functionality in JAVA u2026
Can any one help me how to calculate the length of a string using font type and hight of font... as we use truetype font as arial the length of letter "i" is not the same as 'X' ...
Best regards Jørgen Jensen
My problem is not to do the wordwrap, my problem is to find the right position as the length of 'i' is not the same length of 'X'
example:
iiiiiiiiii (10)
XXXXXXXXXX(10)
must be something like this:
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii(wordwrap position 35)
XXXXXXXXXX(Wordwrap position 10)
I need a way to find the length of a charactor in a given font and size.
Best regards Jørgen Jensen
Class to calculate string length
Hi All,
is there any class having a method to calculate the string length.
Thanks
Hi Ravi,
You can use the FM SWA_STRINGLENGTH_GET
data: lv_length type SWAEXPDEF-ELEMLENGTH,
lv_string type string.
CALL FUNCTION 'SWA_STRINGLENGTH_GET'
EXPORTING
expression = lv_string
* CONDENSE_NO_GAPS =
* CONDENSE =
* WITH_LEADING_BLANKS =
* IMPORTING
LENGTH = lv_length
* EX_MODIFY_EXPRESSION =
hope it helps you
Regards!
Function to convert string to number
Hi there,
I wrote a function which converted a hor minute component of a date to a number. Now I need to do the same with a string (because the hours could be more then 23:95). Anyway here is my function. How can I rewrite it so it will accept a string as in parameter. Somwhow I can not work it out. Thanks a lot.
Chris
function calculate_hours_project(in_hours in DATE)
RETURN number
AS
hrs CHAR(2);
mins CHAR(2);
BEGIN
hrs := to_char(in_day, 'HH24');
mins := to_char(in_day, 'MI');
if hrs is not null and mins is not null then
RETURN to_number(hrs + (mins/60));
else
RETURN 0;
end if;
END calculate_hours_project;
Wouldn't it just be something like this?
sql>create or replace function calculate_hours_project(in_hours in varchar2)
2 return number
3 is
4 begin
5 return to_number(substr(in_hours, 1, instr(in_hours, ':') - 1)) +
6 to_number(substr(in_hours, instr(in_hours, ':') + 1) / 60);
7 end calculate_hours_project;
8 /
Function created.
sql>select calculate_hours_project('08:05') from dual;
CALCULATE_HOURS_PROJECT('08:05')
8.0833333
1 row selected.
sql>select calculate_hours_project('35:34') from dual;
CALCULATE_HOURS_PROJECT('35:34')
35.566667
1 row selected.
How to find out what are the functions supported by string class
Hi,
Can any one let me know how to find what are all the functions supported by the string class in standard(STL) library on solaris.
Regards,
Vignesh
1. Any C++ textbook that covers the Standard Library will tell you about the standard string class. A good tutorial and reference for the entire Standard Library is "The C++ Standard Library" by Nicolai Josuttis, published by Addison Wesley.
2. WIth Sun C++, the command
man -s3C++ basic_string
provides documentation for the default libCstd version of the Standard Library.
3. You could look at the <string> header itself. I don't recommend that approach.
Maybe you are looking for
-
I am setting up email on my iphone. A window came up stating it cannot connect, do I want to try without SSL. I figure from some of the discussion out there I probably need SSL as a security for my iphone. So..now I am at the part where it asks me
-
Need help with data formating.
The following statment places extra spaces to the right of the month. I only want one space to the right of the month. How do I do that select to_char(to_date('08/07/2007','MM/DD/YYYY'),'MONTH DD, YYYY') || ' THRU ' || to_char(to_date('08/20/2007','M
-
Hi Got a New Black berry 8520 from Vodafone (My first). Day 1 was brilliant. The next day I synced it with my desktop using the BlackBerry Desktop Manager & it completely wiped out the OS of it. I then reconnected it, in 40 mins everything was loaded
-
How do I get rid of the Security Pop-Up?
Windows 7 - 64bit IE 8 run in 32 bit Latest version installed of Flash Player All of a sudden (I think it started when a web page tried to open adobe reader) I get a continual IE security popup that keeps re-appearing over and over again on the same
-
Do clients have to purchase contribute in order to update site?
I am confused about Contribute. Do clients have to purchase it in order to update a Dreamweaver-based site, or does the web designer upload it to the server each time for every CMS-based site created? I am considering purchasing as an alternative to