Count of rows in a cursor
please help me with the function to count the number of rows in a cursor.
You can use %ROWCOUNT attribute as follows:
DECLARE
CURSOR C IS
SELECT 1 FROM DUAL;
BEGIN
FOR R IN C LOOP
DBMS_OUTPUT.Put_Line('%ROWCOUNT = ' || C%ROWCOUNT);
END LOOP;
END;
but if you want to have number of rows in a cursor BEFORE you fetch any rows from it - then sorry, no way. You can't have number of rows before you physically count them, i.e. read them from the disk in the first place. Think of tables with billions of rows...
file:///D:/Oracle10g_Docs/B12037_01/appdev.101/b10807/06_ora.htm#sthref800
Similar Messages
-
How to find total count of records in a cursor
Aassume below is the cursor i defined
cursor c1 is select * from emp;
now, i want to find the total count of records in this cursor using an existing function etc., using one line statement.
FYI: c1%rowcount is always giving 0, so i cant rely on this.
Any thoughts, please share.
Thanks in advance.I am just showing this to show how to get the rowcount along with the cursor, if the program has so much gap of between verifying the count(*) and opening the cursor.
Justin actually covered this, he said, oracle has to spend some resources to build this functionality. As it is not most often required, it does not makes much sence to see it as a built-in feature. However, if we must see the rowcount when we open the cursor, here is a way, but it is little bit expensive.
SQL> create table emp_crap as select * from emp where 1 = 2;
Table created.
SQL> declare
2 v_cnt number := 0;
3 zero_rows exception;
4 begin
5 for rec in (select * from (select rownum rn, e.ename from emp_crap e) order by 1 desc)
6 loop
7 if v_cnt = 0 then
8 v_cnt := rec.rn;
9 end if;
10 end loop;
11 if v_cnt = 0 then
12 raise zero_rows;
13 end if;
14 exception
15 when zero_rows then
16 dbms_output.put_line('No rows');
17 end;
18 /
No rows
PL/SQL procedure successfully completed.
-- Now, let us use the table, which has the data
SQL> declare
2 v_cnt number := 0;
3 zero_rows exception;
4 begin
5 for rec in (select * from
6 (select rownum rn, e.ename from emp e)
7 order by 1 desc)
8 loop
9 if v_cnt = 0 then
10 v_cnt := rec.rn;
11 dbms_output.put_line(v_cnt);
12 end if;
13 end loop;
14 if v_cnt = 0 then
15 raise zero_rows;
16 end if;
17 exception
18 when zero_rows then
19 dbms_output.put_line('No rows');
20 end;
21 /
14
PL/SQL procedure successfully completed.Thx,
Sri -
Get the number of rows in a cursor?
Currently I have a pretty simple stored procedure that builds some dynamic SQL then returns those results to some code.
I would like also to be able to return the number of rows in that cursor back to the Java code, how can I do this? Some sample SQL is shown below:
l_query := 'Select * from customer';
OPEN searchResults FOR l_query;
???? Select count(*) into totalResults from searchResults; ????
(^^This last row is the issue)
I need to return the varaible totalResults as the count
Thanks heaps!!Mark,
If I understand you correctly, what you desire cannot be done.
When Oracle opens a cursor, it doesn't know how many rows that cursor will return.
The only two options is either do a separate query to count the number of rows that the original query will return, or fetch all the rows and see how many you got.
I recall seeing an example of that in the JDBC sample code on the OTN Web site.
(But I'm too lazy to look for it for you.)
Good Luck,
Avi. -
Find number of rows in a cursor
How can i find how many rows are in a cursor. I have a situation if my cursor only retruns one row i return the data if it returns more then one row i will need to do additional select.
If you have logic like this
SELECT COUNT(*)
INTO l_cnt
FROM emp
WHERE deptno = p_deptno;
IF( l_cnt > 1 )
THEN
FOR x IN (SELECT * FROM emp WHERE deptno = p_deptno)
LOOP
..where you are counting the rows and then later fetching them, getting the count and then getting the rows will force Oracle to do the work of the query twice. It will also potentially cause logic errors because the number of rows returned by the COUNT(*) won't necessarily match the number of rows fetched from the cursor because some other session may have committed changes between your session executing those two statements.
Can you describe the logic you are trying to implement in a bit more detail? There are potentially a number of different approaches depending on exactly what you are trying to do. Sometimes it may make sense to do a COUNT(*), sometimes it may make sense to fetch the data into a collection, count the collection elements, and then operate on the collection, sometimes it may make sense to do a SELECT INTO and handle the exception if the wrong number of rows are returned, etc.
Justin -
Hi,
I have a procedure doing paging and returning the count of rows:
As you see I used 2 select, one for paging and one for getting total row counts.
Is there a way to get rid of "SELECT count(*) into PO_TOTAL FROM TABLE1;"?
CREATE OR REPLACE PACKAGE BODY MYPACKAGE AS
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE SP_PAGING
PI_STARTID IN NUMBER,
PI_ENDID IN NUMBER,
PO_TOTAL OUT NUMBER,
CUR_OUT OUT T_CURSOR
IS
BEGIN
OPEN CUR_OUT FOR
SELECT *
FROM (SELECT row_.*, ROWNUM rownum_
FROM (
SELECT column1, column2, column3 FROM TABLE1
) row_
WHERE ROWNUM <= PI_ENDID)
WHERE rownum_ >= PI_STARTID;
SELECT count(*) into PO_TOTAL FROM TABLE1;
END SP_PAGING;
END MYPACKAGE;Yes, I can reproduce that:
SQL> create table emp1 as select * from emp
2 /
Table created.
SQL> exec dbms_stats.gather_table_stats('SCOTT','EMP1');
PL/SQL procedure successfully completed.
SQL> EXPLAIN PLAN FOR
2 SELECT ename,
3 job,
4 sal,
5 cnt
6 FROM (
7 SELECT ename,
8 job,
9 sal,
10 count(*) over() cnt,
11 row_number() over(order by 1) rn
12 FROM emp1
13 )
14 WHERE rn BETWEEN 4 AND 9;
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 1444408506
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 728 | 4 (25)| 00:00:01 |
|* 1 | VIEW | | 14 | 728 | 4 (25)| 00:00:01 |
| 2 | WINDOW BUFFER | | 14 | 252 | 4 (25)| 00:00:01 |
| 3 | TABLE ACCESS FULL| EMP1 | 14 | 252 | 3 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
1 - filter("RN">=4 AND "RN"<=9)
15 rows selected.
SQL> EXPLAIN PLAN FOR
2 SELECT *
3 FROM (SELECT row_.*, ROWNUM rownum_
4 FROM (
5 SELECT ename,job,sal, count(*) over() FROM emp1
6 ) row_
7 WHERE ROWNUM <= 9)
8 WHERE rownum_ >= 4;
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 519025698
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 9 | 468 | 2 (0)| 00:00:01 |
|* 1 | VIEW | | 9 | 468 | 2 (0)| 00:00:01 |
|* 2 | COUNT STOPKEY | | | | | |
| 3 | VIEW | | 9 | 351 | 2 (0)| 00:00:01 |
| 4 | WINDOW BUFFER | | 9 | 162 | 2 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL| EMP1 | 9 | 162 | 2 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
1 - filter("ROWNUM_">=4)
2 - filter(ROWNUM<=9)
18 rows selected.
SQL> However, you interpreted it incorrectly. Your query will still fetch all rows in TABLE1. Optimizer is smart enough to stop creating window buffer after 9 rows and that is what you see 9 in explain plan, while my query builds 14 row window buffer and then filters. So your query will be a bit faster.
SY.
Edited by: Solomon Yakobson on Jan 25, 2009 2:51 PM -
Count of rows from different tables.
Hi Friends,
I have 4 tables with a common column name "ID". I would like to get the count of rows from all the four tables which has the same ID.
Ex
select count(a.id) from table1 a,table2 b,table3 c,table4 d where a.id=b.id=c.id=d.id=5;
please suggest me some solutionmay be thsi?
select count(a.id) from table1 a,table2 b,table3 c,table4 d
where a.id=b.id and a.id=c.id and a.id=d.id and a.id=5; -
Hi There,
I am trying to create a measure in cube browser which will return count of rows of a table. If there are some rows, it returns correct result but in other case if table is empty, it returns nothing.
I want to return 0 in later case.
Please advise.You could create a Measure with code. Something like this, it is made in AdventureWorks2014.
CREATE MEMBER CurrentCube.Measures.[Count Rows Dimension] AS
CoalesceEmpty(COUNT([Customer].[Customer].[Customer]),0),
Associated_Measure_Group = 'Measure Group you want it associated to'; -
Hi ,
I want to find count of rows of a particular data set in a table expression. How to do that? Can you please help me out.
Thanks
susheel
sushHi Dimant,
I used countrows. If the dataset set contains 12 rows I am getting the o/p as shown below. I just need one row. Can please help me out.
Thanks
sush -
Count the rows in a list-component
Hi,
How can I count the rows with a value in a list component?
I thought it would be RowCount but as I figured out that shows the number of shown rows, not the number of rows with a value.Hi,
Try list.dataProvider.length -
Count of rows of a table in header
Hi Experts,
I am stuck in a tricky scenario.
I need to get the count of rows of a table in a webi report in the header of the report.
And the count should change dynamically according to the filtering done on the table.
For eg.
If I have 10 countries in a table, so table has 10 rows.
Now the count on header should show 10.
Now if we filter the column to 5 countries, the count on the header should change to 5.
Any Idea's.
Regards,
GauravNops
It doesn't work.
Let me reframe my issue again:
I dragged country object on my report.
UK
US
JAPAN
CANADA
Now lets say in the report title, I write the formula as =Count(country)
It will give me 4.
Now I clicked on the column country and applied filter i.e. country = US ; UK
Now the block shows
UK
US
In the header the cell still shows 4, which I want to see as 2.
Any ideas....?
Thanks
Gaurav -
Calculating a count of rows where value matches another column value in the same table
Hi,
I'm struggling to do something in DAX that seems to me should be super easy (coming from a SQL world)!
That is to count all rows in column 1 where the value matches the current value for column 1?
E.g something like this:
[Col2]=Count of rows in [Col1] where value = this.[Col1]
Where the results are as in the table below:
Col1, Col2
A, 2
A, 2
B, 1
Anyone?
Martin Laukkanen
Nearbaseline blog - nearbaseline.com/blog
Bulk Edit and other Apps - nearbaseline.com/appsThanks, that's perfect!
I knew it had to be something so simple, but after spending over an hour banging my head against those exact functions I couldn't get anything working!
Martin Laukkanen
Nearbaseline blog - nearbaseline.com/blog
Bulk Edit and other Apps - nearbaseline.com/apps -
How to get count of rows for a table?
Hi,
How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
Regards,
DevashishHi Devashish,
WdContext.node<Your_node_name>().size() will give you the no: of rows.
This should be the node that is bound to the table's datasource property.
WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
You can access an attribute of a particular row as
WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
Hope this helps,
Best Regards,
Nibu.
Message was edited by: Nibu Wilson -
Count all rows of a Database table
I want to count all the rows of a table.
I have made correctly the connection with the database and all the other things (make a statement, make the query and the resultSet), I use the MySQL server v4.0.17
Here is the code I use:
int count=0;
String temp=null;
String query = "SELECT COUNT(*) FROM customers";//customers is my Database Table
try {
rs = stmt.executeQuery(query);
}//end try
catch(Exception exc) {
createFeatures.PlayErrorSound(registerRenter);
Optionpane.showMessageDialog(registerRenter,
"MESSAGE", "ERROR", JOptionPane.ERROR_MESSAGE);
}//end catch
try {
while(rs.next()) {
count++; //I use this variable in order to count the rows because the resultSet doesn't tell me the answer
countLine=rs.getInt(1);
}//end while
}//end try
catch(Exception exc) {
createFeatures.PlayErrorSound(registerRenter);
Optionpane.showMessageDialog(registerRenter,
"MESSAGE", "ERROR", JOptionPane.ERROR_MESSAGE);
}//end catch
count=count++; //i increase it aggain because if the rows are initial 0 i want to make it 1
temp = String.valueOf(count);//i use this command in order to display the result into a jtextfield
Any help is appreciated!!!!!This program will work just fine against mysql:
mport java.util.*;
import java.io.*;
import java.sql.*;
public class Test {
public static void main(String []args) {
String url= "jdbc:mysql://localhost/adatabase";
String query = "select count(*) from foo2";
String createQuery="create table foo2(f1 int)";
String dropQuery="drop table foo2";
String insertQuery="insert into foo2 values(1)";
Properties props = new Properties();
props.put("user", "auser");
props.put("password", "xxxxx");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Connecting to the msql server");
Connection con = DriverManager.getConnection(url, props);
Statement stmt = con.createStatement();
try {
stmt.executeUpdate(dropQuery);
} catch(SQLException e) {}
stmt.executeUpdate(createQuery);
stmt.executeUpdate(insertQuery);
stmt.executeUpdate(insertQuery);
PreparedStatement pstmt = con.prepareStatement(query);
System.out.println("***Executing a select");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
System.out.println("RowCount="+ rs.getString(1));
rs.close();
pstmt.close();
stmt.close();
con.close();
} catch(Exception e) {
System.out.println(e.getMessage());
} -
How do I check the number of rows in a CURSOR without a complete fetch,If the records exist it should return a REF cursor else it shouls say no records.
How can this be done%rowcount returns the number of rows fetched, not the number of rows returned by the query
1 DECLARE
2 CURSOR x IS SELECT ename FROM emp;
3 l_ename emp.ename%type;
4 BEGIN
5 OPEN x;
6 FETCH x INTO l_ename;
7 WHILE x%found
8 LOOP
9 dbms_output.put_line( x%rowcount );
10 FETCH x INTO l_ename;
11 END LOOP;
12* END;
SCOTT @ HP92 Local> /
1
2
3
4
5
6
7
8
9
10
11
12
13
14
PL/SQL procedure successfully completed.Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Hi!
I would like to get the count of rows in my ALV report . How to get the count of the rows ? Can anyone guide me in getting it dome please.
ThanksHi Gaddemmedi!
I am attaching the report as you had asked for. I have added the things you asked me to do and now I am getting the count on the top of the page. The problem is that though it shows me the count of the lines from the LAV report on top but when I try to filter the records in the report that count first of all dosent change and remain the same as the initial number of record though after filtering records reduce and over that the count lines keep on increasing I mean the count is shown in repeated lines afet lines. Kindly help please.
Thanks
*& Report ZSD_BILLING_HDR_TEXT_sum *
*& billing doc. and associated header text report *
*& CHANGE LOG *
*& jpoon 2007.08.03 Change request: DEVK905095 *
*& Move request: SD_1451_01 Requestor: Mona Fox *
*& FP14134 - original code. *
REPORT zsd_billing_hdr_text_sum MESSAGE-ID zsd NO STANDARD PAGE HEADING.
* For ALV usage
TYPE-POOLS: slis.
DATA: gs_layout TYPE slis_layout_alv,
tp_print TYPE slis_print_alv,
gt_sort TYPE slis_t_sortinfo_alv,
gt_events TYPE slis_t_event,
t_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
repid TYPE syrepid, " ABAP Program.
gt_list_top_of_page TYPE slis_t_listheader, " Top of page text.
alv_variant TYPE disvariant," Customize Disp. Variant
w_event type slis_alv_event.
DATA: w_field TYPE slis_fieldcat_alv.
TABLES: vbrk, vbrp, vbpa.
DATA SLIS_EV_AFTER_OUTPUT.
data: gs_list_top_of_page type slis_listheader.
*data: gt_list_top_of_page type slis_t_listheader.
* Definition of selection screen *
* By plant, storage location, sold-to customers, material and *
* posting date of the sales orders *
SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln, " billing doc.
s_kunnr FOR vbpa-kunnr, " bill-to customer number.
s_werks FOR vbrp-werks, " line item plant.
s_fkdat FOR vbrk-fkdat, " billing date.
s_fkart FOR vbrk-fkart, " billing type.
s_vkorg FOR vbrk-vkorg. " sales org.
PARAMETERS: p_hold AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK one.
* ALV display layout
SELECTION-SCREEN BEGIN OF BLOCK layout WITH FRAME TITLE text-003.
PARAMETERS: pa_vari TYPE slis_vari DEFAULT ' '. " Display variant.
SELECTION-SCREEN END OF BLOCK layout.
* Data Definitions *
* Storing Extracted Info.
TYPES: BEGIN OF t_extract,
vbeln TYPE vbeln_vf, " Sales order number.
posnr TYPE posnr, " line item
fkart TYPE fkart, " billing type.
vtext TYPE BEZEI20, " billing type description.
fkdat TYPE fkdat, " billing date.
werks TYPE werks_d, " line item plant.
werks_name1 TYPE name1, " plant description.
kunnr TYPE kunnr, " bill-to customer.
kunnr_name1 TYPE name1_gp, " bill-to description.
netwr TYPE netwr, " net value,invoice total $
zzflag TYPE boolean, " hold indicator
zzreason TYPE char30, " header text2 (reason)
zzuser TYPE ernam, " last changed by
zz_changed_date TYPE dats, " last changed date
zz_changed_time TYPE tims, " last changed time
END OF t_extract.
DATA: it_extract TYPE TABLE OF t_extract WITH HEADER LINE,
it_extract2 TYPE TABLE OF t_extract WITH HEADER LINE.
DATA: it_text TYPE TABLE OF tline WITH HEADER LINE.
DATA: wa_thead type thead.
DATA: w_tdname type TDOBNAME.
DATA: L_COUNT TYPE I.
* initialization
INITIALIZATION.
gs_layout-colwidth_optimize = 'X'.
tp_print-no_print_listinfos = 'X'.
tp_print-no_coverpage = 'X'.
PERFORM set_fieldcat.
PERFORM alv_eventtab_build USING:
** Event name Form to execute Event internal table
'TOP_OF_PAGE' 'TOP_OF_PAGE' gt_events[].
* Dropdown list for all created ALV layouts, global or user-specific
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_vari.
PERFORM alv_variant_f4 CHANGING pa_vari.
* Main BODY of processing logic
START-OF-SELECTION.
IF s_vbeln IS INITIAL
AND s_kunnr IS INITIAL
AND s_werks IS INITIAL
AND s_fkdat IS INITIAL
AND s_fkart IS INITIAL
AND s_vkorg IS INITIAL.
MESSAGE i000 WITH text-037 ' ' ' ' ' '.
ELSE.
PERFORM extract_data.
ENDIF.
END-OF-SELECTION.
IF it_extract2[] IS INITIAL.
MESSAGE i000 WITH text-002 ' ' ' ' ' '.
ELSE.
* Build headings for report.
* PERFORM build_top_of_page USING gt_list_top_of_page[].
* describe table it_extract2 lines l_count.
*write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
PERFORM call_alv.
*write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
ENDIF.
*& Form EXTRACT_KEY_DATA
* Retreive the data for the report.
FORM extract_data.
CLEAR: it_extract. REFRESH: it_extract.
* read and select billing documents
IF p_hold IS INITIAL.
SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
vbrk~zzflag vbrk~zzreason vbrk~zzuser
vbrk~zz_changed_date vbrk~zz_changed_time
vbrp~posnr vbrp~werks
INTO CORRESPONDING FIELDS OF TABLE it_extract
FROM vbrk INNER JOIN vbrp ON
vbrk~vbeln = vbrp~vbeln
WHERE vbrk~vbeln IN s_vbeln
AND vbrk~fkart IN s_fkart
AND vbrk~fkdat IN s_fkdat
AND vbrk~vkorg IN s_vkorg
AND vbrk~fksto NE 'X'
AND vbrp~werks IN s_werks.
ELSE.
* read 'held' documents only as per selection
SELECT vbrk~vbeln vbrk~fkart vbrk~fkdat vbrk~netwr
vbrk~zzflag vbrk~zzreason vbrk~zzuser
vbrk~zz_changed_date vbrk~zz_changed_time
vbrp~posnr vbrp~werks
INTO CORRESPONDING FIELDS OF TABLE it_extract
FROM vbrk INNER JOIN vbrp ON
vbrk~vbeln = vbrp~vbeln
WHERE vbrk~vbeln IN s_vbeln
AND vbrk~fkart IN s_fkart
AND vbrk~fkdat IN s_fkdat
AND vbrk~vkorg IN s_vkorg
AND vbrk~fksto NE 'X'
AND vbrk~zzflag = 'X'
AND vbrp~werks IN s_werks.
ENDIF.
IF sy-subrc <> 0.
MESSAGE i000 WITH text-002 ' ' ' ' ' '.
ENDIF.
CHECK sy-subrc = 0.
* only need first line item for this report.
SORT it_extract BY vbeln posnr.
DELETE ADJACENT DUPLICATES FROM it_extract COMPARING vbeln.
LOOP AT it_extract.
* Retrieve and select by sales order bill-to on header level
* as well as lookup bill-to customer name/description
SELECT SINGLE kunnr FROM vbpa INTO it_extract-kunnr
WHERE vbeln = it_extract-vbeln
AND posnr = '000000'
AND parvw = 'RE'.
IF it_extract-kunnr IN s_kunnr.
it_extract-kunnr_name1 = zcl_kna1=>get_name1( it_extract-kunnr ).
ELSE.
DELETE it_extract.
CONTINUE.
ENDIF.
* lookup billing type description
SELECT SINGLE vtext FROM tvfkt
INTO it_extract-vtext
WHERE spras = sy-langu
AND fkart = it_extract-fkart.
IF sy-subrc <> 0.
clear it_extract-vtext.
ENDIF.
* lookup plant description
SELECT SINGLE name1 FROM t001w
INTO it_extract-werks_name1
WHERE werks = it_extract-werks.
IF sy-subrc <> 0.
clear it_extract-werks_name1.
ENDIF.
MOVE-CORRESPONDING it_extract TO it_extract2.
APPEND it_extract2.
ENDLOOP.
describe table it_extract2 lines l_count.
ENDFORM. " EXTRACT_DATA
*& Form SET_FIELDCAT
* Create the field catalogue.
FORM set_fieldcat .
*CLEAR W_EVENT.
*W_EVENT-FORM = SLIS_EV_AFTER_OUTPUT.
*W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT.
*APPEND W_EVENT TO GT_EVENTS.
CLEAR w_field.
CLEAR t_fieldcat. REFRESH t_fieldcat.
w_field-col_pos = 1.
w_field-fieldname = 'ZZFLAG'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Hold Printing'(005).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 2.
w_field-fieldname = 'ZZREASON'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Reason'(036).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 3 .
w_field-fieldname = 'VBELN'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Billing Doc'(028).
w_field-emphasize = 'X'.
w_field-hotspot = 'X'.
APPEND w_field TO t_fieldcat.
CLEAR w_field.
w_field-col_pos = 4 .
w_field-fieldname = 'VTEXT'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Type Description'(030).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 5 .
w_field-fieldname = 'FKDAT'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Billing Date'(031).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 6 .
w_field-fieldname = 'WERKS'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Plant'(012).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 7 .
w_field-fieldname = 'WERKS_NAME1'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Plant Description'(032).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 8.
w_field-fieldname = 'KUNNR'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Bill-to Customer'(033).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 9 .
w_field-fieldname = 'KUNNR_NAME1'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Bill-to Description'(034).
w_field-emphasize = 'X'.
w_field-hotspot = 'X'.
APPEND w_field TO t_fieldcat.
CLEAR w_field.
w_field-col_pos = 10 .
w_field-fieldname = 'NETWR'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Invoice Amount'(035).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 11 .
w_field-fieldname = 'ZZUSER'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Changed By'.
APPEND w_field TO t_fieldcat.
w_field-col_pos = 12 .
w_field-fieldname = 'ZZ_CHANGED_DATE'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Last Changed Date'(006).
APPEND w_field TO t_fieldcat.
w_field-col_pos = 13 .
w_field-fieldname = 'ZZ_CHANGED_TIME'.
w_field-tabname = 'IT_EXTRACT2'.
w_field-seltext_l = 'Last Changed Time'(007).
APPEND w_field TO t_fieldcat.
* W_event-NAME = slis_ev_end_of_list.
* W_event-FORM = 'END_OF_LIST'.
* APPEND W_event TO GT_EVENTS.
* CLEAR W_event .
* w_field-col_pos = 14 .
* w_field-fieldname = 'COUNT'.
* w_field-tabname = 'IT_EXTRACT2'.
* w_field-seltext_l = 'COUNT'.
* APPEND w_field TO t_fieldcat.
ENDFORM. " SET_FIELDCAT
*& Form CALL_ALV
* Call the ALV Grid function.
FORM call_alv .
SORT it_extract BY vbeln.
* repid is necessary since the ALV F.M. does not work properly with
* sy-repid.
repid = sy-repid.
alv_variant-variant = pa_vari.
alv_variant-report = sy-repid.
alv_variant-username = sy-uname.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = repid
i_callback_user_command = 'USER_COMMAND'
is_layout = gs_layout
it_fieldcat = t_fieldcat[]
it_sort = gt_sort[]
i_default = 'X'
i_save = 'A'
is_variant = alv_variant
it_events = gt_events[]
is_print = tp_print
TABLES
t_outtab = it_extract2
EXCEPTIONS
program_error = 1
OTHERS = 2.
write :/ 'TOTAL NO OF ENTRIES', SY-VLINE, 32 L_COUNT.
IF sy-subrc NE 0.
MESSAGE w000 WITH text-004 ' ' ' ' ' '.
ENDIF.
ENDFORM. " CALL_ALV
*& Form alv_eventtab_build
* Pass list of events to be triggered by the ALV function module
FORM alv_eventtab_build USING u_name TYPE slis_alv_event-name
u_form TYPE slis_alv_event-form
alv_lt_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event. " structure for event handling
ls_event-name = u_name.
ls_event-form = u_form.
APPEND ls_event TO alv_lt_events.
ENDFORM. " alv_eventtab_build
* FORM TOP_OF_PAGE *
FORM top_of_page.
*gs_list_top_of_page-type = 'H'.
GS_LIST_TOP_OF_PAGE-INFO = L_COUNT.
APPEND GS_LIST_TOP_OF_PAGE TO GT_LIST_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'NEWALTA_LOGO'
it_list_commentary = gt_list_top_of_page.
ENDFORM. " TOP_OF_PAGE
*& Form user_command
* Process the user command.
* -->R_UCOMM User command
* -->RS_SELFIELD Field selected
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: ltp_vbeln TYPE vbeln. " Sales document number.
CASE r_ucomm.
WHEN '&IC1'.
IF ( rs_selfield-fieldname = 'VBELN'
OR rs_selfield-fieldname = 'BILL_VBELN' )
AND rs_selfield-value IS NOT INITIAL. " Display sales document.
ltp_vbeln = rs_selfield-value.
zcl_sales_doc=>display( ltp_vbeln ).
ENDIF.
ENDCASE.
ENDFORM. "user_command
*& Form alv_v-ariant_f4
* Get the display variant.
* <--CTP_VARI Variant name
FORM alv_variant_f4 CHANGING ctp_vari TYPE slis_vari.
alv_variant-report = sy-repid. " Report ID
alv_variant-username = sy-uname. " User ID
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = alv_variant
i_save = 'A'
IMPORTING
es_variant = alv_variant
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
ctp_vari = alv_variant-variant.
ENDIF.
ENDFORM. " alv_variant_f4
Maybe you are looking for
-
How can I get information off my old hard drive?
Recently my old mac book died. The genius bar said that it would be 750$ for repairs and since it had been 5 years since I'd gotten the laptop, I opted to buy a new MacBook Pro. The problem is I have stuff on my old hard drive that I want to keep (mo
-
Installation Problem-Internet needs to be closed
When I try to use Flash Player, it tells me it's not instaled. I have installed Flash Player numerous times, the one problem seems to be when it installs it says to close Internet Explorer (I do ) but it still doesn't work. I can't run any video on m
-
Nokia Should resolve the c3 video crash problem
Hi friends. I just bought Nokia C3 on 8th November. Everything was okey until itried to play video. I just transfered some video files to my c3's 2gb memory card through Nokia PC Suite. After playing for 5 second the phone hanged and restarted. I tho
-
HT1430 I reset my ipod by accident. HELPPP !
I tried downloading music to my computer from my friends ipod & I accidently reset it and I lost all her pictures and her music won't stop suffling to the next one. What do I do ??????????????????????????????????????????????????????????????????!!!!!!
-
Changing: Currency and Amount for Automatic Payment
Hi Folks, I need to change the value for currency and amount for automatic payment (bseg-pycur and bseg-pyamt) from a user exit from the MIR7. I have found the following exit: EXIT_SAPLMRMC_002 However didn't see the respective fields to change it. A