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

call transaction

Former Member
0 Likes
1,206

how to handle errors in call transaction method?

please. give one example code for it.

11 REPLIES 11
Read only

Former Member
0 Likes
1,159

chk this one

http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm

Message was edited by: Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
1,159

hii

use function module <b>Format_messages</b>

Have a look at this code

data: begin of ITAB OCCURS 0,

IND(02),

LIFNR_001(010),

BSART_002(004),

EKORG_004(004),

EKGRP_005(003),

LPEIN_006(001),

WERKS_007(004),

EMATN(18),

MENGE_01_010(017),

NETPR_01_011(014),

END OF ITAB.

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA : IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA : V_MSG(150),

V_EMATN_FN(18),

V_MENGE_FN(15),

V_NETPR_FN(15),

V_IND(2) TYPE N.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\ME21_TEST.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 <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SORT ITAB BY IND.

LOOP AT ITAB.

V_IND = V_IND + 1.

AT NEW IND.

READ TABLE ITAB INDEX SY-TABIX.

perform bdc_dynpro using 'SAPMM06E' '0100'.

perform bdc_field using 'BDC_CURSOR'

'EKKO-LIFNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'EKKO-LIFNR'

ITAB-LIFNR_001.

perform bdc_field using 'RM06E-BSART'

ITAB-BSART_002.

perform bdc_field using 'EKKO-EKORG'

ITAB-EKORG_004.

perform bdc_field using 'EKKO-EKGRP'

ITAB-EKGRP_005.

perform bdc_field using 'RM06E-LPEIN'

ITAB-LPEIN_006.

perform bdc_field using 'RM06E-WERKS'

ITAB-WERKS_007.

ENDAT.

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

'EKPO-MENGE(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

CONCATENATE 'EKPO-MENGE(' V_IND ')' INTO V_MENGE_FN.

perform bdc_field using V_MENGE_FN

ITAB-MENGE_01_010.

CONCATENATE 'EKPO-EMATN(' V_IND')' INTO V_EMATN_FN.

perform bdc_field using V_EMATN_FN

ITAB-EMATN.

CONCATENATE 'EKPO-NETPR(' V_IND ')' INTO V_NETPR_FN.

perform bdc_field using V_NETPR_FN

ITAB-NETPR_01_011.

AT END OF IND.

<b>PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=BU'.

CLEAR V_IND.

CALL TRANSACTION 'ME21' USING IT_BDCDATA MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_MESSAGES.

LOOP AT IT_MESSAGES where msgtyp = 'E'..

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MESSAGES-MSGID

LANG = 'EN'

NO = IT_MESSAGES-MSGNR

V1 = IT_MESSAGES-MSGV1

V2 = IT_MESSAGES-MSGV2

V3 = IT_MESSAGES-MSGV3

V4 = IT_MESSAGES-MSGV4

IMPORTING

MSG = V_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE : / V_MSG.

ENDLOOP.

ENDAT.

ENDLOOP.</b>

----


  • Start new screen *

----


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.

CLEAR IT_BDCDATA.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

Regards

Naresh

Read only

Former Member
0 Likes
1,159

HI SHREE,

CALL TRANSACTION '<tcoDE>' USING IT_BDCDATA MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_MESSAGES.

WRITe:/ SY-SUBRC.

PERFORM FORMAT_MESSAGES.

AND

form FORMAT_MESSAGES .

DATA: L_MSG(100).

LOOP AT IT_MESSAGES.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MESSAGES-MSGID

LANG = SY-LANGU

NO = IT_MESSAGES-MSGNR

V1 = IT_MESSAGES-MSGV1

V2 = IT_MESSAGES-MSGV2

V3 = IT_MESSAGES-MSGV3

V4 = IT_MESSAGES-MSGV4

IMPORTING

MSG = L_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

write:/ l_msg.

endloop.

endform. " FORMAT_MESSAGES

HOPE THIS HELPS,

DO REWARD IF IT HELPS,

PRIYA.

Read only

Former Member
0 Likes
1,159

hi

CALL TRANSACTION 'PA30' USING IT_BDCDATA MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_MSG.

LOOP AT IT_MSG WHERE MSGTYP = 'E' .

PERFORM CREATE_SESSION.

PERFORM INSERT_INTO_SESSION.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MSG-MSGID

LANG = SY-LANGU

NO = IT_MSG-MSGNR

V1 = IT_MSG-MSGV1

V2 = IT_MSG-MSGV2

V3 = IT_MSG-MSGV3

V4 = IT_MSG-MSGV4

IMPORTING

MSG = V_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Read only

ferry_lianto
Active Contributor
0 Likes
1,159

Hi Shree,

Please check this sample codes from other thread.

*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of it_lfa1 occurs 0,
KTOKK like lfa1-ktokk,
NAME1 like lfa1-name1,
SORTL like lfa1-sortl,
LAND1 like lfa1-land1,
end of it_lfa1.
*** End generated data section ***
data : it_bdc like bdcdata occurs 0 with header line.

*DATA: IT_MESSAGES TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.
*DATA: LV_MESSAGE(255).
data : it_messages like bdcmsgcoll occurs 0 with header line.
data : V_message(255).
data : V_flag.
data : V_datum1 type sy-datum.

data : begin of it_mesg occurs 0,
message(100),
end of it_mesg.

*V_datum1 = sy-datum-1.

parameters : P_Sess like APQI-GROUPID.

start-of-selection.
perform Get_data.
*perform open_group.

loop at it_lfa1.
perform bdc_dynpro using 'SAPMF02K' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-KTOKK'
it_lfa1-KTOKK.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-NAME1'
it_lfa1-name1.
perform bdc_field using 'LFA1-SORTL'
it_lfa1-sortl.
perform bdc_field using 'LFA1-LAND1'
it_lfa1-land1.
call transaction 'XK01' using it_bdc
mode 'N'
update 'S'
messages into it_messages.

if sy-subrc <> 0.
if V_flag <> 'X'.
perform open_group.
V_flag = 'X'.
endif.
perform bdc_transaction. "using 'XK01'.
endif.
perform format_messages.


refresh : it_bdc,it_messages.
.

endloop.
if V_flag = 'X'.
perform close_group.
endif.

*&---------------------------------------------------------------------*
*& Form Get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM Get_data .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:srinu_vendor.txt'
FILETYPE = 'ASC'
TABLES
DATA_TAB = it_lfa1
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " Get_data
*&---------------------------------------------------------------------*
*& Form bdc_dynpro
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0061 text
* -->P_0062 text
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR it_BDC.
it_BDC-PROGRAM = PROGRAM.
it_BDC-DYNPRO = DYNPRO.
it_BDC-DYNBEGIN = 'X'.
APPEND it_BDC.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR it_BDC.
it_BDC-FNAM = FNAM.
it_BDC-FVAL = FVAL.
APPEND it_BDC.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form format_messages
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM format_messages .
loop at it_messages.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = it_messages-MSGID
LANG = 'EN'
NO = it_messages-MSGNR
V1 = it_messages-MSGV1
V2 = it_messages-MSGV2
V3 = it_messages-MSGV3
V4 = it_messages-MSGV4
IMPORTING
MSG = V_message
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write : / V_message.
clear : V_message.
endloop.
ENDFORM. " format_messages
*&---------------------------------------------------------------------*
*& Form open_group
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM open_group .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_Sess
* HOLDDATE = V_datum1
KEEP = 'X'
USER = SY-UNAME
.
IF SY-SUBRC = 0.
write : / 'Session Creating wit Name : ',P_Sess.
ENDIF.

ENDFORM. " open_group
*&---------------------------------------------------------------------*
*& Form close_group
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM close_group .
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDFORM. " close_group
*&---------------------------------------------------------------------*
*& Form bdc_transaction
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0132 text
*----------------------------------------------------------------------*
FORM bdc_transaction. "USING VALUE(P_0132).
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'XK01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = it_bdc
* 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
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " bdc_transaction

Hope this will help.

Regards,

Ferry Lianto

Please reward points if helpful.

Read only

Former Member
0 Likes
1,159

Whenever you use CALL TRANSACTION , you can pass MESSSAGES I_MSG table to it, it is an optional parameter.

After that, you can check for SY-SUBRC for error occurd or not and for what error occured, read this table.

Regds,

Sandip

Read only

Former Member
0 Likes
1,159

HI ,

Using Format_message.

Here is sample code for recording FK01

report zxx_recording_fk01 .

************************************************************************

  • Program name : zsh_recording_fk01 *

  • Title : BDC *

  • Functional req ID : - *

  • Development analyst : - *

  • Developer : *

  • Date : 01/10/2006 *

  • Type : BDC *

  • Description : This program will get all the vendor details *

  • from a flat file . *

************************************************************************

----


  • Change Log

----


  • Date Correction# Changed by Description

----


  • 01/10/2006 - Initial Development

----


************************************************************************

  • T A B L E S *

************************************************************************

tables : lfa1 . " Vendor Master.

************************************************************************

  • I N T E R N A L T A B L E - D E C L A R A T I O N *

************************************************************************

data : begin of it_tab occurs 0,

lifnr(16), "account number of vendor

ktokk(4), "Vendor Number

anred(15), "Account Group

name1(35), "Name

sortl(10), "Sort field

land1(3) , "Land

spras(1), "Language Key

kunnr(10), "customer number

banks(3), "Bank country key

bankl(15), "Bank Key

bankn(18), "Bank Account Number

koinh(60), "Account Holder Name

banka(60), "Name of bank

provz(3), "region

end of it_tab.

data : begin of it_tab1 occurs 0,

banks(3), "Bank country key

bankl(15), "Bank Key

bankn(18), "Bank Account Number

koinh(60), "Account Holder Name

banka(60), "Name of bank

provz(3), "region

end of it_tab1.

DATA:it_BDCtab LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • ERROR MESSAGE TABLE

DATA:it_MSGtab LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

data: program type BDCDATA-PROGRAM,

dynpro type BDCDATA-dynpro,

fnam type BDCDATA-fnam,

fval type BDCDATA-fval.

************************************************************************

  • S E L E C T I O N - S C R E E N *

************************************************************************

selection-screen : begin of block bl1 with frame.

parameter : p_file type rlgrap-filename default

'C:\Vendor.txt.txt' obligatory,

p_file1 type rlgrap-filename default

'C:\Vendor1.txt.txt' obligatory.

selection-screen : end of block bl1.

************************************************************************

  • A T S E L E C T I O N - S C R E E N *

************************************************************************

at selection-screen on value-request for p_file.

  • to get F4 help for p_file

perform f4_get_help using p_file.

  • to get F4 help for p_file

perform f4_get_help1 using p_file1.

************************************************************************

  • S T A R T O F S E L E C T I O N *

************************************************************************

start-of-selection.

  • Uploading data from flat file into it_tab

perform bdc_upload.

perform bdc_upload1.

perform populate_bdc.

************************************************************************

  • E N D O F S E L E C T I O N *

************************************************************************

end-of-selection.

  • displaying fields which r uploaded from flat file.

perform display_report.

************************************************************************

  • T O P _ O F _ P A G E *

************************************************************************

top-of-page.

  • to display header in the report

perform header.

&----


*& Form f4_get_help

&----


  • text

----


  • -->P_P_FILE text

----


form f4_get_help using p_p_file.

call function 'F4_FILENAME'

exporting

program_name = syst-cprog

dynpro_number = syst-dynnr

  • FIELD_NAME = ' '

importing

file_name = p_p_file.

.

endform. " f4_get_help

&----


*& Form bdc_upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form bdc_upload .

data: v_file type string.

v_file = p_file.

call function 'GUI_UPLOAD'

exporting

filename = v_file

filetype = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = it_tab

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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " bdc_upload

&----


*& Form display_report

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form display_report .

uline 1(86).

loop at it_tab .

format color 2.

write :/1 sy-vline,

2 it_tab-lifnr,

12 it_tab-ktokk ,

18 it_tab-anred ,

30 it_tab-name1 ,

55 it_tab-sortl ,

58 it_tab-land1 ,

72 it_tab-spras ,

76 it_tab-kunnr ,

88 it_tab-banks ,

94 it_tab-bankl ,

112 it_tab-bankn ,

132 it_tab-koinh ,

194 it_tab-banka ,

256 it_tab-provz ,

260 sy-vline.

.

endloop.

uline 1(86).

endform. " display_report

&----


*& Form header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form header .

uline 1(86).

format color col_heading.

write :/1 sy-vline,

2 'VEN.NO',

12 'ACC' ,

18 'TITLE' ,

30 'NAME' ,

55 'ST',

58 'LAND' ,

72 'L' ,

76 'CUSTNO',

88 'CKI',

94 'BANKKEY',

112 'B.NO',

132 'ACC HOLDER NAME',

194 'BANK NAME',

256 'reg',

260 sy-vline.

endform. " header

&----


*& Form populate_bdc

&----


  • text

----


form populate_bdc .

loop at it_tab.

perform build_screen_details using 'SAPMF02K' '0105'.

*

perform build_fields using: 'BDC_OKCODE' '/00',

'RF02K-LIFNR' it_tab-lifnr,

'RF02K-KTOKK' it_tab-ktokk.

perform build_screen_details using 'SAPMF02K' '0110'.

perform build_fields using: 'BDC_OKCODE' '/00',

'LFA1-ANRED' it_tab-anred,

'LFA1-NAME1' it_tab-name1,

'LFA1-SORTL' it_tab-sortl,

'LFA1-LAND1' it_tab-land1,

'LFA1-SPRAS' it_tab-spras.

perform build_screen_details using 'SAPMF02K' '0120'.

perform build_fields using: 'BDC_OKCODE' '/00'.

perform build_screen_details using 'SAPMF02K' '0130'.

perform build_fields using: 'BDC_OKCODE' '=BANK',

'LFBK-BANKS(01)' it_tab-banks,

'LFBK-BANKL(01)' it_tab-bankl,

'LFBK-BANKN(01)' it_tab-bankn,

'LFBK-KOINH(01)' it_tab-koinh.

perform build_screen_details using 'SAPLBANK' '0100'.

perform build_fields using: 'BDC_OKCODE' '=ENTR',

'BNKA-BANKA' it_tab-banka,

'BNKA-PROVZ' it_tab-provz.

perform build_screen_details using 'SAPMF02K' '0130'.

perform build_fields using: 'BDC_OKCODE' '=UPDA'.

endloop.

call transaction 'FK01' using it_bdctab mode 'A' update

'S' messages into it_msgtab.

clear it_bdctab.

refresh it_bdctab.

loop at it_msgtab.

perform format_message.

endloop.

endform. " populate_bdc

&----


*& Form build_screen_details

&----


  • text

----


form build_screen_details using p_program type BDCDATA-PROGRAM

p_dynpro type BDCDATA-dynpro.

it_BDCtab-PROGRAM = p_program. " Program Name

it_BDCtab-DYNPRO = p_dynpro. " Screen Number

it_BDCtab-DYNBEGIN = 'X'. " New screen

Append it_bdctab.

clear it_bdctab.

endform. " build_screen_details

&----


*& Form build_fields

&----


  • text

----


form build_fields using p_fnam

p_fval.

it_BDCtab-FNAM = p_fnam.

it_BDCtab-FVAL = p_fval.

Append it_bdctab.

clear it_bdctab.

endform. " build_fields

&----


*& Form format_message

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form format_message .

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 = it_msgtab

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

if sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " format_message

&----


*& Form bdc_upload1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form bdc_upload1 .

data : v_file1 type string.

v_file1 = p_file1.

call function 'GUI_UPLOAD'

exporting

filename = v_file1

FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = it_tab1

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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " bdc_upload1

&----


*& Form f4_get_help1

&----


  • text

----


  • -->P_P_FILE1 text

----


form f4_get_help1 using p_p_file1.

call function 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = p_p_file1

.

endform. " f4_get_help1

if it helps plz reward it

Regards

Laxmi

Read only

Former Member
0 Likes
1,159

You can make use of standard SAP include BDCDRECX1. Use routine bdc_transaction which takes care of calling transaction and also displaying the message in stadard format

Read only

Former Member
0 Likes
1,159

Hi,

check this link..

Regards

vijay

Read only

Former Member
0 Likes
1,159

Hai Shree

go through the following COde

report Z_CALLTRANS_VENDOR_01

no standard page heading line-size 255.

      • Generated data section with specific formatting - DO NOT CHANGE ***

data: begin of it_lfa1 occurs 0,

KTOKK like lfa1-ktokk,

NAME1 like lfa1-name1,

SORTL like lfa1-sortl,

LAND1 like lfa1-land1,

end of it_lfa1.

      • End generated data section ***

data : it_bdc like bdcdata occurs 0 with header line.

*DATA: IT_MESSAGES TYPE TABLE OF BDCMSGCOLL WITH HEADER LINE.

*DATA: LV_MESSAGE(255).

data : it_messages like bdcmsgcoll occurs 0 with header line.

data : V_message(255).

data : V_flag.

data : V_datum1 type sy-datum.

data : begin of it_mesg occurs 0,

message(100),

end of it_mesg.

*V_datum1 = sy-datum-1.

parameters : P_Sess like APQI-GROUPID.

start-of-selection.

perform Get_data.

*perform open_group.

loop at it_lfa1.

perform bdc_dynpro using 'SAPMF02K' '0100'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-KTOKK'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-KTOKK'

it_lfa1-KTOKK.

perform bdc_dynpro using 'SAPMF02K' '0110'.

perform bdc_field using 'BDC_CURSOR'

'LFA1-LAND1'.

perform bdc_field using 'BDC_OKCODE'

'=UPDA'.

perform bdc_field using 'LFA1-NAME1'

it_lfa1-name1.

perform bdc_field using 'LFA1-SORTL'

it_lfa1-sortl.

perform bdc_field using 'LFA1-LAND1'

it_lfa1-land1.

call transaction 'XK01' using it_bdc

mode 'N'

update 'S'

messages into it_messages.

if sy-subrc <> 0.

if V_flag <> 'X'.

perform open_group.

V_flag = 'X'.

endif.

perform bdc_transaction. "using 'XK01'.

endif.

perform format_messages.

refresh : it_bdc,it_messages.

.

endloop.

if V_flag = 'X'.

perform close_group.

endif.

&----


*& Form Get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM Get_data .

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = 'C:\srinu_vendor.txt'

FILETYPE = 'DAT'

TABLES

DATA_TAB = it_lfa1

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " Get_data

&----


*& Form bdc_dynpro

&----


  • text

----


  • -->P_0061 text

  • -->P_0062 text

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR it_BDC.

it_BDC-PROGRAM = PROGRAM.

it_BDC-DYNPRO = DYNPRO.

it_BDC-DYNBEGIN = 'X'.

APPEND it_BDC.

ENDFORM.

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

CLEAR it_BDC.

it_BDC-FNAM = FNAM.

it_BDC-FVAL = FVAL.

APPEND it_BDC.

ENDFORM.

&----


*& Form format_messages

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM format_messages .

loop at it_messages.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = it_messages-MSGID

LANG = 'EN'

NO = it_messages-MSGNR

V1 = it_messages-MSGV1

V2 = it_messages-MSGV2

V3 = it_messages-MSGV3

V4 = it_messages-MSGV4

IMPORTING

MSG = V_message

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

write : / V_message.

clear : V_message.

endloop.

ENDFORM. " format_messages

&----


*& Form open_group

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM open_group .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = P_Sess

  • HOLDDATE = V_datum1

KEEP = 'X'

USER = SY-UNAME

.

IF SY-SUBRC = 0.

write : / 'Session Creating wit Name : ',P_Sess.

ENDIF.

ENDFORM. " open_group

&----


*& Form close_group

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM close_group .

CALL FUNCTION 'BDC_CLOSE_GROUP'.

ENDFORM. " close_group

&----


*& Form bdc_transaction

&----


  • text

----


  • -->P_0132 text

----


FORM bdc_transaction. "USING VALUE(P_0132).

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'XK01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

DYNPROTAB = it_bdc

  • 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

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " bdc_transaction

Thanks & regards

Sreenivasulu P

Read only

nishanthbhandar
Contributor
0 Likes
1,159

Shree,

With the call transaction statement all the system messages triggered can be collected through the MESSAGES into ITAB addition.The internal table ITAB must have the structure BDCMSGCOLL.

Sample code taken from F1 help.

DATA: BDCDATA TYPE TABLE OF BDCDATA.

DATA: ITAB TYPE TABLE OF BDCMSGCOLL.

DATA: PROGRAM LIKE SY-REPID,

WA_BDCDATA TYPE BDCDATA.

WA_BDCDATA-PROGRAM = 'SAPMS38M'.

WA_BDCDATA-DYNPRO = '0100'.

WA_BDCDATA-DYNBEGIN = 'X'.

APPEND WA_BDCDATA TO BDCDATA.

CLEAR WA_BDCDATA.

WA_BDCDATA-FNAM = 'RS38M-PROGRAMM'.

WA_BDCDATA-FVAL = PROGRAM.

APPEND WA_BDCDATA TO BDCDATA.

...

CALL TRANSACTION 'SE38' USING BDCDATA MODE 'N'

MESSAGES INTO ITAB.

Please reward helpful answers.

Cheers

Nishanth