Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Function Module - Urgent

Former Member
0 Kudos
153

Hi Experts,

Need a function module which populate the lfa1 with input parameter BElnR.

I need field lifnr, name1 from lfa1.

Need another FM which populate the SKAT with input parameter belnr.

I need field saknr, txt20 from skat.

Guys i have tried using select query to fetch these, howerver the performance is very slow as im querying bsis and bsak tables. I have used for all entries and also tried creating a view, that was not sucessful. Kindly provide me a solution.

Regards,

Senthil

1 ACCEPTED SOLUTION

Former Member
0 Kudos
113

Hi

If you have the document number (BELNR), but u should have company code (BUKRS) and fyscal year (GJAHR) too:

SELECT SINGLE * FROM T001 WHERE BUKRS = P_BUKRS

SELECT * FROM BSEG WHERE BUKRS = P_BUKRS

AND BELNR = P_BELNR

AND GJAHR = P_GJAHR

AND KOART = 'K'.

EXIT.

ENDSELECT.

SELECT SINGLE * FROM LFA1 WHERE LIFNR = BSEG-LIFNR.

SELECT * FROM BSEG WHERE BUKRS = P_BUKRS

AND BELNR = P_BELNR

AND GJAHR = P_GJAHR

AND KOART = 'S'.

EXIT.

ENDSELECT.

SELECT SINGLE * FROM SKAT WHERE SPRAS = SY-LANGU

AND KTOPL = T001-KTOPL

AND SAKNR = BSEG-HKONT.

Max

8 REPLIES 8

Former Member
0 Kudos
114

Hi

If you have the document number (BELNR), but u should have company code (BUKRS) and fyscal year (GJAHR) too:

SELECT SINGLE * FROM T001 WHERE BUKRS = P_BUKRS

SELECT * FROM BSEG WHERE BUKRS = P_BUKRS

AND BELNR = P_BELNR

AND GJAHR = P_GJAHR

AND KOART = 'K'.

EXIT.

ENDSELECT.

SELECT SINGLE * FROM LFA1 WHERE LIFNR = BSEG-LIFNR.

SELECT * FROM BSEG WHERE BUKRS = P_BUKRS

AND BELNR = P_BELNR

AND GJAHR = P_GJAHR

AND KOART = 'S'.

EXIT.

ENDSELECT.

SELECT SINGLE * FROM SKAT WHERE SPRAS = SY-LANGU

AND KTOPL = T001-KTOPL

AND SAKNR = BSEG-HKONT.

Max

0 Kudos
113

Hi Max,

The performance is affected very worsely if i use BSEG as there are lakhs of record. Kindly provide me some other alternative.

Regards,

Senthil

0 Kudos
113

Hi

Can you post your queries?

U read BSEG or BSIK/BSAK and BSIS/BSAS table, but the performance depend on your selection parameters.

Max

0 Kudos
113

Hi Max,

Check this,

form get_detail.

if itab-awtyp eq 'MKPF' or itab-awtyp eq 'BKPF'.

select single * from ekko where ebeln eq itab-ebeln.

if sy-subrc ne 0.

<b>if itab-blart = 'KR'.

select single * from bsip

where belnr = itab-refbn and gjahr = itab-gjahr.

itab-lifnr2 = bsip-lifnr.

select single * from lfa1 where lifnr = itab-lifnr2.

itab-name2 = lfa1-name1.

modify itab index sy-tabix.

elseif itab-blart = 'SA'.

select single * from bsis

where belnr = itab-refbn and gjahr = itab-gjahr .

itab-hkont = bsis-hkont.

select single * from skat where saknr = itab-hkont.

itab-txt20 = skat-txt20.

modify itab index sy-tabix</b>.

endform.

The perform get_detail is at the top inside loop at itab. endloop.

Regards,

Senthil

0 Kudos
113

Solution plz??

Regards,

Senthil

0 Kudos
113

Hi

I don't know how you have to define ITAB, but you should have the company code too:

DATA: KOART TYPE KOART.

if itab-awtyp eq 'MKPF' or itab-awtyp eq 'BKPF'.

select single * from ekko where ebeln eq itab-ebeln.

if sy-subrc ne 0.

CASE itab-blart.

WHEN 'KR'. KOART = 'K'.

WHEN 'SA'. KOART = 'S'.

ENDCASE.

<b>SELECT * FROM BSEG WHERE BUKRS = ITAB-BUKRS

AND BELNR = ITAB-REFBN

AND GJAHR = ITAB-GJAHR

AND KOART = KOART.</b>

ITAB-LIFNR2 = BSEG-LIFNR.

ITAB-HKONT = BSEG-HKONT.

EXIT.

ENDSELECT.

IF SY-SUBRC = 0.

IF KOART = 'K'.

select single * from lfa1 where lifnr = itab-lifnr2.

itab-name2 = lfa1-name1.

ELSE.

select single * from skat where saknr = itab-hkont.

itab-txt20 = skat-txt20.

ENDIF.

MODIFY ITAB INDEX SY-TABIX.

ENDIF.

This select for BSEG is very fast because all key fields (except BUZEI) are used. So you should only store the company code in ITAB

Max

0 Kudos
113

Thanks max,

The report is fine, however not expected performance.

And there was some error in rewarding points right now, anyway will reward in later time.

Senthil

0 Kudos
113

Hi

SELECT * FROM BSEG WHERE BUKRS = ITAB-BUKRS

AND BELNR = ITAB-REFBN

AND GJAHR = ITAB-GJAHR

AND KOART = KOART.

It's the best query u can do it with the data you have, u can try to improve the performance using INTO TABLE statament:

DATA: T_BSEG TYPE SORDTED TABLE OF BSEG WITH NON UNIQUE KEY BUKRS BELNR GJAHR KOART.

SELECT * FROM BSEG INTO TABLE T_BSEG

FOR ALL ENTRIES IN ITAB WHERE BUKRS = ITAB-BUKRS

AND BELNR = ITAB-REFBN

AND GJAHR = ITAB-GJAHR.

So in this way u have the select for BSEG once and then replace SELECT statament with LOOP/ENDLOOP.

LOOP AT T_BSEG INTO BSEG WHERE BUKRS = ITAB-BUKRS

AND BELNR = ITAB-REFBN

AND GJAHR = ITAB-GJAHR

AND KOART = KOART.

.....

Anyway here the performance can only depends on the record number of itab you have to analyze.

Try!

Max