Skip to Content
0
Former Member
Dec 18, 2006 at 09:35 AM

Problem in extracting po data

27 Views

Hi,

i am using the following code to extract the po data,i am trying to extract multiple pos,but i am not getting multiple items into the excel sheet,i mean if i had one po with 4 items ,i am getting only last item,if any body have the idea kindly send me,

ITS URGENT ISSUE.

&----


*& Report ZTEST *

*& *

&----


*& *

*& *

&----


REPORT ZTEST .

*DATA: BEGIN OF IT_PO_HEADER OCCURS 20,

  • BSART LIKE EKKO-BSART,

  • EBELN LIKE EKKO-EBELN,

  • SUPERFIELD LIKE MEPO_TOPLINE-SUPERFIELD,

  • BEDAT LIKE EKKO-BEDAT,

  • ZTERM LIKE EKKO-ZTERM,

  • NETWR LIKE EKKO-NETWR,

*

TABLES: EKKO.

*PARAMETERS : P_EBELN TYPE EBELN.

SELECT-OPTIONS: S_EBELN FOR EKKO-EBELN OBLIGATORY.

TYPES: BEGIN OF T_PO,

EBELN TYPE EBELN,

END OF T_PO.

DATA: IT_PO TYPE STANDARD TABLE OF T_PO,

WA_PO TYPE T_PO.

DATA : IT_ITEMS TYPE TABLE OF BAPIEKPO WITH HEADER LINE.

DATA: PO_ITEMS_SHEDULE TYPE TABLE OF BAPIEKET WITH HEADER LINE.

DATA: PO_ITEM_TEXT TYPE TABLE OF BAPIEKPOTX WITH HEADER LINE.

DATA: PO_ITEM_ACCOUNT_ASSIGNMENT TYPE TABLE OF BAPIEKKN

WITH HEADER LINE.

DATA: PO_HEADER_TEXTS TYPE TABLE OF BAPIEKKOTX WITH HEADER LINE.

DATA: PO_HEADER TYPE BAPIEKKOL.

DATA: RETURN1 TYPE TABLE OF BAPIRETURN WITH HEADER LINE.

data : begin of itab1 occurs 0,

line(750) type c,

end of itab1.

  • DATA PO_HEADER TYPE BAPIEKKOL .

SELECT EBELN INTO TABLE IT_PO FROM EKKO WHERE EBELN IN S_EBELN.

PERFORM DOWNLOAD_DATA: TABLES IT_ITEMS USING SPACE 'C:/poextract6.txt'.

LOOP AT IT_PO INTO WA_PO.

CLEAR: PO_HEADER_TEXTS[], IT_ITEMS[], PO_ITEM_ACCOUNT_ASSIGNMENT[],

PO_ITEMS_SHEDULE[], PO_ITEM_TEXT[], RETURN1[].

CALL FUNCTION 'BAPI_PO_GETDETAIL'

EXPORTING

PURCHASEORDER = WA_PO-EBELN

ITEMS = 'X'

ACCOUNT_ASSIGNMENT = 'X'

SCHEDULES = 'X'

HISTORY = 'X'

ITEM_TEXTS = 'X'

HEADER_TEXTS = 'X'

IMPORTING

PO_HEADER = PO_HEADER

TABLES

PO_HEADER_TEXTS = PO_HEADER_TEXTS

PO_ITEMS = IT_ITEMS

PO_ITEM_ACCOUNT_ASSIGNMENT = PO_ITEM_ACCOUNT_ASSIGNMENT

PO_ITEM_SCHEDULES = PO_ITEMS_SHEDULE

PO_ITEM_TEXTS = PO_ITEM_TEXT

RETURN = RETURN1.

DATA PO_HEADER1 LIKE TABLE OF PO_HEADER.

APPEND PO_HEADER TO PO_HEADER1.

PERFORM DOWNLOAD_DATA: TABLES PO_HEADER_TEXTS

USING 'X' 'C:/poextract1.xls',

TABLES IT_ITEMS USING 'X' 'C:/poextract2.xls',

TABLES PO_ITEM_ACCOUNT_ASSIGNMENT USING 'X' 'C:/poextract3.xls',

TABLES PO_ITEMS_SHEDULE USING 'X' 'C:/poextract4.xls',

TABLES PO_ITEM_TEXT USING 'X' 'C:/poextract5.xls'

.

PERFORM DOWNLOAD_DATA: TABLES PO_HEADER1 USING SPACE 'C:/poextract6.xls'

.

*DATA: PO_HEADER1 TYPE BAPIEKKOC,

*PO_NUM TYPE BAPIMEPOHEADER-PO_NUMBER,

*BAPI_RET TYPE TABLE OF BAPIRET2 with header line,

*IT_ITEMS1 TYPE TABLE OF BAPIEKPOC WITH HEADER LINE.

*

*MOVE-CORRESPONDING PO_HEADER TO PO_HEADER1.

*PO_HEADER1-PO_NUMBER = ''.

*PO_HEADER1-PURCH_ORG = PO_HEADER-PURCH_ORG.

*

*MOVE-CORRESPONDING IT_ITEMS TO IT_ITEMS1.

*IT_ITEMS1-PO_NUMBER = ''.

*IT_ITEMS1-MATERIAL = IT_ITEMS-MATERIAL.

*APPEND IT_ITEMS1.

*

*

*CALL FUNCTION 'BAPI_PO_CREATE'

  • EXPORTING

  • po_header = PO_HEADER1

  • PO_HEADER_ADD_DATA =

  • HEADER_ADD_DATA_RELEVANT =

  • PO_ADDRESS =

  • SKIP_ITEMS_WITH_ERROR = 'X'

  • ITEM_ADD_DATA_RELEVANT =

  • HEADER_TECH_FIELDS =

  • IMPORTING

  • PURCHASEORDER =

  • tables

  • po_items = IT_ITEMS1

    • PO_ITEM_ADD_DATA =

  • po_item_schedules = PO_ITEMS_SHEDULE

    • PO_ITEM_ACCOUNT_ASSIGNMENT =

    • PO_ITEM_TEXT =

  • RETURN = BAPI_RET

    • PO_LIMITS =

    • PO_CONTRACT_LIMITS =

    • PO_SERVICES =

    • PO_SRV_ACCASS_VALUES =

    • PO_SERVICES_TEXT =

    • PO_BUSINESS_PARTNER =

    • EXTENSIONIN =

    • POADDRDELIVERY =

  • .

  • *

    *

    *CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    • EXPORTING

    • WAIT =

    • IMPORTING

    • RETURN =

  • .

  • *loop at bapi_ret.

    *write: bapi_ret-MESSAGE.

    *

    *endloop.

    ENDLOOP.

    &----


    *& Form DOWNLOAD_DATA

    &----


    FORM DOWNLOAD_DATA TABLES IT_TAB

    USING P_APP

    FILENAME.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    FILENAME = FILENAME "'C:/poextract.xls'

    • APPEND = P_APP

    WRITE_FIELD_SEPARATOR = 'X'

    TABLES

    DATA_TAB = IT_TAB

    • FIELDNAMES = FIELDNAME

    EXCEPTIONS

    FILE_WRITE_ERROR = 1

    NO_BATCH = 2

    GUI_REFUSE_FILETRANSFER = 3

    INVALID_TYPE = 4

    NO_AUTHORITY = 5

    UNKNOWN_ERROR = 6

    HEADER_NOT_ALLOWED = 7

    SEPARATOR_NOT_ALLOWED = 8

    FILESIZE_NOT_ALLOWED = 9

    HEADER_TOO_LONG = 10

    DP_ERROR_CREATE = 11

    DP_ERROR_SEND = 12

    DP_ERROR_WRITE = 13

    UNKNOWN_DP_ERROR = 14

    ACCESS_DENIED = 15

    DP_OUT_OF_MEMORY = 16

    DISK_FULL = 17

    DP_TIMEOUT = 18

    FILE_NOT_FOUND = 19

    DATAPROVIDER_EXCEPTION = 20

    CONTROL_FLUSH_ERROR = 21

    OTHERS = 22.

    IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    ENDFORM. " DOWNLOAD_DATA