Optimization of code
Hi ,
Please help me to optimize this code w.r.t performance tuning. thanks in advance
SELECT v~aufpl
v~aplzl
V~FSAVD
V~FSEDD
V~ISDD
V~IEDD
V~MGVRG
V~GMNGA
V~MEINH
c~ltxa1
c~objnr
C~ARBID
s~werks
s~arbpl
s~vornr
s~aufnr
s~matnr
o~cy_seqnr
o~dispo
D~VERWE
u~usr04
u~use04
INTO TABLE itab
FROM ( ( ( ( ( afvv AS v INNER JOIN afvc AS c ON v~aufpl EQ c~aufpl and v~aplzl eq c~aplzl )
inner join s022 as s on c~objnr eq s~objnr ) INNER JOIN
AFko AS O ON v~AUFPL EQ O~AUFPL AND S~AUFNR EQ O~AUFNR AND S~MATNR EQ O~PLNBEZ ) INNER JOIN CRHD
AS D ON C~ARBID EQ D~OBJID AND S~ARBPL EQ D~ARBPL AND S~WERKS EQ D~WERKS )
inner join afvu as u on v~aufpl eq u~aufpl and v~aplzl eq u~aplzl )
WHERE s~vornr in s_vornr
and s~werks in s_werks
and s~arbpl in s_arbpl
AND D~VERWE IN S_VERWE
and o~aufnr in s_aufnr
and o~cy_seqnr in s_seqnr
and o~dispo in s_dispo
and c~ltxa1 in s_ltxa1
and V~fsavd in p_fsavd
and V~Fsedd in p_fsedd.
Anoop
Please do not confuse a view which is only a definition in the data dictionary and a view which actually
contains data in the database.
My comment above was correct, if you read the statement in the comment above:
>Unless it's a materialized view (which SAP doesn't support), the performance gain through a view is more or less insignificant
>(as far as my experience goes). It may profit a little bit from datebase buffering though, but only if the view is frequently used.
two different kinds of views !!
And for the KNA1VV I see a join in the explain (DB6 database):
SELECT FROM kna1vv :
0 SELECT STATEMENT ( Estimated Costs = 2,292E+03 [timerons] )
1 RETURN
2 MSJOIN
3 [O] FETCH KNA1
4 IXSCAN KNA1~0 #key columns: 1
5 <i> FILTER
6 FETCH KNVV
7 IXSCAN KNVV~0 #key columns: 1
same for DD03VV now on Oracle
SELECT STATEMENT ( Estimated Costs = 11 , Estimated #Rows = 201 )
5 COUNT STOPKEY
Filter Predicates
4 TABLE ACCESS BY INDEX ROWID DD03L
Estim. CPU-Costs = 4.509 Estim. IO-Costs = 0
3 NESTED LOOPS
( Estim. Costs = 10 , Estim. #Rows = 201 )
Estim. CPU-Costs = 133.703 Estim. IO-Costs = 10
1 TABLE ACCESS FULL DD02L
( Estim. Costs = 2 , Estim. #Rows = 69.173 )
Estim. CPU-Costs = 39.023 Estim. IO-Costs = 2
Filter Predicates
2 INDEX RANGE SCAN DD03L~1
Search Columns: 2
Estim. CPU-Costs = 1.824 Estim. IO-Costs = 0
Access Predicates
There are materialized views, but I doubt that this is valid performance optimization in most cases.
Siegfried
Similar Messages
-
Here is the code for indexing.
i want to optimize the code.
please give me some suggestions.
thank you
mitesh...
package search_engine;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.awt.*;
import javax.swing.*;
public class Indexer implements Runnable
public static boolean stopFlag=true;
String dirName="c:/search/repository";
File file=new File(dirName);
String fList[]=file.list();
FileReader indCountRead;
StreamTokenizer countTok;
public void run()
int fileNum;
try{
FileReader indCountRead=new FileReader("c:/search/resources/indexcount.txt");
StreamTokenizer countTok=new StreamTokenizer(indCountRead);
countTok.resetSyntax();
countTok.wordChars(33,65535);
countTok.whitespaceChars(0,' ');
countTok.eolIsSignificant(false);
countTok.nextToken();
fileNum=Integer.parseInt(countTok.sval);
indCountRead.close();
while(stopFlag && fileNum <= fList.length)
String s="c:/search/repository/doc"+fileNum+".txt";
FileReader fr;
StreamTokenizer tok;
Table tab;
try
fr=new FileReader(s);
tok=new StreamTokenizer(fr);
tok.resetSyntax();
tok.wordChars(33,65535);
tok.whitespaceChars(0,' ');
tok.eolIsSignificant(false);
//FrameMain.indFrame.jTextFieldFile.setText("File:"+s);
tab=new Table();
tok.nextToken();
String s1=tok.sval;
while(tok.nextToken()!=tok.TT_EOF)
//FrameMain.indFrame.jTextFieldToken.setText("Token:"+tok.toString());
if(tab.avoidToken(tok.sval)==false)
if(tab.matchedRecord(tok.sval,s1)==false)
tab.insertRecord(tok.sval,s1);
else tab.updateRecord(tok.sval,s1);
}//while end
}//end of try
catch(IOException e)
//System.out.println("File Error1"+e.getMessage());
//FrameMain.indFrame.jTextFieldFile.setText("ERROR:"+e.getMessage());
fileNum++;
}//end outer while
//IndexerFrame.jTextFieldFile.setText("");
//FrameMain.indFrame.jTextFieldToken.setText("");
//FrameMain.indFrame.jButtonStop.setEnabled(false);
//FrameMain.indFrame.jButtonRun.setEnabled(false);
//FrameMain.indFrame.jLabelWarning.setText("");
FileWriter indCountWrite=new FileWriter("c:/search/resources/indexcount.txt",false);
Integer count=new Integer(fileNum);
indCountWrite.write(count.toString(),0,count.toString().length());
indCountWrite.close();
if (fileNum>fList.length)
//IndexerFrame.jLabelPop.setText("ALL FILES INDEXED !! ");
stopFlag=true;
}//end of outer try
catch(Exception e)
//FrameMain.indFrame.jTextFieldFile.setText("ERROR:"+e.getMessage());
}//end of run
}//end of indexer
class Table
String connectionAddress=
"jdbc:odbc:mitesh";
Connection con;
Statement stmt;
ResultSet rs;
public boolean avoidToken(String token)
if(token.equalsIgnoreCase("is")||
token.equalsIgnoreCase("are")||
token.equalsIgnoreCase("am")||
token.equalsIgnoreCase("was")||
token.equalsIgnoreCase("were")||
token.equalsIgnoreCase("have")||
token.equalsIgnoreCase("has")||
token.equalsIgnoreCase("had")||
token.equalsIgnoreCase("may")||
token.equalsIgnoreCase("might")||
token.equalsIgnoreCase("must")||
token.equalsIgnoreCase("shall")||
token.equalsIgnoreCase("will")||
token.equalsIgnoreCase("would")||
token.equalsIgnoreCase("should")||
token.equalsIgnoreCase("can")||
token.equalsIgnoreCase("could")||
token.equalsIgnoreCase("ought")||
token.equalsIgnoreCase("to")||
token.equalsIgnoreCase("do")||
token.equalsIgnoreCase("did")||
token.equalsIgnoreCase("does")||
token.equalsIgnoreCase("a")||
token.equalsIgnoreCase("an")||
token.equalsIgnoreCase("the")||
token.equalsIgnoreCase("in")||
token.equalsIgnoreCase("of")||
token.equalsIgnoreCase("at")||
token.equalsIgnoreCase("as")||
token.equalsIgnoreCase("into")||
token.equalsIgnoreCase("for")||
token.equalsIgnoreCase("from")||
token.equalsIgnoreCase("while")||
token.equalsIgnoreCase("if")||
token.equalsIgnoreCase("then")||
token.equalsIgnoreCase("."))
return true;
else
return false;
public void insertRecord(String key,String fileAddress)
String insertString;
insertString="insert into INDEXER"+
" values('"+key.toLowerCase()+"','"+fileAddress+"',1)";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//myDriver.ClassName");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"",
stmt=con.createStatement();
stmt.executeUpdate(insertString);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println("SQLException2: "+ex.getMessage());
public boolean matchedRecord(String key,String fileAddress)
boolean flag=false;
String query;
query=" select KEYWORD,URLADDRESS from INDEXER "+
"where KEYWORD='"+key.toLowerCase()+"' and URLADDRESS='"+fileAddress+"'";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"",
stmt=con.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
flag= true;
//System.out.println(flag);
else
flag= false;
//System.out.println(flag);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println( "SQLException3: "+ex.getMessage());
return flag;
public void updateRecord(String key,String fileAddress)
String updateString;
updateString="update INDEXER"+
" set FREQUENCY=FREQUENCY+1" + " where KEYWORD='"+key.toLowerCase()+"' and URLADDRESS='"+fileAddress+"'";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"",
stmt=con.createStatement();
stmt.executeUpdate(updateString);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println("SQLException4: "+ex.getMessage());
}i even want to search for Html files.
for that i have written a code for it, and we all call it as crawler.
Please check out.
thank you
mitesh....
import java.text.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import java.net.*;
import java.io.*;
import java.io.PrintWriter;
public class Crawler{
String ret;
public static final String DISALLOW = "Disallow:";
//public static final int SEARCH_LIMIT = 150;
public static int fileCounter=1;
CrawlTable tab;
public Crawler() {
tab=new CrawlTable();
URLConnection.setDefaultAllowUserInteraction(false);
Properties props= new Properties(System.getProperties());
props.put("http.proxySet", "true");
props.put("http.proxyHost", "webcache-cup");
props.put("http.proxyPort", "8080");
Properties newprops = new Properties(props);
System.setProperties(newprops);
String avoidHTMLTag(String s){
StringBuffer sb=new StringBuffer();
sb.ensureCapacity((s.length())*2);
sb.append(s);
int start = 0;
int end = 0;
try{
while (((start = sb.indexOf("<",start)) != -1)|((end = sb.indexOf(">",start)) != -1))
{ try{
if(end<start)
continue;
sb.replace(start,end+1," ");
start--;
end=start;
catch( Exception ex)
System.out.println("ERROR:HTML FORMAT");
String s1=new String (sb);
return s1;
catch(Exception e)
ret="WRONG HTML FORMAT";
return "";
}//end of htmlavoid
public String start (String strURL)
try
FileReader clCountRead=new FileReader("c:/search/resources/crawlcount.txt");
StreamTokenizer countTok=new StreamTokenizer(clCountRead);
countTok.resetSyntax();
countTok.wordChars(33,65535);
countTok.whitespaceChars(0,' ');
countTok.eolIsSignificant(false);
countTok.nextToken();
Crawler.fileCounter=Integer.parseInt(countTok.sval);
clCountRead.close();
//String strURL= CrawlerFrame.jTextFieldUrlAddress.getText();
//out.println("CRAWLER STARTING....");
//CrawlerFrame.jListURL.removeAll();
int counter=0;
boolean condition;
URL url;
try
url = new URL(strURL);
if (!tab.contains(strURL))
// test to make sure it is robot-safe!
//if (robotSafe(url))
tab.insertRecord(strURL);
catch (MalformedURLException e)
if(!strURL.equals("")){
ret="ERROR: invalid URL " + strURL;
//CrawlerFrame.jTextFieldUrlAddress.setText("");
while(((condition=tab.isRecordFalse())||strURL.length()!=0))
if(condition)
strURL = tab.retrieveFirst();
//CrawlerFrame.jTextFieldUrlAddress.setText(strURL);
tab.updateRecord(strURL);
//setStatus("searching " + strURL);
//CrawlerFrame.jListURL.add(strURL);
else
strURL="";
if (strURL.length() == 0)
//ret="Enter a starting URL then press RUN";
break;
try
url = new URL(strURL);
catch (MalformedURLException e)
ret="ERROR: invalid URL " + strURL;
tab.delete(strURL);
//CrawlerFrame.jTextFieldUrlAddress.setText("");
strURL="";
continue;
//tab.updateRecord(strURL);
// CrawlerFrame.jListURL.add(strURL);
// can only search http: protocol URLs
if (url.getProtocol().compareTo("http") != 0)
break;
// test to make sure it is before searching
//if (!robotSafe(url))
//break;
try
// try opening the URL
URLConnection urlConnection = url.openConnection();
urlConnection.setAllowUserInteraction(false);
InputStream urlStream = url.openStream();
String type
= URLConnection.guessContentTypeFromName(url.getFile());
if (type == null)
break;
if (type.compareTo("text/html") != 0)
break;
byte b[] = new byte[1000];
int numRead = urlStream.read(b);
String content = new String(b, 0, numRead);
while (numRead != -1)
//if (Thread.currentThread() != CrawlerFrame.clThread)
//break;
numRead = urlStream.read(b);
if (numRead != -1)
String newContent = new String(b, 0, numRead);
content += newContent;
String fileString=content;
fileString=fileString.replace('(',' ');
fileString=fileString.replace(')',' ');
fileString=fileString.replace(',',' ');
fileString=fileString.replace('.',' ');
fileString=fileString.replace(':',' ');
fileString=fileString.replace('?',' ');
fileString=fileString.replace('!',' ');
fileString=fileString.replace('@',' ');
fileString=fileString.replace('\'',' ');
fileString=fileString.replace('\"',' ');
fileString=strURL+" "+fileString;
//fileString.replace('',' ');
File htmlDoc=new File("c:/search/repository/doc"+fileCounter+".txt");
FileWriter fp=new FileWriter(htmlDoc);
fp.write(avoidHTMLTag(fileString));
//fp.write(fileString);
fp.close();
fileCounter++;
urlStream.close();
//if (Thread.currentThread() != CrawlerFrame.clThread)
//break;
String lowerCaseContent = content.toLowerCase();
int index = 0;
while ((index = lowerCaseContent.indexOf("<a", index)) != -1)
if ((index = lowerCaseContent.indexOf("href", index)) == -1)
break;
if ((index = lowerCaseContent.indexOf("=", index)) == -1)
break;
//if (Thread.currentThread() !=CrawlerFrame.clThread)
//break;
index++;
String remaining = content.substring(index);
StringTokenizer st
= new StringTokenizer(remaining, "\t\n\r\">#");
String strLink = st.nextToken();
URL urlLink;
try
urlLink = new URL(url, strLink);
strLink = urlLink.toString();
catch (MalformedURLException e)
//setStatus("ERROR: bad URL " + strLink);
tab.delete(strLink);
//CrawlerFrame.jTextFieldUrlAddress.setText("");
strURL="";
continue;
if (urlLink.getProtocol().compareTo("http") != 0)
break;
//if (Thread.currentThread() != CrawlerFrame.clThread)
//break;
try
// try opening the URL
URLConnection urlLinkConnection
= urlLink.openConnection();
urlLinkConnection.setAllowUserInteraction(false);
InputStream linkStream = urlLink.openStream();
String strType
= urlLinkConnection.guessContentTypeFromName(urlLink.getFile());
linkStream.close();
// if another page, add to the end of search list
if (strType == null)
break;
if (strType.compareTo("text/html") == 0) {
// check to see if this URL has already been
// searched or is going to be searched
if (!tab.contains(strLink))
// test to make sure it is robot-safe!
//if (robotSafe(urlLink))
tab.insertRecord(strLink);
catch (IOException e)
ret="ERROR: couldn't open URL " + strLink;
continue;
if (strURL.length() == 0)
//ret="Enter a starting URL then press RUN";
/////return;
break;
}//end of try
} catch (IOException e)
ret="ERROR1: couldn't open URL " + strURL;
tab.delete(strURL);
//CrawlerFrame.jTextFieldUrlAddress.setText("");
strURL="";
continue;
}//end while
//setStatus("done");
//CrawlerFrame.jButtonStop.setEnabled(false);
//CrawlerFrame.jButtonRun.setEnabled(true);
FileWriter clCountWrite=new FileWriter("c:/search/resources/crawlcount.txt",false);
Integer count=new Integer(fileCounter);
clCountWrite.write(count.toString(),0,count.toString().length());
clCountWrite.close();
//CrawlerFrame.clThread = null;
}//end of try
catch(Exception e)
ret="ERROR:"+e.getMessage();
return(ret);
//end of run
}//end of classCrawler
class CrawlTable
String connectionAddress="jdbc:odbc:mitesh";
Connection con;
Statement stmt;
ResultSet rs;
public void insertRecord(String urlAddress)
String insertString;
insertString="insert into CRAWLER (URLADDRESS,ISCRAWLED)"+
" values('"+urlAddress+"',false)";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"","");
stmt=con.createStatement();
stmt.executeUpdate(insertString);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println("SQLException2: "+ex.getMessage());
public void delete(String urlAddress)
String deleteString;
deleteString="delete from CRAWLER where URLADDRESS='"+urlAddress+"'";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"","");
stmt=con.createStatement();
stmt.executeUpdate(deleteString);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println("SQLException2: "+ex.getMessage());
public boolean isRecordFalse()
boolean flag=false;
String query;
query=" select URLADDRESS from CRAWLER "+
"where ISCRAWLED=false";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"","");
stmt=con.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
flag= true;
//System.out.println(flag);
else
flag= false;
//System.out.println(flag);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println( "SQLException3: "+ex.getMessage());
return flag;
public String retrieveFirst()
String query,s="";
query=" select URLADDRESS from CRAWLER where "+
"ISCRAWLED=false order by SERIAL";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
return null;
try
con=DriverManager.getConnection(connectionAddress,"","");
stmt=con.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
s=rs.getString("URLADDRESS");
stmt.close();
con.close();
catch(SQLException ex)
System.err.println( "SQLException3: "+ex.getMessage());
return null;
return s;
public boolean contains(String strURL)
boolean flag=false;
String query;
query=" select URLADDRESS from CRAWLER "+
"where URLADDRESS='"+strURL+"'";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"","");
stmt=con.createStatement();
rs=stmt.executeQuery(query);
if(rs.next()==true)
flag= true;
//System.out.println(flag);
else
flag= false;
//System.out.println(flag);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println( "SQLException3: "+ex.getMessage());
return flag;
public void updateRecord(String urlAddress)
String updateString;
updateString="update CRAWLER"+
" set ISCRAWLED=true" + " where URLADDRESS='"+urlAddress+"'";
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
catch(java.lang.ClassNotFoundException e)
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
try
con=DriverManager.getConnection(connectionAddress,"","");
stmt=con.createStatement();
stmt.executeUpdate(updateString);
stmt.close();
con.close();
catch(SQLException ex)
System.err.println("SQLException4: "+ex.getMessage());
} -
Help to optimize my code and reduce 50% processing on my core i7
This is my first time working with labview and I am trying to learn more. I have read free online guides etc and came up with my setup.
Goal:
If I have a square signal coming then 1 square or beginning of the square will equal one change. I need to record change/revolution of a wheel hence the coding seems like that.
Problem:
I can see the change but I have few problems with my code:
If i stop the code then the revolution does not disappear but keeps on counting from there on (If I press run again). I want it to reset.
It does not record data after every 30 mins to a file. I have tried with one of the channel but it ends up saving as one file without having the "time stamp" which I did choose from the advance section. I just need it to record revolution every 30 mins to a file.
My coding is apparently not optimized hence 56% of my processing power is used of my core i7 which is alot. I need to know what part of it is causing this problem. I can guess that I have the same loop for each channel hence its more demanding but I will appreciate if someone can optimize it further or give me a clue to what I should do.
Once I made the exe file out of it. The button to turn on/off did not work anymore while it worked fine during the labview program.
I am looking forward to hearing from you. I will like to thank you in advance for reading this and helping me out.
Future plan:
I am going to try to stop it when a certain amount of revolutions has been reached. I will try that in the future though. If you can give me some advice on that, it would be appreciated.
Attachments:
Interestingscheme.vi 1594 KBaltenbach wrote:
A few more comments:
I don't have DAQ installed, so I cannot look at your DAQ express VIs. How much data do they read with each iteration?
What determines the loop rates of the loops? Do they need to run this fast?
Why do you index out the first elements twice to get the same value twice? Once is enough.
All you ever look at in the array inside the shift register is the first element. Why not simply only keep the first element in the shift register as a scalar? Now you would only need one "index array" instead of four.
As Dennis said, one loop is enough. Right now you need to press 24 buttons to stop the VI.
Once a loop stops, it cannot be restarted. Think "state machine" instead.
Don't confuse the operator. Your switches are green in one state and have a green LED in the other state. Make it more intuitive!
initialize your shift registers
You are counting, thus the numeric should be an integer (blue).
Instead of piles of similar controls and indicators, use arrays.
1 sample on Demand
As you have said that it depends on the 2 cores being saturated. I do not know how to determine the loop rate. I will be glad if you can tell me what to look for here.
Indexing twice is true. I will take that away.
I know that one loop is probably enough but how to do that is the problem. I have 16 signals which are generated by mice running on a wheel. I want to see the revolution for each wheel and want to stop recording revolution for some wheels when pressing the button. I will also try to put in later to stop after reaching certain amount of revolution. (Any idea how I can do that? Should I change to another type of loop)
How do I make it so it stops and starts?
It was the opposite here that when the operator small light was green that meant it isnt on while blank meant on. I did not know how to switch small light hence I changed the color of the whole button.
I know the colors represents different thing in labview but does it really matter if its blue or orange? I mean it still works.
Each control is for different cage where you can turn it off or on and we need to know how many revolutions each mice has made. Unless you meant I can do this in another way then please show me a simple code. -
DATA: v_title(245) TYPE c,
v_butxt(245) TYPE c,
v_tot_recs LIKE sy-tabix,
v_total_pages LIKE sy-tabix,
v_tot_qty LIKE mseg-menge.
TABLES: mara, makt, marc, mard, mkpf, mseg, t001, t001w,t001l.
TABLES: sscrfields.
*TYPE_POOLS
TYPE-POOLS: slis. "ALV Display
TYPES : BEGIN OF stype_mseg_lean,
mblnr LIKE mkpf-mblnr,
mjahr LIKE mkpf-mjahr,
budat LIKE mkpf-budat,
xblnr LIKE mkpf-xblnr,
bukrs LIKE t001-bukrs,
zeile LIKE mseg-zeile,
bwart LIKE mseg-bwart,
matnr LIKE mseg-matnr,
werks LIKE mseg-werks,
lgort LIKE mseg-lgort,
shkzg LIKE mseg-shkzg,
menge LIKE mseg-menge,
meins LIKE mseg-meins,
dmbtr LIKE mseg-dmbtr,
dmbum LIKE mseg-dmbum,
insmk LIKE mseg-insmk,
aufnr LIKE mseg-aufnr,
kostl LIKE mseg-kostl,
anln1 LIKE mseg-anln1,
kdauf LIKE mseg-kdauf.
TYPES : END OF stype_mseg_lean.
TYPES: stab_mseg_lean TYPE STANDARD TABLE OF stype_mseg_lean
WITH KEY mblnr mjahr.
TYPES: BEGIN OF stype_fields,
fieldname TYPE name_feld,
END OF stype_fields.
TYPES: stab_fields TYPE STANDARD TABLE OF stype_fields
WITH KEY fieldname.
DATA: g_t_mseg_fields TYPE stab_fields.
DATA: i_mseg_lean TYPE stype_mseg_lean OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF i_show OCCURS 0,
matnr LIKE mseg-matnr,
maktx(150) type c,
meins LIKE mseg-meins,
op_stock LIKE mseg-menge,
stock_in_a_prd LIKE mseg-menge,
stock_in_a_cstn LIKE mseg-menge,
stock_in_b_issue LIKE mseg-menge,
stock_in_b_trn LIKE mseg-menge,
stock_in_r LIKE mseg-menge,
stock_toprd LIKE mseg-menge,
stock_out_a LIKE mseg-menge,
stock_out_b_issue LIKE mseg-menge,
stock_out_b_trn LIKE mseg-menge,
stock_out_r LIKE mseg-menge,
cl_stock LIKE mseg-menge,
END OF i_show.
DATA : i_show_alv LIKE i_show OCCURS 0 WITH HEADER LINE.
types: BEGIN OF t_mseg_lean_new ,
matnr LIKE mseg-matnr, "Material Number
bwart LIKE mseg-bwart, "Movement Type (Inventory Management)
dmbtr LIKE mseg-dmbtr, "Amount in Local Currency
shkzg LIKE mseg-shkzg, "Debit/Credit Indicator
dmbum LIKE mseg-dmbum, "Revaluation amount on back
menge LIKE mseg-menge, "Quantity
meins LIKE mseg-meins, "Base Unit of Measure
insmk LIKE mseg-insmk, "Stock Type
aufnr LIKE mseg-aufnr, "Order Number
kostl LIKE mseg-kostl, "Cost Center
anln1 LIKE mseg-anln1, "Main Asset Number
lgort LIKE mseg-lgort, "Storage Location
kdauf LIKE mseg-kdauf, "Sales Order Number
budat LIKE mkpf-budat, "Posting Date in the Document
xblnr LIKE mkpf-xblnr, "Reference Document Number
END OF t_mseg_lean_new.
DATA: i_mseg_lean_new type t_mseg_lean_new OCCURS 0
WITH HEADER LINE.
DATA: i_mseg_lean_cl type t_mseg_lean_new OCCURS 0
WITH HEADER LINE.
DATA: i_mseg_lean_cl_final type sorted table of t_mseg_lean_new
with unique key matnr with header line.
DATA: wa_op_stock LIKE mseg-menge,
wa_stock_in_a LIKE mseg-menge,
wa_stock_in_b LIKE mseg-menge,
wa_stock_in_r LIKE mseg-menge,
wa_stock_out_a LIKE mseg-menge,
wa_stock_out_b LIKE mseg-menge,
wa_stock_out_r LIKE mseg-menge,
wa_cl_stock LIKE mseg-menge, "closing stock
wa_stock_321s LIKE mseg-menge, "Debit
wa_stock_321h LIKE mseg-menge. "Credit
DATA: wa_stock_in_a_prd LIKE mseg-menge,
wa_stock_in_a_cstn LIKE mseg-menge,
wa_stock_in_b_issue LIKE mseg-menge,
wa_stock_in_b_trn LIKE mseg-menge,
wa_stock_out_b_issue LIKE mseg-menge,
wa_stock_out_b_trn LIKE mseg-menge.
addition ends
types: BEGIN OF t_mard ,
matnr LIKE mard-matnr,
labst LIKE mard-labst, "UNRESTRICTED STOCK
insme LIKE mard-insme, "STOCK IN QUALITY INSP
cl_stock LIKE mseg-menge, "QTY
END OF t_mard.
data: i_mard type sorted table of t_mard with unique key matnr with
header line.
DATA: v_meins TYPE mseg-meins.
DATA: i_tabb LIKE bdcdata OCCURS 0 WITH HEADER LINE,
wa_options LIKE ctu_params.
DATA: v_objnm TYPE stxh-tdname,
v_object TYPE stxh-tdobject,
v_objid TYPE stxh-tdid.
DATA: n TYPE i.
DATA : v_long_text(22) TYPE c.
DATA : V_DESC(150) TYPE C.
DATA : i_tline LIKE tline OCCURS 0
WITH HEADER LINE.
DATA : BEGIN OF i_text_tab OCCURS 0,
out_lines(150),
END OF i_text_tab.
DATA : i_text_tab1 LIKE i_text_tab OCCURS 0 WITH HEADER LINE.
DATA : BEGIN OF i_tab_text OCCURS 0,
ltext(150),
END OF i_tab_text.
DATA : BEGIN OF i_tab_text1 OCCURS 0,
ltext1(100),
END OF i_tab_text1.
SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_matnr FOR mara-matnr." OBLIGATORY.
PARAMETERS: "p_bukrs LIKE t001-bukrs OBLIGATORY,
p_werks LIKE t001w-werks OBLIGATORY.
SELECT-OPTIONS: s_lgort FOR t001l-lgort.
SELECT-OPTIONS: s_budat FOR mkpf-budat OBLIGATORY.
SELECTION-SCREEN END OF BLOCK one.
PARAMETERS p_alv AS CHECKBOX . "For ALV
If no date is given at all, the range is set to the maximum
extend (1.1.0000 - 31.12.9999).
If only s_budat-low is set, it is interpreted as the day for
which the analysis is wanted --> s_budat-high is filled up.
SELECTION-SCREEN FUNCTION KEY 1.
IF s_budat-low IS INITIAL.
s_budat-low = '00000101'.
IF s_budat-high IS INITIAL.
s_budat-high = '99991231'.
ENDIF.
ELSE.
IF s_budat-high IS INITIAL.
s_budat-high = s_budat-low.
ENDIF.
ENDIF.
RANGES s_werks FOR t001w-werks.
s_werks-sign = 'I'.
s_werks-option = 'EQ'.
s_werks-low = p_werks.
APPEND s_werks.
**********ALV Setting starts***************
*ALV Data Declaration.
DATA : i_events TYPE slis_t_event,
i_list_top_of_page TYPE slis_t_listheader,
g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
i_layout TYPE slis_layout_alv,
i_fieldcat TYPE slis_t_fieldcat_alv ,
gs_print TYPE slis_print_alv,
wa_fieldcat LIKE LINE OF i_fieldcat.
DATA: v_repid TYPE sy-repid.
DATA: gs_variant LIKE disvariant,
first(01) TYPE c,
g_save.
*Initialization for ALV.
INITIALIZATION.
v_repid = sy-repid.
i_layout-detail_popup = 'X'."PERFORM layout_init USING i_layout.
PERFORM layout_init USING i_layout.
PERFORM eventtab_build USING i_events[].
gs_variant-report = v_repid.
g_save = 'A'.
*TOP-OF-PAGE, END-OF-PAGE, END-OF-LIST are called
*dynamically due to PERFORM eventtab_build
**********ALV Setting Ends***************
**For Documentation
INITIALIZATION.
MOVE text-002 TO sscrfields-functxt_01.
AT SELECTION-SCREEN.
**For Documentation
IF sscrfields-ucomm = 'FC01'.
CALL FUNCTION 'RS_TOOL_ACCESS'
EXPORTING
operation = 'DOCS'
object_name = 'ZMMR0100'
object_type = 'PROG'
EXCEPTIONS
not_executed = 1
invalid_object_type = 2
OTHERS = 3.
ENDIF.
START-OF-SELECTION.
PERFORM mkpf_mseg.
PERFORM set_for_segregation.
PERFORM segregation.
PERFORM cl_stock.
PERFORM op_stock.
Added By Essam on 25.02.2008
PERFORM i_show_alv_populate.
Addition Ends
i_show[] = i_show_alv[].
END-OF-SELECTION.
**ADDED BY ESSAM FOR ALV ON 23-FEB-2008
PERFORM SHOW.
IF p_alv = 'X'.
PERFORM display_alv.
ELSE.
PERFORM display_list.
ENDIF.
**ADDITION ENDS FOR ALV
SET TITLEBAR 'ZT1' WITH s_budat-low s_budat-high.
PERFORM show.
SET PF-STATUS 'ZP1'.
TOP-OF-PAGE.
PERFORM top_page.
*AT LINE-SELECTION.
PERFORM next_screen.
*& Form mkpf_mseg
text
--> p1 text
<-- p2 text
FORM mkpf_mseg.
SELECT * INTO CORRESPONDING FIELDS OF TABLE i_mseg_lean
FROM mkpf AS mkpf JOIN mseg AS mseg
ON mkpfmandt = msegmandt AND
mkpfmblnr = msegmblnr AND
mkpfmjahr = msegmjahr
WHERE mseg~matnr IN s_matnr
AND mseg~werks IN s_werks
AND mseg~lgort IN s_lgort
AND mkpf~budat GE s_budat-low.
AND mkpf~budat IN s_budat.
*added by ish on 30.6.04
BELOW CODE CHANGED BY ESSAM ON 19-FEB-2008
SELECT msegmatnr mkpfbudat mkpfxblnr msegbwart
msegdmbtr msegshkzg
msegdmbum msegmenge msegwerks mseglgort
msegmeins mseginsmk msegaufnr msegkostl mseganln1 msegmblnr
mseg~zeile
mseg~kdauf
INTO CORRESPONDING FIELDS OF TABLE i_mseg_lean
FROM mkpf AS mkpf JOIN mseg AS mseg
ON msegmandt = mkpfmandt AND
msegmblnr = mkpfmblnr AND
msegmjahr = mkpfmjahr
WHERE mseg~matnr IN s_matnr
AND mseg~werks IN s_werks
AND mseg~lgort IN s_lgort
AND mkpf~budat IN s_budat.
IF sy-subrc <> 0.
ENDIF.
****testing for optimization.
SELECT msegmatnr mkpfbudat mkpfxblnr msegbwart
msegdmbtr msegshkzg
msegdmbum msegmenge msegwerks mseglgort
msegmeins mseginsmk msegaufnr msegkostl mseganln1 msegmblnr
mseg~zeile
mseg~kdauf
INTO CORRESPONDING FIELDS OF TABLE i_mseg_lean
FROM mkpf AS mkpf JOIN mseg AS mseg
ON msegmandt = mkpfmandt AND
msegmblnr = mkpfmblnr AND
msegmjahr = mkpfmjahr
WHERE mseg~matnr IN s_matnr
AND mseg~werks IN s_werks
AND mseg~lgort IN s_lgort
AND mkpf~budat IN s_budat.
IF sy-subrc <> 0.
ENDIF.
*adding other materials whose transaction is not made during the
*selected period
CLEAR: i_mseg_lean.
SELECT matnr werks lgort FROM mard INTO CORRESPONDING FIELDS OF
i_mseg_lean WHERE
matnr IN s_matnr AND
werks IN s_werks AND
lgort IN s_lgort .
APPEND i_mseg_lean.
ENDSELECT.
*addition ends
SORT i_mseg_lean BY matnr.
ENDFORM. " mkpf_mseg
*& Form segregation
text
--> p1 text
<-- p2 text
FORM segregation.
CLEAR: wa_stock_in_a_prd,wa_stock_in_a_cstn, wa_stock_in_b_issue,
wa_stock_in_b_trn,wa_stock_out_a, wa_stock_out_b_issue,
wa_stock_out_b_trn,wa_stock_in_r, wa_stock_out_r.
LOOP AT i_mseg_lean_new WHERE matnr NE ''.
xx
**As per change log(6)
IF ( ( i_mseg_lean_new-bwart = '101' OR
i_mseg_lean_new-bwart = '102' ) AND i_mseg_lean_new-lgort = ''
AND i_mseg_lean_new-kdauf NE '' ).
do not take into consideration but display the op&cl stock
**ends
****STOCK IN_A
ELSEIF ( i_mseg_lean_new-shkzg = 'S' AND i_mseg_lean_new-aufnr CA '-'
AND i_mseg_lean_new-bwart NE '261' AND
i_mseg_lean_new-bwart NE '262' )
OR ( i_mseg_lean_new-bwart = '521' AND i_mseg_lean_new-shkzg = 'S' )
OR ( i_mseg_lean_new-bwart = '309' AND
i_mseg_lean_new-xblnr CA '-' AND
i_mseg_lean_new-shkzg = 'S' )
OR ( i_mseg_lean_new-bwart = '310' AND
i_mseg_lean_new-xblnr CA '-' AND
i_mseg_lean_new-shkzg = 'S' )
**adeed as per change log(5)
OR i_mseg_lean_new-bwart = '131' OR i_mseg_lean_new-bwart = '531'.
**ends
wa_stock_in_a_prd = wa_stock_in_a_prd + i_mseg_lean_new-menge.
XY
ELSEIF
( i_mseg_lean_new-shkzg = 'H' AND i_mseg_lean_new-aufnr CA '-'
AND i_mseg_lean_new-bwart NE '261' AND
i_mseg_lean_new-bwart NE '262' )
OR ( i_mseg_lean_new-bwart = '522' AND i_mseg_lean_new-shkzg = 'H' )
OR ( i_mseg_lean_new-bwart = '309' AND
i_mseg_lean_new-xblnr CA '-' AND
i_mseg_lean_new-shkzg = 'H' )
OR ( i_mseg_lean_new-bwart = '310' AND
i_mseg_lean_new-xblnr CA '-' AND
i_mseg_lean_new-shkzg = 'H' )
**adeed as per change log(5)
OR i_mseg_lean_new-bwart = '132' OR i_mseg_lean_new-bwart = '532'.
**ends
wa_stock_in_a_prd = wa_stock_in_a_prd - i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '261' AND i_mseg_lean_new-aufnr CA '-' ).
wa_stock_in_a_cstn = wa_stock_in_a_cstn + i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '262' AND i_mseg_lean_new-aufnr CA '-' ) .
wa_stock_in_a_cstn = wa_stock_in_a_cstn - i_mseg_lean_new-menge.
****STOCK IN_B
ELSEIF
i_mseg_lean_new-bwart = '101' OR
( i_mseg_lean_new-bwart = '321' AND i_mseg_lean_new-shkzg = 'S' ).
IF ( i_mseg_lean_new-bwart EQ '101' AND i_mseg_lean_new-shkzg = 'S' )
AND ( i_mseg_lean_new-kostl NE ' ' OR
i_mseg_lean_new-anln1 NE ' ' OR
( i_mseg_lean_new-aufnr NA '-' AND
i_mseg_lean_new-aufnr NE ' ' ) ).
wa_stock_out_b_issue = wa_stock_out_b_issue + i_mseg_lean_new-menge.
ENDIF.
wa_stock_in_b_issue = wa_stock_in_b_issue + i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '321' AND i_mseg_lean_new-shkzg = 'H' ) OR
i_mseg_lean_new-bwart = '102' OR
i_mseg_lean_new-bwart = '122' OR
i_mseg_lean_new-bwart = '922'.
wa_stock_in_b_issue = wa_stock_in_b_issue - i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '309' AND i_mseg_lean_new-shkzg = 'S' ) OR
( i_mseg_lean_new-bwart = '311' AND i_mseg_lean_new-shkzg = 'S' ) OR
( i_mseg_lean_new-bwart = '301' AND i_mseg_lean_new-shkzg = 'S' ) OR
i_mseg_lean_new-bwart = '701'.
wa_stock_in_b_trn = wa_stock_in_b_trn + i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '310' AND i_mseg_lean_new-shkzg = 'S' ) OR
( i_mseg_lean_new-bwart = '312' AND i_mseg_lean_new-shkzg = 'S' ) OR
( i_mseg_lean_new-bwart = '302' AND i_mseg_lean_new-shkzg = 'S' ) OR
i_mseg_lean_new-bwart = '702'.
wa_stock_in_b_trn = wa_stock_in_b_trn - i_mseg_lean_new-menge.
ELSEIF
****STOCK OUT_A
( i_mseg_lean_new-bwart = '601' AND i_mseg_lean_new-shkzg = 'H' )
OR ( i_mseg_lean_new-bwart = '654' AND i_mseg_lean_new-shkzg = 'H' )
*As per change log(7)
OR ( i_mseg_lean_new-bwart = '251' AND i_mseg_lean_new-shkzg = 'H' ).
*Ends
wa_stock_out_a = wa_stock_out_a + i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '602' AND i_mseg_lean_new-shkzg = 'S' )
OR ( i_mseg_lean_new-bwart = '653' AND i_mseg_lean_new-shkzg = 'S' )
*As per change log(7)
OR ( i_mseg_lean_new-bwart = '252' AND i_mseg_lean_new-shkzg = 'S' ).
*Ends
wa_stock_out_a = wa_stock_out_a - i_mseg_lean_new-menge.
*****STOCK OUT_B
ELSEIF
( i_mseg_lean_new-bwart = '261' OR
i_mseg_lean_new-bwart = '241' OR
i_mseg_lean_new-bwart = '201' ).
wa_stock_out_b_issue = wa_stock_out_b_issue + i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '202' OR
i_mseg_lean_new-bwart = '242' OR
i_mseg_lean_new-bwart = '262' ).
**The following line for subtraction was missed out in the
**original coding.
**Added on 16.10.2005 by Firoz.
wa_stock_out_b_issue = wa_stock_out_b_issue - i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '309' AND i_mseg_lean_new-shkzg = 'H' ) OR
( i_mseg_lean_new-bwart = '311' AND i_mseg_lean_new-shkzg = 'H' ) OR
( i_mseg_lean_new-bwart = '301' AND i_mseg_lean_new-shkzg = 'H' ).
wa_stock_out_b_trn = wa_stock_out_b_trn + i_mseg_lean_new-menge.
ELSEIF
( i_mseg_lean_new-bwart = '310' AND i_mseg_lean_new-shkzg = 'H' ) OR
( i_mseg_lean_new-bwart = '312' AND i_mseg_lean_new-shkzg = 'H' ) OR
( i_mseg_lean_new-bwart = '302' AND i_mseg_lean_new-shkzg = 'H' ).
wa_stock_out_b_trn = wa_stock_out_b_trn - i_mseg_lean_new-menge.
ENDIF.
*****addition Ends
v_meins = i_mseg_lean_new-meins.
AT END OF matnr.
if v_meins is initial.
SELECT SINGLE meins FROM mara INTO i_show-meins
WHERE matnr = i_mseg_lean_new-matnr.
endif.
i_show-matnr = i_mseg_lean_new-matnr.
****ADDED BY ESSAM ON 24-FEB-2008
v_long_text = i_show-matnr.
v_objnm = v_long_text.
v_object = 'MATERIAL'.
v_objid = 'GRUN'.
PERFORM read_text TABLES i_tline
USING v_objnm
v_objid
v_object.
CLEAR: v_long_text.
PERFORM split_texts TABLES i_tline i_text_tab1.
DATA : v_lines TYPE sy-tabix,
v_charno TYPE i.
DESCRIBE TABLE i_text_tab1 LINES v_lines.
IF v_lines NE 0.
DO v_lines TIMES.
READ TABLE i_text_tab1 INDEX sy-index.
IF sy-subrc = 0.
i_tab_text-ltext = i_text_tab1-out_lines.
v_desc = i_tab_text-ltext.
ENDIF.
ENDDO.
CLEAR:i_tab_text-ltext,i_tline[],v_charno,i_text_tab1[],v_lines.
ENDIF.
i_show-maktx = v_desc.
i_show-stock_in_a_prd = wa_stock_in_a_prd.
i_show-stock_in_a_cstn = wa_stock_in_a_cstn.
i_show-stock_in_b_issue = wa_stock_in_b_issue.
i_show-stock_in_b_trn = wa_stock_in_b_trn.
i_show-stock_in_r = wa_stock_in_r.
i_show-stock_toprd = wa_stock_321h - wa_stock_321s.
i_show-stock_out_a = wa_stock_out_a.
i_show-stock_out_b_issue = wa_stock_out_b_issue.
i_show-stock_out_b_trn = wa_stock_out_b_trn.
i_show-stock_out_r = wa_stock_out_r.
APPEND i_show.
CLEAR: wa_stock_in_a_prd,wa_stock_in_a_cstn,
wa_stock_in_b_issue,wa_stock_in_b_trn,
wa_stock_out_a,
wa_stock_out_b_issue, wa_stock_out_b_trn,
wa_stock_in_r, wa_stock_out_r,
wa_stock_321s, wa_stock_321h.
ENDAT.
ENDLOOP.
ENDFORM. " segregation
*& Form set_for_segregation
text
--> p1 text
<-- p2 text
FORM set_for_segregation.
*i_mseg_lean_new[] = i_mseg_lean[] .
LOOP AT i_mseg_lean .
i_mseg_lean_new-matnr = i_mseg_lean-matnr.
i_mseg_lean_new-budat = i_mseg_lean-budat.
i_mseg_lean_new-bwart = i_mseg_lean-bwart.
i_mseg_lean_new-dmbtr = i_mseg_lean-dmbtr.
i_mseg_lean_new-shkzg = i_mseg_lean-shkzg.
i_mseg_lean_new-dmbum = i_mseg_lean-dmbum.
i_mseg_lean_new-menge = i_mseg_lean-menge.
i_mseg_lean_new-meins = i_mseg_lean-meins.
i_mseg_lean_new-insmk = i_mseg_lean-insmk.
i_mseg_lean_new-aufnr = i_mseg_lean-aufnr.
i_mseg_lean_new-xblnr = i_mseg_lean-xblnr.
i_mseg_lean_new-kostl = i_mseg_lean-kostl.
i_mseg_lean_new-anln1 = i_mseg_lean-anln1.
i_mseg_lean_new-kdauf = i_mseg_lean-kdauf.
i_mseg_lean_new-lgort = i_mseg_lean-lgort.
APPEND i_mseg_lean_new.
ENDLOOP.
ENDFORM. " set_for_segregation
*& Form display_list
text
--> p1 text
<-- p2 text
FORM display_list.
DATA: v_count TYPE i,
v_div TYPE i,
v_op_stock TYPE mseg-menge,
v_in_a TYPE mseg-menge,
v_in_b TYPE mseg-menge,
v_in_r TYPE mseg-menge,
v_out_a TYPE mseg-menge,
v_out_b TYPE mseg-menge,
v_out_r TYPE mseg-menge,
v_cl_stock TYPE mseg-menge,
v_toprd TYPE mseg-menge.
DATA: v_in_a_prd TYPE mseg-menge,
v_in_a_cstn TYPE mseg-menge,
v_in_b_issue TYPE mseg-menge,
v_in_b_trn TYPE mseg-menge,
v_out_b_issue TYPE mseg-menge,
v_out_b_trn TYPE mseg-menge.
LOOP AT i_show.
IF NOT i_show-op_stock IS INITIAL OR
NOT i_show-cl_stock IS INITIAL OR
NOT i_show-stock_in_a_prd IS INITIAL OR
NOT i_show-stock_in_a_cstn IS INITIAL OR
NOT i_show-stock_in_b_issue IS INITIAL OR
NOT i_show-stock_in_b_trn IS INITIAL OR
NOT i_show-stock_out_a IS INITIAL OR
NOT i_show-stock_out_b_issue IS INITIAL OR
NOT i_show-stock_out_b_trn IS INITIAL.
v_tot_recs = v_tot_recs + 1.
ENDIF.
ENDLOOP.
IF s_lgort-low IS INITIAL AND s_lgort-high IS INITIAL.
v_tot_recs = v_tot_recs + 3.
v_tot_qty = v_tot_recs MOD 51.
IF v_tot_qty NE '0'.
CLEAR v_tot_qty.
v_tot_qty = v_tot_recs / 51.
v_total_pages = v_tot_qty.
IF v_total_pages GT v_tot_qty.
v_total_pages = v_total_pages - 1.
ENDIF.
v_total_pages = v_total_pages + 1.
ELSE.
CLEAR v_tot_qty.
v_total_pages = v_tot_recs / 51.
ENDIF.
ELSE.
v_tot_recs = v_tot_recs + 3.
v_tot_qty = v_tot_recs MOD 50.
IF v_tot_qty NE '0'.
CLEAR v_tot_qty.
v_tot_qty = v_tot_recs / 50.
v_total_pages = v_tot_qty.
IF v_total_pages GT v_tot_qty.
v_total_pages = v_total_pages - 1.
ENDIF.
v_total_pages = v_total_pages + 1.
ELSE.
CLEAR v_tot_qty.
v_total_pages = v_tot_recs / 50.
ENDIF.
ENDIF.
LOOP AT i_show.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/ '|'.
pstl 15 i_show-matnr. HIDE i_show-matnr.
pstl 1 '|'. pstl 150 i_show-maktx.
pstl 1 '|'.pstl 5 i_show-meins.
pstl 1 '|'.pstr 16 i_show-op_stock.
pstl 1 '|'.pstr 16 i_show-stock_in_a_prd.
pstl 1 '|'.pstr 16 i_show-stock_in_a_cstn.
pstl 1 '|'.pstr 16 i_show-stock_in_b_issue.
pstl 1 '|'.pstr 16 i_show-stock_in_b_trn.
pstl 1 '|'.pstr 16 i_show-stock_out_a.
pstl 1 '|'.pstr 16 i_show-stock_out_b_issue.
pstl 1 '|'.pstr 16 i_show-stock_out_b_trn.
pstl 1 '|'.pstr 16 i_show-cl_stock.
pstl 1 '|'.
v_count = v_count + 1.
v_op_stock = v_op_stock + i_show-op_stock.
v_in_a_prd = v_in_a_prd + i_show-stock_in_a_prd.
v_in_a_cstn = v_in_a_cstn + i_show-stock_in_a_cstn.
v_in_b_issue = v_in_b_issue + i_show-stock_in_b_issue.
v_in_b_trn = v_in_b_trn + i_show-stock_in_b_trn.
v_in_r = v_in_r + i_show-stock_in_r.
v_toprd = v_toprd + i_show-stock_toprd.
v_out_a = v_out_a + i_show-stock_out_a.
v_out_b_issue = v_out_b_issue + i_show-stock_out_b_issue.
v_out_b_trn = v_out_b_trn + i_show-stock_out_b_trn.
v_out_r = v_out_r + i_show-stock_out_r.
v_cl_stock = v_cl_stock + i_show-cl_stock.
ENDLOOP.
ULINE AT (351).
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
WRITE:/ '|'.
pstl 15 'Totals:'. pstl 152 ''.
pstl 1 '|'.pstl 5 ''.
pstl 1 '|'.pstr 16 v_op_stock.
pstl 1 '|'.pstr 16 v_in_a_prd.
pstl 1 '|'.pstr 16 v_in_a_cstn.
pstl 1 '|'.pstr 16 v_in_b_issue.
pstl 1 '|'.pstr 16 v_in_b_trn.
pstl 1 '|'.pstr 16 v_out_a.
pstl 1 '|'.pstr 16 v_out_b_issue.
pstl 1 '|'.pstr 16 v_out_b_trn.
pstl 1 '|'.pstr 16 v_cl_stock.
pstl 1 '|'.
ULINE AT (351).
FORMAT COLOR OFF.
ENDFORM. " show
*& Form cl_stock
text
--> p1 text
<-- p2 text
FORM cl_stock.
op (1 a add)
*selecting the current availabe stock in the system for requested
materials
SELECT matnr sum( labst ) sum( insme ) FROM mard INTO TABLE i_mard
WHERE matnr in s_matnr and
werks IN s_werks AND
lgort IN s_lgort group by matnr.
op (1 z add)
IF s_budat-high NE '99991231' AND s_budat-high NE s_budat-low.
*added on 25.01.2004
IF s_budat-high NE '99991231' AND s_budat-high NE sy-datum.
PERFORM mkpf_mseg_closing.
ELSE.
*added on 08.02.2004
LOOP AT i_show.
i_mseg_lean_cl_final-matnr = i_show-matnr.
APPEND i_mseg_lean_cl_final.
CLEAR i_mseg_lean_cl_final.
ENDLOOP.
*addition ends
ENDIF.
CLEAR: wa_cl_stock, v_meins.
IF NOT i_mseg_lean_cl[] IS INITIAL.You should use SE30 or ST05 to find the problem area before posting this.
Rob -
Hello there,
Can anyone help me about my problem in optimizing my code in ABAP..
before i used SDF logical dbf..but simple select in BSIS,BKPF and BSEG tables are much faster than using logical dbf..but my main problem is it took a while also in processing a report while using a select statement..here is my sample code.
It took 2mins in processing a report...Hope someone can help me
Please give me some advice.
Thanks in advance
aVaDuDz
SELECT SINGLE *
FROM skb1
WHERE bukrs EQ p_bukrs
AND saknr EQ p_saknr.
IF sy-subrc EQ 0.
SELECT blart belnr waers monat budat bukrs hkont buzei
shkzg dmbtr wrbtr gjahr
INTO CORRESPONDING FIELDS OF TABLE it_bsis
FROM bsis
WHERE bukrs EQ p_bukrs
AND hkont EQ p_saknr
AND gjahr IN p_gjahr
AND monat IN p_monat.
PERFORM add_record.
ENDIF.
FORM add_record .
LOOP AT it_bsis.
g_percn = 1.
CLEAR g_indic.
g_indic = c_indic.
REPLACE '&' WITH it_bsis-belnr INTO g_indic.
REPLACE '%' WITH it_bsis-buzei INTO g_indic.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = g_percn
text = g_indic.
READ TABLE it_data ASSIGNING <data>
WITH KEY belnr = it_bsis-belnr "document #
buzei = it_bsis-buzei. "Line Item
IF sy-subrc <> 0.
APPEND INITIAL LINE TO it_data ASSIGNING <data>.
<data>-belnr = it_bsis-belnr. "document #
<data>-buzei = it_bsis-buzei. "Line Item
ENDIF.
<data>-bukrs = it_bsis-bukrs. "Company
<data>-hkont = it_bsis-hkont. "G/L Acct.
<data>-gjahr = it_bsis-gjahr.
<data>-waers = it_bsis-waers.
<data>-belnr = it_bsis-belnr.
<data>-monat = it_bsis-monat.
<data>-budat = it_bsis-budat.
<data>-blart = it_bsis-blart.
IF it_bsis-shkzg ='H'.
<data>-wrbtr = it_bsis-wrbtr * -1.
<data>-dmbtr = it_bsis-dmbtr * -1.
ELSE.
<data>-wrbtr = it_bsis-wrbtr.
<data>-dmbtr = it_bsis-dmbtr.
ENDIF.
SELECT SINGLE lifnr sgtxt
FROM bseg
INTO gs_vendor
WHERE belnr = it_bsis-belnr
AND gjahr IN p_gjahr
AND lifnr NE ''.
SELECT SINGLE lifnr name1 stcd1
FROM lfa1
INTO gs_lfa1
WHERE lifnr = gs_vendor-lifnr.
<data>-lifnr = gs_lfa1-lifnr.
<data>-sgtxt = gs_vendor-sgtxt.
<data>-name1 = gs_lfa1-name1.
<data>-stcd1 = gs_lfa1-stcd1.
SELECT SINGLE wt_withcd
FROM with_item
INTO gs_item
WHERE belnr = it_bsis-belnr
AND gjahr IN p_gjahr.
IF sy-subrc EQ 0.
<data>-mwskz = gs_item.
ENDIF.
SELECT SINGLE ppnam usnam bldat
FROM bkpf
INTO gs_bkpf
WHERE belnr = it_bsis-belnr
AND gjahr IN p_gjahr.
<data>-ppnam = gs_bkpf-ppnam.
<data>-usnam = gs_bkpf-usnam.
<data>-bldat = gs_bkpf-bldat.
ENDLOOP.
ENDFORM. " add_recordHi,
Check this code. See the comments where i have mentioned "Add / Remove this".
For tables like BSEG, BKPF and WITH_ITEM you have to provide complete key to read from table. BUKRS should be the first field in select statement.
Also, you do not need to check LIFNR NE '', when you select from BSEG. Just read the first line item. It is vendor / customer line item.
Also, <b>DO NOT USE SAPGUI_PROGRESS_INDICATOR inside loop</b>. It does affect performance.
Let me know if you still have performance issue.
SELECT SINGLE *
FROM skb1
WHERE bukrs EQ p_bukrs
AND saknr EQ p_saknr.
IF sy-subrc EQ 0.
SELECT blart belnr waers monat budat bukrs hkont buzei
shkzg dmbtr wrbtr gjahr
INTO CORRESPONDING FIELDS OF TABLE it_bsis
FROM bsis
WHERE bukrs EQ p_bukrs
AND hkont EQ p_saknr
AND gjahr IN p_gjahr
AND monat IN p_monat.
PERFORM add_record.
ENDIF.
* FORM add_record *
FORM add_record .
LOOP AT it_bsis.
g_percn = 1.
CLEAR g_indic.
g_indic = c_indic.
REPLACE '&' WITH it_bsis-belnr INTO g_indic.
REPLACE '%' WITH it_bsis-buzei INTO g_indic.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = g_percn
text = g_indic.
READ TABLE it_data ASSIGNING <data>
WITH KEY belnr = it_bsis-belnr "document #
buzei = it_bsis-buzei. "Line Item
IF sy-subrc <> 0.
append initial line to it_data assigning <data>.
<data>-belnr = it_bsis-belnr. "document #
<data>-buzei = it_bsis-buzei. "Line Item
ENDIF.
<data>-bukrs = it_bsis-bukrs. "Company
<data>-hkont = it_bsis-hkont. "G/L Acct.
<data>-gjahr = it_bsis-gjahr.
<data>-waers = it_bsis-waers.
<data>-belnr = it_bsis-belnr.
<data>-monat = it_bsis-monat.
<data>-budat = it_bsis-budat.
<data>-blart = it_bsis-blart.
IF it_bsis-shkzg ='H'.
<data>-wrbtr = it_bsis-wrbtr * -1.
<data>-dmbtr = it_bsis-dmbtr * -1.
ELSE.
<data>-wrbtr = it_bsis-wrbtr.
<data>-dmbtr = it_bsis-dmbtr.
ENDIF.
SELECT SINGLE
lifnr
sgtxt FROM bseg
INTO gs_vendor
WHERE bukrs = it_bsis-bukrs " --> Add this
AND belnr = it_bsis-belnr
AND gjahr IN p_gjahr
AND buzei = '001'. " --> Add this
* AND lifnr NE ''. " --> Remove this
SELECT SINGLE lifnr name1 stcd1
FROM lfa1
INTO gs_lfa1
WHERE lifnr = gs_vendor-lifnr.
<data>-lifnr = gs_lfa1-lifnr.
<data>-sgtxt = gs_vendor-sgtxt.
<data>-name1 = gs_lfa1-name1.
<data>-stcd1 = gs_lfa1-stcd1.
SELECT SINGLE wt_withcd
FROM with_item
INTO gs_item
WHERE bukrs = it_bsis-bukrs " --> Add this
AND belnr = it_bsis-belnr
AND gjahr IN p_gjahr.
IF sy-subrc EQ 0.
<data>-mwskz = gs_item.
ENDIF.
SELECT SINGLE ppnam usnam bldat
FROM bkpf
INTO gs_bkpf
WHERE bukrs = it_bsis-bukrs " --> Add this
AND belnr = it_bsis-belnr
AND gjahr IN p_gjahr.
<data>-ppnam = gs_bkpf-ppnam.
<data>-usnam = gs_bkpf-usnam.
<data>-bldat = gs_bkpf-bldat.
ENDLOOP.
ENDFORM.
Regards,
RS -
How to Optimize this code?
Hi All
I have a procedure which runs fine,but since the data in table XYZ,ABC runs into millions it becomes too slow..Can any one guide me in optimising the code.I have already created indexes on these columns.
CREATE OR REPLACE PROCEDURE test AS
CURSOR c1 IS
SELECT
t.cutGrp,
t.cutGrpCode,
t.modelDesc,
t.startdate,
t.enddate,
avg(t.price) price,
avg(t.netprice) netprice,
sum(t.awdQTY) awardqty,
sum(t.planQTY) revplanqty,
FROM
ABC t
GROUP BY
t.cutGrp,
t.cutGrpCode,
t.modelDesc,
t.startdate,
t.enddate;
counter NUMBER := 0;
l_aggregate NUMBER;
BEGIN
FOR rec IN c1
LOOP
counter := counter + 1;
SELECT
sum(t.anotherQTY) INTO l_aggregate
FROM
XYZ t
WHERE
t.cutstomer_Grp = rec.cutGrp
AND t.cutGrp_Code = rec.cutGrpCode
AND t.product_model = rec.modelDesc;
UPDATE XYZ t
SET
t.testQTY = l_aggregate,
t.testprice = rec.price,
t.testnetprice = rec.netprice,
t.testawardQTY = rec.awardqty,
t.testplanQTY = rec.revplanqty,
t.fcstartdate = rec.startdate,
t.fcenddate = rec.enddate
WHERE
t.cutstomer_Grp = rec.cutGrp
AND t.cutGrp_Code = rec.cutGrpCode
AND t.cutGrp_Code = rec.modelDesc;
END LOOP;
COMMIT WORK;
END test;
SHOW ERRORS;Hi All
This the only query i could come up with...But this gives me error
ORA-30926 unable to get a stable set of rows in the source tables.Also this code does not address
SELECT
sum(t.anotherQTY) INTO l_aggregate
FROM
XYZ t
WHERE
t.cutstomer_Grp = rec.cutGrp
AND t.cutGrp_Code = rec.cutGrpCode
AND t.product_model = rec.modelDesc;<b>This is what i came up with </b> so any code help is appreciated
MERGE INTO sgforecastrecord b
USING (
SELECT
cutGrp
cutGrpCode ,
modelDesc,
startdate,
enddate,
avg(price) price,
avg(netprice) netprice,
sum(awdQTY) awardqty,
sum(planQTY) revplanqty
FROM
ABC
GROUP BY
cutGrp,
cutGrp,
modelDesc,
startdate,
enddate
) t
on (
t.cutstomer_Grp = b.cutGrp
AND t.cutGrp_Code = b.cutGrpCode
AND t.product_model = b.modelDesc;
WHEN MATCHED THEN
UPDATE set
b.testprice = t.price,
b.testnetprice = t.netprice,
b.testawardQTY = t.awardqty,
b.testplanQTY = t.revplanqty,
b.fcstartdate = t.startdate,
b.fcenddate = t.enddate
-
How to optimize this code + is design proper
Well I have to implement tree programming here , what i mean by tree
programming is i have data stored in tree format i,e I have parent
object which will have child objects of same type the level of depth can
go any long:
I am able to store objects in tree format and also able to display properly Here
is code but I am facing problems when i have to filter some child nodes based on some conditions:
I have two question is this code fine is there anything wrong with desin Plus how to handle removing child node in tree scenation where child can be in any place.Below is code
package menu;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.chartis.gp.support.util.BrokerSupportUtil;
import com.chartis.gp.support.vo.Links;
import com.chartis.kernel.user.UserVO;
import com.chartis.kernel.utils.Utils;
public class Utility{
/* IN this class NavModel,CModel,CNode are some dummy classes
* which help us read contents form some resources which are stored in dummy format
* as Example of tree format stored data below is the example
* tree
* child1
* child2
* child3
* child3-1
* child:q
* child:r
* child:a
* child3-2
* child4
private static void populateChildLinks(NavModel navModel, Object objectNode, Links parent ){
try{
List<Links> childLinks = new ArrayList<Links>();
Iterator it = navModel.getChildren( objectNode );
while( it.hasNext() ){
NavNode node = (NavNode) it.next();
CNode contentNode = node.getContentNode();
Links links = new Links();
links.setNodeName( contentNode.getNodeName() );
childLinks.add( links );
if( navModel.hasChildren( node ) ){
populateChildLinks( node, links );
parent.setChildren( childLinks );
catch( Exception e ){
private static Links createCategoryLinks(String categoryLinkName){
Links categoryLinks = new Links();
categoryLinks.setNodeName( categoryLinkName );
return categoryLinks;
public static Links setupLinks(String categoryLinkName,String name) {
Links categoryLinks=null;
CModel contentModel = new CModel();
NavModel navModel = new NavModel();
categoryLinks = Utility.createCategoryLinks( categoryLinkName);
Object objectNode = contentModel.getLocator().findByUniqueName(name);
if( objectNode != null ){
if( navModel.hasChildren( objectNode ) ){
populateChildLinks( navModel,objectNode, categoryLinks );
// This is where i am facing issue once i get list of links of childs
// i have to delete how can i find that particular child in the list
// do i have to iterate through all the links and delete or which
// way is better
private static void filterLinks( Links parentNode,
List<Links> childNodeList ){
List<Links> filteredResourceList = new ArrayList<Links>();
if( childNodeList!=null ){
Iterator<Links> childNodeIt = childNodeList.iterator();
while( childNodeIt.hasNext() ){
Links childNode = (Links) childNodeIt.next();
if(childNode.getChildren().size() >0 ){
filterLinks( childNode, childNode.getChildren() );
boolean removeNode = filterContents( childNode);
if(! removeNode ){
filteredResourceList.add( childNode );
Iterator<Links> filteredResourceIt = filteredResourceList.iterator();
while( filteredResourceIt.hasNext() ){
Links childNode = (Links) filteredResourceIt.next();
parentNode.getChildren().remove( childNode );
// Let us consider this as some dummy method which returns true or false based on some conditions
private static boolean filterContents( menu.Links childNode ){
return false;
package menu;
import java.util.List;
public class Links{
private String nodeName;
private List<Links> children;
public List<Links> getChildren(){
return children;
public void setChildren( List<Links> children ){
this.children = children;
public String getNodeName(){
return nodeName;
public void setNodeName( String nodeName ){
this.nodeName = nodeName;
package menu;
public class TreeDisplay{
public static void main( String[] args ){
Links link = Utility.setupLinks( "SomeName", "ResiyrbceBane");
Utility.filterLinks( link, link.getChildren() );
}Is the utility class with so many static class is ok?Vicky wrote:
Thanks TPD
If you could write more on it , it will be great i rarely find ocasations of using interfaces , however i don't think creating a new tree with valid node could be better solution as you have to create a new tree keeping the same hierarchy .The advantage is that all other components do not need to know that they work with a filtered tree.
Certainly you can do it the other way around bye passing the tree and the filter to eg. the <tt>NotePrinter</tt> Object, but than all components working with the tree meight neet to know that ther are Node filters.
I just came up with the Idea to give the nodes themselfes knowlege of the Filter via <tt>setFilter(Filter<Links> myFilter)</tt>. You would call this on the root node and in the <tt>getChildren()</tt> method you would check if the child apllies to the filter and pass that filter to the eliable childs before putting them into a new collection which is returned to the caller. Ofcause you should initialise the <tt>this.filter</tt> property in <tt>Links</tt> with a <tt>ALL_NODES</tt> constant.
Also you should resist the tamptation to make the <tt>this.filter</tt> property in <tt>Links</tt> static. This would save you one line of code in the <tt>getCildren()</tt> method by the cost that you cannot have different trees with different filters in the same JVM.
This kind of interference between threads is pretty hard to find later in production environments...
bye
TPD -
Performance Tuning Issues ( How to Optimize this Code)
_How to Optimize this Code_
FORM MATL_CODE_DESC.
SELECT * FROM VBAK WHERE VKORG EQ SAL_ORG AND
VBELN IN VBELN AND
VTWEG IN DIS_CHN AND
SPART IN DIVISION AND
VKBUR IN SAL_OFF AND
VBTYP EQ 'C' AND
KUNNR IN KUNNR AND
ERDAT BETWEEN DAT_FROM AND DAT_TO.
SELECT * FROM VBAP WHERE VBELN EQ VBAK-VBELN AND
MATNR IN MATNR.
SELECT SINGLE * FROM MAKT WHERE MATNR EQ VBAP-MATNR.
IF SY-SUBRC EQ 0.
IF ( VBAP-NETWR EQ 0 AND VBAP-UEPOS NE 0 ).
IF ( VBAP-UEPVW NE 'B' AND VBAP-UEPVW NE 'C' ).
MOVE VBAP-VBELN TO ITAB1-SAL_ORD_NUM.
MOVE VBAP-POSNR TO ITAB1-POSNR.
MOVE VBAP-MATNR TO ITAB1-FREE_MATL.
MOVE VBAP-KWMENG TO ITAB1-FREE_QTY.
MOVE VBAP-KLMENG TO ITAB1-KLMENG.
MOVE VBAP-VRKME TO ITAB1-FREE_UNIT.
MOVE VBAP-WAVWR TO ITAB1-FREE_VALUE.
MOVE VBAK-VTWEG TO ITAB1-VTWEG.
MOVE VBAP-UEPOS TO ITAB1-UEPOS.
ENDIF.
ELSE.
MOVE VBAK-VBELN TO ITAB1-SAL_ORD_NUM.
MOVE VBAK-VTWEG TO ITAB1-VTWEG.
MOVE VBAK-ERDAT TO ITAB1-SAL_ORD_DATE.
MOVE VBAK-KUNNR TO ITAB1-CUST_NUM.
MOVE VBAK-KNUMV TO ITAB1-KNUMV.
SELECT SINGLE * FROM KONV WHERE KNUMV EQ VBAK-KNUMV AND
KSTEU = 'C' AND
KHERK EQ 'A' AND
KMPRS = 'X'.
IF SY-SUBRC EQ 0.
ITAB1-REMARKS = 'Manual Price Change'.
ENDIF.
SELECT SINGLE * FROM KONV WHERE KNUMV EQ VBAK-KNUMV AND
KSTEU = 'C' AND
KHERK IN ('C','D') AND
KMPRS = 'X' AND
KRECH IN ('A','B').
IF SY-SUBRC EQ 0.
IF KONV-KRECH EQ 'A'.
MOVE : KONV-KSCHL TO G_KSCHL.
G_KBETR = ( KONV-KBETR / 10 ).
MOVE G_KBETR TO G_KBETR1.
CONCATENATE G_KSCHL G_KBETR1 '%'
INTO ITAB1-REMARKS SEPARATED BY SPACE.
ELSEIF KONV-KRECH EQ 'B'.
MOVE : KONV-KSCHL TO G_KSCHL.
G_KBETR = KONV-KBETR.
MOVE G_KBETR TO G_KBETR1.
CONCATENATE G_KSCHL G_KBETR1
INTO ITAB1-REMARKS SEPARATED BY SPACE.
ENDIF.
ELSE.
ITAB1-REMARKS = 'Manual Price Change'.
ENDIF.
CLEAR : G_KBETR, G_KSCHL,G_KBETR1.
MOVE VBAP-KWMENG TO ITAB1-QTY.
MOVE VBAP-VRKME TO ITAB1-QTY_UNIT.
IF VBAP-UMVKN NE 0.
ITAB1-KLMENG = ( VBAP-UMVKZ / VBAP-UMVKN ) * VBAP-KWMENG.
ENDIF.
IF ITAB1-KLMENG NE 0.
VBAP-NETWR = ( VBAP-NETWR / VBAP-KWMENG ).
MOVE VBAP-NETWR TO ITAB1-INV_PRICE.
ENDIF.
MOVE VBAP-POSNR TO ITAB1-POSNR.
MOVE VBAP-MATNR TO ITAB1-MATNR.
MOVE MAKT-MAKTX TO ITAB1-MAKTX.
ENDIF.
SELECT SINGLE * FROM VBKD WHERE VBELN EQ VBAK-VBELN AND
BSARK NE 'DFUE'.
IF SY-SUBRC EQ 0.
ITAB1-INV_PRICE = ITAB1-INV_PRICE * VBKD-KURSK.
APPEND ITAB1.
CLEAR ITAB1.
ELSE.
CLEAR ITAB1.
ENDIF.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM. " MATL_CODE_DESCHi Vijay,
You could start by using INNER JOINS:
SELECT ......
FROM ( VBAK
INNER JOIN VBAP
ON VBAPVBELN = VBAKVBELN
INNER JOIN MAKT
ON MAKTMATNR = VBAPMATNR AND
MAKT~SPRAS = SYST-LANGU )
INTO TABLE itab
WHERE VBAK~VBELN IN VBELN
AND VBAK~VTWEG IN DIS_CHN
AND VBAK~SPART IN DIVISION
AND VBAK~VKBUR IN SAL_OFF
AND VBAK~VBTYP EQ 'C'
AND VBAK~KUNNR IN KUNNR
AND VBAK~ERDAT BETWEEN DAT_FROM AND DAT_TO
AND VBAP~NETWR EQ 0
AND VBAP~UEPOS NE 0
Regards,
John. -
Can you optimize this code with bit shifting?
Hi there,
I was wondering if anyone could make this code run faster, by implementing bitshifting techniques. I'd really appreciate it, and thanks!
public void scaleImage(Image source, Image dest) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
int thumbWidth = dest.getWidth();
int thumbHeight = dest.getHeight();
Graphics g = dest.getGraphics();
int dx, dy = 0;
for (int y = 0; y < thumbHeight; y++) {
for (int x = 0; x < thumbWidth; x++) {
g.setClip(x, y, 1, 1);
dx = x * sourceWidth / thumbWidth;
dy = y * sourceHeight / thumbHeight;
g.drawImage(source, x - dx, y - dy, Graphics.LEFT | Graphics.TOP);
}Message was edited by:
conlanriosyour method reminds me this stuff:
http://www.java-tips.org/java-me-tips/midp/displaying-images-as-thumbnails-on-j2me-devices.html
you can have a look to this article:
http://developers.sun.com/techtopics/mobility/reference/techart/design_guidelines/image_resizing.html -
Please help me optimize this code..
i have already checked the indexes of the tables and used the primary keys.
r_datum-sign = gco_sign_i.
r_datum-low = docdate_from.
IF NOT docdate_to IS INITIAL.
r_datum-option = gco_option_bt.
r_datum-high = docdate_to.
ELSE.
r_datum-option = gco_option_eq.
ENDIF.
APPEND r_datum.
CLEAR r_datum.
r_vbeln-sign = gco_sign_i.
r_vbeln-low = docnum_from.
IF NOT docnum_to IS INITIAL.
r_vbeln-option = gco_option_bt.
r_vbeln-high = docnum_to.
ELSE.
r_vbeln-option = gco_option_eq.
ENDIF.
APPEND r_vbeln.
CLEAR r_vbeln.
process_web_rset salesgroup
r_vkgrp
gco_sign_i
gco_option_eq.
* Get Total (Confirmed) Qty
PERFORM get_valid_itemcateg TABLES gr_pstyv.
* Header
SELECT vbak~vbeln
vbkd~inco1
vbak~erdat
vbak~gueen
vbak~ernam
vbkd~bstkd
vbak~kunnr
APPENDING CORRESPONDING FIELDS OF TABLE lt_hdr
FROM vbak INNER JOIN vbkd
ON vbak~vbeln EQ vbkd~vbeln
WHERE vbak~vbeln IN r_vbeln
AND vbak~erdat IN r_datum
AND vbak~vkgrp IN r_vkgrp
AND vbak~kunnr EQ customer
AND vbkd~posnr EQ lv_posnr
SORT lt_hdr BY vbeln.
LOOP AT lt_hdr.
* Customer Name
SELECT SINGLE kna1~name1
INTO lv_cusname
FROM kna1
WHERE kna1~kunnr EQ lt_hdr-kunnr.
MOVE lt_hdr-vbeln TO listing-sa.
MOVE lt_hdr-ernam TO listing-ordered_thru.
MOVE lt_hdr-bstkd TO listing-po.
MOVE lt_hdr-kunnr TO listing-customer.
MOVE lv_cusname TO listing-customer_name.
MOVE lt_hdr-erdat TO listing-date_created.
MOVE lt_hdr-gueen TO listing-valid_until.
CONCATENATE lt_hdr-erdat+6(2) lt_hdr-erdat+4(2) lt_hdr-erdat+0(4) INTO
listing-date_created SEPARATED BY '.'.
CONCATENATE lt_hdr-gueen+6(2) lt_hdr-gueen+4(2) lt_hdr-gueen+0(4) INTO
listing-valid_until SEPARATED BY '.'.
* Get Mode of Sale
IF lt_hdr-inco1 EQ 'FOB'.
listing-incoterms = co_inco1.
ELSEIF lt_hdr-inco1 EQ 'CIF'.
listing-incoterms = co_inco2.
ENDIF.
* Get Status
SELECT SINGLE bezei
FROM tvbst JOIN vbuk
ON tvbst~statu EQ vbuk~gbstk
INTO listing-status
WHERE tbnam EQ co_tbnam
AND spras EQ co_spras
AND fdnam EQ co_fdnam
AND vbuk~vbeln EQ listing-sa.
* Get Ship to party
SELECT SINGLE name1
FROM vbpa INNER JOIN kna1
ON vbpa~kunnr = kna1~kunnr
INTO listing-ship_to
WHERE vbeln EQ listing-sa
AND posnr EQ lv_posnr
AND parvw EQ 'WE'.
* Get Plant
SELECT SINGLE vbap~werks
t001w~name1
FROM vbap INNER JOIN t001w
ON vbap~werks EQ t001w~werks
INTO (listing-plant,
listing-plant_text)
WHERE vbap~vbeln EQ listing-sa
* Items
SELECT SINGLE
a~matnr
a~pstyv
b~bmeng
b~vrkme
INTO (lv_matnr,
lv_pstyv,
lv_bmeng,
lv_vrkme)
FROM vbap AS a INNER JOIN vbep AS b
ON a~vbeln = b~vbeln
AND a~posnr = b~posnr
WHERE a~vbeln = lt_hdr-vbeln
AND a~posnr EQ co_posnr
AND a~pstyv IN gr_pstyv
* Use zshowitem to identify items for display on SO
lv_convvl = 1.
* Convert Quantity
PERFORM check_conversion USING: lv_bmeng
listing-total_uom
lv_pstyv
lv_vrkme
lv_matnr. "<<CR002-DEVK944861 ins
IF listing-total_uom IS INITIAL.
MOVE lv_vrkme TO listing-total_uom.
ENDIF.
IF listing-total_uom IS INITIAL.
MOVE lv_vrkme TO listing-total_uom.
ENDIF.
vl_sum1 = vl_sum1 + lv_bmeng.
* ENDLOOP.
listing-total_qty = vl_sum1.
REFRESH lv_itab.
CLEAR: vl_sum1,
vl_sum2.
* Scheduling Agreement Item and Served Qty
SELECT SINGLE
b~vbeln AS vbeln2
b~rfmng
b~meins
INTO (lv_vbeln2,
lv_rfmng,
lv_meins)
FROM vbap AS a INNER JOIN vbfa AS b
ON a~vbeln EQ b~vbelv
AND a~posnr EQ b~posnv
WHERE a~vbeln = lt_hdr-vbeln
AND a~pstyv IN gr_pstyv
AND b~vbtyp_n EQ co_vbtyp_n.
IF sy-subrc EQ 0.
* Goods Issue Status per Item
SELECT SINGLE wbstk
FROM vbuk
INTO vl_drstatus
WHERE vbeln = lv_vbeln2.
* Convert Quantity
PERFORM check_conversion USING: lv_rfmng
listing-served_uom
lv_pstyv
lv_meins
lv_matnr. " <<CR002-DEVK944861 ins
* Pass Value
IF listing-served_uom IS INITIAL.
MOVE lv_meins TO listing-served_uom.
ENDIF.
vl_served_qty = vl_served_qty + lv_rfmng.
CLEAR: lt_scheditm,
vl_drstatus,
vl_sum3,
vl_meins.
ENDIF.
listing-served_qty = vl_served_qty.
CLEAR vl_served_qty.
* Append List
APPEND listing.
CLEAR: lt_hdr,
lv_itab,
lt_scheditm,
listing,
vl_datum1,
vl_datum2,
vl_sum1,
vl_sum2,
vl_sum3.
ENDLOOP.
IF sy-subrc <> 0.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = 'W'
cl = 'ZECOM'
number = 000
IMPORTING
return = return.
ELSE.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = 'S'
cl = 'ZECOM'
number = 001
IMPORTING
return = return.
ENDIF.
ENDFUNCTION.As mentioned by others avoid into corresponding fields.
If you have to join vbak/vbkd then at least try to use
Sales Organization
Distribution Channel
Division
FOr customer name do n ot select for each document, select for all entries in lt_hdr_aux before the loop where lt_hdr_aux[] = lt_hdr[] with adjacent duplicates by customer deleted and then in the loop use read instead.
Don't use inner joins on vbap to other tables instead select vbap information for all documents selected and then read.
etc etc
Use st05 to review which table accesses are giving you a problem and concentrate first on those taking into account
- not to retrieve data multiple times e.g. is customer is cust1 for deoc1 and for doc 10 then only retrieve once as detailed above.
- optimise the actual select statement - no into corresponding, using keys etc -
Short code snippet uses a lot of CPU. Suggestions on how to optimize?
What I want to do is to ping a specified address after a specified delay, and then extract the delay and store it in a comma-separated file (optimally along with a timestamp). I could not find any way to make the delay with the ping command in windows XP, so I created a Timer for the task. The program does the trick, but the CPU usage jumps to about 50% when running the application. I'm kind of new to Java, and don't know all the do's and don'ts of threads and infinite loops. Any suggestion to how to optimize the code would be appreciated.
package WitelcomMonitor;
import java.io.*;
import java.util.Timer;
import java.util.TimerTask;
public class WitelcomMonitor {
Timer timer = new Timer(true);
int counter;
public WitelcomMonitor(long delay){
timer.schedule(new TaskPerformer(), 0, 5000);
class TaskPerformer extends TimerTask{
public void run(){
try {
String line;
String[] command = {"ping", "-n","3", "123.12.12.1"};
Process p = Runtime.getRuntime().exec(command);
boolean append = true;
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("delayprofile.txt",append)));
String subline;
int indexEnd,indexStart;
while ((line = input.readLine()) != null) {
if(line.contains("TTL")){
counter++;
indexStart = indexEnd = line.indexOf("ms");
do {
indexStart--;
} while (line.charAt(indexStart)!='=');
subline = line.substring(indexStart+1,indexEnd);
out.print(subline.concat(","));
System.out.println(subline.concat(","));
//System.out.println(counter);
input.close();
out.close();
catch (Exception err) {
err.printStackTrace();
public static void main(String[] args){
long delay = 5000; //milliseconds
new WitelcomMonitor(delay);
while(true);
}Ok, so the while(true) statement by itself drains the CPU, while by asking the main thread to sleep in ten seconds intervals just to sleep again for ten seconds etc. will keep the load on the computer low. Yeah, it worked so I'm happy. I'm not sure though how I can avoid a new thread, as I have to extend TimerTask which requires that I override the run() method. This in turn causes a thread to be run in addition to the main thread. How do you suggest that I avoid this?
-
Time limit error no matter what optimization I do...
Hello Experts,
I am trying to optimize the code below since it always results in time limi error when we transport
it to production server. I have tried eliminating some select inside the loop and using for all entries
but it still gets the error. Anyway, below is the code and I hoe you can help me out on this one guys.
Thank you and take care!
LOOP AT lt_vbap ASSIGNING <wa_vbap>.
IF <wa_vbap>-auart EQ 'ZUCI' OR
<wa_vbap>-auart EQ 'ZURV' OR
<wa_vbap>-auart EQ 'ZUPR'.
Check if a delivery document has been created
CLEAR wa_vbill. "used wa_vbfa-vbeln instead of wa_vbill
*Start of modification - AVH - 04/11/07
*/ Used read table instead of fetching records from database every loop
SELECT SINGLE vbeln
FROM vbfa
INTO wa_vbill
WHERE vbelv = <wa_vbap>-vbeln
AND ( ( vbtyp_n EQ 'J' AND vbtyp_v = 'C' )
OR ( vbtyp_n EQ 'T' AND vbtyp_v = 'H' ) ).
CLEAR wa_vbfa.
READ TABLE lt_vbfa INTO wa_vbfa WITH KEY vbelv = <wa_vbap>-vbeln
vbtyp_n = 'J'
vbtyp_v = 'C'
BINARY SEARCH
TRANSPORTING vbeln.
IF sy-subrc <> 0.
READ TABLE lt_vbfa INTO wa_vbfa WITH KEY vbelv = <wa_vbap>-vbeln
vbtyp_n = 'T'
vbtyp_v = 'H'
BINARY SEARCH
TRANSPORTING vbeln.
ENDIF.
*End of modification - AVH - 04/11/07
IF sy-subrc <> 0.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ELSE.
Check if within selection parameters
CLEAR wa_likp.
*Start of modification - AVH - 04/11/07
READ TABLE lt_likp INTO wa_likp WITH KEY vbeln = wa_vbill.
READ TABLE lt_likp INTO wa_likp WITH KEY vbeln = wa_vbfa-vbeln.
*End of modification - AVH - 04/11/07
*Start of modification - AVH - 04/11/07
*/ Used wa_vbfa instead of variable wa_vbill
IF sy-subrc <> 0.
SELECT SINGLE *
FROM likp
INTO wa_likp
WHERE vbeln = wa_vbill.
SELECT SINGLE *
FROM likp
INTO wa_likp
WHERE vbeln = wa_vbfa-vbeln.
*End of modification - AVH - 04/11/07
APPEND wa_likp TO lt_likp.
ENDIF.
IF NOT wa_likp-wadat_ist IN s_erdat.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
ENDIF.
ELSE.
Check if this has already been billed
CLEAR wa_vbill. "Used wa_vbfa instead of wa_vbill
*Start of modification - AVH - 04/11/07
*/ Used read table instead of fetching records from database every loop
SELECT SINGLE vbeln
FROM vbfa
INTO wa_vbill
WHERE vbelv = <wa_vbap>-vbeln
AND ( ( vbtyp_n EQ 'M' AND vbtyp_v = 'C' )
OR ( vbtyp_n EQ 'O' AND vbtyp_v = 'H' ) ).
CLEAR wa_vbfa.
READ TABLE lt_vbfa INTO wa_vbfa WITH KEY vbelv = <wa_vbap>-vbeln
vbtyp_n = 'M'
vbtyp_v = 'C'
BINARY SEARCH
TRANSPORTING vbeln.
IF sy-subrc <> 0.
READ TABLE lt_vbfa INTO wa_vbfa WITH KEY vbelv = <wa_vbap>-vbeln
vbtyp_n = 'O'
vbtyp_v = 'H'
BINARY SEARCH
TRANSPORTING vbeln.
ENDIF.
*End of modification - AVH - 04/11/07
IF sy-subrc <> 0.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ELSE.
Check if within selection parameters
CLEAR wa_vbrk.
*Start of modification - AVH - 04/11/07
*/ Used wa_vbfa instead of variable wa_vbill.
READ TABLE lt_vbrk INTO wa_vbrk WITH KEY vbeln = wa_vbill.
READ TABLE lt_vbrk INTO wa_vbrk WITH KEY vbeln = wa_vbfa-vbeln.
IF sy-subrc <> 0.
SELECT SINGLE vbeln fkdat
FROM vbrk
INTO wa_vbrk
WHERE vbeln = wa_vbill.
APPEND wa_vbrk TO lt_vbrk.
SELECT SINGLE vbeln fkdat
FROM vbrk
INTO wa_vbrk
WHERE vbeln = wa_vbfa-vbeln.
APPEND wa_vbrk TO lt_vbrk.
ENDIF.
*End of modification
IF NOT wa_vbrk-fkdat IN s_erdat.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
ENDIF.
ENDIF.
Get Material Type and Division
IF <wa_vbap>-spart IS NOT INITIAL.
SELECT SINGLE mtart
FROM mara
INTO lv_mtart
WHERE matnr = <wa_vbap>-matnr.
ELSE.
SELECT SINGLE mtart spart
FROM mara
INTO (lv_mtart,<wa_vbap>-spart)
WHERE matnr = <wa_vbap>-matnr.
ENDIF.
If material division is same as parameter division
IF <wa_vbap>-spart = p_spart.
If material is subsidiary-owned
IF <wa_vbap>-spart in lr_spart.
If customer is the same as that of parameter division
IF <wa_vbap>-kunnr NE lr_kunnr OR <wa_vbap>-auart EQ 'ZUDO' OR <wa_vbap>-auart EQ 'ZUS3'.
If item is a free good, tag order type as 'ZUPR' to treat
the item the same way as 'ZUPR'
IF <wa_vbap>-pstyv = 'TANN' OR
<wa_vbap>-pstyv = 'ZKNF' OR
<wa_vbap>-pstyv = 'ZKNN' OR
<wa_vbap>-pstyv = 'ZFLO' OR
<wa_vbap>-pstyv = 'ZKBF' OR
<wa_vbap>-pstyv = 'ZKLN' OR
<wa_vbap>-pstyv = 'ZREN'.
lv_auart = <wa_vbap>-auart.
IF lv_auart EQ 'ZUPR'.
CLEAR <wa_vbap>-pstyv.
ENDIF.
<wa_vbap>-auart = 'ZUPR'.
CLEAR: lv_mtart.
ENDIF.
Set Cost of Goods Sold Account
<wa_vbap>-cogshkont = '0050000010'.
CASE <wa_vbap>-auart.
WHEN 'ZUDO' OR 'ZUPR' OR 'ZUCI'.
IF p_rtrns EQ 'X'.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
WHEN 'ZURD'.
IF p_issue EQ 'X'.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
WHEN OTHERS.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDCASE.
CASE <wa_vbap>-auart.
WHEN 'ZUPR'.
CASE lv_mtart.
WHEN 'ZUL4'.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
WHEN OTHERS.
Check if division is defined in mapping table
READ TABLE lt_ulsub INTO wa_ulsub
WITH KEY spart = <wa_vbap>-spart.
IF sy-subrc = 0.
<wa_vbap>-kostl = wa_ulsub-kostlp.
<wa_vbap>-bukrs = wa_ulsub-bukrsp.
<wa_vbap>-type = 'TP'.
Set Cost of Goods Sold Account
IF lv_auart = 'ZUPR'.
<wa_vbap>-cogshkont = '0050000006'.
ENDIF.
ELSE.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
ENDCASE.
WHEN 'ZUCI' OR 'ZUDO' OR 'ZURD' OR 'ZUS3'.
Get cost center from header text
PERFORM get_cost_center USING <wa_vbap>-vbeln
CHANGING <wa_vbap>-kostl.
* Change by LGTE 11-02-2006
Check if Medvale sales
IF <wa_vbap>-auart EQ 'ZUCI' AND <wa_vbap>-kostl IS INITIAL.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
Check if UL Cost Center
ELSEIF <wa_vbap>-kostl NE gv_ul_kostl.
IF <wa_vbap>-kostl NE gv_ul_kostl.
* End change.
Get material division and check if subsidiary product
SELECT SINGLE spart FROM mara INTO <wa_vbap>-spart
WHERE matnr = <wa_vbap>-matnr.
READ TABLE lt_ulsub INTO wa_ulsub
WITH KEY spart = <wa_vbap>-spart.
IF sy-subrc = 0.
Get requestor's company code from cost center data
SELECT SINGLE bukrs
FROM csks
INTO <wa_vbap>-bukrs
WHERE kokrs = lc_kokrs
AND kostl = <wa_vbap>-kostl
AND datbi GE sy-datum
AND datab LE sy-datum.
IF sy-subrc = 0.
For donations, only include if a subsidiary company is donating
IF <wa_vbap>-auart EQ 'ZUDO' OR <wa_vbap>-auart EQ 'ZUS3'.
IF NOT <wa_vbap>-kunnr IN lr_kunnrnt.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
CHECK <wa_vbap>-kunnr IN lr_kunnrnt.
ENDIF.
For ZUCI, if the company code of the costcenter is UL, do not include
IF <wa_vbap>-bukrs EQ gc_ul_bukrs.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
IF <wa_vbap>-bukrs = wa_ulsub-bukrsp.
<wa_vbap>-type = 'RV'.
ELSE.
<wa_vbap>-type = 'RV'.
ENDIF.
ELSE.
Check if customer defined in table ZFI_DONATIONS
SELECT SINGLE kunnr FROM zfi_donations INTO <wa_vbap>-kostl
WHERE kunnr = <wa_vbap>-kostl.
IF sy-subrc <> 0.
lv_error = 'X'.
CONCATENATE 'Cost center/Customer' <wa_vbap>-kostl
'does not exist. Please check Sales Order'
<wa_vbap>-vbeln
INTO lt_disp-message SEPARATED BY space.
lt_disp-type = 'E'.
<wa_vbap>-del_ind = 'X'.
APPEND lt_disp.
CONTINUE.
ELSE.
<wa_vbap>-type = 'RV'.
ENDIF.
ENDIF.
ELSE.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
ELSE.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
WHEN OTHERS.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDCASE.
ELSE.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
ELSE.
<wa_vbap>-del_ind = 'X'.
CONTINUE.
ENDIF.
Get company code description
SELECT SINGLE butxt
FROM t001
INTO <wa_vbap>-butxt
WHERE bukrs = <wa_vbap>-bukrs.
IF sy-subrc <> 0.
SELECT SINGLE name1
FROM kna1
INTO <wa_vbap>-butxt
WHERE kunnr = <wa_vbap>-kostl.
ENDIF.
Change by LGTE on 11-02-2006
Get Transaction Type
CASE <wa_vbap>-auart.
WHEN 'ZUPR'. "UL Promo/Samples
IF <wa_vbap>-pstyv = 'TANN' OR
<wa_vbap>-pstyv = 'ZKNF' OR
<wa_vbap>-pstyv = 'ZKNN' OR
<wa_vbap>-pstyv = 'ZFLO' OR
<wa_vbap>-pstyv = 'ZKBF' OR
<wa_vbap>-pstyv = 'ZKLN' OR
<wa_vbap>-pstyv = 'ZREN'.
<wa_vbap>-ltext = 'Free Goods'.
ELSE.
<wa_vbap>-ltext = 'Product Samples'.
ENDIF.
WHEN 'ZUDO'. "Donations - R/3
<wa_vbap>-ltext = 'Donations - R/3'.
WHEN 'ZUCI'. "Donations - ZUCI
<wa_vbap>-ltext = 'Donations - ZUCI'.
WHEN 'ZURD' OR 'ZUS3'. "UL Returns - Donation
<wa_vbap>-ltext = 'UL Returns - Donation'.
ENDCASE.
Get cost center description
SELECT SINGLE ltext FROM cskt INTO <wa_vbap>-ltext
WHERE spras = sy-langu
AND kokrs = lc_kokrs
AND kostl = <wa_vbap>-kostl
AND datbi GE sy-datum.
End of change.
Get material description
SELECT SINGLE maktx
FROM makt
INTO <wa_vbap>-maktx
WHERE matnr = <wa_vbap>-matnr
AND spras = sy-langu.
Get division from material master
SELECT SINGLE spart FROM mara INTO <wa_vbap>-spart
WHERE matnr = <wa_vbap>-matnr.
Get division description
SELECT SINGLE vtext
FROM tspat
INTO <wa_vbap>-vtext
WHERE spras = sy-langu
AND spart = <wa_vbap>-spart.
Get Valuation Class
SELECT SINGLE bklas
FROM mbew
INTO lv_bklas
WHERE matnr = <wa_vbap>-matnr.
Determine G/L of FG Based on Valuation Class
READ TABLE lt_val_cls INTO wa_val_cls WITH TABLE KEY bklas = lv_bklas.
<wa_vbap>-fghkont = wa_val_cls-hkont.
Determine Cost Center of Cogs Account
READ TABLE lt_ulsub INTO wa_ulsub WITH TABLE KEY spart = <wa_vbap>-spart.
<wa_vbap>-cogskostl = wa_ulsub-kostlp.
ENDLOOP. "ENDLOOPHi,
Hopefully it can help you:
1. Try remove all SELECT statement within LOOP, replace with select all data before LOOP using For ALL ENTRIES.
2. Try use READ TABLE using BINARY SEARCH. Don't forget to SORT the table according your Search Key.
If it still couldn;t help, try run your report in background.
Regards, -
Performance optimization related.
Hi.
I am doing Performance optimization on code.
Actually, I am doing performance optimization for old code where it is of JDK1.4 related. I met up with a doubt when I optimize code for JDK1.5.
Problem statement:
Collection errors = new ArrayList();
errors.add(new GenericException(ErrorCodes.EMPLOYEE_INVALID_PERMISSION));
setErrorsInRequest(request, errors);In the above code the compiler tells us to Parameterize the Collection type reference. If we don't make any parameterization for Collection type, will that be dealing with Performace issue?
Please help me out to resolve the problem statement.
Thanks and regards,
Leslie V
www.googlestepper.blogspot.com
www.scrollnroll.blogspot.comIf we don't make any parameterization for Collection type, will that be dealing with Performace issue?No. Not really. But performance isn't really the issue... it's runtime-type-safety which is at issue. There's nothing to prevent me from adding an Integer (like an error number) to your collection of exceptions.
And "GenericException"... Sheesh, come down from the trees allready. WTF am I (the user of this class/method/package) supposed to with a friggin "GenericException"... you may as well have thrown a raw RuntimeException and saved all that cumbersom interveening try/catch code. -
Optimization problems in downloading data of greater size from any URL.
Hi everyone !
I'm trying to download some resource from the internet by providing valid URL. My code takes almost 50-55 minutes to download. The same resource is downloaded within 3-5 minutes by using Internet Explorer and 3-4 minutes using Fire Fox at the same network and Kbps. The sample code is as under:
//I'm using apache's HTTP APIs
public static String url = "http://www.sk.ee/crls/esteid/esteid.crl"; //file size is approx: 10 MB
//httpMethod is instance of HttpMethodBase and I have initialized it with GET method
obj_httpMethod = new GetMethod( obj_httpUrl.getEscapedURI()
InputStream obj_is = obj_httpMethod.getResponseBodyAsStream();
ByteArrayOutputStream obj_data = new ByteArrayOutputStream();
//above code is working fine and giving proper input stream got from response.
//problem start from here....although this code is working ok but it is not optimized
//Is there any way to optimize the code
MyHttpTransporter.copyStream(obj_is, obj_data, 524288); //Buffer Size: 512K [512*1024]
//This method is working fine with files of small sizes but it is not doing well with greater file sizes e.g. 10MB
public static void copyStream(InputStream a_objIs, OutputStream a_objOs,
int a_iblockSize) throws Exception{
System.out.println( "Buffer Size..: " + a_iblockSize);
byte [] byte_Buffer = new byte[a_iblockSize];
int i_byteRead = -1;
while ( (i_byteRead = a_objIs.read(byte_Buffer, 0, a_iblockSize)) > -1) {
System.out.println( "reading stream...." );
a_objOs.write(byte_Buffer, 0, i_byteRead);
System.out.println( "writing stream...." );
System.out.println( i_byteRead );
System.out.println( i_byteRead );
The one thing found in the above code is that, it is ignoring my provided buffer size and always fetching max 2047 bytes from the resource.
Please help me in this regard as I'm unable to progress further in it.
br,
KSASC_KS wrote:
Thanx for the help.
It makes some difference.
the sample code is:
//iblockSize = 524288 [512K]
//1
BufferedInputStream bis = new BufferedInputStream(a_objIs, a_iblockSize);
BufferedOutputStream bos = new BufferedOutputStream(a_objOs, a_iblockSize);
//2
BufferedInputStream bis = (BufferedInputStream)a_objIs;
BufferedOutputStream bos = (BufferedOutputStream)a_objOs;
//what do you suggest 1 or 2 ? BTW I'm using 1
If (2) works then behind the scenes the Apache code is already using Buffered streams (otherwise you would get a class cast exception) so there is going to be little advantage to using further buffering. Also, casting to buffered streams does not offer any performance advantage since any reading/writing you do will already be using the methods on the Buffered streams.
Do I need to concentrate on the block size [reduce or increase what is good practice]. Because again it is fetching maximum 5387B and on average it is fetching the 2047B. But it is improved a little bit.Though the buffer size of the Buffered streams can be set when constructed they cannot be changed later so if the Apache code is not setting the buffer size when it constructs the buffer then you are stuffed. Check the Apache documentation to see if you can change the buffering.
P.S. Of course, since it is open source, you can always modify the Apache code to increase the buffer size.
P.P.S. I always use HttpURLConnection for this and it seems pretty quick though I have never downloaded anything beyond a few hundred KBytes.
Edited by: sabre150 on Nov 21, 2007 11:18 AM -
Hi Guys,
The following code seems to be taking considerable time in production. Is there a better way to optimize theis code.
LOOP AT I_T_DATA...
SELECT SINGLE BUKRS
INTO (l_bukrs)
FROM T001K
WHERE T001K~BWKEY = I_T_DATA-WERKS.
SELECT SINGLE TARGET1 TARGET2
INTO (l_salesorg, l_dischan)
from ZDERIV
where VALID_FROM le sy-datum
and SOUR3_FROM le I_T_DATA-prctr
and SOUR3_TO ge I_T_DATA-prctr
and SOUR2_FROM le l_bukrs
and SOUR2_TO ge l_bukrs
and SOUR1_FROM = 'C100'
and SOUR1_TO = 'C100'.
CASE sy-subrc.
when 0.
SELECT SINGLE PRODH
INTO I_T_DATA-zzPRODH
from mvke
where matnr eq I_T_DATA-matnr
and vkorg eq l_salesorg
and vtweg eq l_dischan.
WHEN 4.
Clear: l_salesorg, l_dischan.
ENDCASE.
Thanksu don't use select statements in side the loop...cause suppoer ur internal table wch is used for loop has 1000 records..and the table wch is used inside the loop T001w had 500 records..
on the database hitting is for I_T_DATA is 1000(for example)
1000*500 = 500000... total 1000+500000see hw many times is...for avoid this one u first select the data form db and put into 1 intenal table ...( so it is comes to ur local buffer)..by using this interal table we can use read statement in side the loop...here no data base hitiing...
here the total db hittings : for I_T_DATA: 1000
T001w is 500
Total is 1500.....see the diffrence...
see the code below:
select bukrs into i_too1 for all entries in I_T_DATA where bwkey = I_T_DATA-werks.
SELECT SINGLE TARGET1 TARGET2
INTO table i_ZDERIV----
here it has fields as target1 and target2
from ZDERIV
for all entries in l_i_data
where VALID_FROM le sy-datum
and SOUR3_FROM le I_T_DATA-prctr
and SOUR3_TO ge I_T_DATA-prctr
and SOUR1_FROM = 'C100'
and SOUR1_TO = 'C100'.
after this..
loop at I_T_DATA into wa_t_data.
read table i_t001w into wa_too1w with key bukrs = wa_i_data-werks.
read table i_ZDERIV
into wa_ZDERIV
and SOUR3_FROM le wa_i_DATA-prctr
and SOUR3_TO ge wa_i_DATA-prctr
and SOUR2_FROM le wa_t001w-bukrs
and SOUR2_TO ge wa_t001w-bukrs
with key bukrs = wa_t_data-werks.
here the value of bukrs in wa_t001w-bukrs...
endloop.
inside the loop we can check the sy-subrc's...
i thnk it is useful for u...please give me rely hw it is woking...
Maybe you are looking for
-
Steps to load the data by using flat file for hierarchies in BI 7.0
Hi Gurus, steps to load the data by using flat file for hierarchies in BI 7.0
-
New User Help Needed Formatting External HD in MS-DOS for PC file migration
I have files on my PC and planned on putting them on a new external HD to transfer to the iMac. I have a new MiniStack V3 external HD with USB and Firewire connections. It comes formatted for the Mac. I want to format the HD on the iMac to MS-DOS so
-
How to see what is in the "other" file on itunes
I updated my iPhone about a week ago, and all my pictures got synced to itunes and of my iPhone. I cant find any of these pictures on i tunes or on my laptop. I think they are somewhere in the "other" folder on itunes, but I just dont know how to ope
-
How to configure Appointment, Phone Calls,Task and Emails
HI All, I have requirement to build the Appointment, Task, Phone Calls and Emails as in the standard. Same like it is available in the Opportunity Sales Activity. Can you please suggest how to configure the same Thanks & Regards, Malkit Singh
-
Clicking on links in safari just gives a loading icon
I am using Yosemite 10.10.1 and ran into this problem just a few days ago. Whenever I click on a link, the mouse just changes to the loading icon and nothing on the page changes. This has happened when I click on anything on youtube, try to play a vi