Application Development and Automation 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: 
Read only

function module for opening balance?

Former Member
0 Likes
9,770

Hi Experts,

I have created a customer outstanding report in which the balance calculation is wrong. The client wants opening balance in the top and then opening balance + debit - credit and then closing balance in the last. And I have just done the debit - credit. Is there any function module to calculate it?

The purpose of the customer outstanding report is that in standard report there is only one column for balance. Client wants to separate it in debit and credit. Please guide.

I have created a cash journal report earlier in which there was opening and closing balance. I copied RFCASH20 into a customized report and made changes according to the user.

Regards

Purnand

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
9,192

Anyone?

26 REPLIES 26
Read only

Former Member
0 Likes
9,193

Anyone?

Read only

0 Likes
9,192

Hi, check BAPI_AR_ACC_GETKEYDATEBALANCE.

Read only

0 Likes
9,192

Hello,

Please refer following thread.It might help you

http://scn.sap.com/thread/694963

Regards

KH

Read only

0 Likes
9,192

Hi,

I followed some other procedure to do it but it failed. I have not worked on bapi's. Can you please elaborate the answer or steps to do that?

Regards

Purnand

Read only

0 Likes
9,192

Hello, using a BAPI is same as using the function module. You can see it in SE37. Pass the input parameters and get the output data. As simple as that!

Read only

0 Likes
9,192

Hi,

Thank you for the response. I will get back to you tomorrow on this. One thing I want to ask. How to find the BAPI for the particular task? Like for opening balance how did find the aove bapi?

Thanks

Purnand

Read only

0 Likes
9,192

BAPI: BAPI_AR_ACC_GETOPENITEMS (Customer Account Open details)

To find BAPI, follow the below steps,

1) Go to T-code "BAPI"

2) Navigate though the process tree to find your application

3) Choose the appropriate options in the tree and get the name of the Function Module in the right side of the screen.

For details, go through this below demo

http://www.youtube.com/watch?v=uEan8s9S8w8

Read only

0 Likes
9,192

Hi,

I am using BAPI for the first time. Following is my code:

   types: begin of ty_final,
      bukrs type bukrs,
       kunnr type kunnr,
       budat type budat,
       wrbtr type wrbtr,
       belnr type belnr_d,
       shkzg type SHKZG,
        budat1 type budat,
       wrbtr1 type wrbtr,
       dr type p decimals 2,
       cr type p decimals 2,
       sno type sy-tabix,
       name1 type kna1-name1,
       name2 type kna1-name2,
       name3 type kna1-name3,
       balance type p decimals 2,
       op_bal type i,
     end of ty_final.

   CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'
  EXPORTING
    COMPANYCODE       = s_bukrs
    CUSTOMER          = s_kunnr
    KEYDATE           = s_date
*   NOTEDITEMS        = ' '
*   SECINDEX          = ' '
* IMPORTING
*   RETURN            =
  TABLES
    LINEITEMS         = it_final

The code is giving dump at LINEITEMS. I do not know how to use it. I checked some formats on net also but its written:

TABLES

    lineitems =                 " bapi3007_2    Line items

    .  "  BAPI_AR_ACC_GETOPENITEMS

I checked the documentation also but I did not get it. Can anyone explain me.

I created a structure with only opening balance and passed its internal table in line items but again its giving dump.

Regards

Purnand

Read only

0 Likes
9,192

Hi,

I just checked se37 also but I could not understand.

Regards

Purnand

Read only

0 Likes
9,192

What have you declared it_final? What is the runtime error that your getting?

Read only

0 Likes
9,192

Hi,

Thank you for the reply. I have declared it_final in the report itself and please check the following screenshot:

Regards

Purnand

Read only

0 Likes
9,192

Anyone?

Read only

0 Likes
9,192

It's a clear flaw, your declarations it_final is not compatible with bapi lineitems. Your structure should be as in bapi lineitems. Please check with associate type of lineitems in the FM.

Read only

0 Likes
9,192

Hi,

Thank you for the reply. I understand that its a clear flaw. But the question is what should I give in the lineitems,

I am out of office right now. I wrote this sample code but its also giving dump:

report zrough.

tables: bsad, bsid.

data: it_bsad type STANDARD TABLE OF bsad,

      it_bsid type STANDARD TABLE OF bsid.

data: wa_bsad type bsad,

      wa_bsid type bsid.

data: it_final type STANDARD TABLE OF BAPI3007_2,

      wa_final type bapi3007_2.

SELECT-OPTIONS: so_bukrs for bsad-bukrs,

                so_kunnr for bsad-kunnr,

                so_budat for bsad-budat.

BREAK-POINT.

CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'

  EXPORTING

    companycode       = so_bukrs

    customer          = so_kunnr

    keydate           = so_budat

*   NOTEDITEMS        = ' '

*   SECINDEX          = ' '

* IMPORTING

*   RETURN            =

  tables

    lineitems         = it_final.

          .

loop at it_final into wa_final.

write:/ wa_Final-lc_amount.

endloop.

I just want the value of lc_amount in my report. How should I get it?

Regards

Purnand

Read only

0 Likes
9,192

Do you remember the fields inside the tables associated structure for lineitems which bapi3007_2??

So, your li_final should be declared in this way....

data: it_final type bapi3007_2. My doubt is that do you have a field to get amount in this structure bapi3007_2? Have you checked on that?

Read only

0 Likes
9,192

Hi,

I just checked that in ides there is a field with the name lc_amount. I want this in the report. Kindly tell me where I am lacking.

Regards

Purnand

Read only

0 Likes
9,192

Ok fine..

Now declare it_final as; data: it_final type bapi3007_2,

And then pass it to the FM. Try this and let me know if you find any complexity.

Also take a screenshot of your code and upload it here in case of further assistance.

Thanks

Jula                               

Read only

0 Likes
9,192

Hi,

Sorry, cannot attach the screenshot but following is the code:

report zrough.

tables: bsad, bsid.

data: it_bsad type STANDARD TABLE OF bsad,

      it_bsid type STANDARD TABLE OF bsid.

data: wa_bsad type bsad,

      wa_bsid type bsid.

data: it_final type STANDARD TABLE OF BAPI3007_2,

      wa_final type bapi3007_2.

SELECT-OPTIONS: so_bukrs for bsad-bukrs,

                so_kunnr for bsad-kunnr,

                so_budat for bsad-budat.

BREAK-POINT.

CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'

  EXPORTING

    companycode       = so_bukrs

    customer          = so_kunnr

    keydate           = so_budat

*   NOTEDITEMS        = ' '

*   SECINDEX          = ' '

* IMPORTING

*   RETURN            =

  tables

   lineitems         = it_final.

          .

loop at it_final into wa_final.

write:/ wa_Final-lc_amount.

endloop.

How to get the value of lc_amount?

Thanks

Purnand

Read only

0 Likes
9,190

Hi Purnand ,

For getting Opening Balance Date wise for a particular Customer the Function Module to be used is BAPI_AR_ACC_GETKEYDATEBALANCE

Now let me clear you some concepts about Opening.

Consider your below example :

Suppose you want opening for Customer ( Creditors Analysis ) say 0000000004 on Posting Date 01.04.2012 ,

Opening will be the balance of this Customer just the day before i.e balance of that customer on 31st march 2012 will be the opening for 1st april.

Now next question is how to find Balance of a customer based on a date , for that there is a very famous and mostly used Standard Report which is FBL5N .

Now the Function Module which provides the functionality of FBL5N is BAPI_AR_ACC_GETKEYDATEBALANCE .

Now see the below case :

FBL5N

Input fields :

Output :

The above highlighted figure is balance of Customer 121 as on 25.03.2013.

Now the BAPI

Execute it and you will get the below output :

This will help you out.

Do take care while passing parameters to BAPI in your Report Code.

Thanks ,

Sij

Read only

0 Likes
9,190

Hi,

You are perfectly right. I have created a different code to run bapi. I have created the logic as well. Its running good but either with parameters or constant value. But my report runs with select options

How to solve this issue now?


Thanks in advance

Purnand

Read only

0 Likes
9,190

Loop inside final internal table and pass the value to BAPI using Work Area.

Read only

0 Likes
9,190

Hi,

I did not get it.

*&---------------------------------------------------------------------*

*& Report  ZROUGH

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT  ZROUGH.

DATA: it_bsad TYPE STANDARD TABLE OF bsad,

       it_bsid TYPE STANDARD TABLE OF bsid.

DATA: wa_bsad TYPE bsad,

       wa_bsid TYPE bsid.

DATA: it_final TYPE STANDARD TABLE OF bapi3007_2,

       wa_final TYPE bapi3007_2.

data: dr type bapi3007_2-lc_amount,

       cr type bapi3007_2-lc_amount,

       dr1 type bapi3007_2-lc_amount,

       cr1 type bapi3007_2-lc_amount,

       op_bal type bapi3007_2-lc_amount.

parameters: lv_bukrs  TYPE bapi3007_1-comp_code,

             lv_kunnr  TYPE bapi3007_1-customer,

              lv_budat TYPE bapi3007-key_date.

**

*

*data: co_code type bapi3007_1-comp_code,

*      cust_no type bapi3007_1-customer,

*      cust_date type bapi3007-key_date.

*

*select-OPTIONS: so_bukrs for co_code,

*                so_kunnr for cust_no,"bapi3007_1-customer,

*                so_budat for cust_date."bapi3007-key_date.

*

CALL FUNCTION 'BAPI_AR_ACC_GETOPENITEMS'

   EXPORTING

     companycode       = '100' "lv_bukrs

     customer          = lv_kunnr

     keydate           = lv_budat

*   NOTEDITEMS        = ' '

*   SECINDEX          = ' '

* IMPORTING

*   RETURN            =

   TABLES

     lineitems         = it_final.

.

sort it_final by pstng_date.

BREAK-POINT.

loop at it_final into wa_final.

if wa_final-db_cr_ind = 'S' and wa_final-pstng_date <> lv_budat.

    dr = wa_final-lc_amount.

    dr1 = dr1 + dr.

    elseif wa_final-db_cr_ind = 'H' and wa_final-pstng_date <> lv_budat.

      cr = wa_final-lc_amount.

        cr1 = cr1 + cr.

      ENDIF.

      ENDLOOP.

    op_bal = dr1 - cr1.

BREAK-POINT.

This is my code which is not working with select-options.

Read only

0 Likes
9,190

Consider your code for customer outstanding report .

Inside that there is a field for Posting date (BUDAT) and a field for Customer ( KUNNR ).

Now while filling the final internal table for that report ( i.e CUSTOMER OUTSTANDING REPORT )

just after filling the values BUDAT and KUNNR call that BAPI .

eg :

LOOP AT BSID.

WA_FINAL-BUDAT = BSID-BUDAT.

WA_FINAL-KUNNR = BSID-KUNNR.

CALL FUNCTION BAPI_AR_ACC_GETKEYDATEBALANCE.

EXPORTING COMPANYCODE = '1000'.

                    CUSTOMER        = BSID-KUNNR

                    KEYDATE           = BSID-BUDAT.

TABLES    KEYBALANCE

ENDLOOP.

Read only

0 Likes
9,190

Hi,

Sorry for replying late. I'll get back to you tomorrow.

Read only

0 Likes
9,190

Hi,

Sorry for replying late. I'll get back to you tomorrow.

Read only

Former Member
0 Likes
9,190

Hi,

Thank you all. Its done