Executing an Arithmatic Formula stored as String
Hi All,
Please help,
I have similar problem with Mr. Vijayakumar V.
I need to get result value of an arithmatic formula which stored as string.
ex:
zform = '( A / 2 ) + ( B * 1.25 + 2 )'.
if I have A = 10, and B = 4.
I do expect the final result to be : 12
for ( 5 + 7 ) = 12
Is there any simple way to do this or
Is there built in function in ABAP to deal with something like this?
Thank you,
Hi Oki,
You can solve your problem by generating subroutine at runtime.
Please look at sample code below:
REPORT z_jr05.
DATA: code(72) OCCURS 10,
prog(8),
msg(120),
lin(3),
wrd(10),
off(3),
var_string(50),
p_result TYPE i.
var_string = 'temp_result = ( A * B ) + 199.'.
REPLACE ALL OCCURRENCES OF'A' IN var_string WITH '10'.
REPLACE ALL OCCURRENCES OF'B' IN var_string WITH '11'.
APPEND 'PROGRAM SUBPOOL.' TO code.
APPEND 'FORM HITUNG changing p_result.' TO code.
APPEND 'data: temp_result type i.' TO code.
APPEND var_string TO code.
APPEND 'p_result = temp_result.' TO code.
APPEND 'ENDFORM.' TO code.
GENERATE SUBROUTINE POOL code NAME prog
MESSAGE msg LINE lin
WORD wrd OFFSET off.
IF sy-subrc <> 0.
WRITE: / 'Error during generation in line', lin,
/ msg,
/ 'Word:', wrd, 'at offset', off.
ELSE.
WRITE: / 'The name of the subroutine pool is', prog.
SKIP 2.
PERFORM hitung IN PROGRAM (prog) CHANGING p_result.
WRITE p_result.
ENDIF.
Regards,
Similar Messages
-
Executing a Arithmatic formula stored in Variable
Hi all,
I need solution to execute a arithmatic operation which is stored in a variable.
For Example:
data : var type string.
var = ABS('-3').
Now by means of the variable var i need to get the absolute value of -3
ie my output should be 3 if i print the variable "var".
Please help.
Regards,
VijayakumarHello,
Do like this.
REPORT ZV_SDN_3 .
DATA: STR TYPE STRING.
DATA: STR1 LIKE STR,
INT TYPE I,
LEN TYPE I.
STR = ABS('-3')..
LEN = STRLEN( STR ).
DO LEN TIMES.
IF NOT STR+INT(1) IS INITIAL.
IF STR+INT(1) CA '0123456789'.
CONCATENATE STR1 STR+INT(1) INTO STR1.
ENDIF.
ENDIF.
ADD 1 TO INT.
ENDDO.
WRITE: STR1.
Hope this will solve ur issue.
Cheers,
Vasanth -
Hi Gurus,
I have a formula inside a string like given below.
DATA: lv_string TYPE c LENGTH 100,
lv_result TYPE p decimals 2.
lv_string = '2 * 3 * 4'.
i want to run/execute the formula in LV_STRING and move result to LV_RESULT. Please help me how to do it. The formula given in LV_STRING could be completely dynamic in ABAP arithmetic sytax.
Please help.
Thanks
Srinialso check this
DATA: l_string(128) TYPE c,
res TYPE i,
ope TYPE c,
c TYPE i,
length TYPE i.
FIELD-SYMBOLS: <fs> TYPE ANY.
FIELD-SYMBOLS: <fs1> TYPE ANY.
l_string = '1 + 2 + 3'.
CONDENSE l_string NO-GAPS.
length = STRLEN( l_string ) + 1.
c = 0.
DO.
IF sy-index = length.
EXIT.
ENDIF.
ASSIGN l_string+c(1) TO <fs>.
ASSIGN res TO <fs1>.
IF <fs> CA '1234567890'.
IF sy-index = 1.
<fs1> = <fs> * 1.
ELSE.
CASE ope.
WHEN '+'.
<fs1> = <fs1> + <fs>.
WHEN '*'.
<fs1> = <fs1> * <fs>.
WHEN '-'.
<fs1> = <fs1> - <fs>.
ENDCASE.
ENDIF.
ELSE.
ope = <fs>.
c = c + 1.
CONTINUE.
ENDIF.
c = c + 1.
ENDDO.
WRITE res.
this works only for single digit no ... apply your logic if u need.
do go for the thread linkmgiven by meroz
Edited by: Keshu Thekkillam on Aug 14, 2009 4:45 PM -
What is the best way to execute immediate particular sql stored in a table
I have a string variable containing row_ids eg "12,24,35,23"
and a table
row_id, sql
1 , "insert into some_table values(23,'Happy');"
6 , "insert into some_other_table values(24,'Sad');"
12 , "insert into some_table values(23,'Crazzzy');"
15 , "insert into some_other_table values(23,'Old');"
23 , "insert into another_table values(23,'Left');"
24 , "insert into stuff_table values(23,'Gold');"
30 , "insert into old_table values(23,'Even');"
35 , "insert into archive_table values(23,"True");"
And I need to write a plsql function that takes the list of row_ids as an argument and executes the sql statements stored in the table that matches.
I am trying a combination of cursor and execute immediate statements to do it at the moment but suspect I am being very inefficient. So any suggestions or examples of similar code anyone knows about would be hugely appreciated.
Cheers
ReubenNot sure why anyone would be doing such a thing as storing their SQL in a table and wanting to dynamically execute it (generally this is bad practice), but if you must...
SQL> select * from testdata;
SQL_ID SQL_TEXT
1 insert into some_table values(23,'Happy');
6 insert into some_other_table values(24,'Sad');
12 insert into some_table values(23,'Crazzzy');
15 insert into some_other_table values(23,'Old');
23 insert into another_table values(23,'Left');
24 insert into stuff_table values(23,'Gold');
30 insert into old_table values(23,'Even');
35 insert into archive_table values(23,'True');
8 rows selected.
SQL> set serverout on
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 v_ids VARCHAR2(4000) := '12,24,35,23';
3 CURSOR cur_fetch IS
4 SELECT sql_text
5 FROM testdata
6 WHERE sql_id IN (SELECT TO_NUMBER(REGEXP_SUBSTR (v_ids, '[^,]+', 1, rownum))
7 FROM DUAL
8 CONNECT BY ROWNUM <= length(regexp_replace(v_ids,'[^,]*'))+1);
9 BEGIN
10 FOR s IN cur_fetch
11 LOOP
12 DBMS_OUTPUT.PUT_LINE(s.sql_text); -- For demo purposes show the sql text
13 -- EXECUTE IMMEDIATE s.sql_text; -- In reality, uncomment this to execute the sql text
14 END LOOP;
15* END;
16 /
insert into some_table values(23,'Crazzzy');
insert into another_table values(23,'Left');
insert into stuff_table values(23,'Gold');
insert into archive_table values(23,'True');
PL/SQL procedure successfully completed.
SQL> -
Error when executing statement for table/stored proc DB2 - Data Truncation
Hi,
I have one call sp in XI with n parameters int and two parameters out.
well, to implement the interface gives the following error
com.sap.aii.af.ra.ms.api.DeliveryException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'SPSAPAR9' (structure 'Statement'): java.sql.SQLException: The number of parameter values set or registered does not match the number of parameters
Thanks for your help
Ximena
Edited by: Ximena Gonzalez on Feb 19, 2008 11:50 AM
Edited by: Ximena Gonzalez on Feb 20, 2008 12:17 PMMy Error is change
Error while parsing or executing XML-SQL document: Error processing request in sax parser: Error when executing statement for table/stored proc. 'SAPPRG.SPSAPAR9' (structure 'Statement'): java.sql.DataTruncation: Data truncation
but de change DT SP
<?xml version="1.0" encoding="UTF-8" ?>
<ns1:AlistReqDet2_MT xmlns:ns1="urn:proxl:tmuc:proxl01:AlistReqItems">
<Statement>
<SPSAPAR9 action="EXECUTE">
<table>SAPPRG.SPSAPAR9</table>
<ISAPNU1 isInput="TRUE" type="STRING">0080000353</ISAPNU1>
<ISAPEM1 isInput="TRUE" type="STRING">'LU'</ISAPEM1>
<ISAPC05 isInput="TRUE" type="STRING">15353</ISAPC05>
<ISAPSEC isInput="TRUE" type="STRING">10</ISAPSEC>
<ISAPLOT isInput="TRUE" type="STRING">'lats'</ISAPLOT>
<ISAPCA1 isInput="TRUE" type="STRING">10</ISAPCA1>
<ISAPCA2 isInput="TRUE" type="STRING">10</ISAPCA2>
<ISAPKIL isInput="TRUE" type="STRING">10</ISAPKIL>
<ISAPES1 isInput="TRUE" type="STRING">'T'</ISAPES1>
<ISAPSW isOutput="TRUE" type="STRING" />
</SPSAPAR9>
</Statement>
</ns1:AlistReqDet2_MT> -
Error when executing statement for table/stored proc
Hi All,
I am getting this error when executing IDOC to JDBC (Stored Procedure) Scenario.
In my stored procedure I have three insert statements to insert rows in to 3 tables.
This stored procedure is working fine for two insert statements i.e,
For this I have created data type for stored procedure with 10 elements and executed the scenario and was successfully running.
when I added 3rd insert statement to stored procedure ie., when i added 5 more elements to the datatype (totally 15 elements) it starts giving the bellow error in Message Monitoring.
<i><b>Exception caught by adapter framework: Error processing request in sax parser: Error when executing statement for table/stored proc. 'COGRP_TMP_PROC_1' (structure 'Statements'): java.sql.SQLException: General error</b></i>
<i><b>Delivery of the message to the application using connection JDBC_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'COGRP_TMP_PROC_1' (structure 'Statements'): java.sql.SQLException: General error</b></i>
Note:- I have run the stored procedure with three insert statements in Sql Server, and also by calling an external program also, and was working fine.
<i><b> Note : Is there any structure needs to be follow when working with IDOC to Stored procedure.</b></i>
I am struck up with the error, can any body resolve this issue.
Thanks in Advance,
MurthyHi narasimha,
This seems to be any error due to incorrect query formation.In your receiver jdbc channel set the parameter logSQLstatement = true.you can find this parameter in the advanced mode. Using this parameter you will be able to see the sql query which is generated at runtime in the audit log in RWB.
Regards,
Pragati -
How can I convert the variable expression stored as string back to variable expression
How can I convert the variable expression stored as string back to variable expression?
I am storing the expression enterd in the TSExpresssionEditControl as simple string and want to convert back to expression since I want to get the data type of that expression.pritam,
I'm not sure what you're trying to do exactly. If you are trying to get the value of a variable and you only have the name of value in a string, then you can use Evaluate() to get its value. If you want the data type, my advise is to use the GetPropertyObject() API method and just pass in the loop up string. Then you'll have a handle to the data object and then proceed from there.
Regards,
Song D
Application Engineer
National Instrument
Regards,
Song Du
Systems Software
National Instruments R&D -
How to execute .sql file in Stored Procedure?
Hi,
I have an urgent requirement, where i have to execute .sql file form Stored Procedure.
This .sql file will have set of update statement. I need to pass value to this update statement.
Kindly please help me.
Regards,
IrfanThis is required as part of Data Migration where i have to do 100 of table's update. Each time update table will defer, so its better to have in separate script file (.sql). Can u paste some sample/syntax to exceute .sql file from stored procedure. I am new to this PL/SQL.
How have you determined that it's "better" to have seperate scripts? I assume you mean the table name will "differ" (and not "defer" - I assume that's just because English isn't your first language? no problem - I think I understand what you're asking).
So what I think you're asking is that you have dynamic table names but each table needs to be updated in the same way?
Question: Why do you have tables with different names that all need the same process doing to them?
Assuming it's a valid requirement (and 99% of the time doing dynamic coding implies it's not).... you could use dynamic code, rather than 'scripts'...
e.g.
create procedure update_table(tbl_name varchar2) is
begin
execute immediate 'update '||tbl_name||' set lastupdate = null';
end;
As you haven't bothered to provide a database version, any example code/data or explanation of what you're actually doing, you're not going to get any detailed answer. Please do take the time to read the FAQ and post appropriate details so people can help you. -
File to JDBC :Error when executing statement for table/stored proc.
Hi,
I am getting following error when i am trying to insert data into z-table using JDBC recr adapter.
Error while parsing or executing XML-SQL document: Error processing request in sax parser: Error when executing statement for table/stored proc. 'ZTEST' (structure 'STATEMENT'): java.sql.SQLException: <u>[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid object name '<b>ZTEST</b>'.</u>
But the database table name 'ZTEST' exists in the system.
XML structure:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_RECR xmlns:ns0="http://urn:srini/FileToJDBC">
<STATEMENT>
<TEST action="INSERT">
<table>ZTEST</table>
<access>
<ROLLNO>123</ROLLNO>
<FIRSTNAME>ABC</FIRSTNAME>
<LASTNAME>XYZ</LASTNAME>
</access>
</TEST>
</STATEMENT>
</ns0:MT_RECR>
Regards,
SrinivasHi,
I have changed my MT str but still getting the same error.Is it possible to insert/ update a z-table using JDBC adapter.
XML str:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_RECR xmlns:ns0="http://urn:srini/FileToJDBC">
<STATEMENT>
<ZTEST action="INSERT">
<access>
<ROLLNO>123</ROLLNO>
<FIRSTNAME>abc</FIRSTNAME>
<LASTNAME>XYZ</LASTNAME>
</access>
</ZTEST>
</STATEMENT>
</ns0:MT_RECR>
Regards,
Srinivas -
Problem with execute SSIS package from stored procedure
Hi,
I would like to execute SSIS package from stored procedure. Therefore, I implemented sp which exec SSISDB.CATALOG.CREATE_EXECUTION method. When I try to test it from SSMS on remote server, I got error that
I was able to solve by adding “WITH EXECUTE AS …”. Then I got another error: The server principal "Domain\user" is not able to access the database "SSISDB" under the current security context. On Internet, I found a couple post that describe
how to access SSIS catalog (one of them by Ke Yang -
http://blogs.msdn.com/b/mattm/archive/2012/03/20/ssis-catalog-access-control-tips.aspx). It didn’t help. I’m still getting the error message.
How to debug this issue?
Any suggestion?
Thanks
SQL Server 2014 BISSMS does not propagate user credentials thus the error
Arthur
MyBlog
Twitter -
How long charactors can stored in 'STRING' type?
HI
I'm just curious how long charactors can stored in 'string' type.
and if there is limit number to store what kind of type is unlimited length type?
and is it possible send a parameter page to page with 'form' 'post' way unlimited length of string?
and is there any type of DB field which is save last number of records automatically when one record is inserted like MANDT?
MANDT is client number though.
Regards.Here is what ABAP key word documentation says about string
The elementary data type STRING is similar to data type C and refers to a variable-length string. Accordingly, the elementary data type XSTRING is similar to data type X and refers to a variable-length byte sequence.
In contrast to a C or X field, the length of a string is not static but variable and adjusts itself to the current field content at runtime. Dynamic memory management is used internally. Strings can have any length.
The initial value of a string is an empty string with length 0. A structure containing a string is seen as deep. A deep structure cannot be used like a C field. Strings can be displayed in the ABAP Debugger and used in the ABAP Dictionary.
It is not yet possible to use strings in screens or database tables. However, strings can be stored in database tables as clusters using EXPORT and transferred using IMPORT.
As far as I know the limit is 4 Giga Byte which equals more or less no limit. I donnot expect that you will meet this limit in practice. Its very likely that will run out of memory before you reach this limit.
In short there is no limit to the data stored in STRING var but the system memory has a limit....
This can be proved with the below program:
For the program system dumps with mess.
"Unable to fulfil request for 127683972 bytes of memory space. "
here's the test prog.:
TABLES ekko.
DATA testmax TYPE string.
DATA z(16) TYPE i.
SELECT * FROM ekko.
CONCATENATE testmax ekko INTO testmax.
z = strlen( testmax ).
IF z = 63841496.
BREAK-POINT.
ENDIF.
ENDSELECT. -
Error when executing statement for table/stored proc. : ORA-00911
Hi All,
I am posting IDOC->XI->JDBC, approx 5000 Idocs.
But few messages are giving following error in XI-_SXMB_MONI
Can any one guide me what is the cause of error? I check whole Idoc data I am not able to see bad character? can any once guide me what are the bad character in XML to post data in oracle? so that i can search in XML and how to avoide this error.
"com.sap.aii.af.ra.ms.api.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'HRP1001' (structure 'INSERT_PAD34'): java.sql.SQLException: ORA-00911: invalid character"> I am talking about following IDOC.<ZRMD_A06> ->
> <E1PLOGI SEGMENT="1">-> <E1PITYP SEGMENT="1"> ->
> <E1PAD34 SEGMENT="1"> -><PROZT>0.00 #</PROZT>.
> Can we remove this # during message mapping in XI??
sure you can remove it using Replace function or by writing UDF.
as I am seing # is last character..<b>so remove # with " " (single space) and then use the TRIM fucntion.</b>
Thanks
Farooq.
*<b>Rewards points if you find it useful*</b> -
I Can't deploy EJB to WebLogic Server 6.1.
I get error:
Checking weblogic-ejb-jar.xml for completeness...
Wrote EJB .jar file to C:\java\webservices\weather\ejb1.jar
Generating WebLogic EJB container classes...
C:\jdk\jdk\jre\bin\javaw.exe -classpath C:\jdk\jdev\lib\ext\weblogic.jar;C:\jdk\jdk\jre\lib\rt.jar;C:\jdk\jdk\jre\lib\i18n.jar;C:\jdk\jdk\jre\lib\sunrsasign.jar;C:\jdk\jdk\jre\lib\jsse.jar;C:\jdk\jdk\jre\lib\jce.jar;C:\jdk\jdk\jre\lib\charsets.jar;C:\jdk\jdk\jre\classes;C:\jdk\jdev\lib\ojc.jar;C:\jdk\jdev\lib\jdev-rt.jar;C:\jdk\jdk\jre\lib\ext\activation.jar;C:\jdk\jdk\jre\lib\ext\jcert.jar;C:\jdk\jdk\jre\lib\ext\jndi.jar;C:\jdk\jdk\jre\lib\ext\jnet.jar;C:\jdk\jdk\jre\lib\ext\jta.jar;C:\jdk\jdk\jre\lib\ext\mail.jar;C:\jdk\j2ee\home\ejb.jar;C:\jdk\j2ee\home\jaxp.jar;C:\jdk\j2ee\home\jdbc.jar;C:\jdk\j2ee\home\jaas.jar;C:\jdk\j2ee\home\jsse.jar weblogic.ejbc -compiler C:\jdk\jdev\bin\ojcw.exe -classpath C:\jdk\jdev\lib\ext\weblogic.jar;C:\jdk\jdk\jre\lib\rt.jar;C:\jdk\jdk\jre\lib\i18n.jar;C:\jdk\jdk\jre\lib\sunrsasign.jar;C:\jdk\jdk\jre\lib\jsse.jar;C:\jdk\jdk\jre\lib\jce.jar;C:\jdk\jdk\jre\lib\charsets.jar;C:\jdk\jdk\jre\classes;C:\jdk\jdev\lib\ojc.jar;C:\jdk\jdev\lib\jdev-rt.jar;C:\jdk\jdk\jre\lib\ext\activation.jar;C:\jdk\jdk\jre\lib\ext\jcert.jar;C:\jdk\jdk\jre\lib\ext\jndi.jar;C:\jdk\jdk\jre\lib\ext\jnet.jar;C:\jdk\jdk\jre\lib\ext\jta.jar;C:\jdk\jdk\jre\lib\ext\mail.jar;C:\jdk\j2ee\home\ejb.jar;C:\jdk\j2ee\home\jaxp.jar;C:\jdk\j2ee\home\jdbc.jar;C:\jdk\j2ee\home\jaas.jar;C:\jdk\j2ee\home\jsse.jar C:\java\webservices\weather\ejb1.jar C:\DOCUME~1\jakubowg\USTAWI~1\Temp\wlejb61185.jar
fatal error: unable to execute java version of ojc, error string <C:\jdk\jdev\bin\ojcw.exe>
Exec failed .. exiting
**** weblogic.ejbc returned with a non-zero exit status:
#### Deployment incomplete. #### 2002-06-27 11:19:29
Does anyone give me some advices?
Grzegorztry to compile your programm from command prompt
change dir to hello.java directory
to compile programm type:
javac hello.java
if it will compile successfully run it by typing
java hello
if it will not be helpfull uninstall JDK 1.4 and instal JDK again. I'd recomend JDK 1.5. -
Issue with Executing OS commands from Stored Procedure
I am trying to execute the scripts provided at :
http://github.com/xtender/XT_SHELL
provided by xtender user.
As required, I have asked my DBAs to grant privileges by executing the following scripts:
Begin
--change to needed permissions and execute
dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/factiva/ODS/bin/CVIM_Rpt_ExportCSVFile’, 'read,write,execute' );
end;
/where CVIM_Rpt_ExportCSVFile is my script residing in the Unix server where my Oracle is installed.
The error I am facing when I try to execute the following command is:
select * from table(xt_shell.shell_exec('/var/scripts/CVIM_Rpt_ExportCSVFile',100))
Exception:the Permission (java.io.FilePermission /var/scripts/CVIM_Rpt_ExportCSVFile execute) has not been granted to ODS. The PL/SQL to grant this is dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/scripts/CVIM_Rpt_ExportCSVFile', 'execute' )I have asked my DBA to also execute the following scripts: - But I still see the same error as above. I am not able to figure out whats going on. Can anyone pls help me out??
EXEC Dbms_Java.Grant_Permission('ODS', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission(ODS', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/scripts/CVIM_Rpt_ExportCSVFile', 'execute' )DUPLICATE
===============================================================
Issue with Executing OS commands from Stored Procedure
============================================================== -
Doing mathematical formulas with numbers stored as strings
Hi Everybody.
I know I must be doing something stupid here, but I just can't see it.
I'm just trying to do a simple maths formula of one number divide by another. However, one of the numbers is stored as a string.
I have tried 'X' / Ccur ({'String'}) and even done a seperate formula that succesfully converts the string to a number and then try 'X' / ({'conversion formula'}) and still no luck.
What am I missing and can anybody help please?
Thanks
GrahamThanks both.
Works perfectly. Didn't see the ToNumber conversion in the choices available and have not used it before.
I'll also provide better descriptions as well in the future.
Regards
Graham
Points awarded accordingley :O)
Maybe you are looking for
-
IE hang (Freeze) if use applet/javascript with JRE 1.4.2_06
When i run my applet on IE 6 with JRE 1.4.2_06 and try to close IE window it freezes the IE window, while if i run the same code in 1.4.1_05 it works fine. The OS is windows 2000 Professional and IE is 6.0.2800.1106. Also the same applet works fine o
-
'Contract Date' in SKU Data of a PO
Dear Experts, I need to fetch the "Contract date" from the SKU Data of a PO ( From Tcode ME23 ) . This is coming from a Structure field J_3ASZDI-YEINDT. I tried my best but not able to figure out from which table it is fetching that date. Please help
-
Memory leak when I use function with bstr_t type
Hello, I use Visual C++ 6 and TestStand 3.1. I use the tool: Purify from Rational Instruments to detect memory leak in my code. When I use in my code, functions from the TestStand API using bstr_t types: GetValString, GetType... memory leaks appear.
-
Material document line item - inventory valuation affected ?
Hello In the framework of building a stock report, I'm trying to know if a material document line item has affected inventory valuation that is to say if a corresponding accounting document line item has been posted. Explored solutions : - there is n
-
Problem of retrieving data using JComboBox
I built 6 JComboBoxes for retrieving starting day and end day. They are all in the same panel. I could get correct indexes for 6 JComboBoxes, however, I couldn't get the correct object of the month of the end day. Sometimes, I could n't get the corre