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

Former Member
0 Likes
403

hi i need bdc for mk01 transaction.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
377

Hi,

Here is BDC for MK01

*report z_nm_bdc_call.

TABLES: LFA1 , LFM1 .

data: begin of itab occurs 0,
lifnr like lfa1-lifnr,
ekorg like lfm1-ekorg,
ktokk like lfa1-ktokk,
name1 like lfa1-name1,
sortl like lfa1-sortl,
land1 like lfa1-land1,
waers like lfm1-waers,
end of itab.

data: bdcdata like bdcdata occurs 0 with header line.

*include Ybdcrecx1.
START-OF-SELECTION.
call function 'GUI_UPLOAD'
exporting
filename = 'C:\RAJ.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 =
*IMPORTING
*FILELENGTH =
*HEADER =
tables
data_tab = itab[]

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 EQ 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

*PERFORM OPEN_GROUP.
loop at itab.

perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
itab-lifnr.
perform bdc_field using 'RF02K-EKORG'
itab-ekorg.
perform bdc_field using 'RF02K-KTOKK'
itab-ktokk.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
'mr'.

IF ITAB-NAME1 = SPACE.

ITAB-NAME1 = 'RS PREM'.

ENDIF.
perform bdc_field using 'LFA1-NAME1'
itab-name1.

perform bdc_field using 'LFA1-SORTL'
itab-sortl.
perform bdc_field using 'LFA1-LAND1'
itab-land1.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
itab-waers.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.


CALL TRANSACTION 'MK01' USING BDCDATA
MODE 'A'
UPDATE 'S'.
CLEAR BDCDATA.
REFRESH BDCDATA.

ENDLOOP.
*perform bdc_transaction using 'MK01'.

*PERFORM CLOSE_GROUP.

*----------------------------------------------------------------------
*
*
*Start new screen *
*----------------------------------------------------------------------
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.

*----------------------------------------------------------------------
*
*Insert field *
*----------------------------------------------------------------------
FORM BDC_FIELD USING FNAM FVAL.


CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.

Best regards

raam

3 REPLIES 3
Read only

Former Member
0 Likes
377

Just do it.

Read only

0 Likes
377

i need information u just said do it

Read only

Former Member
0 Likes
378

Hi,

Here is BDC for MK01

*report z_nm_bdc_call.

TABLES: LFA1 , LFM1 .

data: begin of itab occurs 0,
lifnr like lfa1-lifnr,
ekorg like lfm1-ekorg,
ktokk like lfa1-ktokk,
name1 like lfa1-name1,
sortl like lfa1-sortl,
land1 like lfa1-land1,
waers like lfm1-waers,
end of itab.

data: bdcdata like bdcdata occurs 0 with header line.

*include Ybdcrecx1.
START-OF-SELECTION.
call function 'GUI_UPLOAD'
exporting
filename = 'C:\RAJ.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 =
*IMPORTING
*FILELENGTH =
*HEADER =
tables
data_tab = itab[]

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 EQ 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

*PERFORM OPEN_GROUP.
loop at itab.

perform bdc_dynpro using 'SAPMF02K' '0107'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
itab-lifnr.
perform bdc_field using 'RF02K-EKORG'
itab-ekorg.
perform bdc_field using 'RF02K-KTOKK'
itab-ktokk.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFA1-ANRED'
'mr'.

IF ITAB-NAME1 = SPACE.

ITAB-NAME1 = 'RS PREM'.

ENDIF.
perform bdc_field using 'LFA1-NAME1'
itab-name1.

perform bdc_field using 'LFA1-SORTL'
itab-sortl.
perform bdc_field using 'LFA1-LAND1'
itab-land1.
perform bdc_dynpro using 'SAPMF02K' '0120'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-KUNNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_dynpro using 'SAPMF02K' '0310'.
perform bdc_field using 'BDC_CURSOR'
'LFM1-WAERS'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'LFM1-WAERS'
itab-waers.
perform bdc_dynpro using 'SAPMF02K' '0320'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-LIFNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTR'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.


CALL TRANSACTION 'MK01' USING BDCDATA
MODE 'A'
UPDATE 'S'.
CLEAR BDCDATA.
REFRESH BDCDATA.

ENDLOOP.
*perform bdc_transaction using 'MK01'.

*PERFORM CLOSE_GROUP.

*----------------------------------------------------------------------
*
*
*Start new screen *
*----------------------------------------------------------------------
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.

*----------------------------------------------------------------------
*
*Insert field *
*----------------------------------------------------------------------
FORM BDC_FIELD USING FNAM FVAL.


CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.

Best regards

raam