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: 

passing BAPI inside loop of internal table

Former Member
0 Kudos

Hi,

My internal table has follwing entries and now I should create 3 documents using BAPI.

How do i do this?

job	 Phase	   Quantity
100       9700      60
100       9700      90
**************
200       9500      10
200       9500      20
200       9600      10
200       9600      70
*************
300       9800      30
300       9800      80
300       9900      20
300       9900      50

wa_header is always

wa_header-co_area = 1000.
      wa_header-docdate = sy-datum.
      wa_header-username = sy-uname.

doc_items -1 -  

100       9700      60
100       9700      90

doc_items -2-

200       9500      10
200       9500      20
200       9600      10
200       9600      70

....


 CALL FUNCTION 'BAPI_ACC_STAT_KEY_FIG_POST'
        EXPORTING
          doc_header            = wa_header
         ignore_warnings       = 'X'
        TABLES
          doc_items             = doc_items
          return                = return

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

Can you be more specific about your qestion.

Or looking for this



wa_header-co_area = 1000.
wa_header-docdate = sy-datum.
wa_header-username = sy-uname.

SORT item BY job.
LOOP AT item INTO wa_item.
  APPEND wa_item TO doc_item.
  AT END OF job.
    CALL FUNCTION 'BAPI_ACC_STAT_KEY_FIG_POST'
      EXPORTING
        doc_header      = wa_header
        ignore_warnings = 'X'
      TABLES
        doc_items       = doc_items
        return          = return.
    REFRESH doc_item.
  ENDAT.
ENDLOOP.

Edited by: Avinash Kodarapu on Mar 27, 2009 10:36 PM

5 REPLIES 5

Former Member
0 Kudos

HI,

Can you be more specific about your qestion.

Or looking for this



wa_header-co_area = 1000.
wa_header-docdate = sy-datum.
wa_header-username = sy-uname.

SORT item BY job.
LOOP AT item INTO wa_item.
  APPEND wa_item TO doc_item.
  AT END OF job.
    CALL FUNCTION 'BAPI_ACC_STAT_KEY_FIG_POST'
      EXPORTING
        doc_header      = wa_header
        ignore_warnings = 'X'
      TABLES
        doc_items       = doc_items
        return          = return.
    REFRESH doc_item.
  ENDAT.
ENDLOOP.

Edited by: Avinash Kodarapu on Mar 27, 2009 10:36 PM

former_member376453
Contributor
0 Kudos

Loop 

At end of 'Job'

Call Function 'BAPI........'

Endloop

I think this way you can create a FI doc when job will change

Kuntal

Former Member
0 Kudos

If your internal table is job - phase - quantity

You can do this

wa_header-co_area = 1000.

wa_header-docdate = sy-datum.

wa_header-username = sy-uname.

loop at internal table into work_area.

at new job.

  • fill fields on DOC_ITEMS structures using phase and quantity.

endat.

at end of job.

CALL FUNCTION 'BAPI_ACC_STAT_KEY_FIG_POST'

EXPORTING

doc_header = wa_header

ignore_warnings = 'X'

TABLES

doc_items = doc_items

return = return

endat.

endloop.

Former Member
0 Kudos

Avinash,

Now that I have Internal table in my requried format.

I want to create a document for each Job using BAPI.

There are 3 jobs i.e 100,200,300 & Items should be their respective records

like

doc_items -1 -  
 
100       9700      60
100       9700      90

et..

rgds

Praveen

Former Member
0 Kudos

Hi,

Just try this code once... and then tell if its working or not

wa_header-co_area = 1000.
wa_header-docdate = sy-datum.
wa_header-username = sy-uname.

loop at internal table into work_area.

append work_area to doc_items.  "  if the structure is different then move work_area to doc_items structure 
" and then append it.....  no at events required here

at end of job.
CALL FUNCTION 'BAPI_ACC_STAT_KEY_FIG_POST'
EXPORTING
doc_header = wa_header
ignore_warnings = 'X'
TABLES
doc_items = doc_items
return = return.

clear doc_items.   "  Clearing doc_items is very important.
endat.

endloop.

regards,

Siddarth