04-21-2006 1:04 AM
Hi Friends,
I am trying to upload a .txt file with 5 fields into a ztable using WS_upload. In debug mode i see that the internal table itab has all the fields clustered together seperated by a # symbol. How do i remove this # symbol so that i can upload it into ztable properly .
For eg the error i m getting is
ibm#1042#krj#04-19-2006#PS. All these 5 fields get clustered under material column and not in their respective columns.
Your opinion and advice is greatly appreciated .
Thank you
04-21-2006 1:40 AM
Suppose you have the data from the file in i_text and i_vendor is a structure similar to the database, then you use the following logic to split the text with hash as delimiter.
loop at i_text.
split i_text-text at '#' into i_vendor-lifnr
i_vendor-ekorg
i_vendor-ktokd
i_vendor-name1
i_vendor-sortl
i_vendor-land1
i_vendor-spras
i_vendor-waers.
append i_vendor.
clear :i_vendor,
i_text.
endloop.
Let me send you a sample code. Let me know if this helps.
Award points if the answer helped you !
Session Method: ( Batch Input)
3 Function Modules are there.
1) BDC_OPEN_GROUP
2) BDC_INSERT
3) BDC_CLOSE_GROUP
Instead of all the Call Transactions we use the Function modules here.
1) Go for MK01
2) Go for recording. M4567,0001,0001 enter; test1, abcd, us, en, enter; usdollars; save.
3) Save and come back.
4) Select Vendor and Click on PROGRAM button . Stest_01
5) Select Transfer from recording button.
6) Save as local object
7) Copy the code into a Report program and execute it.
Example:
1) Create a text field having the following entries
t3456,0001,0001,testt3456,abcd123,US,E,USD and save the entries for 4-5 lines of these type.
2) Create a Program.
Report ZBDC_MK01.
*&---------------------------------------------------------------------*
*& Report ZBDC_MK01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBDC_MK01.
* Internal table for file
data : begin of i_text occurs 0,
text(255) type c,
end of i_text.
* Internal table for MK01 Transaction
data : begin of i_vendor occurs 0,
lifnr(10) type c,
ekorg(4) type c,
ktokd(4) type c,
name1(40) type c,
sortl(10) type c,
land1(3) type c,
spras(1) type c,
waers(3) type c,
end of i_vendor.
* Internal table for BDCDATA
data i_bdcdata like bdcdata occurs 0 with header line.
data : v_repid like sy-repid.
parameters p_file like rlgrap-filename.
INITIALIZATION.
v_repid = sy-repid.
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = v_repid
* * DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_file
.
start-of-selection.
* Get the data from file to internal table
perform get_data.
* Open the session
perform open_session.
* Process the bdcdata
perform process_bdcdata.
* Call the close_group
perform close_group.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* WS_UPLOAD FM
*----------------------------------------------------------------------*
FORM get_data .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
* CODEPAGE = ' '
FILENAME = p_file
FILETYPE = 'ASC'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = i_text
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
loop at i_text.
split i_text-text at ',' into i_vendor-lifnr
i_vendor-ekorg
i_vendor-ktokd
i_vendor-name1
i_vendor-sortl
i_vendor-land1
i_vendor-spras
i_vendor-waers.
append i_vendor.
clear :i_vendor,
i_text.
endloop.
endif.
free: i_text.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form open_session
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM open_session .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = 'VENDOR_MK01'
* HOLDDATE = FILLER8
KEEP = 'X'
USER = sy-uname
* RECORD = FILLER1
* PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
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. " open_session
*&---------------------------------------------------------------------*
*& Form process_bdcdata
*&---------------------------------------------------------------------*
* BDCDATA
*----------------------------------------------------------------------*
FORM process_bdcdata .
loop at i_vendor.
perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
i_vendor-lifnr.
perform bdc_field using 'RF02K-EKORG'
i_vendor-ekorg.
perform bdc_field using 'RF02K-KTOKK'
i_vendor-ktokd.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
i_vendor-name1.
perform bdc_field using 'LFA1-SORTL'
i_vendor-sortl.
perform bdc_field using 'LFA1-LAND1'
i_vendor-land1.
perform bdc_field using 'LFA1-SPRAS'
i_vendor-spras.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
i_vendor-waers.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
* Call the transaction code.
perform bdc_insert.
refresh i_bdcdata.
endloop.
ENDFORM. " process_bdcdata
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0264 text
* -->P_0265 text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING p_prog
p_scrn.
clear i_bdcdata.
i_bdcdata-program = p_prog.
i_bdcdata-dynpro = p_scrn.
i_bdcdata-dynbegin = 'X'.
append i_bdcdata.
ENDFORM. " bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM bdc_field USING p_fnam
p_fval.
clear i_bdcdata.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
append i_bdcdata.
ENDFORM. " bdc_field
*&---------------------------------------------------------------------*
*& Form bdc_insert
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM bdc_insert .
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MK01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = i_bdcdata
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
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. " bdc_insert
*&---------------------------------------------------------------------*
*& Form close_group
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
* EXCEPTIONS
* NOT_OPEN = 1
* QUEUE_ERROR = 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.
ENDFORM. " close_group
4) Save and activate.
5) Go to SM35 and see the session created. Vendor_MK01 (group name which was given)
6) Need to go to SM35. Select the Session name and Click on Process. Select BACKGROUND.
7) Click on PROCESSED Tab.
8) For seeing the log file select the session and click on LOG. Click on Display.
Difference between Call Transaction and Sessions Method.:
1) In CT if mode is ¡¥A¡¦ then there wont be log messages. In sessions method we can get log messages in Foreground and Background too.
2) In session method until and unless session Is created it wont update the data. But in CT data is updated immediately.
3) In CT for log messages have to write BDCMSGCOLL structure and Format_Messages function module. Logs are created automatically in Session method.
4) Data UPDATION in CT is Asynchronous. In Session method its Synchronous.
5) In CT we have to split the file. In Session method we need not split the file.
6) In CT we use BEND in Session we have to use END
Real time most of the times its SESSION Method.
Use CT method when:
a) Run time Validation. Example: We are creating a sales order. Here we are validating when selecting Payment Terms etc.
DIRECT INPUT Method:
If anything modified in SAP transaction don¡¦t use DI method. Updation is very fast.
There is no Restart mechanism in DI method.
Ex: have 10 records. 6,7 are error. In session method we needent go to the file. We have to go to BI and process again. Process in Foreground and during this time change at run time.
We need to go for the file. Delete the first files, last files and then upload the data and run again.
Main Transaction Code for DI is SXDB
1) Click on GoTo-----³ DX Tools
2) Object type---Select G/L Account ; Task type: Load Data; Program type: Batch Input; Program: RFBISA00 .
Q) How to copy files from SAP server to local?
Ans) Bcos we don¡¦t get authorization for AL11 transaction. If we know file directory and File name. We can see structure.
In SXDB.
1) Click on GoTo-----³ DX Tools
2) Object type---Select G/L Account (BUS 3006) ; Task type: Load Data; Program type: Batch Input; Program: RFBISA00 .
Go for Copy file. Give the Application Server file name and also he presentation server name and location.
*&---------------------------------------------------------------------*
*& Report ZBDC_MM01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBDC_MM01.
* Constants
constants : c_x type c value 'X'.
* Internal table for file
data : begin of i_text occurs 0,
text(255) type c,
end of i_text.
* iNTERNAL TABLE FOR MATERIAL LOAD
DATA : BEGIN OF I_MATERIAL OCCURS 0,
MATNR(18) TYPE C,
MBRSH(1) TYPE C,
MTART(4) TYPE C,
MAKTX(40) TYPE C,
MEINS(3) TYPE C,
MAKTL(3) TYPE C,
END OF I_MATERIAL.
* INTERNAL TABLE FOR BDCDATA
DATA I_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* internal table for for logs
data i_bdcmsg like bdcmsgcoll occurs 0 with header line.
* Report id
data : v_repid like sy-repid,
v_msg(255) type c.
* Internal tabel for log records
data : begin of i_log occurs 0,
text(255) type c,
end of i_log.
* Selection-screen
selection-screen : begin of block blk with frame title text-001.
parameter p_file like rlgrap-filename.
selection-screen : end of block blk.
* fill the defaut value
INITIALIZATION.
v_repid = sy-repid.
* F4 value for File
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = v_repid
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_file
.
start-of-selection.
* get the data from file to internal table
perform get_data_itab.
* tO PROCEESS BDCDATA
PERFORM PROCESS_BDCDATA.
end-of-selection.
* Process the data into file
perform download_file.
*&---------------------------------------------------------------------*
*& Form get_data_itab
*&---------------------------------------------------------------------*
* ws_upload
*----------------------------------------------------------------------*
FORM get_data_itab .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
* CODEPAGE = ' '
FILENAME = P_FILE
FILETYPE = 'ASC'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = I_TEXT
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
LOOP AT I_TEXT.
SPLIT I_TEXT-TEXT AT ',' INTO I_MATERIAL-MATNR
I_MATERIAL-MBRSH
I_MATERIAL-MTART
I_MATERIAL-MAKTX
I_MATERIAL-MEINS
I_MATERIAL-MAKTL.
APPEND I_MATERIAL.
CLEAR : I_MATERIAL,
I_TEXT.
ENDLOOP.
ENDIF.
ENDFORM. " get_data_itab
*&---------------------------------------------------------------------*
*& Form PROCESS_BDCDATA
*&---------------------------------------------------------------------*
* bdcdata
*----------------------------------------------------------------------*
FORM PROCESS_BDCDATA .
LOOP AT I_MATERIAL.
* First Screen
perform f_get_program using 'SAPLMGMM' '0060'.
perform f_get_field using 'BDC_CURSOR' 'RMMG1-MATNR'.
perform f_get_field using 'BDC_OKCODE' '=AUSW'.
perform f_get_field using 'RMMG1-MATNR' i_material-matnr.
perform f_get_field using 'RMMG1-MBRSH' i_material-mbrsh.
perform f_get_field using 'RMMG1-MTART' i_material-mtart.
* Second screen
perform f_get_program using 'SAPLMGMM' '0070'.
perform f_get_field using 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)'.
perform f_get_field using 'BDC_OKCODE' '=ENTR'.
perform f_get_field using 'MSICHTAUSW-KZSEL(01)' c_x.
* third screen
perform f_get_program using 'SAPLMGMM' '4004'.
perform f_get_field using 'BDC_CURSOR' 'MAKT-MAKTX'.
perform f_get_field using 'BDC_OKCODE' '=BU'.
perform f_get_field using 'MAKT-MAKTX' i_material-maktx.
perform f_get_field using 'MARA-MEINS' i_material-meins.
perform f_get_field using 'MARA-MATKL' i_material-maktl.
** call transaction
call transaction 'MM01'
using i_bdcdata
mode 'N'
messages into i_bdcmsg.
refresh i_bdcdata.
* Log message
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = v_msg
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
i_log-text = v_msg.
append i_log.
clear: i_log,
v_msg.
ENDLOOP.
ENDFORM. " PROCESS_BDCDATA
*&---------------------------------------------------------------------*
*& Form f_get_program
*&---------------------------------------------------------------------*
* Program ,Screen no, Dynbegin
*----------------------------------------------------------------------*
* -->P_0206 text
* -->P_0207 text
*----------------------------------------------------------------------*
FORM f_get_program USING p_prog
p_scrn.
clear : i_bdcdata.
i_bdcdata-program = p_prog.
i_bdcdata-dynpro = p_scrn.
i_bdcdata-dynbegin = c_x.
append i_bdcdata.
ENDFORM. " f_get_program
*&---------------------------------------------------------------------*
*& Form f_get_field
*&---------------------------------------------------------------------*
* field name ,field value
*----------------------------------------------------------------------*
* -->P_0217 text
* -->P_0218 text
*----------------------------------------------------------------------*
FORM f_get_field USING p_fnam
p_fval.
clear i_bdcdata.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
append i_bdcdata.
ENDFORM. " f_get_field
*&---------------------------------------------------------------------*
*& Form download_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_file .
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = ' '
* CODEPAGE = ' '
FILENAME =
'C:Documents and SettingsAdministratorDesktoplog.txt'
FILETYPE = 'ASC'
* MODE = ' '
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* COL_SELECT = ' '
* COL_SELECTMASK = ' '
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = i_log
* FIELDNAMES =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
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_file
04-21-2006 1:10 AM
Hi Hari,
Whats the file type are you using? I think it should be ASC.
How have you defined your internal table?
These two factors will determine if you are uploading the data in the correct format.
Cheers
VJ
04-21-2006 1:30 AM
Hi Rao ,
Thanks for replying . Yes you are right the file type is 'ASC'. But i do not understand why the # symbol is coming up and how to get rid of that . The program work fine in uploading the data but all the 5 fields are clustered into one column as referred earlier .
I have defined the internal table itab like the standard ztable.
Is their any conversion exit or something else through which i can eliminate the # .
Thank you
04-21-2006 1:34 AM
Hi,
Instead of WS_UPLOAD, you can use GUI_UPLOAD with the parameter HAS_FIELD_SEPARATOR = 'X'.
Regards,
Suresh Datti
04-21-2006 1:36 AM
Hi Hari,
There are many ways to remove the # sign, But if your data does not have that then it should not come up. Its better to trouble shoot the problem rather than trying to remove the string from within the program.
Couple of things to check out. How is the data maintained in the txt file? Is it a tab delimited file? Did you copy the text in the notepad from somewhere else? try creating a fresh data and try uploading the data.
Alternatively would suggest to use GUI_UPLOAD as WS_UPLOAD is obsolete.
Let me know if you still have issue.
Cheers
VJ
04-21-2006 1:11 AM
Hi Hari,
Welcome to forum,
You can use this command,
Replace variable_name '#' with ' '
Hope this will help.
Please close the thread if it solves.
shylesh
04-21-2006 1:40 AM
Suppose you have the data from the file in i_text and i_vendor is a structure similar to the database, then you use the following logic to split the text with hash as delimiter.
loop at i_text.
split i_text-text at '#' into i_vendor-lifnr
i_vendor-ekorg
i_vendor-ktokd
i_vendor-name1
i_vendor-sortl
i_vendor-land1
i_vendor-spras
i_vendor-waers.
append i_vendor.
clear :i_vendor,
i_text.
endloop.
Let me send you a sample code. Let me know if this helps.
Award points if the answer helped you !
Session Method: ( Batch Input)
3 Function Modules are there.
1) BDC_OPEN_GROUP
2) BDC_INSERT
3) BDC_CLOSE_GROUP
Instead of all the Call Transactions we use the Function modules here.
1) Go for MK01
2) Go for recording. M4567,0001,0001 enter; test1, abcd, us, en, enter; usdollars; save.
3) Save and come back.
4) Select Vendor and Click on PROGRAM button . Stest_01
5) Select Transfer from recording button.
6) Save as local object
7) Copy the code into a Report program and execute it.
Example:
1) Create a text field having the following entries
t3456,0001,0001,testt3456,abcd123,US,E,USD and save the entries for 4-5 lines of these type.
2) Create a Program.
Report ZBDC_MK01.
*&---------------------------------------------------------------------*
*& Report ZBDC_MK01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBDC_MK01.
* Internal table for file
data : begin of i_text occurs 0,
text(255) type c,
end of i_text.
* Internal table for MK01 Transaction
data : begin of i_vendor occurs 0,
lifnr(10) type c,
ekorg(4) type c,
ktokd(4) type c,
name1(40) type c,
sortl(10) type c,
land1(3) type c,
spras(1) type c,
waers(3) type c,
end of i_vendor.
* Internal table for BDCDATA
data i_bdcdata like bdcdata occurs 0 with header line.
data : v_repid like sy-repid.
parameters p_file like rlgrap-filename.
INITIALIZATION.
v_repid = sy-repid.
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = v_repid
* * DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_file
.
start-of-selection.
* Get the data from file to internal table
perform get_data.
* Open the session
perform open_session.
* Process the bdcdata
perform process_bdcdata.
* Call the close_group
perform close_group.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* WS_UPLOAD FM
*----------------------------------------------------------------------*
FORM get_data .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
* CODEPAGE = ' '
FILENAME = p_file
FILETYPE = 'ASC'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = i_text
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
loop at i_text.
split i_text-text at ',' into i_vendor-lifnr
i_vendor-ekorg
i_vendor-ktokd
i_vendor-name1
i_vendor-sortl
i_vendor-land1
i_vendor-spras
i_vendor-waers.
append i_vendor.
clear :i_vendor,
i_text.
endloop.
endif.
free: i_text.
ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form open_session
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM open_session .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
* DEST = FILLER8
GROUP = 'VENDOR_MK01'
* HOLDDATE = FILLER8
KEEP = 'X'
USER = sy-uname
* RECORD = FILLER1
* PROG = SY-CPROG
* IMPORTING
* QID =
EXCEPTIONS
CLIENT_INVALID = 1
DESTINATION_INVALID = 2
GROUP_INVALID = 3
GROUP_IS_LOCKED = 4
HOLDDATE_INVALID = 5
INTERNAL_ERROR = 6
QUEUE_ERROR = 7
RUNNING = 8
SYSTEM_LOCK_ERROR = 9
USER_INVALID = 10
OTHERS = 11
.
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. " open_session
*&---------------------------------------------------------------------*
*& Form process_bdcdata
*&---------------------------------------------------------------------*
* BDCDATA
*----------------------------------------------------------------------*
FORM process_bdcdata .
loop at i_vendor.
perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
i_vendor-lifnr.
perform bdc_field using 'RF02K-EKORG'
i_vendor-ekorg.
perform bdc_field using 'RF02K-KTOKK'
i_vendor-ktokd.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-NAME1'
i_vendor-name1.
perform bdc_field using 'LFA1-SORTL'
i_vendor-sortl.
perform bdc_field using 'LFA1-LAND1'
i_vendor-land1.
perform bdc_field using 'LFA1-SPRAS'
i_vendor-spras.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0130'.
perform bdc_field using 'BDC_CURSOR'
'LFBK-BANKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
i_vendor-waers.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
* Call the transaction code.
perform bdc_insert.
refresh i_bdcdata.
endloop.
ENDFORM. " process_bdcdata
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0264 text
* -->P_0265 text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING p_prog
p_scrn.
clear i_bdcdata.
i_bdcdata-program = p_prog.
i_bdcdata-dynpro = p_scrn.
i_bdcdata-dynbegin = 'X'.
append i_bdcdata.
ENDFORM. " bdc_dynpro
*&---------------------------------------------------------------------*
*& Form bdc_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM bdc_field USING p_fnam
p_fval.
clear i_bdcdata.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
append i_bdcdata.
ENDFORM. " bdc_field
*&---------------------------------------------------------------------*
*& Form bdc_insert
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM bdc_insert .
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MK01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = i_bdcdata
EXCEPTIONS
INTERNAL_ERROR = 1
NOT_OPEN = 2
QUEUE_ERROR = 3
TCODE_INVALID = 4
PRINTING_INVALID = 5
POSTING_INVALID = 6
OTHERS = 7
.
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. " bdc_insert
*&---------------------------------------------------------------------*
*& Form close_group
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'
* EXCEPTIONS
* NOT_OPEN = 1
* QUEUE_ERROR = 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.
ENDFORM. " close_group
4) Save and activate.
5) Go to SM35 and see the session created. Vendor_MK01 (group name which was given)
6) Need to go to SM35. Select the Session name and Click on Process. Select BACKGROUND.
7) Click on PROCESSED Tab.
8) For seeing the log file select the session and click on LOG. Click on Display.
Difference between Call Transaction and Sessions Method.:
1) In CT if mode is ¡¥A¡¦ then there wont be log messages. In sessions method we can get log messages in Foreground and Background too.
2) In session method until and unless session Is created it wont update the data. But in CT data is updated immediately.
3) In CT for log messages have to write BDCMSGCOLL structure and Format_Messages function module. Logs are created automatically in Session method.
4) Data UPDATION in CT is Asynchronous. In Session method its Synchronous.
5) In CT we have to split the file. In Session method we need not split the file.
6) In CT we use BEND in Session we have to use END
Real time most of the times its SESSION Method.
Use CT method when:
a) Run time Validation. Example: We are creating a sales order. Here we are validating when selecting Payment Terms etc.
DIRECT INPUT Method:
If anything modified in SAP transaction don¡¦t use DI method. Updation is very fast.
There is no Restart mechanism in DI method.
Ex: have 10 records. 6,7 are error. In session method we needent go to the file. We have to go to BI and process again. Process in Foreground and during this time change at run time.
We need to go for the file. Delete the first files, last files and then upload the data and run again.
Main Transaction Code for DI is SXDB
1) Click on GoTo-----³ DX Tools
2) Object type---Select G/L Account ; Task type: Load Data; Program type: Batch Input; Program: RFBISA00 .
Q) How to copy files from SAP server to local?
Ans) Bcos we don¡¦t get authorization for AL11 transaction. If we know file directory and File name. We can see structure.
In SXDB.
1) Click on GoTo-----³ DX Tools
2) Object type---Select G/L Account (BUS 3006) ; Task type: Load Data; Program type: Batch Input; Program: RFBISA00 .
Go for Copy file. Give the Application Server file name and also he presentation server name and location.
*&---------------------------------------------------------------------*
*& Report ZBDC_MM01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBDC_MM01.
* Constants
constants : c_x type c value 'X'.
* Internal table for file
data : begin of i_text occurs 0,
text(255) type c,
end of i_text.
* iNTERNAL TABLE FOR MATERIAL LOAD
DATA : BEGIN OF I_MATERIAL OCCURS 0,
MATNR(18) TYPE C,
MBRSH(1) TYPE C,
MTART(4) TYPE C,
MAKTX(40) TYPE C,
MEINS(3) TYPE C,
MAKTL(3) TYPE C,
END OF I_MATERIAL.
* INTERNAL TABLE FOR BDCDATA
DATA I_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* internal table for for logs
data i_bdcmsg like bdcmsgcoll occurs 0 with header line.
* Report id
data : v_repid like sy-repid,
v_msg(255) type c.
* Internal tabel for log records
data : begin of i_log occurs 0,
text(255) type c,
end of i_log.
* Selection-screen
selection-screen : begin of block blk with frame title text-001.
parameter p_file like rlgrap-filename.
selection-screen : end of block blk.
* fill the defaut value
INITIALIZATION.
v_repid = sy-repid.
* F4 value for File
at selection-screen on value-request for p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = v_repid
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_file
.
start-of-selection.
* get the data from file to internal table
perform get_data_itab.
* tO PROCEESS BDCDATA
PERFORM PROCESS_BDCDATA.
end-of-selection.
* Process the data into file
perform download_file.
*&---------------------------------------------------------------------*
*& Form get_data_itab
*&---------------------------------------------------------------------*
* ws_upload
*----------------------------------------------------------------------*
FORM get_data_itab .
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
* CODEPAGE = ' '
FILENAME = P_FILE
FILETYPE = 'ASC'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = I_TEXT
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
LOOP AT I_TEXT.
SPLIT I_TEXT-TEXT AT ',' INTO I_MATERIAL-MATNR
I_MATERIAL-MBRSH
I_MATERIAL-MTART
I_MATERIAL-MAKTX
I_MATERIAL-MEINS
I_MATERIAL-MAKTL.
APPEND I_MATERIAL.
CLEAR : I_MATERIAL,
I_TEXT.
ENDLOOP.
ENDIF.
ENDFORM. " get_data_itab
*&---------------------------------------------------------------------*
*& Form PROCESS_BDCDATA
*&---------------------------------------------------------------------*
* bdcdata
*----------------------------------------------------------------------*
FORM PROCESS_BDCDATA .
LOOP AT I_MATERIAL.
* First Screen
perform f_get_program using 'SAPLMGMM' '0060'.
perform f_get_field using 'BDC_CURSOR' 'RMMG1-MATNR'.
perform f_get_field using 'BDC_OKCODE' '=AUSW'.
perform f_get_field using 'RMMG1-MATNR' i_material-matnr.
perform f_get_field using 'RMMG1-MBRSH' i_material-mbrsh.
perform f_get_field using 'RMMG1-MTART' i_material-mtart.
* Second screen
perform f_get_program using 'SAPLMGMM' '0070'.
perform f_get_field using 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)'.
perform f_get_field using 'BDC_OKCODE' '=ENTR'.
perform f_get_field using 'MSICHTAUSW-KZSEL(01)' c_x.
* third screen
perform f_get_program using 'SAPLMGMM' '4004'.
perform f_get_field using 'BDC_CURSOR' 'MAKT-MAKTX'.
perform f_get_field using 'BDC_OKCODE' '=BU'.
perform f_get_field using 'MAKT-MAKTX' i_material-maktx.
perform f_get_field using 'MARA-MEINS' i_material-meins.
perform f_get_field using 'MARA-MATKL' i_material-maktl.
** call transaction
call transaction 'MM01'
using i_bdcdata
mode 'N'
messages into i_bdcmsg.
refresh i_bdcdata.
* Log message
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = v_msg
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
i_log-text = v_msg.
append i_log.
clear: i_log,
v_msg.
ENDLOOP.
ENDFORM. " PROCESS_BDCDATA
*&---------------------------------------------------------------------*
*& Form f_get_program
*&---------------------------------------------------------------------*
* Program ,Screen no, Dynbegin
*----------------------------------------------------------------------*
* -->P_0206 text
* -->P_0207 text
*----------------------------------------------------------------------*
FORM f_get_program USING p_prog
p_scrn.
clear : i_bdcdata.
i_bdcdata-program = p_prog.
i_bdcdata-dynpro = p_scrn.
i_bdcdata-dynbegin = c_x.
append i_bdcdata.
ENDFORM. " f_get_program
*&---------------------------------------------------------------------*
*& Form f_get_field
*&---------------------------------------------------------------------*
* field name ,field value
*----------------------------------------------------------------------*
* -->P_0217 text
* -->P_0218 text
*----------------------------------------------------------------------*
FORM f_get_field USING p_fnam
p_fval.
clear i_bdcdata.
i_bdcdata-fnam = p_fnam.
i_bdcdata-fval = p_fval.
append i_bdcdata.
ENDFORM. " f_get_field
*&---------------------------------------------------------------------*
*& Form download_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_file .
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = ' '
* CODEPAGE = ' '
FILENAME =
'C:Documents and SettingsAdministratorDesktoplog.txt'
FILETYPE = 'ASC'
* MODE = ' '
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* COL_SELECT = ' '
* COL_SELECTMASK = ' '
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = i_log
* FIELDNAMES =
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
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_file
04-21-2006 3:35 AM
The '#' is probably a tab, so you are likely uploading a tab delimitted text file. If this comes from an Excel spreadsheet, try saving it as a space delimitted text file (.prn) and upload that.
Rob
04-21-2006 4:48 AM
Dear Hari,
Pl Check on the following:
your .txt file is Tab delimited.
Use filetype = 'DAT' instead of 'ASC' in ws_upload.
However, it is advisable to use GUI_UPLOAD insted.
This is waht I tried and it works perfectly:
DATA : BEGIN OF lit_upld_empl_desig OCCURS 0,
lifnr TYPE lifnr, " Vendor Number
bukrs TYPE bukrs, " Company Code
name1 TYPE addr1_data-name1, " Name
street TYPE lfa1-stras, " Grade
END OF lit_upld_empl_desig.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = 'C:\empl.txt'
FILETYPE = 'DAT'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = lit_upld_empl_desig
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Here is my Excel File Contents. This is a Tab Delimited File:
P277367 G2PV Charu Mahawar CMD
Hope this solves your problem.
Regards,
Reema
04-23-2006 6:53 PM
Hi Friends,
Thanks for all your help . The problem was solved using GUI_UPLOAD function module .
05-10-2006 10:46 AM
Hi Hari Gopalakrishna,
Could you pls share the solution/coding with me.
Thanks in advanced!
05-10-2006 3:45 PM
Hello Hari,
If the format of the file is fixed length then use file type as 'BIN' or if you are trying to upload tab delimited file then use file type as 'ASC'.
Anyway function module WS_UPLOAD is obselete now...SAP remommanded to use 'GUI_UPLOAD'.
In function module 'GUI_UPLOAD' you can specify Field Separator.
Hope this will help you.
Cheers,
Nilesh