Skip to Content
0
Former Member
Mar 27, 2009 at 03:13 PM

looping in Internal table

32 Views

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