BSEG extract
BSEG is a cluster table and I need to improve the performance of the extract as given below. This is really taking a long time to run. Any suggestions as to how I can improve the performance?
SELECT BELNR
BUZEI
BSCHL
SHKZG
PRCTR
KOSTL
HKONT
DMBTR
WRBTR
SGTXT
FROM BSEG
INTO TABLE IBSEG
FOR ALL entries in IBKPF
WHERE BELNR = IBKPF-BELNR
AND HKONT in gl_acct.
Here is a program that I wrote for extracting
data from BSEG. There was a part which had
some "summarized extract", which I have not posted.
REPORT zbseg_extract
LINE-SIZE 100
LINE-COUNT 65
NO STANDARD PAGE HEADING.
TYPE-POOLS : sscr.
TYPES : BEGIN OF ty_bkpf,
bukrs TYPE bkpf-bukrs, "COMPANY CODE(4)
belnr TYPE bkpf-belnr, "DOCUMENT NUMBER(10)
gjahr TYPE bkpf-gjahr, "FISCAL YEAR(4)
blart TYPE bkpf-blart, "DOC TYPE(2)
bldat TYPE bkpf-bldat, "DOC DATE(10)
budat TYPE bkpf-budat, "POSTING DATE(10)
monat TYPE bkpf-monat, "PERIOD(2)
usnam TYPE bkpf-usnam, "USER NAME(12)
tcode TYPE bkpf-tcode, "TCODE(20)
xblnr TYPE bkpf-xblnr, "REF DOC #(16)
stjah TYPE bkpf-stjah, "REVERSE DOC FICAL YR(4)
bktxt TYPE bkpf-bktxt, "DOC HEADER TEXT(25)
waers TYPE bkpf-waers, "CURRENCY KEY(5)
kursf TYPE bkpf-kursf, "EXCHG RATE(12)
bstat TYPE bkpf-bstat, "DOC STATUS(1)
END OF ty_bkpf.
TYPES : BEGIN OF ty_bseg,
bukrs TYPE bkpf-bukrs, "COMPANY CODE
belnr TYPE bkpf-belnr, "DOCUMENT NUMBER
gjahr TYPE bkpf-gjahr, "FISCAL YEAR
buzei TYPE bseg-buzei, "FI LINE ITEM(3)
augdt TYPE bseg-augdt, "CLEARING DATE(10)
augcp TYPE bseg-augcp, "CLEARING ENTRY DATE(10)
augbl TYPE bseg-augbl, "DOC # OF CLEARING DOC(10)
bschl TYPE bseg-bschl, "POSTING KEY(2)
koart TYPE bseg-koart, "ACCOUNT TYPE(1)
shkzg TYPE bseg-shkzg, "DR/CR INDIC(1)
dmbtr TYPE bseg-dmbtr, "AMT IN LOCAL CURRENCY(16)
* sgtxt TYPE bseg-sgtxt, "ITEM TEXT(50)
bewar TYPE bseg-bewar, "TRANSACTION TYPE(3)
kostl TYPE bseg-kostl, "COST CENTER(10)
saknr TYPE bseg-saknr, "G/L ACCOUNT NUMBER(10)
hkont TYPE bseg-hkont, "GENERAL LEDGR ACCT(10)
END OF ty_bseg.
* Itab of file names
TYPES: BEGIN OF ty_file,
file LIKE rlgrap-filename,
END OF ty_file.
* Result of system command
TYPES: BEGIN OF ty_result,
line(132) TYPE c,
END OF ty_result.
TYPES: BEGIN OF ty_sum_bkpf,
bukrs TYPE bkpf-bukrs, "Company Code
belnr TYPE bkpf-belnr, "DOCUMENT NUMBER
gjahr TYPE bkpf-gjahr, "Fiscal year
blart TYPE bkpf-blart, "Document type
monat TYPE bkpf-monat, "Period
END OF ty_sum_bkpf,
BEGIN OF ty_sum_bseg,
bukrs TYPE bseg-bukrs, "COMPANY CODE
belnr TYPE bseg-belnr, "DOCUMENT NUMBER
gjahr TYPE bseg-gjahr, "FISCAL YEAR
hkont TYPE bseg-hkont, "GENERAL LEDGR ACCT
dmbtr TYPE bseg-dmbtr, "AMT IN LOCAL CURRENCY
END OF ty_sum_bseg.
DATA: t_bkpf TYPE TABLE OF ty_bkpf,
t_bseg TYPE TABLE OF ty_bseg,
t_file TYPE TABLE OF ty_file,
t_result TYPE TABLE OF ty_result,
t_sum_bkpf TYPE TABLE OF ty_sum_bkpf,
t_sum_bseg TYPE TABLE OF ty_sum_bseg.
DATA wa_file LIKE LINE OF t_file.
DATA wa_result LIKE LINE OF t_result.
DATA w_cmd(132) TYPE c. "unix command
DATA gv_current_file LIKE rlgrap-filename.
FIELD-SYMBOLS: <bkpf> TYPE ty_bkpf,
<bseg> TYPE ty_bseg,
<bkpf_s> TYPE ty_sum_bkpf,
<bseg_s> TYPE ty_sum_bseg.
DATA: gc_bkpf TYPE cursor,
wa_out(1000) TYPE c,
lv_belnr LIKE bseg-belnr,
lv_kursf(16) TYPE c,
lv_dmbtr(20) TYPE c,
w_monat LIKE bkpf-monat,
lv_dcpfm LIKE usr01-dcpfm, "Decimal point format
w_bkpf_cnt(9) TYPE n, "# of records from BKPF
w_bseg_cnt(9) TYPE n, "# of records from BSEG
w_max TYPE i VALUE 1000,
gv_error(1) TYPE c,
w_current_size(9) TYPE n,
gv_file_ct(8) TYPE n VALUE '1', "initial value of file suffix
wa_bkpf TYPE bkpf,
lv_flag.
DATA : ls_restriction TYPE sscr_restrict,
ls_opt_list TYPE sscr_opt_list,
ls_*** TYPE sscr_***.
CONSTANTS c_pipe(1) TYPE c VALUE '|'.
CONSTANTS: c_x(1) TYPE c VALUE 'X',
c_option(2) VALUE 'EQ',
c_sign(1) VALUE 'I',
c_yes(1) VALUE '1',
c_no(1) VALUE '0',
c_txt(4) TYPE c VALUE '.TXT',
c_gz(3) TYPE c VALUE '.gz',
c_selgrp(3) VALUE 'SEL',
c_pargrp(3) VALUE 'PAR',
c_cmd1(15) TYPE c VALUE 'gzip -v -S .gz',
c_cmd2(8) TYPE c VALUE '2>&1',
c_noint(10) VALUE 'NOINTERVLS',
c_s(1) VALUE 'S',
c_name(7) VALUE 'S_BLART',
c_modgrp(3) VALUE 'MOD'.
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-t03.
PARAMETERS p_detail RADIOBUTTON GROUP rad USER-COMMAND rem.
PARAMETERS p_sum RADIOBUTTON GROUP rad.
SELECTION-SCREEN END OF BLOCK blk.
SELECTION-SCREEN BEGIN OF BLOCK one WITH FRAME TITLE text-t01.
PARAMETERS p_bukrs LIKE bkpf-bukrs OBLIGATORY default 'US15'.
* SELECT-OPTIONS
* s_belnr FOR lv_belnr.
PARAMETERS p_gjahr LIKE bkpf-gjahr OBLIGATORY default sy-datum(4).
PARAMETERS p_monat LIKE bkpf-monat OBLIGATORY
MODIF ID par default sy-datum+4(2).
SELECT-OPTIONS
s_monat FOR w_monat
MODIF ID sel.
SELECT-OPTIONS
s_blart FOR wa_bkpf-blart
NO INTERVALS MODIF ID mod.
SELECTION-SCREEN SKIP.
PARAMETERS p_file LIKE rlgrap-filename OBLIGATORY
DEFAULT text-001.
SELECTION-SCREEN END OF BLOCK one.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK two WITH FRAME TITLE text-t02.
PARAMETERS p_size TYPE i OBLIGATORY
DEFAULT w_max.
PARAMETERS p_count TYPE i OBLIGATORY "Count on the number of
DEFAULT '20000'. "BSEG records per file
PARAMETERS p_zip TYPE c AS CHECKBOX DEFAULT c_x.
SELECTION-SCREEN END OF BLOCK two.
INITIALIZATION.
CLEAR w_bkpf_cnt.
CLEAR w_bseg_cnt.
CLEAR p_monat.
REFRESH s_monat.
REFRESH t_file.
* Restrict the select-options S_BLART
CLEAR ls_opt_list.
ls_opt_list-name = c_noint.
ls_opt_list-options-eq = c_x.
APPEND ls_opt_list TO ls_restriction-opt_list_tab.
CLEAR ls_***.
ls_***-kind = c_s.
ls_***-name = c_name.
ls_***-sg_main = c_sign.
ls_***-sg_addy = space.
ls_***-op_main = c_noint.
ls_***-op_addy = c_noint.
APPEND ls_*** TO ls_restriction-***_tab.
CLEAR ls_opt_list.
CLEAR ls_***.
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
restriction = ls_restriction
EXCEPTIONS
too_late = 1
repeated = 2
selopt_without_options = 3
selopt_without_signs = 4
invalid_sign = 5
empty_option_list = 6
invalid_kind = 7
repeated_kind_a = 8
OTHERS = 9.
AT SELECTION-SCREEN.
IF p_detail EQ c_x.
if s_blart[] is initial.
MESSAGE e257(F0) WITH text-013 text-014.
endif.
ELSEIF p_sum EQ c_x.
ENDIF.
START-OF-SELECTION.
REFRESH t_bkpf.
REFRESH t_sum_bkpf.
CLEAR lv_dcpfm.
* First file name
CONCATENATE p_file gv_file_ct c_txt INTO gv_current_file.
OPEN DATASET gv_current_file IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
IF sy-subrc NE 0.
gv_error = c_x.
FORMAT COLOR COL_NEGATIVE.
WRITE : text-002, gv_current_file.
STOP.
ELSE.
CLEAR wa_out.
CONCATENATE text-010 gv_current_file
INTO wa_out SEPARATED BY space.
TRANSFER wa_out TO gv_current_file LENGTH 1000.
CLEAR wa_out.
IF p_detail EQ c_x.
CONCATENATE text-h01 text-h02 text-h03
INTO wa_out SEPARATED BY c_pipe.
else.
MOVE text-s01 TO wa_out.
endif.
TRANSFER wa_out TO gv_current_file LENGTH 1000.
ENDIF.
IF sy-sysid = c_yrp.
REFRESH s_monat.
s_monat-sign = c_sign.
s_monat-option = c_option.
s_monat-low = p_monat.
APPEND s_monat.
CLEAR: p_monat, s_monat.
ENDIF.
IF p_detail EQ c_x.
perform do_detailed_extract.
ELSEIF p_sum EQ c_x.
perform do_summarized_extract.
endif.
CLOSE DATASET gv_current_file.
IF NOT p_zip IS INITIAL.
* zip the file just created.
CLEAR w_cmd.
REFRESH t_result.
CONCATENATE c_cmd1 gv_current_file c_cmd2
INTO w_cmd SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD w_cmd
ID 'TAB' FIELD t_result[].
WRITE : /1 w_cmd COLOR COL_POSITIVE INTENSIFIED OFF.
LOOP AT t_result INTO wa_result.
WRITE /5 wa_result
COLOR COL_POSITIVE INTENSIFIED ON.
ENDLOOP.
CONCATENATE gv_current_file c_gz INTO gv_current_file.
ENDIF.
* Retain last file name
CLEAR wa_file.
MOVE gv_current_file TO wa_file.
APPEND wa_file TO t_file.
CLEAR wa_file.
END-OF-SELECTION.
IF gv_error IS INITIAL.
* Write out the selection screen parameters
WRITE:/ text-004 COLOR COL_HEADING,
p_bukrs COLOR COL_TOTAL INTENSIFIED OFF,
/ text-005 COLOR COL_HEADING,
p_gjahr COLOR COL_TOTAL INTENSIFIED OFF,
/ text-011 COLOR COL_HEADING,
s_monat-low COLOR COL_TOTAL INTENSIFIED OFF,
/ text-006 COLOR COL_HEADING.
* Display all files generated
CLEAR wa_file.
LOOP AT t_file INTO wa_file.
IF sy-tabix = 1.
WRITE: 15 wa_file COLOR COL_TOTAL INTENSIFIED OFF.
ELSE.
WRITE: /15 wa_file COLOR COL_TOTAL INTENSIFIED OFF.
ENDIF.
CLEAR wa_file.
ENDLOOP.
* # of records processed from BKPF, BSEG
SKIP 2.
WRITE: / text-007,
w_bkpf_cnt COLOR COL_POSITIVE INTENSIFIED OFF,
/ text-008,
w_bseg_cnt COLOR COL_POSITIVE INTENSIFIED OFF.
ELSE.
WRITE text-009 COLOR COL_NEGATIVE.
ENDIF.
*& Form do_detailed_extract
* text
* --> p1 text
* <-- p2 text
FORM do_detailed_extract .
* Detailed Extract *
OPEN CURSOR gc_bkpf FOR
SELECT bukrs
belnr
gjahr
blart
bldat
budat
monat
usnam
tcode
xblnr
stjah
bktxt
waers
kursf
bstat
FROM bkpf
WHERE bukrs EQ p_bukrs
* AND belnr IN s_belnr
AND gjahr EQ p_gjahr
AND blart IN s_blart
AND monat IN s_monat.
CLEAR w_max.
w_max = p_size.
CLEAR w_current_size.
DO.
FETCH NEXT CURSOR gc_bkpf
INTO TABLE t_bkpf
PACKAGE SIZE w_max.
IF sy-subrc NE 0.
CLOSE CURSOR gc_bkpf.
EXIT.
ELSEIF sy-subrc EQ 0.
REFRESH t_bseg.
IF NOT t_bkpf[] IS INITIAL.
SELECT bukrs
belnr
gjahr
buzei
augdt
augcp
augbl
bschl
koart
shkzg
dmbtr
* sgtxt
bewar
kostl
saknr
hkont
FROM bseg
INTO TABLE t_bseg
FOR ALL ENTRIES IN t_bkpf
WHERE bukrs EQ t_bkpf-bukrs
AND belnr EQ t_bkpf-belnr
AND gjahr EQ t_bkpf-gjahr.
IF sy-subrc EQ 0.
* PREPARE THE EXTRACT
LOOP AT t_bkpf ASSIGNING <bkpf>.
w_bkpf_cnt = w_bkpf_cnt + 1.
LOOP AT t_bseg ASSIGNING <bseg>
WHERE bukrs EQ <bkpf>-bukrs
AND belnr EQ <bkpf>-belnr
AND gjahr EQ <bkpf>-gjahr.
CLEAR wa_out.
WRITE <bkpf>-kursf TO lv_kursf.
WRITE <bseg>-dmbtr TO lv_dmbtr.
CONCATENATE <bkpf>-bukrs
<bkpf>-belnr
<bkpf>-gjahr
<bseg>-buzei
<bkpf>-blart
<bkpf>-bldat
<bkpf>-budat
<bkpf>-monat
<bkpf>-usnam
<bkpf>-tcode
<bkpf>-xblnr
<bkpf>-stjah
<bkpf>-bktxt
<bkpf>-waers
lv_kursf
<bkpf>-bstat
<bseg>-augdt
<bseg>-augcp
<bseg>-augbl
<bseg>-bschl
<bseg>-koart
<bseg>-shkzg
lv_dmbtr
* <bseg>-sgtxt
<bseg>-bewar
<bseg>-kostl
<bseg>-saknr
<bseg>-hkont
INTO wa_out SEPARATED BY c_pipe.
REPLACE ',' IN wa_out WITH ''.
TRANSFER wa_out TO gv_current_file LENGTH 1000.
w_bseg_cnt = w_bseg_cnt + 1.
* Logic to split files as per Count on sel. screen
w_current_size = w_current_size + 1.
IF w_current_size EQ p_count.
CLEAR w_current_size.
CLEAR wa_out.
* Denote end of current file
CONCATENATE text-003 gv_file_ct INTO wa_out.
TRANSFER wa_out TO gv_current_file.
CLOSE DATASET gv_current_file.
IF NOT p_zip IS INITIAL.
* zip the file just closed.
CLEAR w_cmd.
REFRESH t_result.
CONCATENATE c_cmd1 gv_current_file c_cmd2
INTO w_cmd SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD w_cmd
ID 'TAB' FIELD t_result[].
WRITE /1 w_cmd COLOR COL_POSITIVE INTENSIFIED OFF.
LOOP AT t_result INTO wa_result.
WRITE /5 wa_result
COLOR COL_POSITIVE INTENSIFIED ON.
ENDLOOP.
CONCATENATE gv_current_file c_gz INTO gv_current_file.
ENDIF.
* Retain name of current file
CLEAR wa_file.
MOVE gv_current_file TO wa_file.
APPEND wa_file TO t_file.
CLEAR wa_file.
CLEAR: wa_out, gv_current_file.
gv_file_ct = gv_file_ct + 1. "increment file counter
CONDENSE gv_file_ct.
CONCATENATE p_file gv_file_ct c_txt
INTO gv_current_file.
* Open next file
OPEN DATASET gv_current_file IN TEXT MODE
FOR OUTPUT ENCODING DEFAULT.
IF sy-subrc NE 0.
gv_error = c_x.
FORMAT COLOR COL_NEGATIVE.
WRITE : text-002, gv_current_file.
STOP.
ELSE.
CLEAR wa_out.
CONCATENATE text-010 gv_current_file
INTO wa_out SEPARATED BY space.
TRANSFER wa_out TO gv_current_file LENGTH 1000.
CLEAR wa_out.
CONCATENATE text-h01 text-h02 text-h03
INTO wa_out SEPARATED BY c_pipe.
TRANSFER wa_out TO gv_current_file LENGTH 1000.
ENDIF.
* End of file split logic
ENDIF.
ENDLOOP.
DELETE t_bseg WHERE bukrs EQ <bkpf>-bukrs
AND belnr EQ <bkpf>-belnr
AND gjahr EQ <bkpf>-gjahr.
ENDLOOP.
CLEAR wa_out.
CONCATENATE text-003 gv_file_ct INTO wa_out.
TRANSFER wa_out TO gv_current_file.
ENDIF. "END OF SY-SUBRC CHECK
ENDIF.
REFRESH: t_bkpf, t_bseg.
ENDIF. " ELSEIF SY-SUBRC EQ 0.
ENDDO. " DO
ENDFORM. " do_detailed_extract
Similar Messages
-
Gurus,
I have to write the logic to fetch data from bkpf and bseg. Need help on how can i do that..
I have to get bukrs belnr gjahr ldgrp from BKPF for a given date and company code. For all these documents, then i have to get the line items from BSEG if the ldgrp is I1 or SPACE.
If the ldgrp is not I1 or SPACE then i have to fetch the records from BSEG_ADD and then generate a ALV report with all the data including the data that was fetched from BKPF.
So, it wil be a combined ALV report that displays header as well as LINE item data together...
Can u please help me with the code...I am not sure how can everything go all together in one internal table....Becoz once its there in one table then only a ALV list can be generated.......
Cheers:
Samhi Sam, this may be of some similar thing.
Use this program, I got this prog from a source and we added a small conditional check in the program which checks document numbers in BSEG and also comapres in BKPF and sees if the output from BSEG falls under the posting data range specified in the initial selection.
Now just so you know, this output is kinda messed up, so you will have to play with it in Excel to extract the document numbers, if that is what you want.
============================
PROGRAM....... ZFI_BSEG_DOWNLOAD
TITLE......... Download BSEG
PROGRAM TYPE.. Download
======================================================================
GENERAL DOCUMENTATION AND COMMENTS
<...>
======================================================================
ASSOCIATED PROGRAMS
<Program>..... <Description>
======================================================================
CHANGE HISTORY
Date By Ticket Description
REPORT zfi_bseg_download.
TABLES: bseg, bkpf.
TYPES: BEGIN OF ty_output,
line(6000) TYPE c,
END OF ty_output.
TYPES: ty_tab_output TYPE TABLE OF ty_output,
ty_tab_nametab TYPE TABLE OF x031l.
CONSTANTS: c_delimiter(04) TYPE c VALUE '"%%"',
c_records TYPE i VALUE 10000.
SELECTION-SCREEN
SELECT-OPTIONS: p_bukrs FOR bseg-bukrs,
p_belnr FOR bseg-belnr,
p_buzei FOR bseg-buzei,
p_gjahr FOR bseg-gjahr,
p_budat for bkpf-budat.
SELECTION-SCREEN SKIP.
PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS: p_append AS CHECKBOX DEFAULT 'X'.
START-OF-SELECTION
START-OF-SELECTION.
PERFORM get_records.
*& Form get_records
FORM get_records.
DATA: l_cursor TYPE cursor,
lt_bseg TYPE TABLE OF bseg,
ls_bseg LIKE LINE OF lt_bseg,
lt_output TYPE ty_tab_output,
ls_output LIKE LINE OF lt_output,
lt_nametab TYPE ty_tab_nametab,
ls_nametab LIKE LINE OF lt_nametab,
l_field(30) TYPE c,
l_output(50) TYPE c,
l_date(10) TYPE c,
l_len TYPE i.
FIELD-SYMBOLS: <field>.
IF p_append NE space.
OPEN DATASET p_file FOR APPENDING IN TEXT MODE.
ELSE.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE.
ENDIF.
Retrieve BSEF fieldnames and data types
PERFORM get_fields CHANGING lt_nametab.
OPEN CURSOR l_cursor FOR
SELECT * FROM bseg
WHERE bukrs IN p_bukrs
AND belnr IN p_belnr
AND buzei IN p_buzei
AND gjahr IN p_gjahr.
Write out fieldnames
IF p_append IS INITIAL.
LOOP AT lt_nametab INTO ls_nametab.
CONCATENATE ls_output ls_nametab-fieldname
INTO ls_output SEPARATED BY c_delimiter.
ENDLOOP.
IF ls_output+0(4) = c_delimiter.
SHIFT ls_output LEFT BY 4 PLACES.
ENDIF.
l_len = strlen( ls_output ).
TRANSFER ls_output TO p_file LENGTH l_len.
ENDIF.
Process BSEG records
DO.
CLEAR lt_bseg.
FETCH NEXT CURSOR l_cursor
INTO TABLE lt_bseg
PACKAGE SIZE c_records.
IF sy-subrc 0.
EXIT.
ENDIF.
LOOP AT lt_bseg INTO ls_bseg.
SELECT single * FROM BKPF
WHERE BUKRS = ls_bseg-BUKRS
AND BELNR = ls_bseg-BELNR
AND GJAHR = ls_bseg-GJAHR
AND BUDAT in p_budat.
if syst-subrc 0.
continue.
endif.
CLEAR ls_output.
Process individual fields of BSEG record
LOOP AT lt_nametab INTO ls_nametab.
CONCATENATE 'LS_BSEG-' ls_nametab-fieldname INTO l_field.
ASSIGN (l_field) TO <field>.
CLEAR l_output.
Process by field data types
CASE ls_nametab-exid.
WHEN 'C' OR 'N' OR 'I'.
Character, Numeric & Integer
l_output = <field>.
WHEN 'D'.
Dates
WRITE <field> TO l_date DD/MM/YYYY.
l_output = l_date.
WHEN 'P'.
Packed decimals
WRITE <field> TO l_output.
WHEN OTHERS.
MESSAGE a000(zs) WITH 'Data type error - ' ls_nametab-exid.
ENDCASE.
SHIFT l_output LEFT DELETING LEADING space.
CONCATENATE ls_output l_output
INTO ls_output SEPARATED BY c_delimiter.
ENDLOOP.
IF ls_output+0(4) = c_delimiter.
SHIFT ls_output LEFT BY 4 PLACES.
ENDIF.
l_len = strlen( ls_output ).
TRANSFER ls_output TO p_file LENGTH l_len.
ENDLOOP.
IF sy-subrc = 0.
ENDIF.
ENDDO.
CLOSE CURSOR l_cursor.
CLOSE DATASET p_file.
ENDFORM. " get_records
*& Form get_fields
FORM get_fields CHANGING pt_nametab TYPE ty_tab_nametab.
CALL FUNCTION 'RFC_GET_NAMETAB'
EXPORTING
tabname = 'BSEG'
TABLES
nametab = pt_nametab
EXCEPTIONS
table_not_active = 1
OTHERS = 2.
IF sy-subrc 0.
ENDIF.
ENDFORM. " get_fields
hope this helps.
cheers,
Hema. -
How to Extract Data for a Maintenance View, Structure and Cluster Table
I want to develop 3 Reports
1) in First Report
it consists only two Fields.
Table name : V_001_B
Field Name1: BUKRS
Table name : V_001_B
Field Name2: BUTXT
V_001_B is a Maintenance View
For this one I don't Find any Datasource
For this Maintenance View, How to Extract the Data.
2)
For the 2nd Report also it consists Two Fields
Table name : CSKSZ
Field Name1: KOSTL (cost center)
Table name : CSKSZ
Field Name2: KLTXT (Description)
CSKSZ is a Structure
For this one I don't Find any Datasource
For this Structure How to Extract the Data
3)
For the 3rd Report
in this Report all Fields are belonging to a Table BSEG
BSEG is a Cluster Table
For this one also I can't Find any Datasource,
I find very Few Objects in the Datasource.
For this One, How to Extract the Data.
Please provide me step by step procedure.
Thanks
PriyaHi sachin,
I don't get your point can you Explain me Briefly.
I have two Fields for the 1st Report
BUKRS
BUTXT
In the 2nd Report
KOSTL
KLTXT
If I use 0COSTCENTER_TEXT Data Source
I will get KOSTL Field only
what about KLTXT
Thanks
Priya -
Performance issue in BI due to direct query on BKPF and BSEG tables
Hi,
We had a requirement that FI document number fieldshould be extracted in BI.
Following code was written which has the correct logic but performance is bad.
It fetched just 100 records in more than 4-5 hrs.
The reason is there was a direct qury written on BSEG and BKPF tables(without WHERE clause).
Is there any way to improve this code like adding GJAHR field in where clause? I dont want to change the logic.
Following is the code:
WHEN '0CO_OM_CCA_9'." Data Source
TYPES:BEGIN OF ty_bkpf,
belnr TYPE bkpf-belnr,
xblnr TYPE bkpf-xblnr,
bktxt TYPE bkpf-bktxt,
awkey TYPE bkpf-awkey,
bukrs TYPE bkpf-bukrs,
gjahr TYPE bkpf-gjahr,
AWTYP TYPE bkpf-AWTYP,
END OF ty_bkpf.
TYPES : BEGIN OF ty_bseg1,
lifnr TYPE bseg-lifnr,
belnr TYPE bseg-belnr,
bukrs TYPE bseg-bukrs,
gjahr TYPE bseg-gjahr,
END OF ty_bseg1.
DATA: it_bkpf TYPE STANDARD TABLE OF ty_bkpf,
wa_bkpf TYPE ty_bkpf,
it_bseg1 TYPE STANDARD TABLE OF ty_bseg1,
wa_bseg1 TYPE ty_bseg1,
l_s_icctrcsta1 TYPE icctrcsta1.
"Extract structure for Datasoure 0co_om_cca_9.
DATA: l_awkey TYPE bkpf-awkey.
DATA: l_gjahr1 TYPE gjahr.
DATA: len TYPE i,
l_cnt TYPE i.
l_cnt = 10.
tables : covp.
data : ref_no(20).
SELECT lifnr
belnr
bukrs
gjahr
FROM bseg
INTO TABLE it_bseg1.
DELETE ADJACENT DUPLICATES FROM it_bseg1 COMPARING belnr gjahr .
SELECT belnr
xblnr
bktxt
awkey
bukrs
gjahr
AWTYP
FROM bkpf
INTO TABLE it_bkpf.
IF sy-subrc EQ 0.
CLEAR: l_s_icctrcsta1,
wa_bkpf,
l_awkey,
wa_bseg1.
LOOP AT c_t_data INTO l_s_icctrcsta1.
MOVE l_s_icctrcsta1-fiscper(4) TO l_gjahr1.
select single AWORG AWTYP INTO CORRESPONDING FIELDS OF COVP FROM COVP
WHERE belnr = l_s_icctrcsta1-belnr.
if sy-subrc = 0.
if COVP-AWORG is initial.
concatenate l_s_icctrcsta1-refbn '%' into ref_no.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY awkey(10) =
l_s_icctrcsta1-refbn
awtyp = COVP-AWTYP
gjahr = l_gjahr1.
IF sy-subrc EQ 0.
MOVE wa_bkpf-belnr TO l_s_icctrcsta1-zzbelnr.
MOVE wa_bkpf-xblnr TO l_s_icctrcsta1-zzxblnr.
MOVE wa_bkpf-bktxt TO l_s_icctrcsta1-zzbktxt.
MODIFY c_t_data FROM l_s_icctrcsta1.
READ TABLE it_bseg1 INTO wa_bseg1
WITH KEY
belnr = wa_bkpf-belnr
bukrs = wa_bkpf-bukrs
gjahr = wa_bkpf-gjahr.
IF sy-subrc EQ 0.
MOVE wa_bseg1-lifnr TO l_s_icctrcsta1-lifnr.
MODIFY c_t_data FROM l_s_icctrcsta1.
CLEAR: l_s_icctrcsta1,
wa_bseg1,
l_gjahr1.
ENDIF.
ENDIF.
ELSE. " IF AWORG IS NOT BLANK -
concatenate l_s_icctrcsta1-refbn COVP-AWORG into ref_no.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY awkey(20) =
ref_no
awtyp = COVP-AWTYP
gjahr = l_gjahr1.
IF sy-subrc EQ 0.
MOVE wa_bkpf-belnr TO l_s_icctrcsta1-zzbelnr.
MOVE wa_bkpf-xblnr TO l_s_icctrcsta1-zzxblnr.
MOVE wa_bkpf-bktxt TO l_s_icctrcsta1-zzbktxt.
MODIFY c_t_data FROM l_s_icctrcsta1.
READ TABLE it_bseg1 INTO wa_bseg1
WITH KEY
belnr = wa_bkpf-belnr
bukrs = wa_bkpf-bukrs
gjahr = wa_bkpf-gjahr.
IF sy-subrc EQ 0.
MOVE wa_bseg1-lifnr TO l_s_icctrcsta1-lifnr.
MODIFY c_t_data FROM l_s_icctrcsta1.
CLEAR: l_s_icctrcsta1,
wa_bseg1,
l_gjahr1.
ENDIF.
ENDIF.
endif.
endif.
CLEAR: l_s_icctrcsta1.
CLEAR: COVP, REF_NO.
ENDLOOP.
ENDIF.Hello Amruta,
I was just looking at your coding:
LOOP AT c_t_data INTO l_s_icctrcsta1.
MOVE l_s_icctrcsta1-fiscper(4) TO l_gjahr1.
select single AWORG AWTYP INTO CORRESPONDING FIELDS OF COVP FROM COVP
WHERE belnr = l_s_icctrcsta1-belnr.
if sy-subrc = 0.
if COVP-AWORG is initial.
concatenate l_s_icctrcsta1-refbn '%' into ref_no.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY awkey(10) =
l_s_icctrcsta1-refbn
awtyp = COVP-AWTYP
gjahr = l_gjahr1.
Here you are interested in those BKPF records that are related to the contents of c_t_data internal table.
I guess that this table does not contain millions of entries. Am I right?
If yes, the the first step would be to pre-select COVP entries:
select BELNR AWORG AWTYP into lt_covp from COVP
for all entries in c_t_data
where belnr = c_t_data-belnr.
sort lt_covp by belnr.
Once having this data ready, you build an internal table for BKPF selection:
LOOP AT c_t_data INTO l_s_icctrcsta1.
clear ls_bkpf_sel.
ls_bkpf_sel-awkey(10) = l_s_icctrcsta1-refbn.
read table lt_covp with key belnr = l_s_icctrcsta1-belnr binary search.
if sy-subrc = 0.
ls_bkpf_sel-awtyp = lt_covp-awtyp.
endif.
ls_bkpf_sel-gjahr = l_s_icctrcsta1-fiscper(4).
insert ls_bkpf_sel into table lt_bkpf_sel.
ENDLOOP.
Now you have all necessary info to read BKPF:
SELECT
belnr
xblnr
bktxt
awkey
bukrs
gjahr
AWTYP
FROM bkpf
INTO TABLE it_bkpf
for all entries in lt_bkpf_sel
WHERE
awkey = lt_bkpf_sel-awkey and
awtyp = lt_bkpf_sel-awtype and
gjahr = lt_bkpf_sel-gjahr.
Then you can access BSEG with the bukrs, belnr and gjahr from the selected BKPF entries. This will be fast.
Moreover I would even try to make a join on DB level. But first try this solution.
Regards,
Yuri -
Required replace BSEG with BSAK BSIK BSIS BSAS for report performance
Hi Experts
i m optimizing a report in which data is extracting from BSEG , 5 time so i reduses the performance of report
so i want replace BSEG with BSAK BSIK BSIS BSAS for the same data what I am getting now . this is report of Purchase of item. code is here.
REPORT zmm_pur_reg_kanhe LINE-SIZE 1023.
*& Des :Purchase Tax Register Report for KANHE
*& Created on :12-07-07
*& Suggested by:Paresh Saini(MM)
*& Changes By: Lailu Philip
*& Changed On: 24.09.2007
*& Changes: New columns for G/L Code Description,VAT Amt,VAT Perc,CST Perc
*& ,SHCESS Amounts,WCT G/L Acc., WCT Amt,Tax Code
*& for Purchase Order,WCT tax code & Percentage.
*& Request No: S6DK921577
Data Declaration
*& changes: by Vincy on 12.01.2007
*& changes: display purchase order with vendor type zpsr(get_zpsr)
*& Request No: S6DK930821
TABLES:ekbe, lfa1, faglflexa.",j_1iexcdtl,lfa1,bkpf,bseg.
TYPE-POOLS: slis. "ALV Declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
DATA: it_sortcat TYPE slis_sortinfo_alv OCCURS 1,
col_pos LIKE fieldcatalog-col_pos .
TYPES :BEGIN OF wa1_ekbe,
belnr TYPE ekbe-belnr,
budat TYPE ekbe-budat,
menge TYPE ekbe-menge,
matnr TYPE ekbe-matnr,
ebelp TYPE j_1iexcdtl-ritem1,
ebeln TYPE ekbe-ebeln,
gjahr TYPE ekbe-gjahr,
lfbnr TYPE ekbe-lfbnr,
lfpos TYPE ekbe-lfpos,
bldat TYPE ekbe-bldat,
REEWR TYPE REEWR,
END OF wa1_ekbe.
TYPES :BEGIN OF wa2_ekbe,
belnr TYPE ekbe-belnr,
budat TYPE ekbe-budat,
menge TYPE ekbe-menge,
ebelp TYPE ekbe-ebelp,
ebeln TYPE ekbe-ebeln,
gjahr TYPE ekbe-gjahr,
lfbnr TYPE ekbe-lfbnr,
lfpos TYPE ekbe-lfpos,
bldat TYPE ekbe-bldat,
REEWR TYPE REEWR,
awkey(20) TYPE c,
MATNR TYPE MATNR,
MWSKZ TYPE EKBE-MWSKZ,
END OF wa2_ekbe.
TYPES :BEGIN OF wa1_j_1iexcdtl,
exnum TYPE j_1iexcdtl-exnum,
exdat TYPE j_1iexcdtl-exdat,
lifnr TYPE j_1iexcdtl-lifnr,
matnr TYPE j_1iexcdtl-matnr ,
maktx TYPE j_1iexcdtl-maktx ,
capind TYPE j_1iexcdtl-capind,
exbas TYPE j_1iexcdtl-exbas,
exbed TYPE j_1iexcdtl-exbed,
ecs TYPE j_1iexcdtl-ecs,
werks TYPE j_1iexcdtl-werks,
ritem1 TYPE j_1iexcdtl-ritem1,
rdoc1 TYPE j_1iexcdtl-rdoc1,
docyr TYPE j_1iexcdtl-docyr,
bedinv type J_1IBEDINV,
ecsinv type J_1IECSINV,
EXADDINV1 type J_1IEXADDINV1,
exaddtax1 TYPE j_1iexcdtl-exaddtax1,
rdoc2 TYPE j_1iexcdtl-rdoc2,
ritem2 TYPE j_1iexcdtl-ritem2,
menge TYPE j_1iexcdtl-menge,
ADDED FOR RUDRAPUR ON 08.03.2008 BY ASHOK.CH
*ENDED ON 08.02.2008
END OF wa1_j_1iexcdtl.
TYPES :BEGIN OF wa1_lfa1,
name1 TYPE lfa1-name1,
ktokk TYPE lfa1-ktokk,
werks TYPE lfa1-werks,
lifnr TYPE lfa1-lifnr,
END OF wa1_lfa1.
TYPES :BEGIN OF wa1_ekexclf,
belnr TYPE ekbe-belnr,
budat TYPE ekbe-budat,
menge TYPE ekbe-menge,
ebelp TYPE ekbe-ebelp,
ebeln TYPE ekbe-ebeln,
gjahr TYPE ekbe-gjahr,
awkey(20) TYPE c,
exnum TYPE j_1iexcdtl-exnum,
exdat TYPE j_1iexcdtl-exdat,
lifnr TYPE j_1iexcdtl-lifnr,
matnr TYPE j_1iexcdtl-matnr ,
maktx TYPE j_1iexcdtl-maktx ,
capind TYPE j_1iexcdtl-capind,
exbas TYPE j_1iexcdtl-exbas,
exbed TYPE j_1iexcdtl-exbed,
ecs TYPE j_1iexcdtl-ecs,
werks TYPE j_1iexcdtl-werks,
ritem1 TYPE j_1iexcdtl-ritem1,
rdoc1 TYPE j_1iexcdtl-rdoc1,
docyr TYPE j_1iexcdtl-docyr,
name1 TYPE lfa1-name1,
ktokk TYPE lfa1-ktokk,
exaddtax1 TYPE j_1iexcdtl-exaddtax1,
added for rudrapur on 08.03.2008 by ASHOK.CH
bedinv type J_1IBEDINV,
ecsinv type J_1IECSINV,
EXADDINV1 type J_1IEXADDINV1,
END OF MODIFICATION ON 08.02.2008
END OF wa1_ekexclf.
TYPES :BEGIN OF wa1_bkpf,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
budat TYPE bkpf-budat,
tcode TYPE bkpf-tcode,
awkey TYPE bkpf-awkey,
END OF wa1_bkpf.
TYPES :BEGIN OF wa1_bseg,
bukrs TYPE bseg-bukrs,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
buzei TYPE bseg-buzei,
bschl TYPE bseg-bschl,
fwbas TYPE bseg-fwbas ,
pswbt TYPE bseg-pswbt,
hkont TYPE bseg-hkont,
wrbtr TYPE bseg-wrbtr,
ktosl TYPE bseg-ktosl,
koart TYPE bseg-koart,
shkzg TYPE bseg-shkzg,
mwskz TYPE bseg-mwskz,
qsskz TYPE bsis-qsskz,
dmbtr TYPE bseg-dmbtr,
lifnr TYPE bseg-lifnr,
matnr TYPE bseg-matnr,
flag TYPE C,
flag_21 TYPE C,
END OF wa1_bseg.
TYPES :BEGIN OF wa1_tax,
belnr TYPE bseg-belnr,
fi_docno TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
bukrs TYPE bseg-bukrs,
awkey TYPE bkpf-awkey,
fwbas TYPE bseg-fwbas ,
cst_amt TYPE bseg-pswbt,
vat_amt TYPE bseg-pswbt,
shcess_amt TYPE bseg-pswbt,
gl_accnt TYPE bseg-hkont,
gl_desc TYPE skat-txt50,
wctglacc TYPE bseg-hkont,
wctamt TYPE bseg-dmbtr,
taxcode TYPE t059z-wt_withcd,
taxperc TYPE t059z-qsatz,
total_value TYPE bseg-wrbtr,
set_off TYPE bseg-wrbtr,
cond_type TYPE konv-kschl,
description(20) TYPE c,
service_tax TYPE bseg-wrbtr,
service_ecess TYPE bseg-wrbtr,
service_shcess TYPE bseg-wrbtr, "vincy on 31.01.08
ebelp TYPE ekbe-ebelp, " on 15.04.08
flag TYPE c,
mwskz TYPE bseg-mwskz,
END OF wa1_tax.
DATA:BEGIN OF itab_skat,
saknr TYPE skat-saknr,
spras TYPE skat-spras,
txt50 TYPE skat-txt50,
END OF itab_skat.
DATA: iskat LIKE itab_skat OCCURS 0,
wa_skat LIKE itab_skat.
DATA : BEGIN OF zbsis OCCURS 0,
bukrs TYPE bsis-bukrs,
hkont TYPE bsis-hkont,
augdt TYPE bsis-augdt,
augbl TYPE bsis-augbl,
zuonr TYPE bsis-zuonr,
gjahr TYPE bsis-gjahr,
belnr TYPE bsis-belnr,
buzei TYPE bsis-buzei,
budat TYPE bsis-budat,
qsskz TYPE bsis-qsskz,
END OF zbsis.
DATA: BEGIN OF zt059z OCCURS 0,
land1 TYPE t059z-land1,
witht TYPE t059z-witht,
wt_withcd TYPE t059z-wt_withcd,
qscod TYPE t059z-qscod,
qsatz TYPE t059z-qsatz,
hkont TYPE bsis-hkont,
belnr TYPE bsis-belnr,
END OF zt059z.
DATA: BEGIN OF it_faglflexa OCCURS 0, "added by vincy
ryear TYPE faglflexa-ryear,
docnr TYPE faglflexa-docnr,
rldnr TYPE faglflexa-rldnr,
rbukrs TYPE faglflexa-rbukrs,
docln TYPE faglflexa-docln,
prctr TYPE faglflexa-prctr,
END OF it_faglflexa.
Final Table***
TYPES :BEGIN OF wa1_final,
belnr TYPE ekbe-belnr,
fi_docno TYPE bseg-belnr,
budat TYPE ekbe-budat,
menge TYPE ekbe-menge,
rate TYPE konv-kbetr,
ebelp TYPE ekbe-ebelp,
ebeln TYPE ekbe-ebeln,
mwskz TYPE bseg-mwskz,
gjahr TYPE ekbe-gjahr,
awkey(20) TYPE c,
exnum TYPE j_1iexcdtl-exnum,
exdat TYPE j_1iexcdtl-exdat,
lifnr TYPE j_1iexcdtl-lifnr,
matnr TYPE j_1iexcdtl-matnr ,
maktx TYPE j_1iexcdtl-maktx ,
capind TYPE string,
exbas TYPE j_1iexcdtl-exbas,
exbed TYPE j_1iexcdtl-exbed,
ecs TYPE j_1iexcdtl-ecs,
werks TYPE j_1iexcdtl-werks,
ritem1 TYPE j_1iexcdtl-ritem1,
rdoc1 TYPE j_1iexcdtl-rdoc1,
docyr TYPE j_1iexcdtl-docyr,
name1 TYPE lfa1-name1,
ktokk TYPE lfa1-ktokk,
fwbas TYPE bseg-fwbas ,
vat_per TYPE konv-kbetr,
vat_amt TYPE bseg-pswbt,
cst_per TYPE konv-kbetr,
cst_amt TYPE bseg-pswbt,
shcess_amt TYPE bseg-pswbt,
gl_accnt TYPE bseg-hkont,
gl_desc TYPE skat-txt50,
wctglacc TYPE bseg-hkont,
wctamt TYPE bseg-dmbtr,
taxcode TYPE t059z-wt_withcd,
taxperc TYPE t059z-qsatz,
total_value TYPE bseg-wrbtr,
total_value1 TYPE bseg-wrbtr,
excise_tax TYPE bseg-wrbtr,
excise TYPE bseg-wrbtr,
set_off TYPE bseg-wrbtr,
inventorised TYPE konv-kawrt,
cond_type TYPE konv-kschl,
cond_type2 TYPE konv-kschl,
description(20) TYPE c,
service_tax TYPE bseg-wrbtr,
service_ecess TYPE bseg-wrbtr,
service_shcess TYPE bseg-wrbtr, "vincy on 31.01.08
END OF wa1_final.
DATA :it2_ekbe TYPE TABLE OF wa1_ekbe WITH HEADER LINE,
it_ekbe TYPE TABLE OF wa1_ekbe WITH HEADER LINE,
it1_ekbe TYPE TABLE OF wa2_ekbe WITH HEADER LINE WITH KEY ebelp ebeln,
it_j_1iexcdtl TYPE TABLE OF wa1_j_1iexcdtl WITH HEADER LINE WITH KEY rdoc1 ritem1,
it_lfa1 TYPE TABLE OF wa1_lfa1 WITH HEADER LINE WITH KEY lifnr,
it_lfa2 TYPE TABLE OF wa1_lfa1 WITH HEADER LINE WITH KEY lifnr,
it_bkpf TYPE TABLE OF wa1_bkpf WITH HEADER LINE,
it_bseg TYPE TABLE OF wa1_bseg WITH HEADER LINE WITH KEY
bukrs belnr gjahr ktosl shkzg koart,
it1_bseg TYPE TABLE OF wa1_bseg WITH HEADER LINE WITH KEY
bukrs belnr gjahr ktosl shkzg koart,
it_tax TYPE TABLE OF wa1_tax WITH HEADER LINE WITH KEY awkey ,
it_ekexclf TYPE TABLE OF wa1_ekexclf WITH HEADER LINE,
it_final TYPE TABLE OF wa1_final WITH HEADER LINE,
it_final1 TYPE TABLE OF wa1_final WITH HEADER LINE, "vincy
wa_ekbe TYPE wa1_ekbe,
wa1_ekbe TYPE wa2_ekbe,
wa_j_1iexcdtl TYPE wa1_j_1iexcdtl,
wa_lfa1 TYPE wa1_lfa1,
wa_lfa2 TYPE wa1_lfa1,
wa_bkpf TYPE wa1_bkpf,
wa_bseg TYPE wa1_bseg,
wa_tax TYPE wa1_tax,
wa_ekexclf TYPE wa1_ekexclf,
PLANT TYPE WERKS_D,
wa_final TYPE wa1_final.
DATA: it_konv TYPE konv OCCURS 0 WITH HEADER LINE ,
wa_konv TYPE konv,
invent TYPE p DECIMALS 4,
invent1 TYPE konv-kawrt.
DATA:d1 TYPE konv-kposn,
d2 TYPE ekbe-ebelp.
DATA: v_belnr TYPE ekbe-belnr,
v_gjahr TYPE ekbe-gjahr,
v_awkey(20) TYPE c,
idx TYPE sy-tabix.
**********by vincy on 12.01.07***********
DATA: BEGIN OF it_ekko OCCURS 0,
ebeln LIKE ekko-ebeln,
bukrs LIKE ekko-bukrs,
bsart LIKE ekko-bsart,
lifnr LIKE ekko-lifnr,
belnr LIKE ekbe-belnr,
END OF it_ekko.
DATA: BEGIN OF it_ekpo OCCURS 0,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
txz01 LIKE ekpo-txz01,
END OF it_ekpo.
DATA: BEGIN OF it_lfa1v OCCURS 0,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
END OF it_lfa1v.
DATA: BEGIN OF s_prctr OCCURS 0,
low LIKE faglflexa-prctr,
END OF s_prctr.
DATA: it_bsegv TYPE TABLE OF wa1_bseg WITH HEADER LINE.
DATA: it_konv1 LIKE konv OCCURS 0 WITH HEADER LINE.
DATA:cnt TYPE i,
awkey1(250).
DATA: LIFNR TYPE LIFNR,
NAME TYPE NAME1_GP,
MTART TYPE MARA-MTART,
MAKTX TYPE MAKTX,
TAX_TOT TYPE KWERT.
***********end of changes by vincy ************
Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_werks1 FOR ekbe-werks,
s_budat1 FOR ekbe-budat,
s_fiscal FOR ekbe-gjahr,
s_lifnr FOR lfa1-lifnr.
SELECTION-SCREEN END OF BLOCK b1.
**"changes being by nahid on 16.04.2008
PARAMETERS : excel AS CHECKBOX DEFAULT 'X'.
PARAMETERS: infile LIKE rlgrap-filename.
DATA : zfile TYPE string.
**"changes ended by nahid on 16.04.2008
AT SELECTION-SCREEN.
IF s_werks1 IS INITIAL.
MESSAGE 'Please Enter Plant details' TYPE 'E'.
ENDIF.
IF s_budat1 IS INITIAL.
MESSAGE 'Please Enter Posting date' TYPE 'E'.
ENDIF.
IF s_fiscal IS INITIAL.
MESSAGE 'Please Enter Fiscal Year' TYPE 'E'.
ENDIF.
*start change by nahid on 16.4.08
AT SELECTION-SCREEN ON VALUE-REQUEST FOR infile.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = infile
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
zfile = infile.
*end change by nahid on 16.4.08
START-OF-SELECTION.
plant = s_werks1-low.
MODIFIED FOR RUDRAPUR BY ASHOK.CH ON 13.03.2008
IF PLANT NE 'RD01'.
PERFORM get_data.
PERFORM get_zpsr. "vincy
ENDIF.
IF PLANT EQ 'RD01'.
PERFORM get_data1.
ENDIF.
*END OF MODIFICATION ON 13.03.2008
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*start chng by nahid on 16.4.08
IF excel = 'X'.
IF NOT infile IS INITIAL.
PERFORM excel_data.
ELSE.
MESSAGE e000(0) WITH 'Please Enter the File Path'.
ENDIF.
ENDIF.
*end by nahid on 16.4.08
*& Form get_data
FORM get_data .
SELECT belnr budat menge matnr ebelp ebeln gjahr lfbnr lfpos bldat REEWR FROM ekbe INTO
TABLE it_ekbe
WHERE werks IN s_werks1 AND
(bewtp EQ 'Q' OR bewtp EQ 'N') AND
bewtp IN ('Q' , 'N') AND "added N by vincy on 6.07.2008
budat IN s_budat1 AND
gjahr IN s_fiscal .
IF sy-subrc = 0. "for 1st ekbe
IF it_ekbe[] IS NOT INITIAL.
SELECT exnum exdat lifnr matnr maktx capind exbas exbed ecs werks
ritem1 rdoc1 docyr bedinv ecsinv EXADDINV1 exaddtax1 rdoc2 ritem2 menge
FROM j_1iexcdtl INTO TABLE it_j_1iexcdtl FOR ALL ENTRIES IN it_ekbe
WHERE rdoc1 = it_ekbe-ebeln
AND ritem1 = it_ekbe-ebelp AND
lifnr IN s_lifnr.
ENDIF.
IF it_j_1iexcdtl[] IS NOT INITIAL.
SELECT name1 ktokk werks lifnr FROM lfa1 INTO
TABLE it_lfa1 FOR ALL ENTRIES IN it_j_1iexcdtl
WHERE lifnr = it_j_1iexcdtl-lifnr.
ENDIF.
LOOP AT it_ekbe INTO wa_ekbe.
wa1_ekbe-belnr = wa_ekbe-belnr.
wa1_ekbe-budat = wa_ekbe-budat.
wa1_ekbe-menge = wa_ekbe-menge.
wa1_ekbe-ebelp = wa_ekbe-ebelp.
wa1_ekbe-ebeln = wa_ekbe-ebeln.
wa1_ekbe-gjahr = wa_ekbe-gjahr.
wa1_ekbe-matnr = wa_ekbe-matnr.
wa1_ekbe-lfbnr = wa_ekbe-lfbnr.
wa1_ekbe-lfpos = wa_ekbe-lfpos.
wa1_ekbe-bldat = wa_ekbe-bldat.
v_belnr = wa_ekbe-belnr.
v_gjahr = wa_ekbe-gjahr.
CONCATENATE v_belnr v_gjahr INTO v_awkey.
wa1_ekbe-awkey = v_awkey.
APPEND wa1_ekbe TO it1_ekbe.
CLEAR :wa_ekbe.
ENDLOOP.
************changes by vincy on 29.05.08 for 'FB08' and 'FB60'**************
LOOP AT s_werks1.
IF s_werks1-low = 'KN01'.
s_prctr-low = 'MUKNHSTM'.
ELSEIF
s_werks1-low = 'NS01'.
s_prctr-low = 'MUNSKSTM'.
ELSEIF
s_werks1-low = 'RD01'.
s_prctr-low = 'MURDPSTM'.
ENDIF.
APPEND s_prctr.
ENDLOOP.
SELECT bukrs belnr gjahr budat tcode awkey FROM bkpf INTO TABLE it_bkpf
WHERE bukrs = 'MU51' AND
gjahr IN s_fiscal AND
budat IN s_budat1 AND
( tcode = 'FB60' OR tcode = 'FB08' ).
IF it_bkpf[] IS NOT INITIAL.
SELECT ryear docnr rldnr rbukrs docln prctr FROM faglflexa INTO TABLE it_faglflexa
FOR ALL ENTRIES IN it_bkpf WHERE rbukrs = 'MU51' AND
ryear = it_bkpf-gjahr AND
docnr = it_bkpf-belnr.
ENDIF.
LOOP AT it_faglflexa.
READ TABLE s_prctr WITH KEY low = it_faglflexa-prctr.
IF sy-subrc <> 0.
DELETE it_faglflexa.
ENDIF.
CLEAR: it_faglflexa, s_prctr.
ENDLOOP.
**************************end of change*************************************
IF it1_ekbe[] IS NOT INITIAL.
SELECT bukrs belnr gjahr budat tcode awkey FROM bkpf APPENDING
TABLE it_bkpf FOR ALL ENTRIES IN it1_ekbe
WHERE bukrs = 'MU51' AND
gjahr IN s_fiscal AND
awkey = it1_ekbe-awkey.
ENDIF.
IF sy-subrc = 0. "bkpf
IF it_bkpf[] IS NOT INITIAL.
SELECT bukrs belnr gjahr buzei bschl fwbas pswbt hkont wrbtr ktosl koart shkzg mwskz qsskz dmbtr lifnr matnr
FROM bseg INTO TABLE it1_bseg FOR ALL ENTRIES IN it_bkpf
WHERE belnr = it_bkpf-belnr AND
gjahr = it_bkpf-gjahr AND
bukrs = it_bkpf-bukrs AND
( bschl = '21' ) AND
lifnr IN s_lifnr. "added 21 for miro cancelation
IF it1_bseg[] IS NOT INITIAL.
SELECT bukrs belnr gjahr buzei bschl fwbas pswbt hkont wrbtr ktosl koart shkzg mwskz qsskz dmbtr lifnr matnr
FROM bseg INTO TABLE it_bseg FOR ALL ENTRIES IN it1_bseg
WHERE belnr = it1_bseg-belnr AND
gjahr = it1_bseg-gjahr AND "changed it_bkpf to it1_bseg
bukrs = it1_bseg-bukrs .
LOOP AT it_bseg.
it_bseg-wrbtr = it_bseg-wrbtr * -1.
it_bseg-fwbas = it_bseg-fwbas * -1.
it_bseg-pswbt = it_bseg-pswbt * -1.
it_bseg-flag_21 = 'X'.
MODIFY it_bseg.
CLEAR it_bseg.
ENDLOOP.
SELECT name1 ktokk werks lifnr FROM lfa1 INTO
TABLE it_lfa2 FOR ALL ENTRIES IN it1_bseg
WHERE lifnr = it1_bseg-lifnr.
ENDIF.
REFRESH it1_bseg.
SELECT bukrs belnr gjahr buzei bschl fwbas pswbt hkont wrbtr ktosl koart shkzg mwskz qsskz dmbtr lifnr matnr
FROM bseg INTO TABLE it1_bseg FOR ALL ENTRIES IN it_bkpf
WHERE belnr = it_bkpf-belnr AND
gjahr = it_bkpf-gjahr AND
bukrs = it_bkpf-bukrs AND
( bschl = '31' ) AND "added bschl and lifnr by vincy
lifnr IN s_lifnr.
IF it1_bseg[] IS NOT INITIAL.
SELECT name1 ktokk werks lifnr FROM lfa1 APPENDING
TABLE it_lfa2 FOR ALL ENTRIES IN it1_bseg
WHERE lifnr = it1_bseg-lifnr.
SELECT bukrs belnr gjahr buzei bschl fwbas pswbt hkont wrbtr ktosl koart shkzg mwskz qsskz dmbtr lifnr matnr
FROM bseg APPENDING TABLE it_bseg FOR ALL ENTRIES IN it1_bseg
WHERE belnr = it1_bseg-belnr AND
gjahr = it1_bseg-gjahr AND "changed it_bkpf to it1_bseg
bukrs = it1_bseg-bukrs AND
bschl <> '35'. "added bschl to avoid vendor paymnt
ENDIF.
SELECT bukrs belnr gjahr buzei bschl fwbas pswbt hkont wrbtr ktosl koart shkzg mwskz qsskz dmbtr lifnr
FROM bseg APPENDING CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE belnr = it_bkpf-belnr AND
gjahr = it_bkpf-gjahr AND
lifnr IN s_lifnr AND
bukrs = it_bkpf-bukrs AND qsskz IN ('WI', 'WJ').
ENDIF.
ENDIF.
SORT it_bseg BY belnr buzei.
IF NOT it_bseg[] IS INITIAL.
SELECT saknr spras txt50 FROM skat
INTO TABLE iskat
FOR ALL ENTRIES IN it_bseg
WHERE saknr = it_bseg-hkont AND spras = 'EN'.
SELECT bukrs hkont augdt augbl zuonr gjahr belnr buzei budat qsskz FROM bsis
INTO TABLE zbsis
FOR ALL ENTRIES IN it_bseg
WHERE bukrs = 'MU51' AND hkont = it_bseg-hkont
AND belnr = it_bseg-belnr AND gjahr = s_fiscal
AND budat IN s_budat1.
ENDIF.
LOOP AT it_bseg.
READ TABLE zbsis WITH KEY hkont = it_bseg-hkont.
IF sy-subrc = 0.
it_bseg-qsskz = zbsis-qsskz.
MODIFY it_bseg.
ENDIF.
CLEAR: it_bseg,zbsis.
ENDLOOP.
LOOP AT zt059z.
LOOP AT it_bseg WHERE qsskz = zt059z-wt_withcd.
zt059z-hkont = it_bseg-hkont.
zt059z-belnr = it_bseg-belnr.
MODIFY zt059z.
CLEAR: it_bseg,zt059z.
ENDLOOP.
ENDLOOP.
CLEAR: wa_bkpf.
*******Filling Wa.
LOOP AT it_bkpf INTO wa_bkpf. "changes by vincy on 14.04.2008
LOOP AT it1_ekbe INTO wa1_ekbe .
READ TABLE it_bkpf INTO wa_bkpf
WITH KEY awkey = wa1_ekbe-awkey.
wa_tax-belnr = wa_bkpf-belnr.
wa_tax-gjahr = wa_bkpf-gjahr.
wa_tax-bukrs = wa_bkpf-bukrs.
wa_tax-awkey = wa_bkpf-awkey.
wa_tax-ebelp = wa1_ekbe-ebelp.
CLEAR: wa_bseg,wa_skat.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr INTO wa_bseg.
IF sy-subrc = 0.
wa_tax-fi_docno = wa_bseg-belnr.
wa_tax-mwskz = wa_bseg-mwskz.
CLEAR: wa_bseg.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'JP4' INTO wa_bseg.
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-gl_accnt = wa_bseg-hkont.
READ TABLE iskat INTO wa_skat WITH KEY saknr = wa_bseg-hkont.
IF sy-subrc = 0.
wa_tax-gl_desc = wa_skat-txt50.
ENDIF.
wa_tax-set_off = wa_bseg-wrbtr.
wa_tax-fwbas = wa_bseg-fwbas.
wa_tax-cst_amt = wa_bseg-pswbt.
wa_tax-description = 'CST CG Sett off'.
wa_tax-cond_type = 'JVCS'.
ENDIF.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'VS1' INTO wa_bseg.
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-fwbas = wa_bseg-fwbas.
ENDIF.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'JP7' INTO wa_bseg.
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-gl_accnt = wa_bseg-hkont.
READ TABLE iskat INTO wa_skat WITH KEY saknr = wa_bseg-hkont.
IF sy-subrc = 0.
wa_tax-gl_desc = wa_skat-txt50.
ENDIF.
wa_tax-set_off = wa_bseg-wrbtr.
wa_tax-fwbas = wa_bseg-fwbas.
wa_tax-vat_amt = wa_bseg-pswbt.
wa_tax-description = 'VAT CG Sett off'.
wa_tax-cond_type = 'JVCD'.
ENDIF.
CLEAR wa_bseg.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'JP5' INTO wa_bseg.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
hkont = '0002868001' INTO wa_bseg. "vat changed for V0 tax code
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-gl_accnt = wa_bseg-hkont.
READ TABLE iskat INTO wa_skat WITH KEY saknr = wa_bseg-hkont.
IF sy-subrc = 0.
wa_tax-gl_desc = wa_skat-txt50.
ENDIF.
wa_tax-vat_amt = wa_bseg-pswbt.
wa_tax-set_off = wa_bseg-wrbtr.
wa_tax-cond_type = 'JVRD'.
wa_tax-fwbas = wa_bseg-fwbas.
wa_tax-description = 'VAT RM Set off'.
ENDIF.
CLEAR: wa_bseg,wa_skat.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
shkzg = 'H'
koart = 'K'
INTO wa_bseg.
IF sy-subrc = 0.
wa_tax-total_value = wa_bseg-wrbtr.
ENDIF.
START OF MODIFICATION BY ASHOK.CH ON 08.02.2008
service_tax
CLEAR wa_bseg.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'VS8' INTO wa_bseg.
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-gl_accnt = wa_bseg-hkont.
READ TABLE iskat INTO wa_skat WITH KEY saknr = wa_bseg-hkont.
IF sy-subrc = 0.
wa_tax-gl_desc = wa_skat-txt50.
ENDIF.
wa_tax-service_tax = wa_bseg-wrbtr.
wa_tax-description = 'Service Tax'.
wa_tax-cond_type = 'JSRT'.
ENDIF.
service_ecess
CLEAR: wa_bseg,wa_skat.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'VS9' INTO wa_bseg.
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-service_ecess = wa_bseg-wrbtr.
ENDIF.
**********changes by vincy on 31.01.08*********************
service_shcess
CLEAR: wa_bseg.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr
flag = ''
ktosl = 'VSE' INTO wa_bseg.
IF sy-subrc = 0.
wa_bseg-flag = 'X'.
MODIFY it_bseg INDEX sy-tabix FROM wa_bseg.
wa_tax-service_shcess = wa_bseg-wrbtr.
ENDIF.
*************************end of changes***********************
END OF MODIFICATION ON 08.02.2008
APPEND wa_tax TO it_tax.
ENDIF.
CLEAR :wa_tax,wa_bseg,wa_bkpf,wa_skat.
ENDLOOP.
CLEAR wa1_ekbe.
LOOP AT it1_ekbe INTO wa1_ekbe.
READ TABLE it_j_1iexcdtl INTO wa_j_1iexcdtl
WITH KEY rdoc1 = wa1_ekbe-ebeln
ritem1 = wa1_ekbe-ebelp.
*New query added by Nilesh
READ TABLE it_j_1iexcdtl INTO wa_j_1iexcdtl
WITH KEY rdoc1 = wa1_ekbe-lfbnr
ritem2 = wa1_ekbe-lfpos.
READ TABLE it_bkpf INTO wa_bkpf
WITH KEY awkey = wa1_ekbe-awkey.
IF sy-subrc = 0.
READ TABLE it_bseg WITH KEY bukrs = wa_bkpf-bukrs
belnr = wa_bkpf-belnr
gjahr = wa_bkpf-gjahr.
IF sy-subrc = 0.
wa_ekexclf-belnr = wa1_ekbe-belnr.
wa_ekexclf-budat = wa1_ekbe-budat.
wa_ekexclf-menge = wa1_ekbe-menge.
wa_ekexclf-ebelp = wa1_ekbe-ebelp.
wa_ekexclf-ebeln = wa1_ekbe-ebeln.
wa_ekexclf-gjahr = wa1_ekbe-gjahr.
wa_ekexclf-awkey = wa1_ekbe-awkey.
wa_ekexclf-lifnr = it_bseg-lifnr.
wa_ekexclf-matnr = it_bseg-matnr .
READ TABLE it_j_1iexcdtl INTO wa_j_1iexcdtl "for records for which either rdoc1 or matnr
WITH KEY rdoc2 = wa1_ekbe-lfbnr "not maintained in ekbe by vincy on 16.06.08
menge = wa1_ekbe-menge.
IF sy-subrc <> 0 .
READ TABLE it_j_1iexcdtl INTO wa_j_1iexcdtl
WITH KEY rdoc1 = wa1_ekbe-ebeln
exdat = wa1_ekbe-bldat
matnr = wa1_ekbe-matnr
menge = wa1_ekbe-menge.
ENDIF.
READ TABLE it_j_1iexcdtl INTO wa_j_1iexcdtl
WITH KEY rdoc1 = wa1_ekbe-ebeln
ritem1 = wa1_ekbe-ebelp.
IF sy-subrc = 0.
wa_ekexclf-belnr = wa1_ekbe-belnr.
wa_ekexclf-budat = wa1_ekbe-budat.
wa_ekexclf-menge = wa1_ekbe-menge.
wa_ekexclf-ebelp = wa1_ekbe-ebelp.
wa_ekexclf-ebeln = wa1_ekbe-ebeln.
wa_ekexclf-gjahr = wa1_ekbe-gjahr.
wa_ekexclf-awkey = wa1_ekbe-awkey.
wa_ekexclf-exnum = wa_j_1iexcdtl-exnum.
wa_ekexclf-exdat = wa_j_1iexcdtl-exdat.
wa_ekexclf-lifnr = wa_j_1iexcdtl-lifnr.
wa_ekexclf-matnr = wa_j_1iexcdtl-matnr .
wa_ekexclf-maktx = wa_j_1iexcdtl-maktx .
wa_ekexclf-capind = wa_j_1iexcdtl-capind.
wa_ekexclf-exbas = wa_j_1iexcdtl-exbas.
wa_ekexclf-exbed = wa_j_1iexcdtl-exbed.
wa_ekexclf-ecs = wa_j_1iexcdtl-ecs.
wa_ekexclf-werks = wa_j_1iexcdtl-werks.
wa_ekexclf-ritem1 = wa_j_1iexcdtl-ritem1.
wa_ekexclf-rdoc1 = wa_j_1iexcdtl-rdoc1.
wa_ekexclf-docyr = wa_j_1iexcdtl-docyr.
wa_ekexclf-exaddtax1 = wa_j_1iexcdtl-exaddtax1.
IF it_bseg-flag_21 = 'X'.
wa_ekexclf-exbas = wa_ekexclf-exbas * -1.
ENDIF.
MODIFIED BY ASHOK.CH ON 08.03.2008
IF wa_j_1iexcdtl-WERKS NE 'RD01' .
wa_ekexclf-exbed = wa_j_1iexcdtl-exbed.
wa_ekexclf-ecs = wa_j_1iexcdtl-ecs.
wa_ekexclf-exaddtax1 = wa_j_1iexcdtl-exaddtax1.
IF it_bseg-flag_21 = 'X'.
wa_ekexclf-exbed = wa_ekexclf-exbed * -1.
wa_ekexclf-ecs = wa_ekexclf-ecs * -1.
wa_ekexclf-exaddtax1 = wa_ekexclf-exaddtax1 * -1.
ENDIF.
ELSE.
wa_ekexclf-exbed = wa_j_1iexcdtl-BEDINV.
wa_ekexclf-ecs = wa_j_1iexcdtl-ecsINV.
wa_ekexclf-exaddtax1 = wa_j_1iexcdtl-exaddINV1.
ENDIF.
END IF MODIFICATION ON 08.03.2008
APPEND wa_ekexclf TO it_ekexclf.
CLEAR :wa_lfa1,wa_j_1iexcdtl,wa1_ekbe.
ENDIF.
READ TABLE it_lfa2 INTO wa_lfa2
WITH KEY lifnr = wa_ekexclf-lifnr.
IF sy-subrc = 0.
wa_ekexclf-name1 = wa_lfa2-name1.
wa_ekexclf-ktokk = wa_lfa2-ktokk.
ENDIF.
APPEND wa_ekexclf TO it_ekexclf.
ENDIF.
ENDIF.
CLEAR :wa_lfa1,wa_j_1iexcdtl,wa1_ekbe,wa_lfa2,wa_ekexclf.
ENDLOOP.
CLEAR wa_ekexclf.
LOOP AT it_ekexclf INTO wa_ekexclf.
wa_final-belnr = wa_ekexclf-belnr.
wa_final-budat = wa_ekexclf-budat.
wa_final-menge = wa_ekexclf-menge.
wa_final-ebelp = wa_ekexclf-ebelp.
wa_final-ebeln = wa_ekexclf-ebeln.
wa_final-gjahr = wa_ekexclf-gjahr.
wa_final-awkey = wa_ekexclf-awkey.
wa_final-exnum = wa_ekexclf-exnum.
wa_final-exdat = wa_ekexclf-exdat.
wa_final-lifnr = wa_ekexclf-lifnr.
wa_final-matnr = wa_ekexclf-matnr .
wa_final-maktx = wa_ekexclf-maktx .
wa_final-shcess_amt = wa_ekexclf-exaddtax1.
IF wa_ekexclf-capind = 'C'.
wa_final-capind = 'Consumables'.
ENDIF.
IF wa_ekexclf-capind = 'A'.
wa_final-capind = 'Assets'.
ENDIF.
IF wa_ekexclf-capind = 'T'.
wa_final-capind = 'Tools'.
ENDIF.
IF wa_ekexclf-capind = ''.
wa_final-capind = 'Raw Material'.
ENDIF.
IF wa_ekexclf-capind = 'N'.
wa_final-capind = 'Non Cenvatable'.
ENDIF.
IF wa_ekexclf-capind NE 'C' AND wa_ekexclf-capind NE 'A' AND
wa_ekexclf-capind NE '' AND wa_ekexclf-capind NE 'N'.
wa_final-capind = wa_ekexclf-capind.
ENDIF.
wa_final-exbas = wa_ekexclf-exbas.
wa_final-exbed = wa_ekexclf-exbed.
wa_final-ecs = wa_ekexclf-ecs.
wa_final-werks = wa_ekexclf-werks.
wa_final-ritem1 = wa_ekexclf-ritem1.
wa_final-rdoc1 = wa_ekexclf-rdoc1.
wa_final-docyr = wa_ekexclf-docyr.
wa_final-name1 = wa_ekexclf-name1.
wa_final-ktokk = wa_ekexclf-ktokk.
wa_final-excise = wa_final-exbas + wa_final-exbed + wa_final-ecs + wa_final-shcess_amt.
CLEAR :wa_tax.Hi ,
I think you are using the redundant selects to fetch the data from BSEG.
First select all the data into an internal table based on bkpf.
Now you can distribute the data into whatever tables you want using the loop,read-binary search and append statements..
Loop at it_bseg.
read it_bseg where
xxxxx
xxxxx
binary search.
append wa to it2_bseg.
endloop
This avoid several database fetches..
Thank you.. -
Problem while selecting BELNR from BSEG
Hi Experts,
I have a report performance problem while fetching BELNR from BSEG table.
I have to print latest BELNR from BSEG where BUZID = M but at the time of execution of report, It is taking too much time (More that hour and sometimes it gets hanged).
I have also gone through the comments provided by experts for previous problems asked in this forum e.g. BSEG is a cluster table that is why data retrieval takes long time etc.
Can any one has any other idea or suggestion or any other way to solve this problem
Regards,
NeerajHi,
1) Try to create an index on BUZID field
2) Don't use SELECT/ENDSELECT statement. Instead of that extract all the concerned entries from BSEG into an internal table :
select belnr from bseg appending table itab where buzid = 'M'.
then do this :
sort itab by belnr.
describe itab lines n.
read table itab index n.
Please reward if helpful.
Regards,
Nicolas. -
How to extract Inventory data from SAP R/3 system
Hi friends How to extract Inventory data from SAP R/3 system? What are report we may expect from the Inventory?
Hi,
Inventory management
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/how%20to%20handle%20inventory%20management%20scenarios.pdf
How to Handle Inventory Management Scenarios in BW (NW2004)
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f83be790-0201-0010-4fb0-98bd7c01e328
Loading of Cube
ref.to page 18 in "Upgrade and Migration Aspects for BI in SAP NetWeaver 2004s" paper
http://www.sapfinug.fi/downloads/2007/bi02/BI_upgrade_migration.pdf
Non-Cumulative Values / Stock Handling
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/93ed1695-0501-0010-b7a9-d4cc4ef26d31
Non-Cumulatives
http://help.sap.com/saphelp_nw2004s/helpdata/en/8f/da1640dc88e769e10000000a155106/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/80/1a62ebe07211d2acb80000e829fbfe/frameset.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/80/1a62f8e07211d2acb80000e829fbfe/frameset.htm
Here you will find all the Inventory Management BI Contents:
http://help.sap.com/saphelp_nw70/helpdata/en/fb/64073c52619459e10000000a114084/frameset.htm
2LIS_03_BX- Initial Stock/Material stock
2LIS_03_BF - Material movements
2LIS_03_UM - Revaluations/Find the price of the stock
The first DataSource (2LIS_03_BX) is used to extract an opening stock balance on a
detailed level (material, plant, storage location and so on). At this moment, the opening
stock is the operative stock in the source system. "At this moment" is the point in time at
which the statistical setup ran for DataSource 2LIS_03_BX. (This is because no
documents are to be posted during this run and so the stock does not change during this
run, as we will see below). It is not possible to choose a key date freely.
The second DataSource (2LIS_03_BF) is used to extract the material movements into
the BW system. This DataSource provides the data as material documents (MCMSEG
structure).
The third of the above DataSources (2LIS_03_UM) contains data from valuated
revaluations in Financial Accounting (document BSEG). This data is required to update
valuated stock changes for the calculated stock balance in the BW. This information is
not required in many situations as it is often only the quantities that are of importance.
This DataSource only describes financial accounting processes, not logistical ones. In
other words, only the stock value is changed here, no changes are made to the
quantities. Everything that is subsequently mentioned here about the upload sequence
and compression regarding DataSource 2LIS_03_BF also applies to this DataSource.
This means a detailed description is not required for the revaluation DataSource.
http://help.sap.com/saphelp_bw32/helpdata/en/05/c69480c357354a8846cc61f7b6e085/content.htm
http://help.sap.com/saphelp_bw33/helpdata/en/ed/16c29a27db6e4d81a015be8673eb80/content.htm
These are the standard data sources used for Inventory extraction.
Hope this helps.
Thanks,
JituK -
Please clarify this requirement for Line Item Data from New GL. my client BMW Inc have configured New GL in ECC 6.0 if i pull all the records to BW from FAGLFLEXA (Line Item Table) is that sufficient to meet the <b>all line item GL data</b> or is there any other tables missing that also shall be combined to bring the Line item GL data. Please help me for this if u can check with any of your friends in FICO.
2. I have seen that BSEG AND BKPF are used earlier in old FI versions so what is there now in New GL ECC 6.0 that will suffice for these BSEG AND BKPF or still i have to pull records by using these tables. for GL Line Item Data.
If you can help me to give the short overview of New GL posting process it would be great.
Thanks
Regards
Soniya Kapoor1. If I use FAGLFLEXA Line Item Table , how to combine the remaining fields such as BLART Document Type etc.. from BSEG AND bkpf
We are using BSEG_ADD instead of bseg with the same DS 0FI_GL_4. you would need to enhance the same DS to read the BSEG_ADD. But I would suggest talk to ur finance folks to see if BSEG_ADD captures all the required fields as that of FAGLFLEXA
2. What is BSEG_ADD: Entry View of Accounting Document for Additional Ledgers, Should i also Include this table since it contains some fields like BSTAT
document status etc for line item.
It is a new table that comes along with the new GL it even captures all the line items just like BSEG as in the old ledger.
3. If I take the approach with line item as per new GL TABLE : FAGLFLEXA. and
BSEG_ADD by creating generic data source on two table and enhance any other required fields like blart Document Type will it solve the line item extraction purpose
If ur finance folks can confirm which table need to be used, ur strategy might change. If say BSEG_ADD is good enough to capture all the items, do as I suggested by enhancing the old DS - fi_gl_4
4. I took the approach as mentioned in Point 3 . but not able to create the generic data source
Not sure of ur approach
5. I have reviewed 0FIGl_4 LINE ITEM Data source and found that it contains only bseg and bkpf but no faglflexa table fields. so suggest if i can proceed as number 4.
Just as I said add code to make it read BSEG_ADD too along with BSEG.
FAGLFLEXA & FAGLFLEXT -
How to Extract data from Cluster table and transperant table
Hello BW Experts ,
I want to extract the data from cluster table BSEG and a transperant table BKPF .
The primary fields are BELNR , GJHAR and BUKRS.
the fields of table BKPF to extarct is BUDAT and fields of BSEG table is HKONT , BSCHL , ZUONR and POSID.
I can not create a view over these two tables as BSEG is a Cluster table.
Please guide me.
Regadrs ,
Amol.hi Amol,
take a look Sigg's weblog
/people/siegfried.szameitat/blog/2005/09/29/generic-extraction-via-function-module
you can use RSAX_BIW_GET_DATA_SIMPLE as sample, there specified import parameters
FUNCTION RSAX_BIW_GET_DATA_SIMPLE.
""Lokale Schnittstelle:
*" IMPORTING
*" VALUE(I_REQUNR) TYPE SRSC_S_IF_SIMPLE-REQUNR
*" VALUE(I_DSOURCE) TYPE SRSC_S_IF_SIMPLE-DSOURCE OPTIONAL
*" VALUE(I_MAXSIZE) TYPE SRSC_S_IF_SIMPLE-MAXSIZE OPTIONAL
*" VALUE(I_INITFLAG) TYPE SRSC_S_IF_SIMPLE-INITFLAG OPTIONAL
*" VALUE(I_READ_ONLY) TYPE SRSC_S_IF_SIMPLE-READONLY OPTIONAL
*" TABLES
*" I_T_SELECT TYPE SRSC_S_IF_SIMPLE-T_SELECT OPTIONAL
*" I_T_FIELDS TYPE SRSC_S_IF_SIMPLE-T_FIELDS OPTIONAL
*" E_T_DATA STRUCTURE SFLIGHT OPTIONAL
*" EXCEPTIONS
*" NO_MORE_DATA
*" ERROR_PASSED_TO_MESS_HANDLER -
Retrive document types from BKPF / BSEG
Hi guys,
I need to extract records with the following document types from BKPF
- RE (Invoice Gross with PO)
- RA (Sub.cred.memo stlmt with PO)
- KR (Vendor Invoice without PO)
- KG (Vendor credit memo without PO)
- ER (E-Payment)
- TE (Travel & expense)
- KD (Down payment)
and then for these records the BSEG entries with these posting keys
- 31 (link to Payment via clearing document)
- 40 (debit entry, for non-PO voucher)
- 50 (credit entry, for non-PO voucher)
- 86 (GR/IR Debit, link to PO Line, positive)
- 96 (GR/IR Credit, link to PO Line, negative)
Extractor 0fi_gl_4 does not provide me wtih all these doc types, only a subset.
0fi_ap_4 is not an option for me, because in the data warehouse I need to link the bkpf/bseg records to the PO (ekko/ekpo), while we have no po reference in bsik/bsik that are read by 0fi_ap_4.
Is there a way to extend the fi_gl_4 so it contains the doc types I need?
Or do you know another way of retrieving bseg records of specific types?
Regards,
Arjenok,
I have checked again and if you didn't change the business content, both fields BLART (doctype) and BSCHL (key) are extracted; how was your delta init done? with selections? Did you apply some specific TRules or URules? Check you PSA for a record you are missing and simulate the update in order to see what's going on.
As I said, I got everything in my ODS.
you can also check this in R/3; Tx RSA3 with a comp_code and a fiscal period selection...
hope this helps
Olivier.
Message was edited by:
Olivier Cora -
Can anybody tell me how to extract sales value and cost value for an materi
dear all,
Can anybody tell me how to extract sales value and cost value for an material sold .
All the values of cost value and sale values are getting stored in bseg-wrbtr field .
How to identify them uniquely.
Or there is another way to find the sale and cost values.
Regards
MaveHi Mave!
Normally there is no condition change, when something is sold.
But sales price depends on sales conditions (not only price, but also surcharges, discounts, taxes - if customized).
Nevertheless, after selling you have a invoice document, where correct values <i>should</i> be stored (see VBRP fields mentioned above). If here is a problem, then customizing of price determination is in question, not a programming of user-exits with MARD selection for costs (or some other tries to get a price).
When you specify your requirements more in detail, you might get better answers - but currently only general hints are possible ('see in invioce / G/L accounts').
Regards,
Christian -
Query is too slow from bseg selection
SELECT BELNR BLDAT BUDAT XBLNR GJAHR tcode WAERS AWKEY FROM BKPF INTO
TABLE
ITBKPF WHERE BUKRS EQ P_BUKRS AND BELNR IN S_BELNR AND BUDAT IN
P_BUDAT
AND STBLG = ''
AND ( TCODE = 'MIRO' OR
TCODE = 'MR8M' OR
TCODE = 'MB11' OR
TCODE = 'MB1B' OR
TCODE = 'MIGO_GI' OR
TCODE = 'MIGO_TR' OR
TCODE = 'MB1A' ).
IF SY-SUBRC EQ 0.
SORT itBKPF.
ELSE.
MESSAGE 'No data for the relevant date' TYPE 'A'.
LEAVE LIST-PROCESSING.
ENDIF.
SELECT A1LIFNR A1NAME1 A1ORT01 A1STRAS B1~j_1icstno
INTO TABLE it_werks
FROM ( LFA1 AS A1 INNER JOIN j_1imocomp AS B1 ON A1werks = B1werks )
**********************************************this is too slow*************
SELECT BUKRS BELNR GJAHR BUZEI BUZID BSCHL SHKZG GSBER MWSKZ
DMBTR HKONT LIFNR LANDL Matnr werks MENGE EBELP xref3
INTO CORRESPONDING FIELDS OF TABLE ITABBSEG
FROM BSEG
FOR ALL ENTRIES IN ITBKPF
WHERE BELNR = ITBKPF-BELNR
AND GJAHR = ITBKPF-GJAHR
AND ( BSCHL = '86' OR BSCHL = '96' or BSCHL = '89' OR BSCHL = '99' )
AND WERKS IN S_WERKS
AND BUZID <> 'F' .
****************************************this is too slow
Moderator message: Please Read before Posting in the Performance and Tuning Forum
locked by: Thomas Zloch on Aug 5, 2010 2:08 PMYou should have provided the full key of the cluster file behind BSEG (RFBLG), every key is in BKPF, so add BUKRS
SELECT bukrs belnr gjahr buzei buzid bschl shkzg gsber mwskz
dmbtr hkont lifnr landl matnr werks menge ebelp xref3
INTO CORRESPONDING FIELDS OF TABLE itabbseg
FROM bseg
FOR ALL ENTRIES IN itbkpf
WHERE bukrs = itbkpf-bukrs
AND belnr = itbkpf-belnr
AND gjahr = itbkpf-gjahr
AND ( bschl EQ '86' OR bschl EQ '96' OR bschl EQ '89' OR bschl EQ '99' )
AND werks IN s_werks
AND buzid EQ 'F' .
You could also extract the whole accounting document in the internal table, and then delete record using the not-database-key selections.
SELECT bukrs belnr gjahr buzei buzid bschl shkzg gsber mwskz
dmbtr hkont lifnr landl matnr werks menge ebelp xref3
INTO CORRESPONDING FIELDS OF TABLE itabbseg
FROM bseg
FOR ALL ENTRIES IN itbkpf
WHERE bukrs = itbkpf-bukrs
AND belnr = itbkpf-belnr
AND gjahr = itbkpf-gjahr.
DELETE itabbseg WHERE
( bschl NE '86' AND bschl NE '96' AND bschl NE '89' AND bschl NE '99' )
OR NOT ( werks IN s_werks )
OR BUZID NE 'F' .
In both case, perform some tests with tools like SE30 or ST05.
Regards,
Raymond -
Data from Bseg taking too much time
Hi ,
I need to extract data from BSEG and it is goin in timeout.
my query is :
1 : on the basis of VBRK i need to fetch data from bseg.
loop at it_vbrk.
awkk = it_vbrk-vbeln.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = awkk
IMPORTING
output = awkk.
it_awkey-vbeln = it_vbrk-vbeln.
it_awkey-awkey = awkk.
append it_awkey.
endloop.
2.
if it_awkey[] is not initial.
select bukrs BELNR gjahr BLART AWKEY from bkpf into table it_bkpf for all entries in it_awkey
where
bukrs = '5000'
and blart EQ 'RV'
and awkey = it_awkey-awkey.
endif.
Please guide me to get solution
Ashish GautamOk, u can use the secondary index tables of BSEG...
BSAS
BSIS,
BSAD,
BSID,
BSAK,
BSIK,
BSIM.
whatever is in BSEG is also in these tables....
and if u use BSEG, then try to match the key fields of BSEG, then only it will give the best performance....
eg.
BUKRS
BELNR
GJAHR
BUZEI
use the same order as given in the database...
and do not use any other fields except the key fields in the where clause...
and do not use 'NE' 'Not in' in the where clause....
regards
Sukriti.... -
GL Line items and Opening balance extraction
Hi
I would like to extract BSEG line item details into BI, and this I can achieve using the extractor 0FI_GL_4 (we are still using the old GL ledger). We need to have the WBS and Profit Center fields for this extractor, and this availble in the BSEG
However, as we know this extractor does not bring in the opening balances.
We need to have opening balances as well and this can be achieved using the extractor 0FI_GL_6. But this does not have the fields WBS and Profit Center. Can this totals extracor be enhanced to include these two fields or would this become a very big challenge? If it can be done what tables can be used to do the join.
ThanksHi Bal
Check the link below if it answers your query.
FI_GL Line items-Opening Balance
Regards
Anindya -
Hi all,
Does anyone know how to enhance the extraction structures with additional fields for datasources 0FI_GL_4 (General ledger: line item), 0FI_AP_4 (vendors: line item) and 0FI_AR_4 (customers: line item).
Thanks,
Sabrina.Hi
Here are the two scenario's described in the note:
1. All the fields of the customer enhancement in the customer include are contained in the read structure (see the table above). Then no additional action is required. The fields of the customer enhancement are filled automatically by the datasource from the assigned read structure via "move-corresponding".
Example: The extraction structure DTFIGL_4 for datasource 0FI_GL_4 (General ledger: line item) should be enhanced by the VALUT (value date) field.
To do this, create structure CI_BSIS in the data dictionary of the R/3 source system and include the VALUT field in it. The data dictionary in the R/3 source system shows that the VALUT field is contained in the read structure of the datasource (table BSIS). For that reason the VALUT field is automatically filled by datasource 0FI_GL_4.
2. Fields of the customer enhancement in the customer include are not contained in the read structure (see the table above). In this case you have to program a function module to fill the field of the customer enhancement. To do this, there is a Business Transaction Event available (open FI interface for process 00005021). Create any function module you like and use function module SAMPLE_PROCESS_00005021 as a template for the interface (input parameter, changing parameter).
Interface of function module SAMPLE_PROCESS_00005021:
Input-parameter I_OLTPSOURCE: datasource that is currently extracting data from the R/3 source system.
Changing-Parameter C_STRUCTURE: Extraction structure of the data source currently extracting including fields from the assigned customer include. When you call this customer defined function module, all the fields of the extract structure are transferred filled.
Check whether the type pool SBIWA is declared in the TOP include of the function group.
If not, add it with the statement TYPE-POOLS: SBIWA.
Then maintain table TPS31 with Transaction SM30. Create the following entry:
PROCS LAND APPLK FUNCT
00005021 <fname>
<fname> stands for the customer defined function module.
By doing so, the function module you defined is called for each extracted record. Note that in this case the performance of the extraction may be reduced significantly regardless of the table read and the complexity of the programmed logic.
Example:
You want to enhance the extraction structure DTFIAR_3 for datasource 0FI_AR_4 (customers: line item) by the ORT01 (city) field from the customer master record.
To do this, create structure CI_BSID in data dictionary of the R/3 source system and include the ORT01 field in that. The data dictionary in the R/3 source system displays that the ORT01 field is NOT contained in the read structure of datasource 0FI_AR_4 (Table BSID).
Therefore you have to program a function module that reads the customer master in the R/3 system (table KANN1) and fills the ORT01 field of the customer enhancement. In the changing parameter C_STRUCTURE the filled fields of the extraction structure DTFIAR_3 are available to you. With the KUNNR field of extraction structure DTFIAR_3, you can select the respective master data record from table KNA1 and determine field ORT01 of the customer enhancement.
1. All the fields of the customer enhancement in the customer include are contained in the read structure (see the table above).
Then no additional action is required. The fields of the customer enhancement are filled automatically by the datasource from the assigned read structure via "move-corresponding".
Example:
The extraction structure DTFIGL_4 for datasource 0FI_GL_4 (General ledger: line item) should be enhanced by the VALUT (value date) field.
To do this, create structure CI_BSIS in the data dictionary of the R/3 source system and include the VALUT field in it. The data dictionary in the R/3 source system shows that the VALUT field is contained in the read structure of the datasource (table BSIS). For that reason the VALUT field is automatically filled by datasource 0FI_GL_4.
ATTENTION:
By using Note 430303 you can enhance DataSource 0FI_GL_4 by all fields from table BSEG (instead of BSIS); then the fields are filled automatically in the extractor.
1. Fields of the customer enhancement in the customer include are not contained in the read structure (see the table above).
In this case you have to program a function module to fill the field of the customer enhancement. To do this, there is a Business Transaction Event available (open FI interface for process 00005021). Create any function module you like and use function module SAMPLE_PROCESS_00005021 as a template for the interface (input parameter, changing parameter).
Interface of function module SAMPLE_PROCESS_00005021:
Input-parameter I_OLTPSOURCE: datasource that is currently extracting data from the R/3 source system.
Changing-Parameter C_STRUCTURE: Extraction structure of the data source currently extracting including fields from the assigned customer include. When you call this customer defined function module, all the fields of the extract structure are transferred filled.
Check whether the type pool SBIWA is declared in the TOP include of the function group.
If not, add it with the statement TYPE-POOLS: SBIWA.
Then maintain table TPS31 with Transaction SM30. Create the following entry:
PROCS LAND APPLK FUNCT
00005021 <fname>
<fname> stands for the customer defined function module.
By doing so, the function module you defined is called for each extracted record. Note that in this case the performance of the extraction may be reduced significantly regardless of the table read and the complexity of the programmed logic.
Example:
You want to enhance the extraction structure DTFIAR_3 for datasource 0FI_AR_4 (customers: line item) by the ORT01 (city) field from the customer master record.
To do this, create structure CI_BSID in data dictionary of the R/3 source system and include the ORT01 field in that. The data dictionary in the R/3 source system displays that the ORT01 field is NOT contained in the read structure of datasource 0FI_AR_4 (Table BSID).
Therefore you have to program a function module that reads the customer master in the R/3 system (table KANN1) and fills the ORT01 field of the customer enhancement. In the changing parameter C_STRUCTURE the filled fields of the extraction structure DTFIAR_3 are available to you. With the KUNNR field of extraction structure DTFIAR_3, you can select the respective master data record from table KNA1 and determine field ORT01 of the customer enhancement.
After you create the customer include in the R/3 source system you have to post process the accompanying datasource with Transaction RSA6. Select the application component according to the above table and change the datasource that fits the customer include. The "Hide fields" flag should be removed in the field list for the fields of the customer include. Then save the field list.
If the fields of the customer include is not displayed in Transaction RSA6, refer to note 415530.
1. After you create the customer include in the R/3 source system you have to post process the accompanying datasource with Transaction RSA6. Select the application component according to the above table and change the datasource that fits the customer include. The "Hide fields" flag should be removed in the field list for the fields of the customer include. Then save the field list.
If the fields of the customer include is not displayed in Transaction RSA6, refer to note 415530.
Please let me know.
Thanks,
Sabrina.
Maybe you are looking for
-
Catch a value from a pl*sql function in a shell script
Hi all, I have a shell script that simply calls the following pl*sql function. echo "execute scott.my_pkg.test('FDLmaster');\n exit;" >./pippo.sql sqlplus scott/tiger @/fidcap_ftp/FDL/SCRIPTS/pippo.sql What I have to do to catch the value returned fr
-
Can't install iTunes on my PC goes to a certain spot and stops tried threetimes
iTunes stops installing on my PC at the same spot and won't continue. Has happened three times.
-
Our server sends order emails to our clients and have recently (past week) started to bounce back. 213.199.180.150 does not like recipient. Remote host said: 550 5.7.1 Service unavailable; Client host [213.246.109.24] blocked using Blocklist 1, mail
-
Hi, and Happy Holidays. Recently ran MacJanitor, and got this: Rebuilding locate database: Rebuilding whatis database: find: /usr/local/man: No such file or directory makewhatis: /usr/share/man/man1/c++.1: No such file or directory makewhatis: /usr/s
-
Hi, SRM50 ECS scenario In standard SRM, as soon as the SRM PO is printed, the delete button at PO header level is greyed. This is BBP_PD 200 message "Purchase orders that have been ordered cannot be deleted". Thus it is impossible to delete PO. All y