Академический Документы
Профессиональный Документы
Культура Документы
Welcome, Guest
Login
Register
Store
Products
About SCN
Downloads
Industries
Partnership
Developer Center
Lines of Business
University Alliances
Innovation
ABAP Development / Data Transfers - BAPI, BDC, ALE, LSMW, DX-WB / Batch Input - BDC
1) Suppose w e need to enter some records in a ztable through table maintenance generator SM30. For this first you have to create a program from SHDB after recording .record how a record is entered in
the table zvbak from the transaction SM30 and create a program. Now that source code is required in this program.
Let the table is zvbak and it has four fields, so first create an internal table to get the records from the flat file. And start coding like this.
2) This count variable is to count the number of lines displayed at one time in the table control.
DATA: V_COUNT1 TYPE I.
DATA: V_COUNT(3) TYPE C.
DATA: V_CHAR(16).
3) Now take the file from w here records are to be uploaded.
PARAMETERS: P_FILE TYPE LOCALFILE.
start-of-selection.
DATA: W_FILE TYPE STRING.
W_FILE = P_FILE.
4) Call function gui_upload to upload the records from flatfile to an internal table itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename
= W_FILE
FILETYPE
= 'DAT'
* HAS_FIELD_SEPARATOR
* HEADER_LENGTH
* READ_BY_LINE
=''
=0
= 'X'
* DAT_MODE
=''
* CODEPAGE
=''
* IGNORE_CERR
= ABAP_TRUE
* REPLACEMENT
= '#'
* CHECK_BOM
* VIRUS_SCAN_PROFILE
* NO_AUTH_CHECK
=''
=
=''
https://wiki.scn.sap.com/wiki/display/ABAP/bdc+on+table+control
1/5
6/30/16
* IMPORTING
* FILELENGTH
* HEADER
tables
data_tab
= ITAB
* EXCEPTIONS
* FILE_OPEN_ERROR
=1
* FILE_READ_ERROR
=2
* NO_BATCH
=3
* GUI_REFUSE_FILETRANSFER
* INVALID_TYPE
=4
=5
* NO_AUTHORITY
=6
* UNKNOWN_ERROR
=7
* BAD_DATA_FORMAT
=8
* HEADER_NOT_ALLOWED
=9
* SEPARATOR_NOT_ALLOWED
* HEADER_TOO_LONG
= 10
= 11
* UNKNOWN_DP_ERROR
= 12
* ACCESS_DENIED
= 13
* DP_OUT_OF_MEMORY
* DISK_FULL
= 14
= 15
* DP_TIMEOUT
= 16
* OTHERS
= 17
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
ENDIF.
5) Now call function BDC_open_group to open the session.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT
* DEST
= SY-MANDT
= FILLER8
GROUP
= 'ZBDC'
* HOLDDATE
= FILLER8
KEEP
= 'X'
USER
= SY-UNAME
* RECORD
PROG
= FILLER
= SY-CPROG
* DCPFM
= '%'
** DATFM
= '%,'
* IMPORTING
* QID
EXCEPTIONS
CLIENT_INVALID
DESTINATION_INVALID
GROUP_INVALID
=1
=2
=3
GROUP_IS_LOCKED
=4
HOLDDATE_INVALID
=5
https://wiki.scn.sap.com/wiki/display/ABAP/bdc+on+table+control
2/5
6/30/16
INTERNAL_ERROR
=6
QUEUE_ERROR
=7
RUNNING
=8
SYSTEM_LOCK_ERROR
USER_INVALID
=9
= 10
OTHERS
= 11
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
ENDIF.
6) Here w e w ill use the source code obtained from the recording.
perform bdc_dynpro
perform bdc_field
'VIEWNAME'.
perform bdc_field
using 'BDC_OKCODE'
'=SHOW'.
perform bdc_field
using 'VIEWNAME'
'ZVBAK'.
perform bdc_field
using 'VIMDYNFLDS-LTD_DTA_NO'
'X'.
perform bdc_dynpro
perform bdc_field
'ZVBAK-VBELN(01)'.
perform bdc_field
using 'BDC_OKCODE'
'=AEND'.
perform bdc_dynpro
perform bdc_field
'ZVBAK-VBELN(01)'.
perform bdc_field
using 'BDC_OKCODE'
'=NEWL'.
7) Now w hen bdcdata table is being filled w ith the records then keep on incrementing the count variable by 1 as it is representing the line number of the table control . concatenate the field name w ith the
count to represent the row and column of the table control.
LOOP AT ITAB.
V_COUNT1 = V_COUNT1 + 1.
V_COUNT = V_COUNT1.
CONDENSE V_COUNT.
perform bdc_dynpro
*perform bdc_field
*
'ZVBAK-SPART(01)'.
CLEAR V_CHAR.
CONCATENATE 'ZVBAK-VBELN(' V_COUNT ')' INTO V_CHAR.
perform bdc_field
using V_CHAR
ITAB-VBELN.
CLEAR V_CHAR.
CONCATENATE 'ZVBAK-VKORG(' V_COUNT ')' INTO V_CHAR.
perform bdc_field
using V_CHAR
https://wiki.scn.sap.com/wiki/display/ABAP/bdc+on+table+control
3/5
6/30/16
CLEAR V_CHAR.
CONCATENATE 'ZVBAK-VTWEG(' V_COUNT ')' INTO V_CHAR.
perform bdc_field
using V_CHAR
ITAB-VTWEG.
8) When the last line of the table control is reached then again reset the value of the count as one and set the command of page up i.e. '=P+' inside the loop only. This is done only for that screen w here
table control is being used.
IF V_COUNT1 = 24.
V_COUNT1 = 1.
perform bdc_field
using 'BDC_OKCODE'
'=P+'.
ENDIF.
* CLEAR V_CHAR.
*CONCATENATE 'ZVBAK-SPART(' V_COUNT ')' INTO V_CHAR.
*perform bdc_field
*
using V_CHAR
ITAB-SPART.
ENDLOOP.
9) After the loop statement continue the steps as per recording.
perform bdc_dynpro
perform bdc_field
'ZVBAK-VBELN(02)'.
perform bdc_field
using 'BDC_OKCODE'
'=SAVE'.
perform bdc_dynpro
perform bdc_field
'ZVBAK-VBELN(03)'.
perform bdc_field
using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro
perform bdc_field
'ZVBAK-VBELN(03)'.
perform bdc_field
using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro
perform bdc_field
'/EBACK'.
perform bdc_field
using 'BDC_CURSOR'
'VIEWNAME'.
10) Now call the function bdc_insert and pass the bdcdata table to this function.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE
* POST_LOCAL
* PRINTING
* SIMUBATCH
* CTUPARAMS
= 'SM30'
= NOVBLOCAL
= NOPRINT
=''
=''
TABLES
dynprotab
= BDCDATA
https://wiki.scn.sap.com/wiki/display/ABAP/bdc+on+table+control
4/5
6/30/16
* 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
*
ENDIF.
11) Now close the group.
CALL FUNCTION 'BDC_CLOSE_GROUP'
* EXCEPTIONS
* NOT_OPEN
=1
* QUEUE_ERROR
* OTHERS
=2
=3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
ENDIF.
12) Define the subroutines used in the recording here.
Insert field
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
No labels
Contact Us
Privacy
Legal Disclosure
https://wiki.scn.sap.com/wiki/display/ABAP/bdc+on+table+control
Copyright
Follow SCN
5/5