Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

bdc program

Former Member
0 Likes
414

Hi,

I created a report like this.

&----


*& Report ZRAKESH_BDCDEMO1

*&

&----


*&

*&

&----


REPORT zrakesh_bdcdemo1.

CONSTANTS: infile(30) VALUE 'rakesh1.txt'.

DATA: bdc_tab LIKE STANDARD TABLE OF bdcdata INITIAL SIZE 8 WITH HEADER LINE,

session LIKE apqi-groupid VALUE 'SESSION2-XX'.

DATA: BEGIN OF inrec,

vendnum(10),

street(35),

phone(16),

fax(31),

END OF inrec.

START-OF-SELECTION.

OPEN DATASET infile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = session

* HOLDDATE = ' '

keep = 'X'

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.

WRITE: / 'Batch input session ', session, ' opened'.

ELSE.

WRITE: / 'Error opening session - SY-SUBRC =', sy-subrc.

ENDIF.

DO.

READ DATASET infile INTO inrec.

IF sy-subrc <> 0.

EXIT.

ENDIF.

PERFORM fill_bdc_tab.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'FK02' " transaction code must be capitalized

TABLES

dynprotab = bdc_tab

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

OTHERS = 5.

IF sy-subrc = 0.

WRITE: / inrec-vendnum, 'inserted into session'.

ELSE.

WRITE: / 'Error inserting', inrec-vendnum, 'SY-SUBRC =', sy-subrc.

ENDIF.

ENDDO.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2

OTHERS = 3.

IF sy-subrc = 0.

WRITE: / 'Batch input session ', session, ' closed'.

ELSE.

WRITE: / 'Error closing session - SY-SUBRC =', sy-subrc.

ENDIF.

CLOSE DATASET infile.

&----


*& Form FILL_BDC_TAB

&----


  • text

----


FORM fill_bdc_tab.

REFRESH bdc_tab.

PERFORM populate_bdc_tab USING:

'1' 'SAPMF02K' '0106', " initial change vendor screen

' ' 'RF02K-LIFNR' inrec-vendnum, " vendor number field

' ' 'RF02K-D0110' 'X', " address check box

'1' 'SAPMF02K' '0110', " address screen

' ' 'LFA1-STRAS' inrec-street, " street field

' ' 'LFA1-TELF1' inrec-phone, " telephone 1 field

' ' 'LFA1-TELFX' inrec-fax, " fax number field

' ' 'BDC_OKCODE' '/11'. " save the record

ENDFORM. "FILL_BDC_TAB

&----


*& Form POPULATE_BDC_TAB

&----


  • text

----


  • -->FLAG text

  • -->VAR1 text

  • -->VAR2 text

----


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. "POPULATE_BDC_TAB

My requirement is based on vendor number update the address details of vendor.

1 REPLY 1
Read only

Former Member
0 Likes
376

hey in u r internal table declaration the address check box is not there ... but u have recorded address checkbox also ....there lies the mistake ....

CONSTANTS: infile(30) VALUE 'rakesh1.txt'.

DATA: bdc_tab LIKE STANDARD TABLE OF bdcdata INITIAL SIZE 8 WITH HEADER LINE,

session LIKE apqi-groupid VALUE 'SESSION2-XX'.

DATA: BEGIN OF inrec,

vendnum(10),

<b>address(1)</b>

street(35),

phone(16),

fax(31),

END OF inrec.

START-OF-SELECTION.

OPEN DATASET infile FOR INPUT IN TEXT MODE ENCODING DEFAULT.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = session

  • HOLDDATE = ' '

keep = 'X'

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.

WRITE: / 'Batch input session ', session, ' opened'.

ELSE.

WRITE: / 'Error opening session - SY-SUBRC =', sy-subrc.

ENDIF.

DO.

READ DATASET infile INTO inrec.

IF sy-subrc <> 0.

EXIT.

ENDIF.

PERFORM fill_bdc_tab.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = 'FK02' " transaction code must be capitalized

TABLES

dynprotab = bdc_tab

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

OTHERS = 5.

IF sy-subrc = 0.

WRITE: / inrec-vendnum, 'inserted into session'.

ELSE.

WRITE: / 'Error inserting', inrec-vendnum, 'SY-SUBRC =', sy-subrc.

ENDIF.

ENDDO.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2

OTHERS = 3.

IF sy-subrc = 0.

WRITE: / 'Batch input session ', session, ' closed'.

ELSE.

WRITE: / 'Error closing session - SY-SUBRC =', sy-subrc.

ENDIF.

CLOSE DATASET infile.

&----


*& Form FILL_BDC_TAB

&----


  • text

----


FORM fill_bdc_tab.

REFRESH bdc_tab.

PERFORM populate_bdc_tab USING:

'1' 'SAPMF02K' '0106', " initial change vendor screen

' ' 'RF02K-LIFNR' inrec-vendnum, " vendor number field

'<b> ' 'RF02K-D0110' 'X', " address check box</b>

'1' 'SAPMF02K' '0110', " address screen

' ' 'LFA1-STRAS' inrec-street, " street field

' ' 'LFA1-TELF1' inrec-phone, " telephone 1 field

' ' 'LFA1-TELFX' inrec-fax, " fax number field

' ' 'BDC_OKCODE' '/11'. " save the record

ENDFORM. "FILL_BDC_TAB

&----


*& Form POPULATE_BDC_TAB

&----


  • text

----


  • -->FLAG text

  • -->VAR1 text

  • -->VAR2 text

----


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. "POPULATE_BDC_TAB

reward points if helpful....