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: 

looping in Internal table

Former Member
0 Kudos

Hi,

I am trying to create a document using BAPI.It works for single header and single item.

I want to enhance this for multiple jobs.

My internal table has following records ..mentioned in code. I am confused on how to pass these in loop.

REPORT x.

DATA: doc_header TYPE STANDARD TABLE OF bapidochdrp .
DATA: doc_items TYPE STANDARD TABLE OF bapiskfitm  .
DATA: return TYPE STANDARD TABLE OF bapiret2 .

DATA: wa_header TYPE  bapidochdrp .
DATA: wa_return TYPE bapiret2 .


TYPES: BEGIN OF t_doc ,
job(10) TYPE c,
phase(10) TYPE c,
hour(6) TYPE c,
amount(10) TYPE c,

END OF t_doc.

DATA: it_doc TYPE STANDARD TABLE OF t_doc.
DATA: wa_doc TYPE t_doc.

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '30.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '20' TO wa_doc-hour.
MOVE '20.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '30' TO wa_doc-hour.
MOVE '40.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '200' TO wa_doc-job.
MOVE '9500' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '20.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '200' TO wa_doc-job.
MOVE '9600' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '70.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '300' TO wa_doc-job.
MOVE '9800' TO wa_doc-phase.
MOVE '30' TO wa_doc-hour.
MOVE '80.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '300' TO wa_doc-job.
MOVE '9900' TO wa_doc-phase.
MOVE '20' TO wa_doc-hour.
MOVE '50.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


WRITE:/10 'Job' , 20 'Phase', 30 'Hour', 50 'Amount'.
ULINE.
LOOP AT it_doc INTO wa_doc.

  WRITE:/10 wa_doc-job, 20 wa_doc-phase, 30 wa_doc-hour, 50 wa_doc-amount.



ENDLOOP.


*Header file will be always

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

*    ** doc_items should be like this below.(Other words it will be JOb/Phase/Hours  , & Job/Phase/Amounts everytime)
*    first doc_items  - 100, 9700,sum of hours(60)
*     second doc_items -100, 9700, sum of amounts(90)
*     third doc_items -200, 9500, sum of hours(10)
*     fourth doc_items -200, 9500, sum of amounts(20)
*     fifth doc_items -200, 9600, sum of hours(10)
*     sixth doc_items -200, 9600, sum of amounts(70)

*** My BAPI should create only one document per  job. i mean 1 for 100 , 2nd one for 200 and so on..


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

Edited by: PRAVEEN s on Mar 27, 2009 4:15 PM

Edited by: PRAVEEN s on Mar 27, 2009 4:28 PM

Edited by: PRAVEEN s on Mar 27, 2009 4:29 PM

4 REPLIES 4

Former Member
0 Kudos

Hi,

LOOP AT i_header INTO g_HEADER.

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

Loop at i_item WHERE co_area =  g_header-co_area'

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '30.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.
Clear it_doc. 

AT END OF CO_AREA.

WRITE:/10 'Job' , 20 'Phase', 30 'Hour', 50 'Amount'.
ULINE.
LOOP AT it_doc INTO wa_doc.
 
  WRITE:/10 wa_doc-job, 20 wa_doc-phase, 30 wa_doc-hour, 50 wa_doc-amount.
  
ENDLOOP.

CALL FUNCTION 'BAPI_ACC_STAT_KEY_FIG_POST'
  EXPORTING
    doc_header      = wa_header
    ignore_warnings = 'X'
  TABLES
    doc_items       = doc_items
    return          = return.
  
Clear wa_header.
Refresh doc_item.

ENDDAT.

ENDLOOP.

Former Member
0 Kudos
 
loop at itab. 
     perform populate_bapi.
     .....call bapi. 
     .....bapi_transaction_commit / rollback. 
     .....clear bapi structures/ fields/tables. 
endloop. 

0 Kudos

Hi,

Looks like I should have to breaken down the problem first.

I just want to process my internal table and bring it into required format.where it sums up by job/phase/Hours & job/phase/Amount by creating duplicate rows.

REPORT x.


TYPES: BEGIN OF t_doc ,
job(10) TYPE c,
phase(10) TYPE c,
hour(6) TYPE c,
amount(10) TYPE c,

END OF t_doc.

DATA: it_doc TYPE STANDARD TABLE OF t_doc.
DATA: wa_doc TYPE t_doc.

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '30.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '20' TO wa_doc-hour.
MOVE '20.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.

MOVE '100' TO wa_doc-job.
MOVE '9700' TO wa_doc-phase.
MOVE '30' TO wa_doc-hour.
MOVE '40.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '200' TO wa_doc-job.
MOVE '9500' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '20.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '200' TO wa_doc-job.
MOVE '9600' TO wa_doc-phase.
MOVE '10' TO wa_doc-hour.
MOVE '70.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '300' TO wa_doc-job.
MOVE '9800' TO wa_doc-phase.
MOVE '30' TO wa_doc-hour.
MOVE '80.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


MOVE '300' TO wa_doc-job.
MOVE '9900' TO wa_doc-phase.
MOVE '20' TO wa_doc-hour.
MOVE '50.00' TO wa_doc-amount.
APPEND wa_doc TO it_doc.


WRITE:/10 'Job' , 20 'Phase', 30 'Hour', 50 'Amount'.
ULINE.
LOOP AT it_doc INTO wa_doc.

  WRITE:/10 wa_doc-job, 20 wa_doc-phase, 30 wa_doc-hour, 50 wa_doc-amount.


ENDLOOP.


*    ** doc_items should be 2 times for every job.
*    first doc_items  - 100, 9700,sum of hours(60)
*     second doc_items -100, 9700, sum of amounts(90)
*     third doc_items -200, 9500, sum of hours(10)
*     fourth doc_items -200, 9500, sum of amounts(20)
*     fifth doc_items -200, 9600, sum of hours(10)
*     sixth doc_items -200, 9600, sum of amounts(70)

Former Member
0 Kudos

opened another ticket by break down issue