100% found this document useful (1 vote)
108 views14 pages

ZBDC - Ctran Heading: No Standard Page

1. The document describes calling a transaction method to insert employee data using BDC programming. 2. It uploads employee data from a file, then loops through the records to perform BDC calls to populate fields and save the data in transaction SAPMZEMP. 3. After the data is inserted, it displays any messages from the BDC calls.

Uploaded by

Farooq Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
108 views14 pages

ZBDC - Ctran Heading: No Standard Page

1. The document describes calling a transaction method to insert employee data using BDC programming. 2. It uploads employee data from a file, then loops through the records to perform BDC calls to populate fields and save the data in transaction SAPMZEMP. 3. After the data is inserted, it displays any messages from the BDC calls.

Uploaded by

Farooq Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Call transaction method.

*&---------------------------------------------------------
------------*
*& Report ZBDC_CTRAN
*&
*&---------------------------------------------------------
------------*
*&
*&
*&---------------------------------------------------------
------------*

REPORT ZBDC_CTRAN NO STANDARD PAGE HEADING.

data: begin of it_emp occurs 0,


* data element: ZEMPID
empid_001(006),
* data element: NAME1_GP
name1_002(035),
* data element: NAME2_GP
name2_003(035),
* data element: ORT01
ort01_004(025),
* data element: LAND1_GP
land1_005(003),
* data element: REGIO
regio_006(003),
* data element: TELF1
telf1_007(016),
* data element: TELFX
telfx_008(031),
* data element: ZMAILD
maild_009(020),
* data element: ZBID1
bid01_010(005),
* data element: ZACCN
accno_012(010),
end of it_emp.
data : it_bdcdata type table of bdcdata with header line.

data : it_bdcmsg TYPE TABLE OF bdcmsgcoll WITH HEADER LINE


.

perform upload_data.

PERFORM call_tran.

PERFORM summry.

form call_tran.

loop at it_emp .
refresh it_bdcdata.

*& copy paste the req code from SHDB gen program
*& all the BDC_DYNPRO and BDC_FIELD as it is .
*& edit the code as required

perform bdc_dynpro using 'SAPMZEMP' '9002'.


perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'BDC_CURSOR'
'ZEMP01-MAILD'.
perform bdc_field using 'ZEMP01-EMPID'
it_emp-empid_001.
perform bdc_field using 'ZEMP01-NAME1'
it_emp-name1_002.
perform bdc_field using 'ZEMP01-NAME2'
it_emp-name2_003.
perform bdc_field using 'ZEMP01-ORT01'
it_emp-ort01_004.
perform bdc_field using 'ZEMP01-LAND1'
it_emp-land1_005.
perform bdc_field using 'ZEMP01-REGIO'
it_emp-regio_006.
perform bdc_field using 'ZEMP01-TELF1'
it_emp-telf1_007.
perform bdc_field using 'ZEMP01-TELFX'
it_emp-telfx_008.
perform bdc_field using 'ZEMP01-MAILD'
it_emp-maild_009.
perform bdc_dynpro using 'SAPMZEMP' '9003'.
perform bdc_field using 'BDC_OKCODE'
'=GET'.
perform bdc_field using 'BDC_CURSOR'
'ZBANK-BID01'.
perform bdc_field using 'ZBANK-BID01'
it_emp-bid01_010.
perform bdc_dynpro using 'SAPMZEMP' '9003'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'BDC_CURSOR'
'ZEMPBNK-ACCNO'.
perform bdc_field using 'ZBANK-BID01'
it_emp-bid01_010.
perform bdc_field using 'ZEMPBNK-ACCNO'
it_emp-accno_012.

CALL TRANSACTION 'ZEMPBNK' " tcode using which we prefrom


BDC
USING it_bdcdata " internal table BDCDATA
mode 'A'
UPDATE 'A'
MESSAGES INTO IT_BDCMSG.

endloop.
endform. " BDC_SES_INSERT

form bdc_dynpro using program dynpro.


clear it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
append it_bdcdata.
endform.

*----------------------------------------------------------
------------*
* Insert field
*
*----------------------------------------------------------
------------*
form bdc_field using fnam fval.
* if fval <> nodata.
clear it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
append it_bdcdata.
* endif.
endform.

form upload_data .
call function 'GUI_UPLOAD'
exporting
filename = 'C:\Users\farooq.sank
anur\Documents\upload.txt'
filetype = 'ASC'
has_field_separator = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = it_emp
* 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 and it_emp is not initial.
message 'data uploaded' type 'S'.
else.
message 'No data found' type 'S'.
* Implement suitable error handling here
endif.

endform. " UPLOAD_DATA


*&---------------------------------------------------------
------------*
*& Form SUMMRY
*&---------------------------------------------------------
------------*
* text
*----------------------------------------------------------
------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------
------------*
form SUMMRY .
LOOP AT IT_BDCMSG.
WRITE: /
it_bdcmsg-msgv1.
ENDLOOP.
endform. " SUMMRY

*&---------------------------------------------------------
------------*
*& Report ZBDC_SES
*&
*&---------------------------------------------------------
------------*
*&
*&
*&---------------------------------------------------------
------------*

report zbdc_ses line-size 244.

data: begin of it_emp occurs 0,


* data element: ZEMPID
empid_001(006),
* data element: NAME1_GP
name1_002(035),
* data element: NAME2_GP
name2_003(035),
* data element: ORT01
ort01_004(025),
* data element: LAND1_GP
land1_005(003),
* data element: REGIO
regio_006(003),
* data element: TELF1
telf1_007(016),
* data element: TELFX
telfx_008(031),
* data element: ZMAILD
maild_009(020),
* data element: ZBID1
bid01_010(005),
* data element: ZACCN
accno_012(010),
end of it_emp.

parameters : session type c length 7,


keep as checkbox,
date type sy-datum.

data : it_bdcdata type table of bdcdata with header line.

perform upload_data.

perform check_data.

perform bdc_session_open_group.

perform bdc_ses_insert.

perform bdc_close.

*&---------------------------------------------------------
------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------
------------*
* text
*----------------------------------------------------------
------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------
------------*
form upload_data .
call function 'GUI_UPLOAD'
exporting
filename = 'C:\Users\farooq.sank
anur\Documents\upload.txt'
filetype = 'ASC'
has_field_separator = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* VIRUS_SCAN_PROFILE =
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
tables
data_tab = it_emp
* 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 and it_emp is not initial.
message 'data uploaded' type 'S'.
else.
message 'No data found' type 'S'.
* Implement suitable error handling here
endif.

endform. " UPLOAD_DATA


*&---------------------------------------------------------
------------*
*& Form CHECK_DATA
*&---------------------------------------------------------
------------*
* text
*----------------------------------------------------------
------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------
------------*
form check_data .
loop at it_emp.
write : /
it_emp-empid_001,
it_emp-name1_002,
it_emp-name2_003,
it_emp-ort01_004,
it_emp-land1_005,
it_emp-regio_006,
it_emp-telf1_007,
it_emp-telfx_008,
it_emp-maild_009,
it_emp-bid01_010,
it_emp-accno_012.

endloop.
endform. " CHECK_DATA
*&---------------------------------------------------------
------------*
*& Form BDC_SESSION_OPEN_GROUP
*&---------------------------------------------------------
------------*
* text
*----------------------------------------------------------
------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------
------------*
form bdc_session_open_group .
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt
group = 'SESSION' " session name
holddate = date
keep = keep
user = sy-uname
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 'Session created check SM35 Tcode' type 'I'.
* Implement suitable error handling here
endif.

endform. " BDC_SESSION_OPEN_GROUP


*&---------------------------------------------------------
------------*
*& Form BDC_SES_INSERT
*&---------------------------------------------------------
------------*
* text
*----------------------------------------------------------
------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------
------------*
form bdc_ses_insert .
break-point.
loop at it_emp .
refresh it_bdcdata.

*& copy paste the req code from SHDB gen program
*& all the BDC_DYNPRO and BDC_FIELD as it is .
*& edit the code as required

perform bdc_dynpro using 'SAPMZEMP' '9002'.


perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'BDC_CURSOR'
'ZEMP01-MAILD'.
perform bdc_field using 'ZEMP01-EMPID'
it_emp-empid_001.
perform bdc_field using 'ZEMP01-NAME1'
it_emp-name1_002.
perform bdc_field using 'ZEMP01-NAME2'
it_emp-name2_003.
perform bdc_field using 'ZEMP01-ORT01'
it_emp-ort01_004.
perform bdc_field using 'ZEMP01-LAND1'
it_emp-land1_005.
perform bdc_field using 'ZEMP01-REGIO'
it_emp-regio_006.
perform bdc_field using 'ZEMP01-TELF1'
it_emp-telf1_007.
perform bdc_field using 'ZEMP01-TELFX'
it_emp-telfx_008.
perform bdc_field using 'ZEMP01-MAILD'
it_emp-maild_009.
perform bdc_dynpro using 'SAPMZEMP' '9003'.
perform bdc_field using 'BDC_OKCODE'
'=GET'.
perform bdc_field using 'BDC_CURSOR'
'ZBANK-BID01'.
perform bdc_field using 'ZBANK-BID01'
it_emp-bid01_010.
perform bdc_dynpro using 'SAPMZEMP' '9003'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'BDC_CURSOR'
'ZEMPBNK-ACCNO'.
perform bdc_field using 'ZBANK-BID01'
it_emp-bid01_010.
perform bdc_field using 'ZEMPBNK-ACCNO'
it_emp-accno_012.

call function 'BDC_INSERT'


exporting
tcode = 'ZEMPBNK'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
tables
dynprotab = it_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.
* Implement suitable error handling here
endif.
endloop.
endform. " BDC_SES_INSERT

form bdc_dynpro using program dynpro.


clear it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
append it_bdcdata.
endform.

*----------------------------------------------------------
------------*
* Insert field
*
*----------------------------------------------------------
------------*
form bdc_field using fnam fval.
* if fval <> nodata.
clear it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
append it_bdcdata.
* endif.
endform.
*&---------------------------------------------------------
------------*
*& Form BDC_CLOSE
*&---------------------------------------------------------
------------*
* text
*----------------------------------------------------------
------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------
------------*
form bdc_close .
call function 'BDC_CLOSE_GROUP'
* EXCEPTIONS
* NOT_OPEN = 1
* QUEUE_ERROR = 2
* OTHERS = 3
.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.

endform. " BDC_CLOSE

You might also like