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: 

function module in loop

former_member476503
Participant
0 Kudos
165

i m using "BAPI_GL_GETGLACCPERIODBALANCES" FUNCTION MODULE.

LOOP AT IT_OUTPUT INTO WA_OUTPUT .
CALL FUNCTION 'BAPI_GL_GETGLACCPERIODBALANCES'
  EXPORTING
    COMPANYCODE                   = WA_OUTPUT-BUKRS
    GLACCT                        = WA_OUTPUT-HKONT                                         (A/C NO)
    FISCALYEAR                    = WA_OUTPUT-GJAHR
    CURRENCYTYPE                  = '10'
* IMPORTING
*   BALANCE_CARRIED_FORWARD       =
*   RETURN                        =
  TABLES
    ACCOUNT_BALANCES              = IT_OUTPUT.
ENDLOOP.

I M GETTING ALL RECORDS IN IT_OUTPUT.BUT WHEN I AM USING THIS FM, I AM NOT GETTING RECORDS FOR ALL A/C NO.

PLZ SUGGEST .....

THANKS

Moderator message: please do not post in all upper case.

Edited by: Thomas Zloch on Mar 15, 2011 9:06 AM

1 ACCEPTED SOLUTION

Rushikesh_Yeole
Contributor
0 Kudos
84

Take one internal table like it_output.

After each call of FM append entries of it_output to that internal tabl.e

At final, you will get all entries.

10 REPLIES 10

Rushikesh_Yeole
Contributor
0 Kudos
85

Take one internal table like it_output.

After each call of FM append entries of it_output to that internal tabl.e

At final, you will get all entries.

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos
84

You need to collect each exporting parameters in an internal table inside the loop.soemthing like append it_ouptut to it_output _final .

lijisusan_mathews
Active Contributor
0 Kudos
84

With this code, your IT_OUTPUT will be populated with values of last ACC_NO .. ie the last value in wa_output... This is because the table it_output will be overwritten each time.. You may have to store the values into a separate table, or take teh sum of the same as necessary for your logic.

0 Kudos
84

THANKS GUYZ FOR REPLYING

I AM STORING IT ANOTHER TABLE "IT_BALNCE".

AND APPENDING THE TABLE IT_BALNCE.

BUT STILL THE OUTPUT IS SAME.

Moderator message: please do not post in all upper case!

Edited by: Thomas Zloch on Mar 15, 2011 9:07 AM

0 Kudos
84

Hi Sanket,

You need to have three tables of type IT_OUTPUT,

1) One which will have the input values that you need to pass to the BAPI - IT_OUTPUT_IN.

2) The second table to get the out from the BAPI - IT_OUTPUT_OUT.

3) The third table to accumulate the output from the BAPI - IT_OUTPUT_FINAL.

change the code as given below,

LOOP AT IT_OUTPUT_IN INTO WA_OUTPUT .

CALL FUNCTION 'BAPI_GL_GETGLACCPERIODBALANCES'

EXPORTING

COMPANYCODE = WA_OUTPUT-BUKRS

GLACCT = WA_OUTPUT-HKONT (A/C NO)

FISCALYEAR = WA_OUTPUT-GJAHR

CURRENCYTYPE = '10'

  • IMPORTING

  • BALANCE_CARRIED_FORWARD =

  • RETURN =

TABLES

ACCOUNT_BALANCES = IT_OUTPUT_OUT.

append lines of IT_OUTPUT_OUT to IT_OUTPUT_FINAL.

REFRESH: IT_OUTPUT_OUT.

ENDLOOP.

With your current code: You are overwriting the entries of IT_OUTPUT every time you are calling the BAPI, and re-using the same entries in the loop.

Regards,

Chen

former_member182040
Active Contributor
0 Kudos
84

See the following example :


FORM GET_BALANCE.


CALL FUNCTION 'BAPI_GL_GETGLACCPERIODBALANCES'
              EXPORTING
                      COMPANYCODE = P_BUKRS
                      GLACCT = P_HKONT
                      FISCALYEAR = B_YEAR
                      CURRENCYTYPE = '10'
             IMPORTING
                      RETURN = RETURN
             TABLES
                      ACCOUNT_BALANCES = ACCOUNT_BALANCES.


IF RETURN-TYPE IS INITIAL.
   LOOP AT ACCOUNT_BALANCES WHERE FIS_PERIOD = S_PERI.
   B_BALANCE = ACCOUNT_BALANCES-BALANCE.
   REPTAB-BUDAT = S_DATE.
   REPTAB-DMBTR_T = B_BALANCE.
   APPEND REPTAB.
   ENDLOOP.
ELSE.
   REPTAB-BUDAT = S_DATE.
   REPTAB-DMBTR_T = 0.
   APPEND REPTAB.
ENDIF.
ENDFORM.

0 Kudos
84

Can u please explain what did u put in RETURN Value?

0 Kudos
84

after Finish BAPI process system give message in return so You can define return like

DATA: RETURN LIKE BAPIRETURN.

0 Kudos
84

after Finish BAPI process system give message in return so You can define return like

DATA: RETURN LIKE BAPIRETURN.

former_member476503
Participant
0 Kudos
84

Thanks krupaji