Sum number from first record in each grioup?
Hi,
I'm trying to sum a number from the first record of each group to display at the report footer.
I write a formula like this to do the sumation:
WhilePrintingRecords;
Global NumberVar cnt:=0;
if PreviousIsNull({data.grp) OR previous({data.grp}) <> {data.grp} then
cnt = cnt + {data.num};
and then one like this to retrieve sumation for footer, but it always returns zero:
WhilePrintingRecords;
Global NumberVar cnt;
cnt
What am I doing wrong?
If you have placed this formula in group header, then it might be re-setting the variable to zero everytime a group changes.
WhilePrintingRecords;
Global NumberVar cnt:=0;
if PreviousIsNull({data.grp) OR previous({data.grp}) {data.grp} then
cnt = cnt + {data.num};
Declare/set the variable in a separate formula and place that in report header so that the formula in the group header contains (note the colon when incrementing cnt):
WhilePrintingRecords;
Global NumberVar cnt;
if PreviousIsNull({data.grp) OR previous({data.grp}) {data.grp} then
cnt := cnt + {data.num};
Also, you might want to alter the formula, if the above doesn't work, by using " not inrepeatedgroupheader".
Alter the formula in the report footer to:
WhilePrintingRecords;
Global NumberVar cnt;
cnt;
Try it and see if it works.
Similar Messages
-
How can I get the number of distinct records that each field of a DB table has?
Hi everyone,
I would like to know how to get he number of distinct records that each field of a DB table has. When tracing a SQL statement either in ST12 or ST05, in the plan execution, if the sentence made useage of an index, then I can click in the index name and see this kind of information (no. of distinct values for each field of that index).
Can I do something like this but with the whole fields of a table?
What I have found until now is in Tx ST10; I search for whatever kind of table statistics and then use the function of "Analyze table" (which takes me to Tx DB05). In here, I can enter a table and up to 5 fields in order to get the information that I want.
Is there any other way to do this?
Regards,
David RezaHi David,
You can export the same to excel and sort as per requirement.
Sorry is that what you are looking for ?
Regards,
Deepanshu Sharma -
How do I remove the page number from first page?
I'm new at Ai so this may be basic. I can't figure out how to eliminate the page number from the first page. Any help would be appreciated.
Normally I would have a different master page for the first page, then have no page number on that master page.
Apply this master to the first page.
Or you can manually override the frame by holding CTRL SHIFT and clicking on the frame, then delete it. -
Finding CRM Order number from Interaction Record number
In our scenario when a CRM Order is created, an interaction record also gets simultaneously created. If I want to find out the Order number based on the corresponding interaction record number, how will I achieve it through linking tables?
Hi,
Use FM CRM_ORDER_READ and check ET_DOC_FLOW.
Hope this helps!
Best regards,
Caíque Escaler -
INSERT of two records into different tables (pk value from first to second)
Hi there!
Have probably stupid question
Need to insert one record into table with primary key and then insert into other table record with value of primary key field from first record
How can I do it?
Thanks a lot!!!You have several possibilities. Most easiest one is listed first :)
SQL> create table a (a number);
Table created.
SQL> alter table a add constraint a_pk primary key (a);
Table altered.
SQL> create table b (a number);
Table created.
SQL> alter table b add constraint b_a_fk foreign key (a) references a(a);
Table altered.
SQL> insert into a values (0);
1 row created.
SQL> insert into b values (0);
1 row created.Though that may not help always, so the next possibility maybe just using sequence with nextval and currval (currval can be used only in the same session and only after you have issued at least one nextval)
SQL> create sequence a_seq;
Sequence created.
SQL> insert into a values (a_seq.nextval);
1 row created.
SQL> insert into b values (a_seq.currval);
1 row created.And you can use also famous returning clause. It is a bit easier to show that in the pl/sql block than pure SQL.
SQL> declare
2 v number;
3 begin
4 insert into a values (a_seq.nextval) returning a into v;
5 insert into b values (v);
6 end;
7 /
PL/SQL procedure successfully completed.And at last contents of the tables :)
SQL> select * from b;
A
0
1
2
SQL> select * from a;
A
0
1
2Gints Plivna
http://www.gplivna.eu -
Creating view to get first row for each table !!
I am having tables(more than 10) which are related using foreign key and primary key relationship.
Example:
Table1:
T1Prim T1Col1 T1Col2
Table2
T2For T2Prim T2Col1 T2Col2 T2Col3
(here T2For will have value same as T1Prim and in my design it has same column name i.e. T1Prim)
Table3
T3For T3Prim T3Col1 T3Col2 T3Col3
(here T3For will have value same as T2Prim)
and so on.
The data in the tables is like For table1 there will be one record, for table2 there will be one record and for table 3 there are more than one records.
Can i view either the first record for each of them or all records from each of them by writing the following view.
I have written a view like this:
Create or replace view test (T1Prim,T1Col1, T1Col2,T2Prim,T2Col1 T2Col2, T2Col3, T3Prim,T3Col1, T3Col2, T3Col3)
As
Select
Table1.T1Prim,
Table1.T1Col1,
Table1.T1Col2,
Table2.T2Prim,
Table2.T2Col1,
Table2.T2Col2,
Table2.T2Col3,
Table3.T3Prim,
Table3.T3Col1,
Table3.T3Col2,
Table3.T3Col3
From
Table1,
Table2,
Table3
where
Table1.Prim = Table2.For
and Table2.Prim = Table3.For
When i ran the select statement on the view I am not getting any data. Whereas there is data when select is ran on individual table.
Can someone please tell me where i am goofing.
Thanks in the anticipation that i will get some hint to solve this.
Eagerly waiting for reply.
Thanks !!I mean use a collection :
Collection Methods
A collection method is a built-in function or procedure that operates on collections and is called using dot notation. The methods EXISTS, COUNT, LIMIT, FIRST, LAST, PRIOR, NEXT, EXTEND, TRIM, and DELETE help generalize code, make collections easier to use, and make your applications easier to maintain.
EXISTS, COUNT, LIMIT, FIRST, LAST, PRIOR, and NEXT are functions, which appear as part of an expression. EXTEND, TRIM, and DELETE are procedures, which appear as a statement. EXISTS, PRIOR, NEXT, TRIM, EXTEND, and DELETE take integer parameters. EXISTS, PRIOR, NEXT, and DELETE can also take VARCHAR2 parameters for associative arrays with string keys. EXTEND and TRIM cannot be used with index-by tables.
For more information, see "Using Collection Methods".
Syntax
Text description of the illustration collection_method_call.gif
Keyword and Parameter Description
collection_name
This identifies an index-by table, nested table, or varray previously declared within the current scope.
COUNT
COUNT returns the number of elements that a collection currently contains, which is useful because the current size of a collection is not always known. You can use COUNT wherever an integer expression is allowed.
For varrays, COUNT always equals LAST. For nested tables, normally, COUNT equals LAST. But, if you delete elements from the middle of a nested table, COUNT is smaller than LAST.
DELETE
This procedure has three forms. DELETE removes all elements from a collection. DELETE(n) removes the nth element from an index-by table or nested table. If n is null, DELETE(n) does nothing. DELETE(m,n) removes all elements in the range m..n from an index-by table or nested table. If m is larger than n or if m or n is null, DELETE(m,n) does nothing.
EXISTS
EXISTS(n) returns TRUE if the nth element in a collection exists. Otherwise, EXISTS(n) returns FALSE. Mainly, you use EXISTS with DELETE to maintain sparse nested tables. You can also use EXISTS to avoid raising an exception when you reference a nonexistent element. When passed an out-of-range subscript, EXISTS returns FALSE instead of raising SUBSCRIPT_OUTSIDE_LIMIT.
EXTEND
This procedure has three forms. EXTEND appends one null element to a collection. EXTEND(n) appends n null elements to a collection. EXTEND(n,i) appends n copies of the ith element to a collection. EXTEND operates on the internal size of a collection. So, if EXTEND encounters deleted elements, it includes them in its tally. You cannot use EXTEND with index-by tables.
FIRST, LAST
FIRST and LAST return the first and last (smallest and largest) subscript values in a collection. The subscript values are usually integers, but can also be strings for associative arrays. If the collection is empty, FIRST and LAST return NULL. If the collection contains only one element, FIRST and LAST return the same subscript value.
For varrays, FIRST always returns 1 and LAST always equals COUNT. For nested tables, normally, LAST equals COUNT. But, if you delete elements from the middle of a nested table, LAST is larger than COUNT.
index
This is an expression that must yield (or convert implicitly to) an integer in most cases, or a string for an associative array declared with string keys.
LIMIT
For nested tables, which have no maximum size, LIMIT returns NULL. For varrays, LIMIT returns the maximum number of elements that a varray can contain (which you must specify in its type definition).
NEXT, PRIOR
PRIOR(n) returns the subscript that precedes index n in a collection. NEXT(n) returns the subscript that succeeds index n. If n has no predecessor, PRIOR(n) returns NULL. Likewise, if n has no successor, NEXT(n) returns NULL.
TRIM
This procedure has two forms. TRIM removes one element from the end of a collection. TRIM(n) removes n elements from the end of a collection. If n is greater than COUNT, TRIM(n) raises SUBSCRIPT_BEYOND_COUNT. You cannot use TRIM with index-by tables.
TRIM operates on the internal size of a collection. So, if TRIM encounters deleted elements, it includes them in its tally.
Usage Notes
You cannot use collection methods in a SQL statement. If you try, you get a compilation error.
Only EXISTS can be applied to atomically null collections. If you apply another method to such collections, PL/SQL raises COLLECTION_IS_NULL.
You can use PRIOR or NEXT to traverse collections indexed by any series of subscripts. For example, you can use PRIOR or NEXT to traverse a nested table from which some elements have been deleted.
EXTEND operates on the internal size of a collection, which includes deleted elements. You cannot use EXTEND to initialize an atomically null collection. Also, if you impose the NOT NULL constraint on a TABLE or VARRAY type, you cannot apply the first two forms of EXTEND to collections of that type.
If an element to be deleted does not exist, DELETE simply skips it; no exception is raised. Varrays are dense, so you cannot delete their individual elements.
PL/SQL keeps placeholders for deleted elements. So, you can replace a deleted element simply by assigning it a new value. However, PL/SQL does not keep placeholders for trimmed elements.
The amount of memory allocated to a nested table can increase or decrease dynamically. As you delete elements, memory is freed page by page. If you delete the entire table, all the memory is freed.
In general, do not depend on the interaction between TRIM and DELETE. It is better to treat nested tables like fixed-size arrays and use only DELETE, or to treat them like stacks and use only TRIM and EXTEND.
Within a subprogram, a collection parameter assumes the properties of the argument bound to it. So, you can apply methods FIRST, LAST, COUNT, and so on to such parameters. For varray parameters, the value of LIMIT is always derived from the parameter type definition, regardless of the parameter mode.
Examples
In the following example, you use NEXT to traverse a nested table from which some elements have been deleted:
i := courses.FIRST; -- get subscript of first element
WHILE i IS NOT NULL LOOP
-- do something with courses(i)
i := courses.NEXT(i); -- get subscript of next element
END LOOP;
In the following example, PL/SQL executes the assignment statement only if element i exists:
IF courses.EXISTS(i) THEN
courses(i) := new_course;
END IF;
The next example shows that you can use FIRST and LAST to specify the lower and upper bounds of a loop range provided each element in that range exists:
FOR i IN courses.FIRST..courses.LAST LOOP ...
In the following example, you delete elements 2 through 5 from a nested table:
courses.DELETE(2, 5);
In the final example, you use LIMIT to determine if you can add 20 more elements to varray projects:
IF (projects.COUNT + 20) < projects.LIMIT THEN
-- add 20 more elements
Related Topics
Collections, Functions, Procedures
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/13_elems7.htm#33054
Joel P�rez -
I have report in BEx where we want to find the first time a customer ordered Quantity of more than 500 in a data range (For Ex: From April 10 to April 30). In a particluar date range the customer may order more than once (Qty > 500). The catch is we want display only one first time he ordered qty > 500.
Customer Date Qty > 500.
ABC 4/21/2005 2,035 CA
4/22/2005 12,290 CA
4/23/2005 4,826 CA
4/26/2005 6,397 CA
4/27/2005 1,538 CA
4/28/2005 4,849 CA
XYZ 4/25/2005 2,000 CA
4/26/2005 12,000 CA
4/27/2005 4,500 CA
4/28/2005 6,300 CA
In the output report we want to display the first record for each customer as:
Customer Date Qty > 500.
ABC 4/21/2005 2,035 CA
XYZ 4/25/2005 2,000 CA
Your help is really appreciated. Thanks.jayant,
i think, you could use your date as a condition to filter by in your report... try looking that the properties of your KF and, under Calculations, set the 'Calculate Result as...' to the first value only.
hope this helps - don't forget to give out points. =)
ryan.
ps. i've tried this, and it sort of works - just need a bit more of tweaking around. =)
Message was edited by: Ryan Kristoffer Tan -
I have report in BEx where we want to find the first time a customer ordered Quantity of more than 500 in a data range (For Ex: From April 10 to April 30). In a particular date range the customer may order more than once (Qty > 500). The catch is we want display only one first time he ordered qty > 500.
Customer Date Qty > 500.
ABC 4/21/2005 2,035 CA
4/22/2005 12,290 CA
4/23/2005 4,826 CA
4/26/2005 6,397 CA
4/27/2005 1,538 CA
4/28/2005 4,849 CA
XYZ 4/25/2005 2,000 CA
4/26/2005 12,000 CA
4/27/2005 4,500 CA
4/28/2005 6,300 CA
In the output report we want to display the first record for each customer as:
Customer Date Qty > 500.
ABC 4/21/2005 2,035 CA
XYZ 4/25/2005 2,000 CA
Your help is really appreciated. Thanks.Hello Jayant,
I don't think that you will be able to achieve this in BEx.
One option that can be explored is writing a VBA exit in a workbook.
The other one is using a virtual characteristic but that would mean quite a lot of development.
Cheers
Aneesh -
Need dissociation street name and street number from one column?
Hi all,
I have one table A with one column with Street name and street number.
And I was adding second column and now need update this second column with street number
and delete street number from first column.
How can unpluging street name and street number from one column?
(street name are 90% char, number is 100 numeric, in 10% street name name
starts with number (1.HEROES 223, 1.HEROES 224...)
GordanHi,
Solution of Mr. Wijk come first, however I like to post (it's very similar and incomplete, I know...). Supose you have a table call address (use position -1 like Mr. Wijk to look backward). It's better in cases like '1.My Street 123' (the space before the number is very important)
SELECT substr(a.street_name,
1,
instr(a.street_name,
-1) - 1) street_name,
substr(a.street_name,
instr(a.street_name,
-1) + 1) street_number
FROM address a;Regards, -
Want to get sum/avg first 90% records in each grouped record set.
Hi Gurus,
Need your help or example query which help me to achieve sum/avg first 90% records in each grouped record set. Let me show you the basic query and output and proposed output.
select Pid, Sum(SalesAmt) TotalSaleAmt, Avg(SalesAmt) AvgSaleAmt, count(*) NoOfSales from ProductSales group by Pid;
PID TotalSaleAmt AvgSaleAmt NoOfSales
1 12000 100 120
2 24000 50 480
Now I need for PID =1 TotalSaleAmt of first 90% of NoOfSale i.e.120(this is basically nuber of rows found in PrdocutSales Table).
I hope I am clear enough explain my requirement... I would appreciate if we have some Analytical function available..
Gurus Pls help me asap..
Thanks In adavance...
Srichan.Now I need for PID =1 TotalSaleAmt of first 90% of NoOfSale i.e.120(this is basically nuber of rows found in PrdocutSales Table).
first 90% should mean first 90% by some order, so in this case, which 108 rows (of the 120) do you want to take into consideration?
with
the_sample as
(select 1 the_pid,10 the_sale,1 the_order from dual union all
select 1 the_pid,20 the_sale,2 the_order from dual union all
select 1 the_pid,15 the_sale,3 the_order from dual union all
select 1 the_pid,12 the_sale,4 the_order from dual union all
select 1 the_pid,12 the_sale,5 the_order from dual union all
select 1 the_pid,13 the_sale,6 the_order from dual union all
select 1 the_pid,19 the_sale,7 the_order from dual union all
select 1 the_pid,11 the_sale,8 the_order from dual union all
select 1 the_pid,15 the_sale,9 the_order from dual union all
select 1 the_pid,12 the_sale,10 the_order from dual union all
select 2 the_pid,25 the_sale,1 the_order from dual union all
select 2 the_pid,22 the_sale,2 the_order from dual union all
select 2 the_pid,22 the_sale,3 the_order from dual union all
select 2 the_pid,23 the_sale,4 the_order from dual union all
select 2 the_pid,29 the_sale,5 the_order from dual union all
select 2 the_pid,21 the_sale,6 the_order from dual union all
select 2 the_pid,25 the_sale,7 the_order from dual union all
select 2 the_pid,22 the_sale,8 the_order from dual
select the_pid,the_sum,the_avg
from (select the_pid,
sum(the_sale) over (partition by the_pid order by the_order) the_sum,
round(avg(the_sale) over (partition by the_pid order by the_order),2) the_avg,
the_order,
floor((0.9 * max(the_order) over (partition by the_pid))) to_pick
from the_sample
where the_order = to_pickRegards
Etbin -
How to skip first record while inserting data from a flat file to BW system
Hi Experts,
In my project we have to upload flat file into a BW system. I have written a program and it is working fine.
Now we have got another requirement. The flat file will have a header record (first row). While uploading the flat file we have to skip this record. How I can do so?
The code is as below:
FORM upload1.
DATA : wf_title TYPE string,
lt_filetab TYPE filetable,
l_separator TYPE char01,
l_action TYPE i,
l_count TYPE i,
ls_filetab TYPE file_table,
wf_delemt TYPE rollname,
wa_fieldcat TYPE lvc_s_fcat,
tb_fieldcat TYPE lvc_t_fcat,
rows_read TYPE i,
p_error TYPE char01,
l_file TYPE string.
DATA: wf_object(30) TYPE c,
wf_tablnm TYPE rsdchkview.
wf_object = 'myprogram'.
DATA i TYPE i.
DATA:
lr_mdmt TYPE REF TO cl_rsdmd_mdmt,
lr_mdmtr TYPE REF TO cl_rsdmd_mdmtr,
lt_idocstate TYPE rsarr_t_idocstate,
lv_subrc TYPE sysubrc.
TYPES : BEGIN OF test_struc,
/bic/myprogram TYPE /bic/oimyprogram,
txtmd TYPE rstxtmd,
END OF test_struc.
DATA : tb_assum TYPE TABLE OF /bic/pmyprogram.
DATA: wa_ztext TYPE /bic/tmyprogram,
myprogram_temp TYPE ziott_assum,
wa_myprogram TYPE /bic/pmyprogram.
DATA : test_upload TYPE STANDARD TABLE OF test_struc,
wa2 TYPE test_struc.
DATA : wa_test_upload TYPE test_struc,
ztable_data TYPE TABLE OF /bic/pmyprogram,
ztable_text TYPE TABLE OF /bic/tmyprogram,
wa_upld_text TYPE /bic/tmyprogram,
wa_upld_data TYPE /bic/pmyprogram,
t_assum TYPE ziott_assum.
DATA : wa1 LIKE test_upload.
wf_title = text-026.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = wf_title
default_extension = 'txt'
file_filter = 'Tab delimited Text Files (*.txt)'
CHANGING
file_table = lt_filetab
rc = l_count
user_action = l_action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
OTHERS = 3. "#EC NOTEXT
IF sy-subrc <> 0.
EXIT.
ENDIF.
LOOP AT lt_filetab INTO ls_filetab.
l_file = ls_filetab.
ENDLOOP.
CHECK l_action = 0.
IF l_file IS INITIAL.
EXIT.
ENDIF.
l_separator = 'X'.
wa_fieldcat-fieldname = 'test'.
wa_fieldcat-dd_roll = wf_delemt.
APPEND wa_fieldcat TO tb_fieldcat.
CALL FUNCTION 'MESSAGES_INITIALIZE'.
CLEAR wa_test_upload.
Upload file from front-end (PC)
File format is tab-delimited ASCII
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
has_field_separator = l_separator
TABLES
data_tab = i_mara
data_tab = test_upload
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
EXIT.
ELSE.
CALL FUNCTION 'MESSAGES_INITIALIZE'.
IF test_upload IS NOT INITIAL.
DESCRIBE TABLE test_upload LINES rows_read.
CLEAR : wa_test_upload,wa_upld_data.
LOOP AT test_upload INTO wa_test_upload.
CLEAR : p_error.
rows_read = sy-tabix.
IF wa_test_upload-/bic/myprogram IS INITIAL.
p_error = 'X'.
MESSAGE s153 WITH wa_test_upload-/bic/myprogram sy-tabix.
CONTINUE.
ELSE.
TRANSLATE wa_test_upload-/bic/myprogram TO UPPER CASE.
wa_upld_text-txtmd = wa_test_upload-txtmd.
wa_upld_text-txtsh = wa_test_upload-txtmd.
wa_upld_text-langu = sy-langu.
wa_upld_data-chrt_accts = 'xyz1'.
wa_upld_data-co_area = '12'.
wa_upld_data-/bic/zxyzbcsg = 'Iy'.
wa_upld_data-objvers = 'A'.
wa_upld_data-changed = 'I'.
wa_upld_data-/bic/zass_mdl = 'rrr'.
wa_upld_data-/bic/zass_typ = 'I'.
wa_upld_data-/bic/zdriver = 'yyy'.
wa_upld_text-langu = sy-langu.
MOVE-CORRESPONDING wa_test_upload TO wa_upld_data.
MOVE-CORRESPONDING wa_test_upload TO wa_upld_text.
APPEND wa_upld_data TO ztable_data.
APPEND wa_upld_text TO ztable_text.
ENDIF.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM ztable_data.
DELETE ADJACENT DUPLICATES FROM ztable_text.
IF ztable_data IS NOT INITIAL.
CALL METHOD cl_rsdmd_mdmt=>factory
EXPORTING
i_chabasnm = 'myprogram'
IMPORTING
e_r_mdmt = lr_mdmt
EXCEPTIONS
invalid_iobjnm = 1
OTHERS = 2.
CALL FUNCTION 'MESSAGES_INITIALIZE'.
**Lock the Infoobject to update
CALL FUNCTION 'RSDG_IOBJ_ENQUEUE'
EXPORTING
i_objnm = wf_object
i_scope = '1'
i_msgty = rs_c_error
EXCEPTIONS
foreign_lock = 1
sys_failure = 2.
IF sy-subrc = 1.
MESSAGE i107(zddd_rr) WITH wf_object sy-msgv2.
EXIT.
ELSEIF sy-subrc = 2.
MESSAGE i108(zddd_rr) WITH wf_object.
EXIT.
ENDIF.
*****Update Master Table
IF ztable_data IS NOT INITIAL.
CALL FUNCTION 'RSDMD_WRITE_ATTRIBUTES_TEXTS'
EXPORTING
i_iobjnm = 'myprogram'
i_tabclass = 'M'
I_T_ATTR = lt_attr
TABLES
i_t_table = ztable_data
EXCEPTIONS
attribute_name_error = 1
iobj_not_found = 2
generate_program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'MESSAGE_STORE'
EXPORTING
arbgb = 'zddd_rr'
msgty = 'E'
txtnr = '054'
msgv1 = text-033
EXCEPTIONS
OTHERS = 3.
MESSAGE e054(zddd_rr) WITH 'myprogram'.
ELSE.
CALL FUNCTION 'MESSAGE_STORE'
EXPORTING
arbgb = 'zddd_rr'
msgty = 'S'
txtnr = '053'
msgv1 = text-033
EXCEPTIONS
OTHERS = 3.
ENDIF.
*endif.
*****update Text Table
IF ztable_text IS NOT INITIAL.
CALL FUNCTION 'RSDMD_WRITE_ATTRIBUTES_TEXTS'
EXPORTING
i_iobjnm = 'myprogram'
i_tabclass = 'T'
TABLES
i_t_table = ztable_text
EXCEPTIONS
attribute_name_error = 1
iobj_not_found = 2
generate_program_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'MESSAGE_STORE'
EXPORTING
arbgb = 'zddd_rr'
msgty = 'E'
txtnr = '055'
msgv1 = text-033
EXCEPTIONS
OTHERS = 3.
ENDIF.
ENDIF.
ELSE.
MESSAGE s178(zddd_rr).
ENDIF.
ENDIF.
COMMIT WORK.
CALL FUNCTION 'RSD_CHKTAB_GET_FOR_CHA_BAS'
EXPORTING
i_chabasnm = 'myprogram'
IMPORTING
e_chktab = wf_tablnm
EXCEPTIONS
name_error = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
****Release locks on Infoobject
CALL FUNCTION 'RSDG_IOBJ_DEQUEUE'
EXPORTING
i_objnm = 'myprogram'
i_scope = '1'.
ENDIF.
ENDIF.
PERFORM data_selection .
PERFORM update_alv_grid_display.
CALL FUNCTION 'MESSAGES_SHOW'.
ENDFORM.
Please let me know how I can skip first record of the flat file?
Regards,
Sgo through this hope u can get some idea
REPORT ztest no standard page heading line-size 255.
Declaration *
TYPES t_itab1 TYPE alsmex_tabline.
types: begin of t_csks,
kostl like csks-kostl,
end of t_csks.
types: begin of t_cska,
kstar like cska-kstar,
end of t_cska.
data: begin of t_flatfile,
docdate like COHEADER-BLDAT,
postdate like COHEADER-BUDAT,
doctext like COHEADER-BLTXT,
costele like RK23F-KSTAR,
amount like RK23F-WTGBTR,
scostctr like RK23F-SKOSTL,
rcostctr like RK23F-EKOSTL,
rintorder like RK23F-EAUFNR,
end of t_flatfile.
data: begin of t_flatfile1,
docdate like COHEADER-BLDAT,
postdate like COHEADER-BUDAT,
doctext like COHEADER-BLTXT,
costele like RK23F-KSTAR,
amount like RK23F-WTGBTR,
scostctr like RK23F-SKOSTL,
rcostctr like RK23F-EKOSTL,
rintorder like RK23F-EAUFNR,
NUM LIKE SY-INDEX,
end of t_flatfile1.
data: itab like table of t_flatfile with header line.
data: itab2 like table of t_flatfile1 with header line.
DATA: it_itab1 TYPE STANDARD TABLE OF t_itab1 WITH HEADER LINE,
MESSTAB1 LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,
MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
data: begin of bdcdata occurs 0.
include structure bdcdata.
data: end of bdcdata.
data:t_lin type i VALUE '0',
u_rec type i VALUE '0',
s_rec type i VALUE '0'.
data: it_csks type standard table of t_csks,
wa_csks type t_csks.
data: it_cska type standard table of t_cska,
wa_cska type t_cska.
*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-010.
parameters: p_docdat LIKE COHEADER-BLDAT obligatory,
p_postda LIKE COHEADER-BUDAT obligatory,
p_doctxt LIKE COHEADER-BLTXT.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-011.
parameters: p_file LIKE RLGRAP-FILENAME obligatory,
DIS_MODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N'.
SELECTION-SCREEN END OF BLOCK b2.
A T S E L E C T I O N S C R E E N *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_local_file_name USING p_file.
*Start of Selection
START-OF-SELECTION.
Perform get_Excel_data.
perform validate_data.
Perform Process_Data.
end-of-selection
end-of-selection.
perform display_data.
*& Form get_local_file_name
text
-->P_P_FILE text
FORM get_local_file_name USING P_P_FILE.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = p_file.
ENDFORM. " get_local_file_name
*& Form get_Excel_data
text
--> p1 text
<-- p2 text
FORM get_Excel_data .
FIELD-SYMBOLS : <FS>.
DATA : V_INDEX TYPE I.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_begin_row = 1
i_end_col = 256
i_end_row = 9999 "65536
TABLES
intern = it_itab1
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Message text-013 type 'E'.
ENDIF.
IF IT_ITAB1[] IS INITIAL.
Message text-001 type 'E'.
else. "IF IT_ITAB1[] IS INITIAL.
data: itab2 like itab occurs 0 with header line.
SORT IT_ITAB1 BY ROW COL.
LOOP AT IT_ITAB1.
MOVE :IT_ITAB1-COL TO V_INDEX.
ASSIGN COMPONENT V_INDEX OF STRUCTURE itab2 TO <FS>.
MOVE : IT_ITAB1-VALUE TO <FS>.
AT END OF ROW.
MOVE-CORRESPONDING itab2 TO itab.
APPEND itab.
CLEAR:itab,itab2.
ENDAT.
endloop.
describe table itab lines t_lin.
endif. "IF IT_ITAB1[] IS INITIAL.
ENDFORM. " get_Excel_data
*& Form Process_Data
text
--> p1 text
<-- p2 text
FORM Process_Data .
data:l_tabix type sy-tabix.
data:l_periv like t001-periv,
l_monat like bkpf-monat,
l_gjahr like bkpf-gjahr,
l_amt(21) type c.
data: l_ddate(10),
l_pdate(10).
WRITE p_docdat TO l_ddate.
WRITE p_postda TO l_pdate.
clear: l_periv,l_monat,l_gjahr.
select single periv from t001 into l_periv where bukrs = '5000'. "P_bukrs
if sy-subrc eq 0.
l_gjahr = p_postda+0(4).
call function 'FI_PERIOD_DETERMINE'
EXPORTING
i_budat = p_postda
i_bukrs = '5000' "p_bukrs
i_periv = l_periv
i_gjahr = l_gjahr
IMPORTING
e_monat = l_monat.
clear:l_periv.
endif.
loop at itab2.
refresh:bdcdata.
clear:bdcdata.
l_tabix = sy-tabix.
perform bdc_dynpro using 'SAPLK23F1' '1200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'COHEADER-SEND_REC_REL'
'10SAP'.
perform bdc_field using 'RK23F-STATUS'
'S'.
perform bdc_field using 'COHEADER-BLDAT'
itab-docdate.
l_ddate.
perform bdc_field using 'COHEADER-BUDAT'
itab-postdate.
l_pdate.
perform bdc_field using 'COHEADER-PERIO'
l_monat. "'9'.
perform bdc_field using 'COHEADER-BLTXT'
itab-doctext.
p_doctxt.
perform bdc_field using 'RK23F-KSTAR'
itab2-costele.
WRITE itab2-amount TO l_amt.
l_amt = itab-amount.
condense l_amt no-gaps.
perform bdc_field using 'RK23F-WTGBTR'
l_amt.
itab-amount.
perform bdc_field using 'RK23F-WAERS'
'USD'.
*perform bdc_field using 'RK23F-SGTXT'
itab-doctext.
perform bdc_field using 'RK23F-SKOSTL'
itab2-scostctr.
perform bdc_field using 'BDC_CURSOR'
'RK23F-EAUFNR'.
perform bdc_field using 'RK23F-EKOSTL'
itab2-rcostctr.
perform bdc_field using 'RK23F-EAUFNR'
itab2-rintorder.
perform bdc_dynpro using 'SAPLK23F1' '1200'.
perform bdc_field using 'BDC_OKCODE'
'=POST'.
perform bdc_field using 'COHEADER-SEND_REC_REL'
'10SAP'.
perform bdc_field using 'RK23F-STATUS'
'S'.
perform bdc_field using 'COHEADER-BLDAT'
itab-docdate.
l_ddate.
perform bdc_field using 'COHEADER-BUDAT'
itab-postdate.
l_pdate.
perform bdc_field using 'COHEADER-PERIO'
'9'.
l_monat.
perform bdc_field using 'COHEADER-BLTXT'
itab-doctext.
p_doctxt.
perform bdc_field using 'BDC_CURSOR'
'RK23F-KSTAR'.
perform bdc_field using 'RK23F-WAERS'
'USD'.
CALL TRANSACTION 'KB15N' USING BDCDATA MODE DIS_MODE MESSAGES INTO MESSTAB.
If sy-subrc = 0.
s_rec = s_rec + 1.
ELSE.
u_rec = u_rec + 1.
move ITAB2-NUM to messtab1-msgv1.
concatenate itab2-costele ' | ' itab2-scostctr ' | ' itab2-rcostctr ' | ' itab2-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
endif.
clear:itab2.
endloop.
ENDFORM. " Process_Data
BDC_DYNPRO *
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM. "BDC_DYNPRO
BDC_FIELD *
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ''. "NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM. "BDC_FIELD
*& Form display_data
text
--> p1 text
<-- p2 text
FORM display_data .
skip 2.
write:/15 text-002.
skip 2.
write:/8 text-003.
SKIP.
write:/12 text-008,
25 P_DOCDAT.
SKIP.
write:/12 text-009,
25 P_POSTDA.
SKIP.
write:/12 text-012,
25 P_DOCTXT.
SKIP.
write:/12 text-004,
25 p_file.
skip 2.
write:/8 text-005,
60 t_lin.
skip.
write:/8 text-006,
60 s_rec.
skip.
write:/8 text-007,
60 u_rec.
skip.
write:/10 'row no',
20 'Information'.
skip.
loop at messtab1.
write:/10 messtab1-msgv1,
20 messtab1-msgv2.
clear:messtab1.
endloop.
ENDFORM. " display_data
*& Form validate_data
text
--> p1 text
<-- p2 text
FORM validate_data .
data: l_tabix1 type sy-tabix.
data: l_tabix2 type sy-tabix.
if not itab[] is initial.
select kostl from CSKS into table it_csks.
if sy-subrc eq 0.
sort it_csks by kostl.
endif.
select kstar from CSKA into table it_cska.
if sy-subrc eq 0.
sort it_cska by kstar.
endif.
loop at itab.
l_tabix1 = sy-tabix.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = itab-scostctr
IMPORTING
OUTPUT = itab-scostctr .
read table it_csks into wa_csks with key kostl = itab-scostctr.
if sy-subrc ne 0.
u_rec = u_rec + 1.
L_TABIX2 = l_tabix1 + 1.
move l_tabix2 to messtab1-msgv1.
move l_tabix1 to messtab1-msgv1.
move itab-rintorder to messtab1-msgv2.
concatenate itab-costele ' | ' itab-scostctr ' | ' itab-rcostctr ' | ' itab-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
clear:wa_csks.
CLEAR:L_TABIX2.
continue.
endif.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = itab-rcostctr
IMPORTING
OUTPUT = itab-rcostctr .
read table it_csks into wa_csks with key kostl = itab-rcostctr.
if sy-subrc ne 0.
u_rec = u_rec + 1.
L_TABIX2 = l_tabix1 + 1.
move l_tabix2 to messtab1-msgv1.
move l_tabix1 to messtab1-msgv1.
concatenate itab-costele ' | ' itab-scostctr ' | ' itab-rcostctr ' | ' itab-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
clear:wa_csks.
CLEAR:L_TABIX2.
continue.
endif.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = itab-costele
IMPORTING
OUTPUT = itab-costele .
read table it_cska into wa_cska with key kstar = itab-costele.
if sy-subrc ne 0.
u_rec = u_rec + 1.
L_TABIX2 = l_tabix1 + 1.
move l_tabix2 to messtab1-msgv1.
move l_tabix1 to messtab1-msgv1.
concatenate itab-costele ' | ' itab-scostctr ' | ' itab-rcostctr ' | ' itab-rintorder into messtab1-msgv2.
condense messtab1-msgv2.
condense messtab1-msgv1.
append messtab1.
clear:wa_csks.
CLEAR:L_TABIX2.
continue.
endif.
move-corresponding itab to itab2.
MOVE l_tabix1 TO ITAB2-NUM.
append itab2.
clear: itab2.
clear:itab.
endloop.
else.
message 'No records in File' type 'S'.
endif.
ENDFORM. " validate_data -
SQL help: return number of records for each day of last month.
Hi: I have records in the database with a field in the table which contains the Unix epoch time for each record. Letz say the Table name is ED and the field utime contains the Unix epoch time.
Is there a way to get a count of number of records for each day of the last one month? Essentially I want a query which returns a list of count (number of records for each day) with the utime field containing the Unix epoch time. If a particular day does not have any records I want the query to return 0 for that day. I have no clue where to start. Would I need another table which has the list of days?
Thanks
RayPeter: thanks. That helps but not completely.
When I run the query to include only records for July using a statement such as following
============
SELECT /*+ FIRST_ROWS */ COUNT(ED.UTIMESTAMP), TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD') AS DATA
FROM EVENT_DATA ED
WHERE AGENT_ID = 160
AND (TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY')+(ED.UTIMESTAMP/86400)), 'MM/YYYY') = TO_CHAR(SYSDATE-15, 'MM/YYYY'))
GROUP BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD')
ORDER BY TO_CHAR((TO_DATE('01/01/1970','MM/DD/YYYY') + (ED.UTIMESTAMP/86400)), 'MM/DD');
=============
I get the following
COUNT(ED.UTIMESTAMP) DATA
1 07/20
1 07/21
1 07/24
2 07/25
2 07/27
2 07/28
2 07/29
1 07/30
2 07/31
Some dates donot have any records and so no output. Is there a way to show the missing dates with a COUNT value = 0?
Thanks
Ray -
Number for every record that is retrieved from (query)
Hello
I wish to put a number for every record that is retrieved
from the record that is output by this query
For example
For the first recored/row
Generated number, ksnumber, date
1, gg111 11/05/05
2, oo235 12/06/05
the query returned 2 records 1 and 2 are the number that is
generated with this code.
In addition if there is a built in function, where in the
code do I put it???
<cfquery name="gelov datasource="kl90">
SELECT
FROM
WHERE
ORDER BY
<cfswitch expression="#Form.orderBy#">
<cfks value="KSNUMBER">
KS.KS_NBR
</cfks>
<cfks value="CREATIONDATE">
KS.KREATDAT
</cfks>
</cfswitch>
</cfquery>
<!---html report--->
<cfswitch expression="#Form.outputFormat#">
<cfks value="HTML">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Ctwye Kss Report</title>
</head>
<style type="text/css">
table{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
td{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
th{
font-family:Arial, Helvetica, sans-serif;
font-size:10px;
h2{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
h3{
font-family:Arial, Helvetica, sans-serif;
font-size:13px;
</style>
<body>
<cfoutput>
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="center">
<h3>Ctwye Kss
Report</h3><br><br></td>
</tr>
<tr>
<td align="center">
</h2>report returned #getCtwyeKss.RecordCount#
records</h2></td>
</tr>
<tr>
<td>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="160">Ks Number</td>
<td>Creation Date</td>
<!--- <td class="dataField">Address</td>
<td class="dataField">Type</td>
<td class="dataField">Description</td>--->
</tr>
<cfloop query="getCtwyeKss">
<tr bgcolor="<cfif currentrow mod
2>GHOSTWHITE<cfelse>WHITE</cfif>">
<td>#KS_NBR#</td>
<td>#dateformat(KREATDAT,"mm/dd/yyyy")#</td>
</tr>
</cfloop>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>
</cfoutput>
</cfks>
<cfks value="CSV">
<CFHEADER NAME="Content-Disposition" VALUE="attachment;
filename=ctwye.csv">
<cfcontent type="application/msexcel">"Ks
Number","Creation Date"
<cfoutput
query="getCtwyeKss">#ltrim(KS_NBR)#,"#dateformat(KREATDAT,"mm/dd/yyyy")#"
<tr #IIF(getCtwyeKss.CurrentRow MOD
2,DE(''),DE('backgroundColor="##999"'))#>
<!---<tr bgcolor="<cfif currentrow mod
2>##808080<cfelse>##ffffff</cfif>"> --->
</cfoutput>
</cfks>
</cfswitch><cfks> is not a Coldfusion tag. Use <cfcase>
instead.
The following code will print the row numbers
<cfquery name="gelov" datasource="kl90">
select ksnumber, date
from yourTable
</cfquery>
<cfoutput query="gelov">
#currentrow#, #ksnumber#, #date#<br>
</cfoutput> -
How to restrict number of Data Records from Source system?
Hi,
How can I restrict the number of Data records from R3 source system that are being loaded into BI. For example I have 1000 source data records, but only wish to transfer the first 100. How can I achieve this? Is there some option in the DataSource definition or InfoPackage definition?
Pls help,
SDHi SD,
You can surely restrict the number of records, best and simplest way is, check which characteristics are present in selection screen of InfoPackage and check in R3, which characteristics if given a secection could fetch you the desired number of records. Use it as selection in InfoPackage.
Regards,
Pankaj -
Merge 2 internal tables into one and show first record from common fields
Hello PPl,
I have 3 tables kna1 knb1 and knvp i have to join kna1 and knb1 on kunnr and move the data into an internal table it_data then on the basis of that data in it_data i have to retrieve records FOR ALL ENTRIES from KNVP and move it into it_knvp.
Then both it_data and it_knvp should be merged in it_alv and from that internal table report has to be displayed.
[NOTE: i had tried using loop twice but the report got messed up]
Apart from that for these set of values
0000000004
0000000418
0000000954
0000001190
0000001222
0000001451
0000001453
0000001455
0000001470
0000001508
finally knvp is showing records in such a way that for 2 records kunnr is same and so does all the other fields except PARZA and KUNN2 so the req. is to display only the first record among 2.
Plz help me by providing code for that its urgent......
Below i m providing my code so far, i hope it will be of some help.
TREMENDOUS REWARD POINTS GURANTEED!!!!!
REPORT zfanz_alv_report_whv.
TYPE-GROUPS *
TYPE-POOLS: slis.
TYPES *
TYPES: BEGIN OF ty_data,
kunnr TYPE kunnr,
ort01 TYPE ort01,
pstlz TYPE pstlz,
regio TYPE regio,
bukrs TYPE bukrs,
zterm TYPE zterm,
END OF ty_data,
BEGIN OF ty_knvp,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
parvw TYPE parvw,
parza TYPE parza,
kunn2 TYPE kunn2,
lifnr TYPE lifnr,
END OF ty_knvp,
BEGIN OF ty_alv,
kunnr TYPE kunnr,
ort01 TYPE ort01,
pstlz TYPE pstlz,
regio TYPE regio,
bukrs TYPE bukrs,
zterm TYPE zterm,
vkorg TYPE vkorg,
vtweg TYPE vtweg,
spart TYPE spart,
parvw TYPE parvw,
parza TYPE parza,
kunn2 TYPE kunn2,
lifnr TYPE lifnr,
END OF ty_alv,
BEGIN OF ty_kna1,
kunnr TYPE kunnr,
END OF ty_kna1,
BEGIN OF ty_knb1,
bukrs TYPE bukrs,
END OF ty_knb1.
*DATA: IT_KNVP TYPE KNVP,
DATA: it_knvp TYPE STANDARD TABLE OF ty_knvp WITH HEADER LINE.
DATA: it_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.
Report data to be shown.
DATA: it_alv TYPE STANDARD TABLE OF ty_alv WITH HEADER LINE.
Heading of the report.
DATA: t_heading TYPE slis_t_listheader.
*DATA: fieldcatalog type standard table of slis_fieldcat_alv with header
*line.
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE.
*TABLES
tables:knvp,kna1,knb1.
CONSTANTS *
CONSTANTS: c_kunnr TYPE char5 VALUE 'KUNNR',
c_ort01 TYPE char5 VALUE 'ORT01',
c_pstlz TYPE char5 VALUE 'PSTLZ',
c_regio TYPE char5 VALUE 'REGIO',
c_bukrs TYPE char5 VALUE 'BUKRS',
c_zterm TYPE char5 VALUE 'ZTERM',
c_vkorg TYPE char5 VALUE 'VKORG',
c_vtweg TYPE char5 VALUE 'VTWEG',
c_spart TYPE char5 VALUE 'SPART',
c_parvw TYPE char5 VALUE 'PARVW',
c_parza TYPE char5 VALUE 'PARZA',
c_kunn2 TYPE char5 VALUE 'KUNN2',
c_lifnr TYPE char5 VALUE 'LIFNR'.
WORKAREA *
DATA: wa_data TYPE ty_data,
wa_knvp TYPE ty_knvp,
wa_alv TYPE ty_alv,
wa_fcat TYPE slis_fieldcat_alv,
wa_layout TYPE slis_layout_alv.
======================= Selection Screen ==========================
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
*DATA: wa_kunnr LIKE kna1-kunnr,
wa_bukrs LIKE knb1-bukrs,
wa_vkorg LIKE knvp-vkorg,
wa_vtweg LIKE knvp-vtweg,
wa_spart LIKE knvp-spart,
wa_parvw LIKE knvp-parvw.
SELECT-OPTIONS *
SELECT-OPTIONS s_kunnr FOR kna1-kunnr NO INTERVALS OBLIGATORY
SELECT-OPTIONS: s_bukrs FOR knb1-bukrs NO-EXTENSION NO INTERVALS,
s_vkorg FOR knvp-vkorg NO-EXTENSION NO INTERVALS,
s_vtweg FOR knvp-vtweg NO-EXTENSION NO INTERVALS,
s_spart FOR knvp-spart NO-EXTENSION NO INTERVALS,
s_parvw FOR knvp-parvw NO-EXTENSION NO INTERVALS.
SELECTION-SCREEN: END OF BLOCK b1.
AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON s_kunnr.
PERFORM validate_data.
START-OF-SELECTION *
START-OF-SELECTION.
PERFORM get_data. "fetch data from table and perform join on them
PERFORM final_table.
PERFORM build_fieldcatalog. "populate field catalog
PERFORM build_layout.
PERFORM grid_display. "display the result in ALV grid
END-OF-SELECTION *
END-OF-SELECTION.
describe
SUBROUTINES (FORMS)
*& Form get_data
Gets the information to be shown in the report.
Join on tables KNA1, KNB1 and for all enteries in KNVP
--> p1 text
<-- p2 text
FORM get_data.
SELECT kna1~kunnr
kna1~ort01
kna1~pstlz
kna1~regio
knb1~bukrs
knb1~zterm
INTO TABLE it_data
FROM kna1 INNER JOIN knb1
ON kna1kunnr = knb1kunnr
WHERE kna1~kunnr IN s_kunnr
AND knb1~bukrs IN s_bukrs.
SELECT vkorg
vtweg
spart
parvw
parza
kunn2
lifnr
INTO TABLE it_knvp FROM knvp
FOR ALL ENTRIES IN it_data
WHERE knvp~kunnr = it_data-kunnr
AND vkorg IN s_vkorg
AND vtweg IN s_vtweg
AND spart IN s_spart
AND parvw IN s_parvw.
ENDFORM. " get_data
*ENDFORM. " get_data
*& Form FINAL_TABLE
text
--> p1 text
<-- p2 text
FORM final_table .
LOOP AT it_data.
it_alv-kunnr = it_data-kunnr.
it_alv-ort01 = it_data-ort01.
it_alv-pstlz = it_data-pstlz.
it_alv-regio = it_data-regio.
it_alv-bukrs = it_data-bukrs.
it_alv-zterm = it_data-zterm.
APPEND it_alv.
CLEAR it_alv.
ENDLOOP.
LOOP AT it_knvp.
it_alv-vkorg = it_knvp-vkorg.
it_alv-vtweg = it_knvp-vtweg.
it_alv-spart = it_knvp-spart.
it_alv-parvw = it_knvp-parvw.
it_alv-parza = it_knvp-parza.
it_alv-kunn2 = it_knvp-kunn2.
it_alv-lifnr = it_knvp-lifnr.
APPEND it_alv.
CLEAR it_alv.
ENDLOOP.
ENDFORM. " FINAL_TABLE
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
FORM build_fieldcatalog.
IF it_alv[] IS NOT INITIAL.
wa_fcat-fieldname = c_kunnr.
wa_fcat-seltext_l = 'Customer Master'(001).
wa_fcat-col_pos = 1.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_ort01.
wa_fcat-seltext_l = 'City'(002).
wa_fcat-col_pos = 2.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_pstlz.
wa_fcat-seltext_l = 'Postal Code'(003).
wa_fcat-col_pos = 3.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_regio.
wa_fcat-seltext_l = 'Region'(004).
wa_fcat-col_pos = 4.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_bukrs.
wa_fcat-seltext_l = 'Company Code'(005).
wa_fcat-col_pos = 5.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_zterm.
wa_fcat-seltext_l = 'Terms of payment'(006).
wa_fcat-col_pos = 6.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_vkorg.
wa_fcat-seltext_l = 'Sales Organization'(007).
wa_fcat-col_pos = 7.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_vtweg.
wa_fcat-seltext_l = 'Distribution Channel'(008).
wa_fcat-col_pos = 8.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_spart.
wa_fcat-seltext_l = 'Division'(009).
wa_fcat-col_pos = 9.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_parvw.
wa_fcat-seltext_l = 'Partner function'(010).
wa_fcat-col_pos = 10.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_kunn2.
wa_fcat-seltext_l = 'Customer number of partner'(011).
wa_fcat-col_pos = 11.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_lifnr.
wa_fcat-seltext_l = 'Account Number of Vendor'(012).
wa_fcat-col_pos = 12.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
wa_fcat-fieldname = c_parza.
wa_fcat-seltext_l = 'Partner counter'(013).
wa_fcat-col_pos = 13.
APPEND wa_fcat TO fieldcatalog.
CLEAR wa_fcat.
*fieldcatalog-fieldname = c_kunnr.
fieldcatalog-seltext_l = 'Customer Master'(001).
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_ort01.
fieldcatalog-seltext_l = 'City'(002).
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_pstlz.
fieldcatalog-seltext_l = 'Postal Code'(003).
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_regio.
fieldcatalog-seltext_l = 'Region'(004).
fieldcatalog-col_pos = 4.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_bukrs.
fieldcatalog-seltext_l = 'Company Code'(005).
fieldcatalog-col_pos = 5.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_zterm.
fieldcatalog-seltext_l = 'Terms of payment'(006).
fieldcatalog-col_pos = 6.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_vkorg.
fieldcatalog-seltext_l = 'Sales Organization'(007).
fieldcatalog-col_pos = 7.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_vtweg.
fieldcatalog-seltext_l = 'Distribution Channel'(008).
fieldcatalog-col_pos = 8.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_spart.
fieldcatalog-seltext_l = 'Division'(009).
fieldcatalog-col_pos = 9.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_parvw.
fieldcatalog-seltext_l = 'Partner function'(010).
fieldcatalog-col_pos = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_kunn2.
fieldcatalog-seltext_l = 'Customer number of partner'(011).
fieldcatalog-col_pos = 11.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_lifnr.
fieldcatalog-seltext_l = 'Account Number of Vendor'(012).
fieldcatalog-col_pos = 12.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = c_parza.
fieldcatalog-seltext_l = 'Partner counter'(013).
fieldcatalog-col_pos = 13.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG
*& Form build_layout
text
--> p1 text
<-- p2 text
form build_layout .
Set layout field for field attributes(i.e. input/output)
wa_layout-stylefname = 'FIELD_STYLE'.
wa_layout-zebra = 'X'.
endform. " build_layout
*& Form GRID_DISPLAY
text
FORM grid_display. "using t_data type ty_tbl_data.
IF it_alv[] IS NOT INITIAL.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
IS_LAYOUT = wa_layout
it_fieldcat = fieldcatalog[]
TABLES
t_outtab = it_alv[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "GRID_DISPLAY
*& Form VALIDATE_DATA
text
--> p1 text
<-- p2 text
FORM validate_data .
DATA : li_kna1 TYPE STANDARD TABLE OF ty_kna1,
li_knb1 TYPE STANDARD TABLE OF ty_knb1,
li_knvp TYPE STANDARD TABLE OF ty_knvp.
SELECT kunnr
FROM kna1
INTO TABLE li_kna1
WHERE kunnr IN s_kunnr.
IF sy-subrc <> 0.
MESSAGE 'Invalid Customer Number'(013) TYPE 'E'.
ENDIF.
SELECT bukrs
FROM t001
INTO TABLE li_knb1
WHERE bukrs IN s_bukrs.
IF sy-subrc <> 0.
MESSAGE 'Invalid Company Code'(014) TYPE 'E'.
ENDIF.
SELECT vkorg
FROM tvko
INTO TABLE li_knvp
WHERE vkorg IN s_vkorg.
IF sy-subrc <> 0.
MESSAGE 'Invalid Sales Organization'(015) TYPE 'E'.
ENDIF.
SELECT vtweg
FROM tvtw
INTO TABLE li_knvp
WHERE vtweg IN s_vtweg.
IF sy-subrc <> 0.
MESSAGE 'Invalid Distribution Channel'(016) TYPE 'E'.
ENDIF.
SELECT spart
FROM tspa
INTO TABLE li_knvp
WHERE spart IN s_spart.
IF sy-subrc <> 0.
MESSAGE 'Invalid Division'(017) TYPE 'E'.
ENDIF.
SELECT parvw
FROM tpar
INTO TABLE li_knvp
WHERE parvw IN s_parvw.
IF sy-subrc <> 0.
MESSAGE 'Invalid Partner function'(018) TYPE 'E'.
ENDIF.
ENDFORM. " VALIDATE_DATA*1----
FORM get_data.
SELECT kna1~kunnr
kna1~ort01
kna1~pstlz
kna1~regio
knb1~bukrs
knb1~zterm
INTO TABLE it_data
FROM kna1 INNER JOIN knb1
ON kna1kunnr = knb1kunnr
WHERE kna1~kunnr IN s_kunnr
AND knb1~bukrs IN s_bukrs.
CHECK it_data[] IS NOT INITIAL.
SELECT kunnr
vkorg
vtweg
spart
parvw
parza
kunn2
lifnr
INTO TABLE it_knvp FROM knvp
FOR ALL ENTRIES IN it_data
WHERE kunnr = it_data-kunnr
AND vkorg IN s_vkorg
AND vtweg IN s_vtweg
AND spart IN s_spart
AND parvw IN s_parvw.
IF sy-subrc EQ 0.
SORT it_knvp BY kunnr.
ENDIF.
ENDFORM. " get_data
*2----
FORM final_table .
LOOP AT it_data INTO wa_data.
READ TABLE it_knvp
INTO wa_knvp
WITH KEY kunnr = wa_data-kunnr
BINARY SEARCH .
IF sy-subrc = 0.
MOVE-CORRESPONDING wa_data TO wa_alv.
MOVE-CORRESPONDING wa_knvp TO wa_alv.
APPEND wa_alv TO it_alv.
ENDIF.
ENDLOOP.
ENDFORM. " FINAL_TABLE
Edited by: Faisal Khan on Mar 27, 2008 1:59 PM
Maybe you are looking for
-
How to retrieve the data from Website and Upload it in SAP table?
Dear ABAPers, I want to retrieve the data from website and upload the same in SAP Database Table is that possible.Please help me.It is very Urgent. Thanks & Regards, Ashok.
-
Using 9iAS Database for BI Applications?
We have a 9205 Database that is serving as our data warehouse. I have created several servlets and java client classes using BI Beans and JDeveloper. I want to deploy them using 9i Application Server. The 9iAS install installs another database. Shoul
-
How to create new Wage type specifically for IT14 and IT15 only
Hi Gurus, I was assigned to create a new wage type to be used for Infotypes 14 and 15 only. Another thing is to have this for % deduction rather than having a fixed amount ($). Appreciate all your help. thanks!
-
Error Starting Calendar Server
I have OCV2 installed on Solaris 8 and I am getting the following error in cws.log when I try to start the calendar server. ./unistart unistart: Oracle Calendar Server 9.0.4 unistart: Copyright (c) 1993, 2003, Oracle. unistart: All rights reserved. u
-
Possible to import GIS data into the Map app?
I would love to be able to import lat/long data into the Map app to display transit stop info on the job, as I do now with a crappy PC portable and Delorme Street Atlas. Possible? Thanks