UDF for BigDecimal Sum
Hi All,
I have to sum all of my amount values in Detail Records. I want to use BigDecimal in UDF because if I use the standard sum, the precision is going to be more than 4 digits. So if we use BigDecimal then I will get the exact result. Can anyone please help me for writing the UDF for getting the sum of all my numbers using BigDecimal.
Your inputs are highly appreciated.
Cheers,
korobee
Hi,
Refer this Blog <a href="/people/thorsten.nordholmsbirk/blog/2006/08/25/new-arithmetic-and-statistical-functions-in-message-mappings-in-sp18 Arithmetic and Statistical Functions in Message Mappings in SP18</a>.
Following is the code to add two numbers using BigDecimal.
String add(String a, String b)
BigDecimal bigA = new BigDecimal(a);
BigDecimal bigB = new BigDecimal(b);
BigDecimal bigSum = bigA.add(bigB);
return bigSum.toString();
Refer: Blog
Thanks,
SaNv...
Similar Messages
-
Unable to sum RDR1 UDF for ORDR header use.
Hi Forum,
Trying to run a query at Sales Order Header Level ORDR to get a sum of a UDF in Sales lines level RDR1.
I tried following two queries and they all fail with given error code:
1. Fails with internal error code - 3006
SELECT sum($[$38.U_RA_TotWODisc.number]) FROM RDR1 T0 INNER JOIN ORDR T1 ON T1.DocEntry = T0.DocEntry WHERE T1.[DocNum]=$[ordr.docnum]
2. Fails with internal error code - 1004
SELECT sum($[RDR1.U_RA_TotWODisc.number]) FROM RDR1 T0 INNER JOIN ORDR T1 ON T1.DocEntry = T0.DocEntry WHERE T1.[DocNum]=$[ordr.docnum]
How could I make it work please? Thank you.Hi Syed Aleem.....
The FMS query for column sum won't work during runtime.
You can make it to work when your document is added......
Regards,
Rahul -
Create UDF for table not in the List of tables
Hi all,
I know that my question maybe easy or been asked before, but I couldn't find the answer.
To create a UDF in SAP B1 version 9.0 you should go Tools -> Customization Tools -> User-Defined Fields - Management...
which is ok and working perfect. but my question is:
If I want to create UDF for a table not in the list of tables there what should I do? I need to create 2 UDFs for table OMRC [Manufacturers], and can't find it in master data tables.
anyone had this issue before?
EDIT : Is it good to add the field by using sql server? I know it's possible, but will it be visible in SAP
thank you
Message was edited by: Samira HarounHi Samira,
There is noit a simple link for this, I advise you to study the documentation for TB1300 SBO Development Certification.
Ypu should also have knowledge of .net, and C# or VB, because you have to make a small program/addon to add the fields
Kind regards
Ad Kerremans -
UDF For Retrieving the Tax Code based on PO
Hi all,
Mine is a file to Idoc scenario.
I wrote a FM to retrieve the Tax Code based on PO .
Created the udf which directly gets the Taxcode from the r/3 with out importing in to the imported objects,is this correct i never tried this before.
Find the UDF for the Same.
final String CHANNEL_NAME = "GeneratedReceiverChannel_RFC",
VALNOTFOUND = "VALUE_NOT_FOUND",
SAPRFCNS = "urn:sap-com:document:sap:rfc:functions",
TAG_FM = "Z_P_INT012_RFC_LOOKUP",
TAG_TAX_CODE = "T_TAX_CODE",
TAG_TAX_CODE_P = "TAX_CODE";
AbstractTrace trace = container.getTrace();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
factory.setNamespaceAware(false);
factory.setValidating(false);
try {
builder = factory.newDocumentBuilder();
} catch (Exception e) {
trace.addWarning("Error creating DocumentBuilder - " + e.getMessage());
Document docReq = null;
try {
// Building up RFC Request Document
docReq = builder.newDocument();
Node root = docReq.appendChild(docReq.createElementNS(SAPRFCNS, TAG_FM));
Node nodeTbOpt = root.appendChild(docReq.createElement(TAG_TAX_CODE));
for (int i = 0; i < pernr.length; i++) {
Node nodeTbOptItem = nodeTbOpt.appendChild(docReq.createElement("item"));
nodeTbOptItem.appendChild(docReq.createElement(TAG_TAX_CODE_P)).appendChild(docReq.createTextNode(TAX_CODE<i>));
} catch (Exception e) {
trace.addWarning("Error while building RFC Request - " + e);
trace.addInfo("RFC Request XML: " + docReq.toString());
//trace.addWarning("RFC Request XML: " + docReq.toString());
// Lookup
Payload load = null;
try {
Channel channel = LookupService.getChannel(receiver[0], CHANNEL_NAME);
RfcAccessor accessor = LookupService.getRfcAccessor(channel);
InputStream is = new ByteArrayInputStream(docReq.toString().getBytes());
XmlPayload payload = LookupService.getXmlPayload(is);
load = accessor.call(payload);
} catch (LookupException e) {
trace.addWarning("Error during lookup - " + e);
// Parsing RFC Response Document
Document docRsp = null;
try {
docRsp = builder.parse(load.getContent());
} catch (Exception e) {
trace.addWarning("Error when parsing RFC Response - " + e.getMessage());
trace.addInfo("RFC Response XML: " + docRsp.toString());
//trace.addWarning("RFC Response XML: " + docRsp.toString());
try {
NodeList res = docRsp.getElementsByTagName("item");
for(int i=0;i<res.getLength();i++){
NodeList itemNodes = res.item(i).getChildNodes();
Map itemMap = new HashMap();
for(int j=0;j<itemNodes.getLength();j++){
itemMap.put(itemNodes.item(j).getNodeName(), itemNodes.item(j).getFirstChild().getNodeValue());
rows.add(itemMap);
catch (Exception e) {
trace.addWarning("Result value not found in DOM - " + e);
result.addValue("true");
Error:
16:24:08 Start of test
Source code has syntax error: /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:598: 'class' or 'interface' expected public void TaxValues$(String[] a,String[] b,ResultList result,Container container){ ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:618: 'class' or 'interface' expected } ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:619: 'class' or 'interface' expected ^ 3 errors Source code has syntax error: /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:598: 'class' or 'interface' expected public void TaxValues$(String[] a,String[] b,ResultList result,Container container){ ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:618: 'class' or 'interface' expected } ^ /usr/sap/XD1/DVEBMGS30/j2ee/cluster/server0/./temp/classpath_resolver/Map283041f0edf311dd960b0003bacd2461/source/com/sap/xi/tf/_MM_INT012_INVOICE_DET_.java:619: 'class' or 'interface' expected ^ 3 errors
16:24:11 End of test.Hi Potharaju,
Why don't you try this, that really works:
If you are using PI 7.1:
http://help.sap.com/saphelp_nwpi71/helpdata/en/33/1ec6ced273493a993a80c2301c03da/frameset.htm
If you are using XI 3.0, PI 7.0
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1b439
Try with these.
Regards,
Juan -
Purchase Order Row UDF for Received Qty
Hi experts,
Can someone please recommend a way to create a row UDF for purchase orders to show the qty received? We cannot use a simple calculation like Qty-Open Qty because if the row is closed manually, the open qty becomes zero. Another problem is how to prompt the PO to update this value if additional GR PO's or AP Invoices are created. Thanks.I should explain the circumstances more clearly. There is no problem with the standard GR PO or AP invoice receiving method. What I want is a reference field on the original PO showing the total qty received to date. For example: total of 1,000 pcs ordered -> 900 pcs received against several GR PO's -> want to see that 900 has been received back on the PO. Then let's say we want to close the PO line 100 pcs short.
I can think of 2 ways to go about this:
Method 1: Change the ordered qty from 1,000 to 900 -> row is closed, but lose the reference of the original order qty being 1,000.
Method 2: Close row manually and maintain the original order qty as reference, but lose b/o qty and it is difficult to tell how many pcs where received/closed short.
Is there another way to keep all the reference information? -
UDF for leading zero's in message mapping
Dear team,
I need UDF for leading zero's in my message mapping.
Source and Target both structures contains matnr field.But we have to maintain total 18 chars at target matnr , because RFC in R/3 needed.So I want to add leading zero's when mapping. Can anybody provide the UDF code.
Matnr[source]--->split by value(eachvalue) ->UDF->Matnr[Target]
Ex::if source matnr conatains value "9846538" ; I need matnr value at target side like "000000000009846538"[total 18 chars].
-DrumiHi Ambrish,
Good day...
I have enterd what you said and I got below error... and I gave "input" in place of var1, 18 in place of filedlenght in below program...
=================================
int len = Integer.parseInt(18);
int inputLength = input.length();
try {
Integer.parseInt(input);
// If it is an integer, add 0 (len - inputLength) times
for (int i=0; i< len-inputLength;i++)
input = "0" + input;
return input;
} catch (NumberFormatException numForEx) {
// return as it is, if alphanumeric
return input;
====================================
ERROR:
Source text of object Message Mapping: Lubrisur_SHPMNT_SHPMNT05_TO_WMMBXY_WMMBID02_TransferPosting | urn:bp:xi:dwn:lu:common:Logistics:100 has syntax errors:
Function LeadingZeros, Line 1:
cannot find symbol symbol : method parseInt(int) location: class java.lang.Integer int len = Integer.parseInt(18); ^ 1 error
=======================
Please suggest -
I am facing some issue while importing the SQL meta-data from db2 in PI 7.1 , guess the db2 version is old and not compatible with 7.1 or could be problem with drivers, I want to go head with writing UDF for the jdbc lookup, can you please let me know the code and how it can be written or blogs, thanks
>>> can you please let me know the code and how it can be written or blogs, thanks
You can try this link if you dont want to use graphical jdbc lookup... Follow this link , it has code to use ...
/people/siva.maranani/blog/2005/08/23/lookup146s-in-xi-made-simpler
Also refer these links
For 7.0 - http://scn.sap.com/people/william.li/blog/2007/03/30/using-jdbc-connection-pool-in-xi-message-mapping
For 7.1 http://scn.sap.com/people/jin.shin/blog/2008/02/15/sap-pi-71-mapping-enhancements-series-graphical-support-for-jdbc-and-rfc-lookups -
Query to Lookup Ship To in a UDF for the Inventory Transfer
Good Day Experts!
I created a UDF for the Ship To Code in the Inventory Transfer Window. The problem is I do not know how to create a query to be used in the Formatted Search for this UDF wherein it will lookup all the Ship To Codes in the table CRD1 of that particular Customer selected in the Inventory Transfer window. The objective is to choose a Ship to code just like in the sales document.
My next problem would be how to display automatically the whole Ship To Address in another UDF based on the Ship To Code chosen in the UDF Ship To Code.
Your inputs would be highly appreciated.
Regards,
JenTo get the Complete ShipTO Address, use the following Code
SELECT T0.cardname+CHAR(13)+isnull(T0.Address,'')+CHAR(13)+
cast(T0.Building as varchar(100))+CHAR(13)+isnull(T0.city,'')+CHAR(13)
+isnull(T0.zipcode,'') as Address FROM CRD1 T0
WHERE T0.CardCode =$[OWTR.CardCode] and T0.cardtype='S' and
T0.Address=$[OWTR.UDF1]
Here Replace UDF1 with the Name of the UDF in which Shipto Address Names are shown as per my previous post.
Hope you understand -
Hello experts,
My code is like below....
Loop at itab into wa.
at new WERKS.
SUM.
endat.
endloop.
Our CLNT standards doesn't allow to use keyword SUM.
any alternative solution for kewword SUM ?
pls provide suggestions..........
Thanks in adavnce.
Zak.REPORT ZSRK_068 .
DATA : BEGIN OF ITAB OCCURS 0,
WERKS LIKE MARC-WERKS,
MTART LIKE MARA-MTART,
F1 TYPE I,
END OF ITAB.
DATA : L_SUM TYPE I,
FLAG.
DATA : ITAB1 LIKE ITAB OCCURS 0 WITH HEADER LINE.
ITAB-WERKS = '1000'.
ITAB-MTART = 'XYX'.
ITAB-F1 = 5.
APPEND ITAB.
CLEAR ITAB.
ITAB-WERKS = '1000'.
ITAB-MTART = 'XXX'.
ITAB-F1 = 10.
APPEND ITAB.
CLEAR ITAB.
ITAB-WERKS = '2000'.
ITAB-MTART = 'XXY'.
ITAB-F1 = 4.
APPEND ITAB.
CLEAR ITAB.
ITAB-WERKS = '3000'.
ITAB-MTART = 'XYX'.
ITAB-F1 = 2.
APPEND ITAB.
CLEAR ITAB.
ITAB-WERKS = '3000'.
ITAB-MTART = 'YYY'.
ITAB-F1 = 6.
APPEND ITAB.
CLEAR ITAB.
ITAB-WERKS = '3000'.
ITAB-MTART = 'ZZZ'.
ITAB-F1 = 1.
APPEND ITAB.
CLEAR ITAB.
SORT ITAB BY WERKS.
LOOP AT ITAB.
L_SUM = L_SUM + ITAB-F1.
AT END OF WERKS.
FLAG = 'X'.
ENDAT.
IF FLAG EQ 'X'.
ITAB-F1 = L_SUM.
MODIFY ITAB TRANSPORTING F1
WHERE WERKS EQ ITAB-WERKS.
CLEAR : FLAG , L_SUM.
ENDIF.
CLEAR ITAB.
ENDLOOP.
LOOP AT ITAB.
WRITE : / ITAB-WERKS , ITAB-MTART, ITAB-F1.
ENDLOOP. -
Reg: UDF for removing values after decimals
HI,
Please help me on the below issue,
I need an UDF for the follwing requirement,
as my input value is 12354.12354875 then the result will be like 12345.123,
After deceimal it should get only 3 values.
Please help me points will be awarded.
Edited by: UDAY on Apr 5, 2010 3:56 PM>
UDAY wrote:
> yes its needed to be truncated only not rounded.
In that case even the standard function FormatNum can also help.
Regards,
Abhishek. -
Hi Experts,
I am working on one scenrio, where i am fetching the file name dynamically by adapter module.
Now, the file name needs to be checked for the following conditions:
BOOKING_REF_DELIVERYNO_WB.pdf
BOOKING_REF_DELIVERYNO_BOLCOPY.PDF
DELIVERYNO_AWB.PDF
Depending upon the type of file being picked up by PI from the mail box,following needs to be done:
1.time stamp needs to be added ..
ex..
for file SO10162239_123_458_BOLCOPY.pdf--> the file name must be changed to :
SO10162239_X2100_20101206_123_458_BOLCOPY.pdf.
Please suggest if this can be done by graphical mapping ?
Thanks,
Sushamahi,
I am using following UDF..
FileName->ParseFile>getNykFilename>concat--
Current date-> concat> Trim> FileName
concat----
|
constatnt[.pdf]--->
UDF for parse file:
String[] sarray;
String regex = "\"";
String retstring;
String fname;
int l= raw.length();
try {
sarray = raw.split(regex, 3);
retstring = sarray[1];
fname=sarray[l-1];
if( fname=="WB")
raw.concat("_X2100_");
else if (fname=="BOLCOPY")
raw.concat("_X2101_");
else if (fname=="AWB")
raw.concat("_X2102_");
} catch (Exception e) {
retstring = "no_att_name_found.err";
return retstring;
UDF for getNykFileName:
String[] sarray;
String regex = "[_]";
String retstring;
if(!orgName.endsWith(".err")){
try {
sarray = orgName.split(regex, 3);
retstring = sarray[0];
} catch (Exception e) {
retstring = "nyk_filename.err";
return retstring;
}else{
return orgName;
But, its not working..
Its giving the file name as:
no_att_name_found.err20101206 for the input file : 801243209_81473641_wb.pdf
Display queue result for parsefileName:
"no_att_name_found.err"
Please suggest.
Thanks,
Suahama -
Hi Friends,
I have one difficult issue which have one mapping rule to write user defined function. I am sending mapping rule Please give me java coding to create udf for this mapping rule which is following below:
CRFT.COSTR = M_ORD_01 and
CRFT.CRID = CRHE.CRID and
CRFV.FTNO = CRFT.FTNO and
CRFV.ATNAM = ZPPI_ORDER_SCHED_EN_DATE
And
CRFT.COSTR = M_ORD_01 and
CRFT.CRID = CRHE.CRID and
CRFV.FTNO = CRFT.FTNO and
CRFV.ATNAM = ZPPI_ORDER_SCHED_EN_TIME
From ATWRT of ZPPI_ORDER_SCHED_EN DATE+ ATWRT of ZPPIORDER_SCHED_EN_TIME
In format yyyy-MM-ddTHH:mm:ss
using this mapping rule, ATWART field can map with target field "End Time" i think.
Actually source field is CALCULATE but this field is not in Source structure
target field is "End Time" this field is in Target Structure.
I will wait for ur response
Thanks adn regards
SaiHi Jagadish,
This RFC is CONTROL_RECIPE_DOWNLOAD
in this RFC, i want to map ATWRT field to Target field "End Time" with mapping rule which i had already given.
In Graphical mapping, i am doing . but i can not get it because mapping condition is difficult. if you have any idea in graphical mapping give me early
before that i have to give explantion about this is date value and time value passed through this ATWRT field as different records.
i am doing as a condition ie first i have taken date condition. from that condition, first two fields CRFT.COSTER and M_ORD_01 has given to "equals" funtion like that have done remaining fileds then the output of those "equals" functions given to "and" functions finally i get one output of "and" function. while sending DATE values from RFC this output of "and " function.
Like this, for Time condtion i have done mapping same way and giving a TIME values from RFC as Second record then output of this "and" function while sending second record with time value.
here mainly i am getting problem is .....
here i am taking source field ATWRT( in this field i am sending date format adn time format as different records) with the outputs of the mapping conditons as input vaules of another function. i dont have any idea for another function why because is first date record should be wait until the time record comes in this function.after then both vaules should concat .
now here whenever you send date value through this field ATWRT as first record and after satishfy the date condition form mapping rule, The date value of ATWRT should go to input of concat function. next i will send time value like date value through ATWRT as second record . It should go to another input of concat function. Then here both date value and time value concat with T and should be come output in the format yyyy-MM-ddTHH:mm:ss and this will go to Target field "End Time".
I will be wait for ur possitive reply
thanks for giving response
Thanks adn regards
sai -
Hi,
I could like to create an UDF for file to IDoc secenario.
Srouce:
MTCashPosting_
Header
CashPosting
PubDiv
DocType
DocDate
PostDate
RefDocNo
HeaderTxt
Customer
Value
Currency
ExchangeRate
Ledger
Item
Material
TaxValue
VAtValue
Trailer
Traget: (IDOC Type: FIDCCP02 Message Type: FIDCC2)
FIDCCP02
IDoc (Under FIDCCP02)
Begin (Under IDoc)
EDIDC40_:DISABLED
E1FIKPF (Under IDoc)
E1FISEG (Under E1FIKPF)
Segment
buzei
bschl
shkzg
mwskz
dmbtr
hkont
matnr
"The secenario is the 'Value,TaxVAlue & VatValue' should be handled by replicating E1FISEG like (HAve used External definition for IDoc)"
Value -> Line item 1
IF TaxValue exists->Line Item 2
IF VatValue exists-> Line item 3
Finally Line item 4 for cerdit.All above are debit
Value____________UDF______________E1FISEG
TaxValue_________|
VatValue_________|
Value____________UDF______________DMBTR
TaxValue_________|
VatValue_________|
How should I map?? Inputs plzzzzzHi
I am not sure whether my understanding is correct.
As per my understanding
You need to duplicate E1F1SEG segment 4 times as there are 4 conditions
and those nodes need to be enabled or suppressed based on your condition .
Regards
sandeep -
UDF for Special Character Conversion
Hello All,
Can any one help me with the UDF for special character conversion code.
I mean if a special character is given it should pass a blankspace.
<< Moderator message - Everyone's problem is important >>
Many thanks,
Rahul.
Edited by: Rob Burbank on Oct 29, 2010 4:32 PMHi Rahul ,
the best way to deal with special character is to use proper encoding in your Sender Communication channel it self .So that in your payload you will get proper value .
IF you are getting some special character which is not covered in encoding UTF-8 thne you can use encoding IS0-8859-1 .You can easily refer in help that how to use encoding in your communication channel .
Regards,
Saurabh -
UDF for Checking the field value
Hi
I want to check the whether the fiels conatins any value or not in mapping ... if not i want to raise the exception using the UDF
DO any one have sample code for writing the UDF
SVHi SV
what is your requirement first that should br clear.
i am giving you two UDF
1) i have written this uDF for string and comparing the field value XYZ
2) i am entering a string and its returning aa string which starts from the index of your input fixed length
int len = a.length();
String res = "";
String temp = "";
if ( len >= 10)
temp = a.substring(0,10);
if ( temp.equals("XYZ"))
res = temp;
else
res = "";
return res;
=======================================
String fixed = "ABCD";
String res = "";
int index = -1;
index = a.indexOf(fixed);
if (index == -1)
res = "NO INDEX FOUND";// or if u wanna set it as null res = "";
else
res = b.substring(index4,index12);
return res;
===
hope these may solve your problem
Thanks
Sandeep sharma
If helpful reward points
Maybe you are looking for
-
Count of rows in a schema tables
Hi, i wrote a script to get all the select count(*) from test; i have about 70 tables select statements spooled to a file. so far is ok but i want to see the table name in thsi so i know for what table these counts are for how to do this. urgent plea
-
Add Opportunity status fld to task search
Hi Experts, I have a requirement of adding Opportunity status field only fto Task search.How can i do that?In Standard search for activities provided by SAP it hasOpportunity Id and Name,Please let me know end to end details what I need to do,which s
-
Does anyone know if the change in the way daylight savings times start and stop will have any effect on Discoverer? We're using Discoverer 4. Is there any settings that need to be changed in Discoverer, or will operating system patches be enough for
-
How can i deliver a single pulse of varying amplitude using Analog output and USB-6251?
I am trying to generate an analog output for the following waveform: Pulse width: 300 usec, Frequency 40 Hz, Amplitude is following a sine wave with a 2 second period. My approach is: Use an async timer with 1/[40 Hz] sec interval. I set the DAQ out
-
CF10 ServerManager Not Reading Scheduled Tasks
Hello, Is anyone else seeing this on startup / login to ColdFusion ServerManager? CONFIRM! "Failed to read the scheduled tasks from myServerName. Continue to read charting settings from myServerName?" I'm running Coldfusion Standard 10.0.5.283319 on