‎2006 Jul 24 8:03 AM
Hi friends,
I have one query regarding BAPI. Suppose I wanted to update all the purchase order in database. I have one excel sheet having all the new records to be uploaded in database.
I wanted to ask what is the function module for this(to upload). May i use the function module UPLOAD???
Remember that I am dealing with BAPI.
‎2006 Jul 24 8:08 AM
Hi salil,
1. First we have to create an internal table,
for getting the data contained in text file.
2. then use GUI_UPLOAD,
to get the contents of the file,
in the internal table ITAB.
3. then Loop at ITAB
4. And call the corresponding BAPI
(with proper fields)
5. also call the FM
BAPI_TRANSACTION_COMMIT
at last (or in each loop pass),
so that data is committed and written to the database.
regards,
amit m.
‎2006 Jul 24 8:05 AM
Hi Salil,
You will have to use the FM GUI_UPLOAD to upload the record from the excel sheet to internal tables and you will have to pass those internal tables to the BAPI BAPI_PO_CREATE.
You can use the FM 'UPLOAD' but that is now obsolete so better to use the FM 'GUI_UPLOAD'.
‎2006 Jul 24 8:08 AM
Hi salil,
1. First we have to create an internal table,
for getting the data contained in text file.
2. then use GUI_UPLOAD,
to get the contents of the file,
in the internal table ITAB.
3. then Loop at ITAB
4. And call the corresponding BAPI
(with proper fields)
5. also call the FM
BAPI_TRANSACTION_COMMIT
at last (or in each loop pass),
so that data is committed and written to the database.
regards,
amit m.
‎2006 Jul 24 10:58 AM
Hi Salil,
If you know how to use a function module then the same way you can work with the BAPI.bapi is also a function module.just first get the data into one internal table and then populate the internal tables which are required to execute the bapi by using the data in the flat file internal table. pass those internal tables to the FM and don't forget to use transaction commit.here some bapi's contains commit as a parameter in the FM itself, put 'X' there if it is not there call the FM transaction commit.
regards,
Suresh
‎2006 Jul 25 9:50 AM
Hi,
Here I provide the sample code which suites your requirement.
*& This program is to create standard sales order using bapi method
*& created by : Vasu
*& dated : 25/07/06 *
&----
REPORT ZVASU_BAPI_MAT_CREATE .
****& bapi method declarations
DATA: T_ORDER_HEADER_IN LIKE BAPISDHEAD OCCURS 0 WITH HEADER LINE,
T_ORDER_ITEMS_IN LIKE BAPIITEMIN OCCURS 0 WITH HEADER LINE,
T_ORDER_PARTNERS LIKE BAPIPARTNR OCCURS 0 WITH HEADER LINE,
T_RETURN TYPE BAPIRETURN1 OCCURS 0 WITH HEADER LINE,
T_SOLD_TO_PARTY TYPE BAPISOLDTO OCCURS 0 WITH HEADER LINE,
T_SHIP_TO_PARTY TYPE BAPISHIPTO OCCURS 0 WITH HEADER LINE,
T_SALESDOCUMENT LIKE BAPIVBELN-VBELN.
*******& Source table to accept legacy data
DATA: BEGIN OF T_SOURCE OCCURS 0,
AUART TYPE AUART,
VKORG TYPE VKORG,
VTWEG TYPE VTWEG,
SPART TYPE SPART,
MATNR TYPE MATNR,
WMENGC TYPE WMENGC,
PARVW TYPE PARVW,
KUNNR TYPE KUNNR,
END OF T_SOURCE.
*********& target table for fn module ALSM_EXCEL_TO_INTERNAL_TABLE
DATA: JTAB TYPE STANDARD TABLE OF ALSMEX_TABLINE INITIAL SIZE 1 WITH HEADER LINE.
DATA: ROW TYPE I.
ROW = '1'.
Fn Module to upload data from Excel sheet
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = 'E:\VA01.XLS'
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '9'
i_end_row = '2'
tables
intern = JTAB
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
to check whether the data has been correctly uploaded
to Fn Module internal table
*LOOP AT JTAB.
*
WRITE:/ JTAB-VALUE.
*ENDLOOP.
*************
READ TABLE JTAB INDEX 1.
LOOP AT JTAB.
CASE JTAB-COL.
WHEN '0001'.
T_SOURCE-AUART = JTAB-VALUE.
WHEN '0002'.
T_SOURCE-VKORG = JTAB-VALUE.
WHEN '0003'.
T_SOURCE-VTWEG = JTAB-VALUE.
WHEN '0004'.
T_SOURCE-SPART = JTAB-VALUE.
WHEN '0005'.
T_SOURCE-MATNR = JTAB-VALUE.
WHEN '0006'.
T_SOURCE-WMENGC = JTAB-VALUE.
WHEN '0007'.
T_SOURCE-PARVW = JTAB-VALUE.
WHEN '0008'.
T_SOURCE-KUNNR = JTAB-VALUE.
APPEND T_SOURCE.
ENDCASE.
ENDLOOP.
**************************
********& to check whether the data is present in source table r not
LOOP AT T_SOURCE.
*
WRITE:/ T_SOURCE-AUART,
T_SOURCE-VKORG,
T_SOURCE-VTWEG,
T_SOURCE-SPART,
T_SOURCE-MATNR,
T_SOURCE-WMENGC,
T_SOURCE-PARVW,
T_SOURCE-KUNNR.
ENDLOOP.
******************
LOOP AT T_SOURCE.
T_ORDER_HEADER_IN-DOC_TYPE = T_SOURCE-AUART.
T_ORDER_HEADER_IN-SALES_ORG = T_SOURCE-VKORG.
T_ORDER_HEADER_IN-DISTR_CHAN = T_SOURCE-VTWEG.
T_ORDER_HEADER_IN-DIVISION = T_SOURCE-SPART.
APPEND T_ORDER_HEADER_IN.
T_ORDER_ITEMS_IN-MATERIAL = T_SOURCE-MATNR.
T_ORDER_ITEMS_IN-REQ_QTY = T_SOURCE-WMENGC.
APPEND T_ORDER_ITEMS_IN.
T_ORDER_PARTNERS-PARTN_ROLE = T_SOURCE-PARVW.
T_ORDER_PARTNERS-PARTN_NUMB = T_SOURCE-KUNNR.
APPEND T_ORDER_PARTNERS.
ENDLOOP.
**************
T_SOLD_TO_PARTY-SOLD_TO = '1000'.
*
APPEND T_SOLD_TO_PARTY.
*
T_SHIP_TO_PARTY-SHIP_TO = '1000'.
*
APPEND T_SHIP_TO_PARTY.
********& bapi method to create standard sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
ORDER_HEADER_IN = T_ORDER_HEADER_IN
WITHOUT_COMMIT = ' '
CONVERT_PARVW_AUART = ' '
IMPORTING
SALESDOCUMENT = T_SALESDOCUMENT
SOLD_TO_PARTY = T_SOLD_TO_PARTY
SHIP_TO_PARTY = T_SHIP_TO_PARTY
BILLING_PARTY =
RETURN = T_RETURN
TABLES
ORDER_ITEMS_IN = T_ORDER_ITEMS_IN
ORDER_PARTNERS = T_ORDER_PARTNERS
ORDER_ITEMS_OUT =
ORDER_CFGS_REF =
ORDER_CFGS_INST =
ORDER_CFGS_PART_OF =
ORDER_CFGS_VALUE =
ORDER_CCARD =
ORDER_CFGS_BLOB =
ORDER_SCHEDULE_EX =
.
to commit the data transferred to R/3 externally
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT =
IMPORTING
RETURN =
.
to check for any error messages
WRITE:/ T_RETURN-MESSAGE,
T_RETURN-TYPE.
WRITE:/ 'SALES_ORDER_NUMBER_CREATED',T_SALESDOCUMENT.
With Regards
Vasu
reward points if it is useful