Selection from bsak & bseg
Hi experts,
Iam trying to extract data from bsak & bseg something like..
Litm pk
001 31 19000038 20050303 20050610
but i need to extract compelete Line items & posting keys like..
Litm pk budat belnr augbl
001 31 20051010 190000038 20050303
002 40
003 40
004 40
001 31 20051010 190000039 20050303
002 40
003 40
004 40
Could any one tell me how can achieve this logic through internal table?Points guaranteed.
reward guaranteed
Kaki
Hi all,
Pls look into my code.I need to display complete "Line item" and "posting keys" for the particular "Doc no".
REPORT Z1F_RFKEPL00 no standard page heading
line-size 140
line-count 65
message-id Z1.
TABLES: LFA1,t005t,bsak,bseg,t001,skat.
data: begin of t_bsak occurs 0,
bukrs like bsak-bukrs, "company code
lifnr like bsak-lifnr, "Vendor acc number
augdt like bsak-augdt, "Clearing date
AUGBL like bsak-AUGBL, "Clearing Document
GJAHR like bsak-GJAHR, "year
belnr like bsak-belnr, "Document number
BUZEI like bsak-BUZEI, "Line Item
budat like bsak-budat, "Posting Date in the Document
bldat like bsak-bldat, "Document date in document
blart like bsak-blart, "Document type
BSCHL like bsak-BSCHL, "Posting key
WAERS like bsak-WAERS, "Currency key
CPUDT like bsak-cpudt, "Accounting Document Entry Date
SHKZG like bsak-shkzg, "Debit/Credit Indicator
DMBTR like bsak-dmbtr, "Amount in local currency
WRBTR like bsak-wrbtr, "Amount in document currency
SGTXT like bsak-sgtxt, "Item Text
SAKNR LIKE bsak-saknr, "G/L Account Number
hkont like bsak-hkont, "General Ledger Account
SKFBT LIKE BSAK-SKFBT, "Amount Eligible for Cash Discount
KOSTL LIKE BSEG-KOSTL, "Cost center
ktopl like t001-ktopl, "chart of accounts
txt20 like skat-txt20, "Short test for the GL acc
end of t_bsak.
data: begin of t_lfa1 occurs 0,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
land1 like lfa1-land1,
landx like t005t-landx,
end of t_lfa1.
data: begin of t_header occurs 0,
bukrs like bsak-bukrs,
hkont like bsak-hkont,
lifnr like bsak-lifnr,
land1 like lfa1-land1,
landx like t005t-landx,
end of t_header.
data: begin of t_data occurs 0,
belnr like bsak-belnr,
bukrs like bsak-bukrs,
gjahr like bsak-gjahr,
hkont like bsak-hkont,
augbl like bsak-augbl,
bschl like bsak-bschl,
buzei like bsak-buzei,
KOSTL LIKE BSEG-KOSTL,
end of t_data.
selection-screen begin of block blk1 with frame title text-001.
select-options: s_lifnr for bsak-lifnr,
s_bukrs for bsak-bukrs.
selection-screen end of block blk1.
selection-screen begin of block blk2 with frame title text-002.
parameters s_budat like bsik-budat default sy-datum.
select-options: s_augdt for bsak-augdt.
selection-screen end of block blk2.
selection-screen begin of block blk3 with frame title text-003.
parameters: stand as checkbox default 'X',
park as checkbox.
selection-screen end of block blk3.
start-of-selection.
perform process_data.
top-of-page.
perform set_page_header.
*& Form process_data
text
form process_data.
data: line like t_bsak occurs 0 with header line.
data: l_wrbtr(10) type c.
data: l_debit type bsak-wrbtr,l_credit type bsak-wrbtr,
l_balance type bsak-wrbtr.
data:l_hkont(10) type n.
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR BUZEI BUDAT BLDAT
CPUDT WAERS BLART BSCHL SHKZG DMBTR WRBTR SGTXT HKONT SKFBT
from bsak
into corresponding fields of table t_bsak
where BUKRS in s_bukrs and budat le s_budat " Open items
order by lifnr.
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR BUDAT BLDAT CPUDT
WAERS BLART SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL BSCHL hkont BUZEI
from bsak into corresponding fields of table t_bsak
where BUKRS eq '1000' and
lifnr = 'AARONWU'.
sort t_bsak by BUDAT.
loop at t_bsak.
select belnr bukrs gjahr hkont buzei bschl from bseg
into table t_data where belnr = t_bsak-belnr and
bukrs = t_bsak-bukrs and
gjahr = t_bsak-gjahr.
select single * from bseg
where belnr = t_bsak-belnr and
bukrs = t_bsak-bukrs and
gjahr = t_bsak-gjahr.
move-corresponding bseg to t_data.
move bseg-belnr to t_data-belnr.
move bseg-bukrs to t_data-bukrs.
move bseg-gjahr to t_data-gjahr.
move bseg-hkont to t_data-hkont.
move bseg-kostl to t_data-kostl.
move bseg-bschl to t_data-bschl.
if sy-subrc = 0.
append t_data.
clear t_data.
endif.
endloop.
loop at t_bsak.
to get vendor name
select single * from lfa1 where lifnr = t_bsak-lifnr.
move lfa1-lifnr to t_lfa1-lifnr.
move lfa1-land1 to t_lfa1-land1.
move lfa1-name1 to t_lfa1-name1.
if sy-subrc = 0.
append t_lfa1.
clear t_lfa1.
endif.
endloop.
to get vendor country
loop at t_lfa1.
select single * from t005t where land1 = t_lfa1-land1 and
SPRAS = 'E'.
move t005t-landx to t_lfa1-landx.
if sy-subrc = 0.
modify t_lfa1.
clear t_lfa1.
endif.
endloop.
delete adjacent duplicates from t_lfa1.
*Display----
*to display header
data: l_buzei type bseg-buzei.
loop at t_lfa1.
write:/1(6) t_bsak-bukrs color 2,
7(8) t_bsak-hkont color 2,
18(10) t_bsak-lifnr color 2.
write:/30(10) t_lfa1-name1.
write:/30(10) t_lfa1-landx.
uline.
loop at t_bsak where lifnr = t_lfa1-lifnr.
l_wrbtr = t_bsak-wrbtr.
if t_bsak-wrbtr = t_bsak-skfbt.
concatenate l_wrbtr '-' into l_wrbtr.
endif.
loop at t_data where belnr = t_bsak-belnr and
bukrs = t_bsak-bukrs and
gjahr = t_bsak-gjahr.
l_buzei = t_data-buzei.
endloop.
write:/15(10) t_bsak-BUDAT no-zero color 2,
26(5) t_bsak-BLART color 2,
30(10) t_bsak-belnr color 2,
42(10) t_bsak-BLDAT color 2,
58(5) t_bsak-buzei color 2,
63(4) t_bsak-BSCHL color 2,
75(7) t_bsak-AUGDT color 2,
84(10) t_bsak-AUGBL color 2,
119(7) t_bsak-WAERS color 2,
126(12) t_bsak-WRBTR color 2.
126(12) l_wrbtr color 2.
write:/55 t_bsak-sgtxt.
write:/60(10) t_bsak-hkont,
80(10) t_bsak-kostl,
90(30) t_bsak-txt20.
clear l_wrbtr.
endloop.
uline.
write:/1(6) t_bsak-bukrs color 2,
7(8) t_bsak-hkont color 2,
18(10) t_bsak-lifnr color 2.
uline.
endloop.
write:/1(6) t_bsak-bukrs color 2,
7(8) t_bsak-hkont color 2,
18(10) t_bsak-lifnr color 2,
105(5) t_bsak-waers color 2.
line[] = t_bsak[].
loop at line.
if line-shkzg = 'H'.
l_debit = l_debit + line-wrbtr.
endif.
if line-shkzg = 'S'.
l_credit = l_credit + line-wrbtr.
endif.
endloop.
l_balance = l_debit - l_credit.
write:115(15) l_debit. write:135(1) 'D'.
write:/115(15) l_credit. write:135(1) 'C'.
for balnce
write:/90(5) 'Bal.:'.
write:115(15) l_balance.
clear: l_debit,l_credit,l_balance.
uline.
endform. "process_data
*& Form set_page_header
text
FORM set_page_header.
call function 'Z_REPORT_TITLE'
EXPORTING
line_size = sy-linsz
sy_title = 'List of Vendor Line Items'
uline = 'X'
first_page_only = ' '.
write :1(15) 'Allocation' color col_heading,
15(10) 'Pstng' color col_heading,
25(5) 'Do' color col_heading,
30(10) 'Documnet' color col_heading,
40(10) 'Doc' color col_heading,
50(8) 'BusA' color col_heading,
58(5) 'LIm' color col_heading,
63(4) 'PK' color col_heading,
67(4) 'S' color col_heading,
71(4) 'P' color col_heading,
75(7) 'Clrg' color col_heading,
82(10) 'Clearing' color col_heading,
92(20) 'D/c discount Amnt' color col_heading,
112(5) 'Rsn' color col_heading,
117(2) 'G' color col_heading,
119(7) 'Curr-' color col_heading,
126(12) 'Amount in' color col_heading,
138(2) 'T' color col_heading.
write space.
write :1(15) 'number' color col_heading,
15(10) 'date' color col_heading,
25(5) 'ty' color col_heading,
30(10) 'number' color col_heading,
40(18) 'date' color col_heading,
58(5) '' color col_heading,
63(4) '' color col_heading,
67(4) 'I' color col_heading,
71(4) 'K' color col_heading,
75(7) 'date' color col_heading,
82(24) 'doc.no' color col_heading,
105(20) 'in LC' color col_heading,
112(5) 'code' color col_heading,
117(2) 'L' color col_heading,
119(7) 'ency' color col_heading,
126(12) 'doc.curr.' color col_heading,
138(2) 'X' color col_heading.
write space.
uline.
ENDFORM. " set_page_header
Similar Messages
-
Hi,
Iam trying to use bsak-budat with bseg-gjahr.But lengths are not same. I had offsetting with budat.But values are not matching...could any one tell me how to do that?
points guaranteed
cheers
kaki
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR BUZEI BUDAT BLDAT
CPUDT WAERS BLART BSCHL SHKZG DMBTR WRBTR SGTXT HKONT SKFBT
from bsak
into corresponding fields of table t_bsak
where
lifnr in s_lifnr and
BUKRS in s_bukrs and
budat le s_budat and augdt in s_augdt.
loop at t_bsak.
l_year = t_bsak-budat(4).
endloop.
CHECK NOT t_bsak[] IS INITIAL.
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR
SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL BSCHL HKONT BUZEI
into corresponding fields of table t_bseg from bseg
FOR ALL ENTRIES IN t_bsak
where belnr = t_bsak-belnr and
gjahr = l_year and " xxxxxx
bukrs = t_bsak-bukrs.Define a field I_YEAR in int table T_BSAK.
DATA Begin of t_BSAK,
I_YEAR LIKE BSEG-GJAHR,
end of t_bsak.
loop at t_bsak.
t_bsak-l_year = t_bsak-budat(4).
modify t_bsak.
endloop.
Then
select BUKRS LIFNR AUGDT AUGBL GJAHR BELNR
SHKZG DMBTR WRBTR SGTXT SKFBT KOSTL BSCHL HKONT BUZEI
into corresponding fields of table t_bseg from bseg
FOR ALL ENTRIES IN t_bsak
where belnr = t_bsak-belnr and
gjahr = t_bsak-i_year and " xxxxxx
bukrs = t_bsak-bukrs.
Alternatively why not select gjahr from BSAK .
Cheers .
Sanjay -
Hi
The below mentioned piece of code is throwing a dump in Production system.
Is there any way of alternate selection.
IF NOT it_pos[] IS INITIAL.
SELECT * FROM bseg INTO
TABLE it_bseg
FOR ALL ENTRIES IN it_pos
WHERE bukrs IN dd_bukrs
AND belnr = it_pos-belnr
AND gjahr = it_pos-gjahr.
ENDIF.
Regards
Subin.SI think you need to post a few more details of the environment and error to assist people in offering solution.
Questions I think of are:
- What type of dump are you getting? - Out of Time? Out of Memory? Other?
- How many entries are in internal table it_pos[] before the BSEG select starts?
- How many entries are in BSEG approximately?
- Do you need all the BSEG records to be selected into an internal table at once or can you process them in smaller sets?
- Do you have a number of other large internal tables in your program? Can any of these be cleared to free up memory?
- can you run SQL trace (ST05) against the program to see the execution time for each fetch from BSEG and how many records each fetch returns?
- why are you doing two selects from BSEG? What is the difference between them? normally better to get all the fields at the same time instead of selecting twice.
- in Development or Test where there is less data, does tha program run OK? If so, can you run it in SE30 to see what that transaction highlights as performance or similar issues?
- what table or tables do you fill table it_pos[] from? are there any duplicate records in this internal table?
- what SAP version are you running? 32 bit or 64 bit? What database?
To solve an issue like this with a program these and probably dozens of other questions must be asked and answered - and as the person on the site you are the only one able to get the answers.
Posting more details will help forum readers to evaluate the issue in light of their experience and to provide further suggestions. The more information you can give - the more likely that someone will be able to answer.
thanks
Andrew -
Need to select from BSEG on Non Key fields.
Hi all,
I am developing a report on Work Order Cost Analysis. The selection screen has Order Type (AFPO-DAUAT), Plant (AFPO-DWERK), Date range (AFKO-GLTRI) and Part Number (AFKO-PLNBEZ) as the selection criteria. <b>All the orders and their corresponding object numbers (OBJNR) are picked in an internal table</b>, for all orders that fulfill the selection criteria and their Actual Finish Date (AFKO-GLTRI) falls between the entered date range.
Now comes the problem, <b>corresponding to these Order Numbers I need to pick records from BSEG.</b> Since this is not a key field in BSEG, its not indexed and the report times out on the Development Server itself.
<b>I also tried using COEP</b> table as the fields that I need are present there as well (Though I am not sure weather it would be give me all the lines of records that I need from BSEG), but that operation also times out.
LDBs also don't seem to help. Is there any way I can achieve the above?
<b>PLEASE HELP. REWARDS GUARANTEED.</b>
Regards,
NikhilOK - a couple of things:
In the select from covp, you are retrieving the CO document data not the FI document data, so you need the reference documents.
Even though OBJNR is the first field of a key it will not be very selective. It would be better if you could specify more fields. Fortunately, some are standard and you can probably figure out what to use. If you can limit this to a single fiscal year, it would be best. Failing that, you should specify any (or all) fiscal years in a range table (using =).
This is the select that I came up with:
SELECT refbk refbn refgj refbz
FROM covp
INTO CORRESPONDING FIELDS OF TABLE it_covp
FOR ALL ENTRIES IN it_worder
WHERE lednr = '00' "Standard ledger
AND objnr = it_worder-objnr
AND gjahr IN s_gjahr
AND wrttp = '04' "Actuals
AND versn = '000' "Plan/Actual ver.
AND orgvg = 'RFBU'. "FI Postings
I filled s_gjahr with the individual years from 1995 to 2006 and it ran in under 20 minutes. (The first select was wide open and selected all.)
Rob
By the way - do you still need to go to BSEG, or can you get everything you need from COVP?
Message was edited by: Rob Burbank -
Hi all,
Can someone help me optimize the performance of this code as i don't know how else to select from BSEG as i cannot use a join coz its a cluster table. I need to find a way to improve the perfomance.Any help would be much appreciated.
SELECT belnr gjahr bukrs budat stblg awkey blart
FROM bkpf INTO CORRESPONDING FIELDS OF TABLE t_bkpf
WHERE belnr IN s_belnr and
gjahr = p_gjahr and
bukrs = p_bukrs.
LOOP AT t_bkpf.
SELECT belnr gjahr buzei ebeln ebelp
wrbtr fipos geber fistl fkber
augbl augdt shkzg
INTO CORRESPONDING FIELDS OF table t_bseg
FROM bseg
WHERE belnr = t_bkpf-belnr
AND gjahr = t_bkpf-gjahr
AND bukrs = t_bkpf-bukrs.
Thanks alot
seemaHi Seema,
You have to avoid the database retrival inside the loop.You can use for all entries.
This is taken from a link.
Some of the SAP tables are not transparant, but pooled or clustered. Be aware of this !
There are a lot of limitations on how such tables can be accessed. You can not include such
tables in database views and join constructs. The FI-GL table BSEG, which is one of our
biggest PR1 tables, is an example of a clustered table. At the database-level, there is no table
called BSEG, but instead RFBLG is being used for the BSEG data. Most of the fields known
in BSEG are not known in the database table RFBLG, but are compressed in a VARDATA
field of RFBLG. So tests in the WHERE clause of SELECTs agains BSEG are not used by
the database (e.g. lifnr = vendor account number, hkont = G/L account, kostl = cost center).
As a consequence, these tests are done after the facts similar to using the CHECK statement,
and as already said in tip 1, CHECK statements are worse than tests in the WHERE-clause.
Check this link also.
How to Read BSEG Efficiently
you'll never select table bkpf alone.
alternatives:
1) select with header information from bkpf
2) use secondary index tables
Re: Tuning cluster table selection
3) use logical data base e.g.: BRF
Hope this helps.If so,reward points.Otherwise, get back. -
Selecting from bseg misses dupicalte entry
Hi,
i select entries from bkpf/bseg as below:
select bukrs belnr gjahr budat bldat waers
into table lt_bkpf
from bkpf
where bukrs in s_bukrs
and blart in s_blart
and bldat in s_bldat
and budat in s_budat
select bukrs belnr hkont wrbtr dmbtr shkzg vbund
from bseg
into table lt_bseg
for all entries in lt_bkpf
where bukrs = lt_bkpf-bukrs
and belnr = lt_bkpf-belnr
and gjahr = lt_bkpf-gjahr
and hkont in s_hkont.
this works fine except for a few docs which all have the same 'issue' where there is a duplicate WRBTR value in bseg. e.g.
BUKRS|BELNR|BUZEI|WRBTR|HKONT
1000|12345678|001|1000.00|7777
1000|12345678|002|1355.00|7777
1000|12345678|003|1000.00|7777
1000|12345678|004|9879.00|7777
my select statements output :
1000|12345678|001|1000.00|7777
1000|12345678|002|1355.00|7777
1000|12345678|004|9879.00|7777
Notice that item 3 is not found.
Note 416076 looks kind of related but we are on 470 and that is only for 4.6X.
Any ideas, as I am stumped?
thanks.This is a trap when using the FOR ALL ENTRIES option on a select. It is mentioned in the documentation of the command. It is not related to indexes of the table.
FOR ALL ENTRIES has the same result as a SELECT DISTINCT -- duplicates are removed from the result set.
to get all entries that exist, make sure you specify ALL fields of the table primary key in the list of fields you retrieve.
so add the missing two fields to your internal table and modify your BSEG select to the following.
select bukrs belnr GJAHR BUZEI hkont wrbtr dmbtr shkzg vbund
from bseg
into table lt_bseg
for all entries in lt_bkpf
where bukrs = lt_bkpf-bukrs
and belnr = lt_bkpf-belnr
and gjahr = lt_bkpf-gjahr
and hkont in s_hkont.
This will get all BSEG entries.
To prove this in DEV/Unit Test environment with less data available, try the following:
select bukrs shkzg
from bseg
into table lt_bseg
for all entries in lt_bkpf
where bukrs = lt_bkpf-bukrs
and belnr = lt_bkpf-belnr
and gjahr = lt_bkpf-gjahr
and hkont in s_hkont.
Andrew -
Hi all
In one of my program i have to use selection from BSEG by using non key fields like anln1, hkont etc.
My program run time taking too much time i.e 1.5 to 2hrs
Is there any criteria to reduce my run time.
plz help
thks
sateeshHi
If you need a select by field hkont (so G/L account) use the table BSIS (open item) and BSAS (cleared item) instead of BSEG, just Eric said.
SELECT * FROM BSAS WHERE BUKRS = BUKRS
AND HKONT = HKONT.
SELECT SINGLE * FROM BSEG WHERE BUKRS = BSAS-BUKRS
AND BELNR = BSAS-BELNR
AND GJAHR = BSAS-GJAHR
AND BUZEI = BSAS-BUZEI.
SELECT SINGLE * FROM BKPF WHERE BUKRS = BSAS-BUKRS
AND BELNR = BSAS-BELNR
AND GJAHR = BSAS-GJAH.
Max
Edited by: max bianchi on Nov 5, 2008 11:03 AM -
Select statement using BSEG table
Hello SAPinas,
I am using the following lines of code in one of my program. Becuase of that code I am getting Performance issue.
Note : BSEG is Cluster Table.
Could you please help me how I will use in another way
loop at t_hdr.
select buzei buzid koart shkzg mwskz dmbtr hwbas sgtxt vbund kostl
aufnr anln1 anln2 hkont kunnr lifnr matnr werks ebeln ebelp
zekkn rewrt prctr txjcd projk
into (t_item-buzei, t_item-buzid, t_item-koart, t_item-shkzg,
t_item-mwskz, t_item-dmbtr, t_item-hwbas, t_item-sgtxt,
t_item-vbund, t_item-kostl, t_item-aufnr, t_item-anln1,
t_item-anln2, t_item-hkont, t_item-kunnr, t_item-lifnr,
t_item-matnr, t_item-werks, t_item-ebeln, t_item-ebelp,
t_item-zekkn, t_item-rewrt, t_item-prctr, t_item-txjcd,
t_item-projk)
from bseg
where bukrs = t_hdr-bukrs
and belnr = t_hdr-belnr
and gjahr = t_hdr-gjahr
and hkont in s_hkont
and mwskz in s_mwskz
and kostl in s_kostl
and prctr in s_prctr
and werks in s_werks.
Skip record if not in selection screen range for state
check t_item-txjcd(2) in s_state.
if t_item-shkzg = c_debit. "S
endif.
if t_item-shkzg = c_credit. "H
t_item-dmbtr = t_item-dmbtr * ( -1 ).
t_item-rewrt = t_item-rewrt * ( -1 ).
t_item-hwbas = t_item-hwbas * ( -1 ).
endif.
**&MWB 04/08/2005 ... add additional US Bayer Tax dept requested fields
clear: t_item-basetax, t_item-accrtax, t_item-vendtax,
t_item-taxrate, t_item-invbase, t_item-invtax.
**&MWB ... end insert 04/08/2005
clear t_item-hwbas.
move-corresponding t_hdr to t_item.
append t_item.
clear t_item.
endselect.
endloop.
Thank you very much Advance.............:-)As BSEG is in a cluster table RFBLG, the only index available is the primary one, so only BUKRS, BELNR and GJAHR keys are actually available. So for other criteria resolution, the program will read the whole cluster, unpacking the records and executing the selection. When most criteria come from BKPF header, you may select from BKPF and then from BSEG using the full key of the cluster, and using a [FOR ALL ENTRIES|http://help.sap.com/abapdocu/en/ABENOPEN_SQL_PERFO.htm] IN a table with the keys from BKPF.
Try to use one or more of the secondary indexes provide by SAP
- BSAD Accounting: Secondary Index for Customers (Cleared Items)
- BSAK Accounting: Secondary Index for Vendors (Cleared Items)
- BSAS Accounting: Secondary Index for G/L Accounts (Cleared Items)
- BSID Accounting: Secondary Index for Customers
- BSIK Accounting: Secondary Index for Vendors
- BSIM Secondary Index, Documents for Material
- BSIS Accounting: Secondary Index for G/L Accounts
These indexes are actual tables, so you may create/use indexes, they are also easily appended, as they are filled via move-corresponding statements.
Try a little search at sdn on keywords like [BSEG, cluster and performance|https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=bsegclusterperformance&adv=false&sortby=cm_rnd_rankvalue].
Regards -
Getting data from table BSEG taking too long ... any solutions.
Hello people I am currently trying to get data from table BSEG for one particular G/L Account Number With restrictions using For All Entries.
The problem is that even with such tight restrictions its causing my report program to run way too slow. I put an option where you dont have to access table bseg. And it runs just fine. (all of this is done during PRD Server).
My question is
1.) How come BSEG seems to make the report slow, even though I put some tight restrictions. <b>Im using For All Entries where Zuonr eq i_tab-zuonr</b>it seems to work fine in DEV and <b>hkont EQ '0020103101'</b>(Customer Deposits).
2.) Is there a way for me to do the same thing as what I mentioned in #1 but only much faster.
Thanks guys and take careHi
It should be better you don't read BSEG table if you haven't the keys BUKRS and BELNR, because the reading could take many times if there are many hits.
If you want to find out the records of G/L Account it's better read the index table BSIS (for open items) and BSAS (for cleared items), here the field HKONT is a key (and ZUONR too). So you can improve the performance:
DATA: T_ITEMS LIKE STANDARD TABLE OF BSIS.
SELECT * FROM BSAS INTO TABLE T_ITEMS
FOR ALL ENTRIES I_ITAB WHERE BUKRS = <BUKRS>
AND HKONT = '0020103101'
AND ZUONR = I_ITAB-ZUONR.
SELECT * FROM BSIS APPENDING TABLE T_ITEMS
FOR ALL ENTRIES I_ITAB WHERE BUKRS = <BUKRS>
AND HKONT = '0020103101'
AND ZUONR = I_ITAB-ZUONR.
Remember every kind of item has an own index tables:
- BSIS/BSAS for G/L Account
- BSIK/BSAK for Vendor
- BSID/BSAD for Customer
These table have the same informations you can find out from BSEG and BKPF.
Max -
Restrict selection from LDB 'DDF' based on FI Doc number(BELNR)?
Hi all,
I am trying to restrict selection from LDB 'DDF' based on FI Doc number(BELNR).
Even if i pass only one document number in selection-screen, the program is still printing lot of documents?
Where I am going wrong?
*& Report ZSUB_READ_LDB
REPORT ZSUB_READ_LDB.
DATA wa_BSEG TYPE BSEG.
SELECT-OPTIONS s_BELNR FOR wa_BSEG-BELNR.
DATA: callback TYPE TABLE OF ldbcb,
callback_wa LIKE LINE OF callback.
DATA: seltab TYPE TABLE OF rsparams,
seltab_wa LIKE LINE OF seltab.
callback_wa-ldbnode = 'BSEG'.
callback_wa-get = 'X'.
callback_wa-get_late = 'X'.
callback_wa-cb_prog = sy-repid.
callback_wa-cb_form = 'CALLBACK_BSEG'.
APPEND callback_wa TO callback.
CLEAR callback_wa.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'BELNR'.
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_BELNR TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
ldbname = 'DDF'
variant = ' '
TABLES
callback = callback
selections = seltab
EXCEPTIONS
ldb_not_reentrant = 1
ldb_incorrect = 2
ldb_already_running = 3
ldb_error = 4
ldb_selections_error = 5
ldb_selections_not_accepted = 6
variant_not_existent = 7
variant_obsolete = 8
variant_error = 9
free_selections_error = 10
callback_no_event = 11
callback_node_duplicate = 12
OTHERS = 13.
IF sy-subrc ne 0.
WRITE: 'Exception with SY-SUBRC', sy-subrc.
ENDIF.
*& Form CALLBACK_BSEG
text
-->NAME text
-->WA text
-->EVT text
-->CHECK text
FORM CALLBACK_BSEG USING name TYPE ldbn-ldbnode
wa TYPE BSEG
evt TYPE c
check TYPE c.
CASE evt.
WHEN 'G'.
WRITE: / wa-BELNR.
ULINE.
WHEN 'L'.
ULINE.
ENDCASE.
ENDFORM. "CALLBACK_BSEGHi Andreas,
I have included bukrs and gjahr too...but if I input only one invoice number the report is printing a lot of invoices.
Not sure from where the data is being picked up?
Sorry of poor formatting of code.
Thanks ,
Subba
*& Report ZSUB_READ_LDB
REPORT ZSUB_READ_LDB.
TYPE-POOLS: RSDS, RSFS.
DATA wa_BSEG TYPE BSEG.
SELECT-OPTIONS s_BELNR FOR wa_BSEG-BELNR.
SELECT-OPTIONS s_BUKRS FOR wa_BSEG-BELNR.
SELECT-OPTIONS s_GJAHR FOR wa_BSEG-BELNR.
DATA: callback TYPE TABLE OF ldbcb,
callback_wa LIKE LINE OF callback.
DATA: seltab TYPE TABLE OF rsparams,
seltab_wa LIKE LINE OF seltab.
DATA: TEXPR TYPE RSDS_TEXPR,
FSEL TYPE RSFS_FIELDS.
start-of-selection.
callback_wa-ldbnode = 'BSEG'.
callback_wa-get = 'X'.
callback_wa-get_late = 'X'.
callback_wa-cb_prog = sy-repid.
callback_wa-cb_form = 'CALLBACK_BSEG'.
APPEND callback_wa TO callback.
CLEAR callback_wa.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'BELNR'.
*seltab_wa-LOW =
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_BELNR TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'BUKRS'.
*seltab_wa-LOW =
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_BUKRS TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'GJAHR'.
*seltab_wa-LOW =
LOOP AT s_BELNR.
MOVE-CORRESPONDING s_GJAHR TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
ldbname = 'DDF'
variant = ' '
EXPRESSIONS = TEXPR
FIELD_SELECTION = FSEL
TABLES
callback = callback
selections = seltab
EXCEPTIONS
ldb_not_reentrant = 1
ldb_incorrect = 2
ldb_already_running = 3
ldb_error = 4
ldb_selections_error = 5
ldb_selections_not_accepted = 6
variant_not_existent = 7
variant_obsolete = 8
variant_error = 9
free_selections_error = 10
callback_no_event = 11
callback_node_duplicate = 12
OTHERS = 13.
IF sy-subrc ne 0.
WRITE: 'Exception with SY-SUBRC', sy-subrc.
ENDIF.
*& Form CALLBACK_BSEG
text
-->NAME text
-->WA text
-->EVT text
-->CHECK text
FORM CALLBACK_BSEG USING name TYPE ldbn-ldbnode
wa TYPE BSEG
evt TYPE c
check TYPE c.
CASE evt.
WHEN 'G'.
WRITE: / wa-BELNR.
ULINE.
WHEN 'L'.
ULINE.
ENDCASE.
ENDFORM. "CALLBACK_BSEG -
Selection from a Maintenance View
Hi,
I have to fetch data from a view, unfotunately that view is a mainteance view. Is there any other way to select/fetch data from that view in my report program ?
Regards,
Bharath Mohan BHi
U cannot access the data from maintanence view.
Only projection and database view can be used in ABAP code.
If u want to access the Data from more the one table , Create the DATABASE VIEW and use this view in ur program.
For example : UR Database view name is Ztest
in ur program
table Ztest.
select * from Ztest ***************
*******************UR Business Logic
<b>Reward if useful</b> -
URGENT : select from table statement in ABAP OO
Hi all,
I am an absolute ABAP OO beginner and need some quick help from an expert. How can I make a selection from an existing table (eg MARA) in an BADI which is programmed according to ABAP OO principles.
In the old ABAP school you could make a TABLES statement at the beginning and the do a SELECT¨* FROM but this does not work in ABAP OO.
How should i define such simple selections from existing tables. Anyone ?
Thanks a lot,
Eric Hassenberg*define internal table
data: i_mara like standard table of mara.
*select to this table
select * from mara into table i_mara.
Also you have to define work area for this internal table in order to use it.
data:w_mara like line of i_mara. -
Select from v$sql_plan in a procedure
Hi
I''m attempting to save plans (from V$SQL_PLAN) into a table using a procedure in schema APPS, but keep getting missing table error,
PL/SQL: ORA-00942: table or view does not existI then granted an explicit SELECT to APPS on the V$SQL_PLAN table from a schema with
a DBA role, but still get the same error when compiling the procedure.
SQL> create table gl_imp_post_plans as ( select * from v$sql_plan where rownum < 1);
Table created.
SQL> select count(*) from v$sql_plan;
COUNT(*)
13506
SQL> create or replace procedure Ins_Plan_from_Dictionary as
2
3 begin
4 insert into GL_Imp_Post_Plans
5 select sqo.*
6 from v$sql_plan sqo
7 where (sqo.sql_id) not in (select distinct gipi.SQL_ID
8 from GL_Imp_Post_Plans gipi)
9 and (sqo.sql_id) in (select distinct
10 sqi.sql_id
11 from v$sql_plan sqi
12 where sqi.object_owner = 'APPS'
13 and sqi.object_name in ('GL_BALANCES','GL_DAILY_BALANCES','GL_JE_LINES') );
14 commit;
15
16
17 exception
18 when others then
19 rollback;
20 -- sysao_util.Message ('O', 'Error ' || sqlerrm);
21
22 end Ins_Plan_from_Dictionary;
23 /
Warning: Procedure created with compilation errors.
SQL> show err
Errors for PROCEDURE INS_PLAN_FROM_DICTIONARY:
LINE/COL ERROR
4/5 PL/SQL: SQL Statement ignored
11/40 PL/SQL: ORA-00942: table or view does not exist
SQL>
SQL> l 11
11* from v$sql_plan sqiThe same error occurs when I attempt to select from GV$SQL_PLAN or DBA_HIST_SQL_PLAN.
Could anybody suggest how I can persist the rows into a table using a procedure?
thanksthanks, yes this works:
create or replace procedure Ins_Plan_from_Dictionary as
begin
execute immediate 'begin
insert into GL_Imp_Post_Plans
select sqo.*
from v$sql_plan sqo
where (sqo.sql_id) not in (select distinct gipi.SQL_ID
from GL_Imp_Post_Plans gipi)
and (sqo.sql_id) in (select distinct
sqi.sql_id
from v$sql_plan sqi
where sqi.object_owner = ''APPS''
and sqi.object_name in (''GL_BALANCES'',''GL_DAILY_BALANCES'',''GL_JE_LINES'') );
commit;
end;';
exception
when others then
rollback;
-- sysao_util.Message ('O', 'Error ' || sqlerrm);
end Ins_Plan_from_Dictionary;
/ -
Can not select from v$mttr_target_advice
Hello
When i try to select from the view it never comes back and is a problem for the mmon process. Anyone have any ideas.Could you pleasse post the error message and the version you are using?
Best Regards
Krystian Zieja / mob -
Can not select from my own MV. Please help.
Hello Gurus,
I have created a MV with following clauses
CREATE or REPLACE MATERIALIZED VIEW "OWNER_NAME1"."MV_Name1"
BUILD IMMEDIATE
USING INDEX
REFRESH COMPLETE
AS
SELECT column1, column2 .... from table1,table2
where .....
I have logged in to DB with the 'owner_name1' schema itself which is the owner of the MV.
But, when I try to select from the above MV. It gives error "Ora-00942 table or view does not exist"
I can see the same under 'user_objects' view as an object of owner_name1 schema.
Could you please help me in understanding where I have gone wrong?
DB - Oracle 9i on unix platform.
Thanks in advance!
Abhijit.Oh! I missed to mention the exact steps followed by me which created error for me,
viz.
1) I have 2 Database and their users as follows
bq. i) DB1 in local server - 'localUser'
bq. ii) DB2 in remote server - 'RemoteUser1' and 'RemoteUser2'
2) 'RemoteUser2' user in DB2 has 'select' privilage on table 'RemoteTable1' of 'RemoteUser1' ( both are remote DB's users ! )
i.e. select * from RemoteUser1.RemoteTable1; --works okay when logged into RemoteUser2. no synonyms are created hence using schema_name.table_name convention.
3) Logged in to 'localUser' in DB1.
4) Created a DB link 'local_to_remote2' in 'localUser' schema ( in DB1) to 'RemoteUser2' schema (in DB2)
i.e.
create database link local_to_remote2 connect to RemoteUser2 identified by password using 'connection_string';
DBLink was created successfully.
5) I could select from the tables of 'RemoteUser2' using DB Link. (by logging in to 'localUser')
i.e. select * from RemoteUser1.RemoteTable1@local_to_remote2 ; --- gives me expected output. no issues!
6) Now, I created below MV in 'localUser' ( no need to tell in 'DB1' )
the exact syntax I used is as follows,
CREATE or REPLACE MATERIALIZED VIEW "localUser"."MV_Name1"
BUILD IMMEDIATE
USING INDEX
REFRESH COMPLETE
AS
SELECT column1, column2
From RemoteUser1.RemoteTable1@local_to_remote2
where condition1
and condition2;
The MV was created successfully, and I could see it as an 'Valid' object of 'localUser' schema.
i.e. select * from user_objects where object_name ='MV_NAME1' and status ='VALID' --- tells that above create MV is an object of owner 'localUser'
But, when I try to select from the said MV. it gives me error "Ora-00942 table or view does not exist"
i.e. select * from MV_Name1; ---- neither this
select * from localUser.MV_Name1; ---- nor this works :(
Even when I try to drop the same MV it gives me same error. :(
Could you please suggest me anything so that I will be able to select from MY OWN MV ?
Please help Gurus.
Maybe you are looking for
-
Is there a way to create a web link page in Captivate 7?
I would like to create a source page for training that includes web resources with multiple links, but when the slide stops playing the links no longer work. At this time the links are on a PowerPoint slide and pulled into Captivate, but I have also
-
Open document SSO using trusted authentication.
Hi , I have a issue, We configured trusted authentication with SSO and it is working fine. Now we want to configure open document SSO for trusted authentication. We are using Remote _ user method for trusted authentication. Any one please help me on
-
Hi All, I've asked this before, but did not get the answer I was hoping for; maybe I didn't state my problem clear enough. Let me ask again. If I have a table as below(format is: int, string, string): 1, Todd, Smith 10, Chris, Lee 5, Sue, Wilson How
-
What do you do if you forget the password to you login?
I forgot my password to my computer. Now i cannot change things nor can i download things.
-
How do I NOT show pictures in mail?
My supervisor doesn't want attached pictures to show up in email when he receives them. He'd rather them show as attached files with the small icon at the top of the email. Is there a way to do this? He said if he wants to print out an email it print