Wednesday, May 14, 2008

ABAP Internal Table to Excel Sheet

  Transferring Data from ABAP Internal Table to Excel Sheet

If you wish to transfer data from ABAP internal table to EXCEL you can use the following function module.

MS_EXCEL_OLE_STANDARD_DAT

This function module populates an existing excel sheet with the data from the ABAP internal table. Please find below code which shows hwo to declare and populate the import and important parameters. In the next section we will see in depth how this function module operates.

REPORT ZEX_DATATOEXCEL .

Parameters: P_file like RLGRAP-FILENAME.

data : begin of int_head occurs 0,
Filed1(20) type c,                     " Header Data
end of int_head.

data : begin of int_data occurs 0,
Field1(20) type c,                     " Data
Field2(20) type c,
Field3(20) type c,
Field4(20) type c,
end of int_data.


int_head-Filed1 = 'Sales Ord'.
APPEND int_head.
CLEAR  int_head.

int_head-Filed1 = 'Sold-to-Party'.
APPEND int_head.
CLEAR  int_head.

int_head-Filed1 = 'Purchase Ord'.
APPEND int_head.
CLEAR  int_head.

int_head-Filed1 = 'Ship-to-Party'.
APPEND int_head.
CLEAR  int_head.

int_data-field1 = '1JOHN'.
int_data-field2 = '2TOM'.
int_data-field3 = '3BRAD'.
int_data-field4 = '4PETER'.
Append int_data.
Clear int_data.


CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = p_file " path offile where u need to download
* CREATE_PIVOT = 0
* DATA_SHEET_NAME = ' '
* PIVOT_SHEET_NAME = ' '
* PASSWORD = ' '
* PASSWORD_OPTION = 0
TABLES
* PIVOT_FIELD_TAB =
data_tab = int_data "internal table with data
fieldnames = int_head "internal table with header
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
OTHERS = 9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.



Purchase Order BAPI SAP ABAP

Purchase Order BAPI SAP ABAP

If you wish to transfer Purchase Order related Data to SAP, you can do so by using the following BAPI.

BAPI_PO_CREATE

Many a times there is a requirement to transfer purchase order data from a third party to SAP, it can be done by the following methods.

1) BAPI
3) BDC
3) EDI

This this tutorial we will see how to create a Purchase Order using the above mentioned BAPI.

Please note that if you wish to create Real Time Purchase Orders from an external system into SAP R/3 then you need to use either the JCO connector, .NET connector or XI. The example below shows creation of a single purchase order, if you have data required to create purchase orders then you first need to upload it into an internal table and then pass the table to the BAPI.

Please find the code below to create a Purchase order using the BAPI BAPI_PO_CREATE

REPORT ZEX_POCREATE .



Data: int_pohead like BAPIEKKOC,
      int_poitem like BAPIEKPOC occurs 0 with header line,
      int_posched like BAPIEKET occurs 0 with header line,
      int_ret like BAPIRETURN occurs 0 with header line.
Data: d_purchord like BAPIEKKOC-PO_NUMBER.

Move: 'NB' to int_pohead-DOC_TYPE,
      '1000' to int_pohead-PURCH_ORG,
      '001' to int_pohead-PUR_GROUP,
      '0000001234' to int_pohead-vendor,


      '00010' to int_poitem-po_item,
      'Material' to int_poitem-material,
      'Material' to int_poitem-pur_mat,
      '1000' to int_poitem-plant,


      '00010' to int_posched-PO_ITEM,
      '20080531' to int_posched-DELIV_DATE,
      '2'        to int_posched-QUANTITY.


Append int_poitem.
Clear int_poitem.
APPEND int_posched.
CLEAR int_posched.

CALL FUNCTION 'BAPI_PO_CREATE'
  EXPORTING
   PO_HEADER                        = int_pohead
*   PO_HEADER_ADD_DATA               =
*   HEADER_ADD_DATA_RELEVANT         =
*   PO_ADDRESS                       =
    SKIP_ITEMS_WITH_ERROR            = 'X'
*   ITEM_ADD_DATA_RELEVANT           =
 IMPORTING
   PURCHASEORDER                     = d_purchord
  TABLES
    PO_ITEMS                         = int_poitem
*   PO_ITEM_ADD_DATA                 =
    PO_ITEM_SCHEDULES                = int_posched
*   PO_ITEM_ACCOUNT_ASSIGNMENT       =
*   PO_ITEM_TEXT                     =
    RETURN                           = int_ret
*   PO_LIMITS                        =
*   PO_CONTRACT_LIMITS               =
*   PO_SERVICES                      =
*   PO_SRV_ACCASS_VALUES             =
*   PO_SERVICES_TEXT                 =
*   PO_BUSINESS_PARTNER              =
*   EXTENSIONIN                      =
*   POADDRDELIVERY                   =
          .

If sy-subrc = 0.
  Write:/ 'Purchase Order Number is', d_purchord.
endif.