Skip to Content
0
Former Member
May 31, 2007 at 10:59 AM

BDC call transaction

21 Views

Hi,

I have to upload data from text file and create customers using bdc call transaction.

This is the code I have written but getting no output.

Pls help me out.

Thanks

REPORT znewbdc

NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES: kna1.

DATA: gv_program LIKE bdcdata-program,

gv_dynpro LIKE bdcdata-dynpro,

gv_dynbegin LIKE bdcdata-dynbegin,

gv_fnam LIKE bdcdata-fnam,

gv_fval LIKE bdcdata-fval.

*--Internal Table to Store Error Records.

DATA : BEGIN OF gt_errcust OCCURS 0,

kunnr,

emsg(255),

END OF gt_errcust.

*--Internal Table to Store Successful Records.

DATA : BEGIN OF gt_succust OCCURS 0,

kunnr,

smsg(255),

END OF gt_succust.

*--Internal Table for Storing the BDC data.

DATA : gt_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

*--Internal Table for storing the messages

DATA : gt_bdcmsgcoll LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA : v_flag1(1) VALUE ' ', "Flag used for opening session.

v_tlines LIKE sy-tabix, "For storing total records processed.

v_elines LIKE sy-tabix, "For storing the no of error records.

v_slines LIKE sy-tabix. "For storing the no of success records.

DATA: BEGIN OF tp_kna1 OCCURS 0,

ktokd,

bukrs,

name1,

sort1,

land1,

ktocd,

akont,

message(100) TYPE c,

END OF tp_kna1.

DATA: gs_bdc_tcode LIKE tstc-tcode.

SELECTION-SCREEN BEGIN OF BLOCK b1.

PARAMETERS : v_fname LIKE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

DATA : lv_file TYPE string.

lv_file = v_fname.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lv_file

  • FILETYPE = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

data_tab = tp_kna1

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.

DESCRIBE TABLE tp_kna1 LINES v_tlines.

ENDIF.

LOOP AT tp_kna1.

PERFORM bdc_dynpro USING 'SAPMF02D' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF02D-BUKRS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RF02D-BUKRS'

tp_kna1-bukrs. "'0001'.

PERFORM bdc_field USING 'RF02D-KTOKD'

tp_kna1-ktokd. "'CPD'.

PERFORM bdc_dynpro USING 'SAPMF02D' '0110'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KNA1-SPRAS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_field USING 'KNA1-NAME1'

'tp_KNA1-NAME1'.

PERFORM bdc_field USING 'KNA1-SORTL'

'tp_KNA1-SORTL'.

PERFORM bdc_field USING 'KNA1-LAND1'

'TP_KNA1-LAND1'.

PERFORM bdc_field USING 'KNA1-SPRAS'

'TP_KNA1-SPRAS'.

PERFORM bdc_dynpro USING 'SAPMF02D' '0120'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KNA1-KTOCD'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_field USING 'KNA1-KTOCD'

'TP_KNA1-KTOCD'.

PERFORM bdc_dynpro USING 'SAPMF02D' '0210'.

PERFORM bdc_field USING 'BDC_CURSOR'

'KNB1-AKONT'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=UPDA'.

PERFORM bdc_field USING 'KNB1-AKONT'

'140000'.

CALL TRANSACTION 'XD01' USING gt_bdcdata MODE 'N' UPDATE 'S'

MESSAGES INTO gt_bdcmsgcoll.

*--Getting the total no of error records.

DESCRIBE TABLE gt_errcust LINES v_elines.

*--Getting the total no of successful records.

DESCRIBE TABLE gt_succust LINES v_slines.

DATA : lv_msg(255).

IF NOT gt_bdcmsgcoll IS INITIAL.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = sy-msgid

lang = sy-langu

no = sy-msgno

v1 = sy-msgv1

v2 = sy-msgv2

v3 = sy-msgv3

v4 = sy-msgv4

IMPORTING

msg = lv_msg

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc = 0.

WRITE :/ lv_msg.

ENDIF.

ULINE.

ENDIF.

ENDLOOP.

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_GV_PROGRAM text

  • -->P_GV_DYNPRO text

----


FORM bdc_dynpro USING p_gv_program LIKE bdcdata-program

p_gv_dynpro LIKE bdcdata-dynpro.

CLEAR gt_bdcdata.

gt_bdcdata-program = p_gv_program.

gt_bdcdata-dynpro = p_gv_dynpro.

gt_bdcdata-dynbegin = 'X'.

APPEND gt_bdcdata.

ENDFORM. "BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • text

----


  • -->P_GV_FNAM text

  • -->P_GV_FVAL text

----


FORM bdc_field USING p_gv_fnam

p_gv_fval.

CLEAR gt_bdcdata.

gt_bdcdata-fnam = p_gv_fnam.

gt_bdcdata-fval = p_gv_fval.

APPEND gt_bdcdata.

ENDFORM. "BDC_FIELD