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: 

Retrieving Accounting Document number based on PO numbers

Former Member
0 Kudos

Hey All,

I have a list of PO numbers(EBELN) for which I am trying to get all Accounting information from BSIS. But before going to BSIS I am trying to determine the Accounting document number(BELNR) from some other table so that my select on BSIS will be efficient.

What I have tried uptill now is to go to EKBE with the PO numbers and get the Material document numbers. For some cases the material document number is the accounting document number and for others I have to go to BKPF with this material document number to get the accounting document number.

Is there any other easier and efficeint way of doing this?

Any input is highly appreciated.

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Aparna,

try this

In case of PO u will get A/c Documents from EKBE table.

BSEG will contains all items data.

try to make use of this FM

AC_DOCUMENT_RECORD.

or

call function 'FI_DOCUMENT_RECORD'

exporting

i_awtyp = 'RMRP'

i_awref = w_awref1 --->IR number of PO

i_aworg = w_gjahr1----.year

I_AWSYS = ' '

I_AWTYP_INCL = ' '

I_AWTYP_EXCL = ' '

I_BUKRS = ' '

tables

t_documents = t_doc.

regards

Prabhu

9 REPLIES 9

Former Member
0 Kudos

Hi Aparna,

try this

In case of PO u will get A/c Documents from EKBE table.

BSEG will contains all items data.

try to make use of this FM

AC_DOCUMENT_RECORD.

or

call function 'FI_DOCUMENT_RECORD'

exporting

i_awtyp = 'RMRP'

i_awref = w_awref1 --->IR number of PO

i_aworg = w_gjahr1----.year

I_AWSYS = ' '

I_AWTYP_INCL = ' '

I_AWTYP_EXCL = ' '

I_BUKRS = ' '

tables

t_documents = t_doc.

regards

Prabhu

Former Member
0 Kudos

Please see:

[Quickly Retrieving FI document Data from BSEG|]

There is a section there that does what you are doing.

Rob

0 Kudos

Thanks Rob,

As you might have already figured out this thread is related to a previous thread of mine concering

performance Issue with BSIS. I am trying this approach, so that I can retrieve data in small packages of

PO numbers, so that I can atleast avoid the perfromance problem with Huge data.

Do you think this will help at all? I mean in terms of Overall runtime?

0 Kudos

Nope - packages will help with memory issues when retrieving a large amount of data. What does you code look like?

Rob

0 Kudos

I am retrieving Large amounts of data, around 1.5 million from BSIS.

The code related to our discussion looks like this:



"First I get all related PO's for the last three years and determine the no of packets.

DO v_no_of_packets TIMES.
      IF v_end_indx GT v_total.
        v_end_indx = v_total.
      ENDIF.
      REFRESH i_ebeln_range[].
      APPEND LINES OF t_ebeln_range FROM v_start_indx TO v_end_indx TO i_ebeln_range.
      v_start_indx = v_end_indx + 1.
      v_end_indx   = v_end_indx + p_pkjsiz.

 IF NOT i_ebeln[] IS INITIAL.
  CLEAR l_bkpf.
  REFRESH l_bkpf[].
  SELECT ebeln ebelp zekkn vgabe gjahr belnr buzei FROM EKBE INTO TABLE t_belnr
                     WHERE ebeln IN i_ebeln_range
                      AND vgabe IN ('1' ,'2').

  IF sy-subrc EQ 0.
    LOOP AT t_belnr.
    l_awkey+0(10) = t_belnr-belnr.
    l_awkey+10(10) = t_belnr-gjahr.

    IF t_belnr-vgabe = '1'.
      l_awtyp = 'MKPF'.
    ELSE.
      l_awtyp = 'RMRP'.
    ENDIF.
    SELECT SINGLE bukrs belnr gjahr blart budat
      FROM bkpf INTO l_bkpf
        WHERE awtyp = l_awtyp
        AND   awkey = l_awkey.

      IF sy-subrc EQ 0.
         APPEND l_bkpf.
      ENDIF.
    ENDLOOP.

  ENDIF.
ENDIF.

"Then 
  SELECT zuonr hkont gjahr belnr buzei budat blart wrbtr shkzg xblnr
waers bukrs
   INTO TABLE i_bsis
   FROM bsis
   FOR ALL ENTRIES IN l_bkpf
    WHERE bukrs = l_bkpf-bukrs
                      AND  hkont IN r_hkont   "Contains all Accounts
                      AND  budat = l_bkpf-budat
                      AND  augdt = 0
                      AND  augbl = space
                      AND  gjahr = l_bkpf-gjahr
                      AND  belnr = l_bkpf-belnr
                      AND  blart = l_bkpf-blart
                      AND  gsber = c_zrl1.

  SELECT zuonr hkont gjahr belnr buzei budat blart wrbtr shkzg xblnr
waers bukrs
   APPENDING TABLE i_bsis
   FROM bsas
    FOR ALL ENTRIES IN l_bkpf
    WHERE bukrs = l_bkpf-bukrs
                      AND  hkont IN r_hkont
                      AND  budat = l_bkpf-budat
                      AND  augdt = 0
                      AND  augbl = space
                      AND  gjahr = l_bkpf-gjahr
                      AND  belnr = l_bkpf-belnr
                      AND  blart = l_bkpf-blart
                      AND  gsber = c_zrl1.

"Then process this data

0 Kudos

You should be using BSEG rather than BSIS and BSAS.

Rob

naimesh_patel
Active Contributor
0 Kudos

You can use the AC_DOCUMENT_RECORD FM to get the FI document based on the Incoming Invoice posted in the PO.

From the PO you can find the incoming invoice from the EKBE.

Regards,

Naimesh Patel

0 Kudos

Naimesh,

Thank you four answer. Prabhu was also suggesting the same thing, but my problem is that I am pulling all documents for the last three years. I am dealing with 2 million records. I am not sure if calling the FM in a loop a million times will be a good idea.

Rob,

I will try with BSEG. Thanks.

0 Kudos

Oh .. for those many records the FM would not be the great choice. Instead ot he FM you can read the BKPF with the AWTYP and AWKEY.

In IT_SELECTIONs you can fill the documents from the EKBE.


      SELECT * FROM bkpf                                         
               INTO CORRESPONDING FIELDS OF TABLE lt_accdn_awkey 
               FOR ALL ENTRIES IN lt_selections                  
               WHERE awtyp = 'RMRP'                
               AND   awkey = lt_selections-awkey.

Than you can go to BSIS / BSAS or BSEG to fatch the required data.

Regards,

Naimesh Patel