Date post: | 26-Oct-2014 |
Category: |
Documents |
Upload: | anil-kumar |
View: | 32 times |
Download: | 3 times |
OBJECTIVE:- To Change the address of some customers thru data upload from flat file
******FLAT FILE********"DON3 orissa 123457 HYD IN E 0000100131"KISH hyd 343453 GNT IN E 0000100132
First , we have to know from which BAPI we can change the address of customer
For this,go to T-CODE BAPI…. And search
Dbclick on that Fm to navigate to se37 .see the Import and export parameters….
Our task is to change the address …so make use of that address related structure BAPIKNA101
Import parameters in the above screenshot has Address.
First execute the above screenshot i.e execute the FM
In PI_ADDRESS We have to fill the following fields
NAME,STREET,POSTALCODE,CITY,COUNTRY,LANGUAGE
PI_SALESORG =1000
PI_DISTR_CHAN = 10
PI_DIVISION = 00
CUSTOMER NO = 10130 “””WE HAVE CREATED THIS CUSTOMER THRU VD01
F8.
If the ‘RETURN’ value is empty i.e INITIAL then our execution is correct.
What we want to do exactly?
We have to make use of the ADDRESS structure BAPIKNA101 and create one structure..
We have to create ITAB for that structure
We have to upload the flat file to that itab created using FM:- GUI_UPLOAD
Next, before calling the FUNCTIONMODULE 'BAPI_CUSTOMER_CHANGEFROMDATA'We have to populate the data from itab we have created to the itab (which is of type BAPIKNA101.).
The program code is…………………….
*&---------------------------------------------------------------------**& Report YKR_BAPI_SO*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*
REPORT YKR_BAPI_SO.
types: BEGIN OF T_CUST, NAME TYPE BAPIKNA101-NAME, STREET TYPE BAPIKNA101-STREET, POSTL_CODE TYPE BAPIKNA101-POSTL_CODE, CITY TYPE BAPIKNA101-CITY, COUNTRY TYPE BAPIKNA101-COUNTRY, LANGU TYPE BAPIKNA101-LANGU,
customerno type kunnr, “”””””THIS IS NOT FROM THE STRUCTURE BAPIKNA101 END OF T_CUST.types : tt_cust type standard table of t_cust.data : lt_cust type tt_cust, lw_cust type t_cust.
data :lw_BAPIKNA101 type BAPIKNA101. data lw_return type BAPIreturn.
parameters : p_file type localfile.
at selection-screen on value-request for p_file. CALL FUNCTION 'F4_FILENAME' EXPORTING
PROGRAM_NAME = SYST-CPROG DYNPRO_NUMBER = SYST-DYNNR FIELD_NAME = ' ' IMPORTING FILE_NAME = p_file.
perform getdata. perform bapi_upload. .*&---------------------------------------------------------------------**& Form getdata*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM getdata . data: file type string. file = p_file. CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = file FILETYPE = 'ASC' HAS_FIELD_SEPARATOR = '#'* HEADER_LENGTH = 0* READ_BY_LINE = 'X'* DAT_MODE = ' '* CODEPAGE = ' '* IGNORE_CERR = ABAP_TRUE* REPLACEMENT = '#'* CHECK_BOM = ' '* VIRUS_SCAN_PROFILE =* IMPORTING* FILELENGTH =* HEADER = TABLES DATA_TAB = lt_cust EXCEPTIONS FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2 NO_BATCH = 3 GUI_REFUSE_FILETRANSFER = 4 INVALID_TYPE = 5 NO_AUTHORITY = 6 UNKNOWN_ERROR = 7 BAD_DATA_FORMAT = 8 HEADER_NOT_ALLOWED = 9 SEPARATOR_NOT_ALLOWED = 10 HEADER_TOO_LONG = 11 UNKNOWN_DP_ERROR = 12 ACCESS_DENIED = 13 DP_OUT_OF_MEMORY = 14 DISK_FULL = 15 DP_TIMEOUT = 16 OTHERS = 17 . 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. " getdata*&---------------------------------------------------------------------**& Form bapi_upload
*&---------------------------------------------------------------------** text
*----------------------------------------------------------------------** --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*FORM bapi_upload .
*******POPULATING THE DATA INTO LW_BAPIKNA101
loop at lt_cust into lw_cust. lw_BAPIKNA101-name = lw_cust-name. lw_BAPIKNA101-street = lw_cust-street. lw_BAPIKNA101-postl_code = lw_cust-postl_code. lw_BAPIKNA101-city = lw_cust-city. lw_BAPIKNA101-country = lw_cust-country. lw_BAPIKNA101-langu = lw_cust-langu.
CALL FUNCTION 'BAPI_CUSTOMER_CHANGEFROMDATA' EXPORTING PI_ADDRESS = lw_BAPIKNA101 “THIS ONE IS EFFECTED THRU THE FLATFILE PI_SALESORG = '1000' “HARDCODED PI_DISTR_CHAN = '10' “HARDCODED PI_DIVISION = '00' “HARDCODED CUSTOMERNO = lw_cust-customerno “THIS IS EFFECTED FROM FLATFILE IMPORTING* PE_ADDRESS = RETURN = lw_return.
if lw_return is initial. commit work. “This is for making changes in the database asynchronously. “This is mandatory. “OR we can make use of FM ‘BAPI_TRANSACTION_COMMIT’instead “ OF COMMIT WORK. write : / 'success'. else. write : / 'failure'. endif. endloop. ENDFORM. " bapi_upload
OUTPUT
SUCCESS.