10-11-2007 1:09 PM
Hi All ,
I want to generate BDC program for pb30 i.e it should upload data from excel file , and generate applicant no. itself . plz guide me in this .
Thanks.
10-11-2007 1:14 PM
Hi
<b>i am giving example code for another transaction</b>
Transaction Recorder (SHDB)
How to Upload Presentation Server Flat file to SAP R/3 system???
How to upload application server file to R/3 system?
Definition
Example - Call Transaction Method
<b>Transaction Recorder (SHDB)</b>
Before you work with the Batch Input methods, you should know the purpose of the tool
Transaction Recorder.
Use:
You can use the transaction recorder to record a series of transactions and their screens.
Features:
You can use the recording to create
Data transfer programs that use batch input or CALL TRANSACTION
Batch input sessions
Test data
Function modules.
Note: It doesnt record F1, F4 and Scrollbar movements
<b>Upload Flat file from Presentation Server to SAP R/3</b>
CALL FUNCTION GUI_UPLOAD'
EXPORTING
CODEPAGE = IBM'
FILENAME = P_UFILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = INT_TAB
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
OTHERS = 10 .
IF SY-SUBRC NE 0.
MESSAGE E999(FR) WITH 'ERROR IN FILE UPLOAD'.
ENDIF.
<b>Upload file from application server to SAP R/3</b>
Open the the application server file
OPEN DATASET <dsn> FOR INPUT <mode>
Read the data from application server file
READ DATASET <dsn> INTO <wa>
And then close the application server file
CLOSE DATASET <dsn>
<b>Definition- Declaring BDC Table</b>
DATA: BDC_TAB LIKE STANDARD TABLE OF
BDCDATA INITIAL SIZE 6
WITH HEADER LINE .
The internal table used to collect the transactions information must be declared LIKE BDCDATA.
<b>Filling BDC Table Method #1</b>
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = SAPMF02K.
BDC_TAB-DYNPRO = 01016.
BDC_TAB-DYNBEGIN = X.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = RF02K-LIFNR.
BDC_TAB-FVAL = TEST1.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = RF02K-D0010.
BDC_TAB-FVAL = X.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-PROGRAM = SAPMF02K.
BDC_TAB-DYNPRO = 0110.
BDC_TAB-DYNBEGIN = X.
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = LFA1-STRAS.
BDC_TAB-FVAL = 123 Main St..
APPEND BDC_TAB.
CLEAR BDC_TAB.
BDC_TAB-FNAM = BDC_OKCODE.
BDC_TAB-FVAL = /11.
APPEND BDC_TAB.
ENDFORM.
<b>Filling BDC Table Method #</b>2
FORM FILL_BDC_TAB.
REFRESH BDC_TAB.
PERFORM POPULATE_BDC_TAB
USING:
1 SAPMF02K 0106,
RF02K-LIFNR TEST1,
RF02K-D0010 X,
1 SAPMF02K 0110,
LFA1-STRAS, 123 Main St.,
BDC_OKCODE, /11.
ENDFORM.
FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.
CLEAR BDC_TAB.
IF FLAG = 1.
BDC_TAB-PROGRAM = VAR1.
BDC_TAB-DYNPRO = VAR2..
BDC_TAB-DYNBEGIN = X.
ELSE.
BDC_TAB-FNAM = VAR1.
BDC_TAB-FVAL = VAR2.
ENDIF.
APPEND BDC_TAB.
ENDFORM.
This two subroutine method to fill the BDC table is preferable because the POPULATE_BDC_TABLE subroutine is reusable throughout all batch input programs.
Example #1 - Change Vendor (Call Transaction Method)
<b>Example #1- Declaration Section</b>
REPORT Y180DM10.
DATA: BDC_TAB LIKE STANDARD TABLE OF
BDCDATA INITIAL SIZE 6 WITH HEADER LINE.
INFILE(20) VALUE /tmp/bc180_file4.
DATA: BEGIN OF INREC.
VENDNUM LIKE LFA1-LIFNR.
STREET LIKE LFA1-STRAS.
END OF INREC.
PARAMETERS: DISPMODE DEFAULT A,
UPDAMODE DEFAULT S.
START-OF-SELECTION.
OPEN DATASET INFILE
FOR INPUT IN TEXT MODE.
DO.
READ DATASET INFILE INTO INREC.
IF SY-SUBRC < > 0. EXIT. ENDIF.
PERFORM FILL_BDC_TAB.
CALL TRANSACTION FK02
USING BDC_TAB
MODE DISPMODE
UPDATE UPDAMODE.
IF SY-SUBRC < > 0.
WRITE: /ERROR.
ENDIF.
ENDDO.
CLOSE DATASET INFILE.
<b>synchronous updating</b>
DO.
PERFORM FILL_BDC_TAB.
CALL TRANSACTION FK02
USING BDC_TAB
MODE N
UPDATE S.
IF SY-SUBRC < > 0.
WRITE: /ERROR.
ENDIF.
ENDDO.
With synchronous updating, we can check SY-SUBRC to determine the success of the transaction and the actual update to the database.
<b>asynchronous updating</b>
DO.
PERFORM FILL_BDC_TAB.
CALL TRANSACTION FK02
USING BDC_TAB
MODE N
UPDATE A.
IF SY-SUBRC < > 0.
WRITE: /ERROR.
ENDIF.
ENDDO.
With asynchronous updating, we can check SY-SUBRC to determine the success of the transaction only, not the actual update to the database.
<b>Error Handling</b>
Write an error report.
Send the record(s) in error to an error file.
Create a batch input session with the record(s) in error.
To store error messages ( CALL TRANSACTION )
data: begin of Tab_Mess occurs 0.
include structure bdcmsgcoll.
data : end of Tab_Mess,
CALL TRANSACTION FK02 USING BDC_TAB MODE N UPDATE S
MESSAGES INTO TAB_MESS.
IF SY-SUBRC NE 0.
WRITE: / Tab_MESS-TCODE, Tab_MESS-DYNUMB, Tab_MESS-MSGTYP ,
Tab_MESS-MSGID.
ENDIF.
<b>Reward if usefull</b>
10-11-2007 1:20 PM
Hi Check the below link.
Table control in BDC
http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm
or
Check the example below..
See The below code for Purchase order change ,it is BDC program and it handles Table control.
report zpochange.
data : i_error like bdcmsgcoll occurs 0 with header line.
data : i_bdcdata like bdcdata occurs 0 with header line.
tables : ekko, ekpo.
data :c1(10) value 'ME22',
c2(1) value ',',c3(10).
data : var1(20). " LIKE EKKO-EBELN.
data : var2 like ekko-ebeln.
data : begin of i_ekko occurs 0,
header(2),
ebeln like ekko-ebeln,
end of i_ekko.
data : begin of i_ekpo occurs 0,
item(2),
ebeln like ekpo-ebeln,
ebelp like ekpo-ebelp,
menge(10), " LIKE EKPO-MENGE,
end of i_ekpo.
data : v like ekpo-ebelp.
data: begin of itab occurs 0,
text(300),
end of itab.
parameters: p_file like ibipparms-path.
*PARAMETERS: PONUMBER LIKE EKPO-EBELN.
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
.
start-of-selection.
*SELECT EBELN FROM EKKO INTO TABLE I_EKKO WHERE EBELN = PONUMBER.
*
SELECT EBELN EBELP MENGE FROM EKPO INTO TABLE I_EKPO WHERE EBELN
*= PONUMBER.
*
perform get_data.
*LOOP AT ITAB.
WRITE 😕 ITAB.
ENDLOOP.
loop at itab.
var1 = itab-text+0(1).
if var1 = 'H'.
*I_EKKO-EBELN = ITAB-TEXT.
split itab at c2 into i_ekko-header
i_ekko-ebeln.
SPLIT ITAB AT ',' INTO I_EKKO-EBELN.
" I_EKPO-EBELP
" I_EKPO-MENGE
" var1.
append i_ekko.
else.
split itab at c2 into i_ekpo-item
i_ekpo-ebeln
i_ekpo-ebelp
i_ekpo-menge.
append i_ekpo.
endif.
*var2 = i_ekpo-ebeln.
MOVE VAR1 TO I_EKPO-EBELN.
MOVE VAR1 TO I_EKKO-EBELN.
APPEND: I_EKPO.
*if not var1 is initial.
split var1 at ',' into i_ekpo-ebelp
i_ekpo-menge.
i_ekpo-ebeln = var2.
append i_ekpo.
*endif.
endloop.
loop at i_ekpo.
write 😕 i_ekpo.
endloop.
*
loop at i_ekko.
perform fill_data. " TABLES I_EKPO.
endloop.
LOOP AT I_EKPO.
WRITE 😕 I_EKPO.
ENDLOOP.
*&----
*& Form GET_DATA
*&----
text
*----
--> p1 text
<-- p2 text
*----
*LOOP AT I_ERROR.
WRITE 😕 I_ERROR.
ENDLOOP.
*
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 = itab
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
others = 10
.
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. " GET_DATA
*&----
*& Form FILL_DATA
*&----
text
*----
-->P_I_EKPO text
*----
form fill_data. " tables i_ekpo .
perform bdcscreen using 'SAPMM06E' '0105'.
perform bdcfield using 'RM06E-BSTNR' i_ekko-ebeln.
perform bdcfield using 'BDC_OKCODE' '/00'.
loop at i_ekpo where ebeln = i_ekko-ebeln.
V = I_EKPO-EBELP.
perform bdcscreen using 'SAPMM06E' 0120.
perform bdcfield using 'BDC_CURSOR' 'RM06E-EBELP'.
perform bdcfield using 'RM06E-EBELP' i_ekpo-ebelp.
perform bdcfield using 'BDC_OKCODE' '/00'.
perform bdcscreen using 'SAPMM06E' 0120.
perform bdcfield using 'BDC_CURSOR' 'EKPO-MENGE(01)'.
perform bdcfield using 'RM06E-EBELP' i_ekpo-ebelp.
perform bdcfield using 'EKPO-MENGE(01)' i_ekpo-menge.
perform bdcfield using 'BDC_OKCODE' '/00'.
*PERFORM BDCSCREEN USING 'SAPMM06E' 0120.
*
*PERFORM BDCFIELD USING 'BDC_CURSOR' 'RMO6E-EBELP'.
*
*CLEAR V.
endloop.
perform bdcfield using 'BDC_OKCODE' '=BU'.
call transaction c1 using i_bdcdata mode 'A'
messages into i_error.
refresh i_bdcdata.
endform. " FILL_DATA
*&----
*& Form BDCSCREEN
*&----
text
*----
-->P_0140 text
-->P_0120 text
*----
form bdcscreen using p_program p_screen.
i_bdcdata-program = p_program.
i_bdcdata-dynpro = p_screen.
i_bdcdata-dynbegin = 'X'.
append i_bdcdata.
clear i_bdcdata.
endform. " BDCSCREEN
*&----
*& Form BDCFIELD
*&----
text
*----
-->P_0145 text
-->P_I_EKPO_EBELN text
*----
form bdcfield using fnam fval.
i_bdcdata-fnam = fnam.
i_bdcdata-fval = fval.
append i_bdcdata.
clear i_bdcdata.
endform. " BDCFIELD
Regards
vasu