Application Development 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: 

Catching Errors in Call Transaction

former_member252723
Participant
0 Kudos

Hi All,

I have develop the BDC using call transaction for MM01 transaction but i need to catch the success messages as well as errors in a log file that i wanna download. below is the code for the same and is it mandatory to give the update mode.please let me know.

DATA: i_bdcdata TYPE bdcdata OCCURS 0 WITH HEADER LINE,

i_error TYPE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY,

p_mode(1) DEFAULT 'A'.

p_erfile TYPE rlgrap-filename.

SELECTION-SCREEN : BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.

PARAMETER: PBROW_HD TYPE I, PEROW_HD TYPE I, PBCOL_HD TYPE I, PECOL_HD TYPE I.

SELECTION-SCREEN : END OF BLOCK BLK1.

DATA: T_EXCEL LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

Data: begin of record occurs 0,

MATNR(40),

MBRSH(01),

MTART(04),

MAKTX(40),

MEINS(03),

MATKL(09),

BISMT(18),

UMREN_02(05),

UMREN_03(05),

MEINH_02(03),

MEINH_03(03),

UMREZ_02(05),

UMREZ_03(05),

WERKS(04),

EKGRP(3) ,

LGORT(04),

DISMM(02),

DISPO(03), "Cash Discount Indicator

DISLS(02),

BESKZ(1),

DZEIT(3),

FHORI(3),

PERKZ(1),

MTVFP(02),

IPRKZ(01),

END OF RECORD.

DATA: v_filename LIKE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • PERFORM read_file CHANGING p_file.

CALL FUNCTION 'F4_FILENAME'

  • * EXPORTING

  • * PROGRAM_NAME = SYST-CPROG

  • * DYNPRO_NUMBER = SYST-DYNNR

  • * FIELD_NAME = ' '

IMPORTING

FILE_NAME = P_FILE.

start-of-selection.

PERFORM upload_file.

PERFORM bdc

PERFORM error_download

FORM UPLOAD_FILE .

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_file

i_begin_col = PBCOL_HD

i_begin_row = PBROW_HD

i_end_col = PECOL_HD

i_end_row = PEROW_HD

TABLES

intern = T_EXCEL

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

LOOP AT T_EXCEL.

CASE T_EXCEL-COL.

WHEN 1. MOVE T_EXCEL-VALUE TO record-MATNR.

WHEN 2. MOVE T_EXCEL-VALUE TO record-MBRSH.

WHEN 3. MOVE T_EXCEL-VALUE TO RECORD-MTART.

WHEN 4. MOVE T_EXCEL-VALUE TO RECORD-MAKTX.

WHEN 5. MOVE T_EXCEL-VALUE TO RECORD-MEINS.

WHEN 6. MOVE T_EXCEL-VALUE TO RECORD-MATKL.

WHEN 7. MOVE T_EXCEL-VALUE TO RECORD-BISMT.

WHEN 8. MOVE T_EXCEL-VALUE TO RECORD-UMREN_02.

WHEN 9. MOVE T_EXCEL-VALUE TO RECORD-UMREN_03.

WHEN 10. MOVE T_EXCEL-VALUE TO RECORD-MEINH_02.

WHEN 11. MOVE T_EXCEL-VALUE TO RECORD-MEINH_03.

WHEN 12. MOVE T_EXCEL-VALUE TO RECORD-UMREZ_02.

WHEN 13. MOVE T_EXCEL-VALUE TO RECORD-UMREZ_03.

WHEN 14. MOVE T_EXCEL-VALUE TO RECORD-WERKS.

WHEN 15. MOVE T_EXCEL-VALUE TO RECORD-EKGRP.

WHEN 16. MOVE T_EXCEL-VALUE TO RECORD-LGORT.

WHEN 17. MOVE T_EXCEL-VALUE TO RECORD-DISMM.

WHEN 18. MOVE T_EXCEL-VALUE TO RECORD-DISPO.

WHEN 19. MOVE T_EXCEL-VALUE TO RECORD-DISLS.

WHEN 20. MOVE T_EXCEL-VALUE TO RECORD-BESKZ.

WHEN 21. MOVE T_EXCEL-VALUE TO RECORD-DZEIT.

WHEN 22. MOVE T_EXCEL-VALUE TO RECORD-FHORI.

WHEN 23. MOVE T_EXCEL-VALUE TO RECORD-PERKZ.

WHEN 24. MOVE T_EXCEL-VALUE TO RECORD-MTVFP.

WHEN 25. MOVE T_EXCEL-VALUE TO RECORD-IPRKZ.

ENDCASE.

AT END OF ROW.

APPEND record.

CLEAR record.

ENDAT.

ENDLOOP.

ENDFORM. " UPLOAD_FILE

&----


*& Form BDC

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM BDC .

loop at record.

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MATNR'

record-matnr.

perform bdc_field using 'RMMG1-MBRSH'

record-mbrsh.

perform bdc_field using 'RMMG1-MTART'

record-mtart.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(01)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X'.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=ZU01'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'BDC_CURSOR'

'MARA-BISMT'.

perform bdc_field using 'MARA-MEINS'

record-meins.

perform bdc_field using 'MARA-MATKL'

record-matkl.

perform bdc_field using 'MARA-BISMT'

record-bismt.

perform bdc_dynpro using 'SAPLMGMM' '4300'.

perform bdc_field using 'BDC_OKCODE'

'=ZU02'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_dynpro using 'SAPLMGMM' '4300'.

perform bdc_field using 'BDC_OKCODE'

'=MAIN'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'BDC_CURSOR'

'SMEINH-UMREZ(03)'.

perform bdc_field using 'SMEINH-UMREN(02)'

record-umren_02.

perform bdc_field using 'SMEINH-UMREN(03)'

record-umren_03.

perform bdc_field using 'SMEINH-MEINH(02)'

record-meinh_02.

perform bdc_field using 'SMEINH-MEINH(03)'

record-meinh_03.

perform bdc_field using 'SMEINH-UMREZ(02)'

record-umrez_02.

perform bdc_field using 'SMEINH-UMREZ(03)'

record-umrez_03.

*perform bdc_dynpro using 'SAPLMGMM' '4300'.

*perform bdc_field using 'BDC_OKCODE'

  • '=MAIN'.

*perform bdc_field using 'BDC_CURSOR'

  • 'MAKT-MAKTX'.

*perform bdc_field using 'MAKT-MAKTX'

  • record-maktx.

*perform bdc_dynpro using 'SAPLMGMM' '4004'.

*perform bdc_field using 'BDC_OKCODE'

  • '=SP02'.

*perform bdc_field using 'BDC_CURSOR'

  • 'MAKT-MAKTX'.

*perform bdc_field using 'MAKT-MAKTX'

  • record-maktx.

*perform bdc_field using 'MARA-MEINS'

  • record-meins.

*perform bdc_field using 'MARA-MATKL'

  • record-matkl.

*perform bdc_field using 'MARA-BISMT'

  • record-bismt.

perform bdc_dynpro using 'SAPLMGMM' '4004'.

perform bdc_field using 'BDC_OKCODE'

'=SP09'.

perform bdc_field using 'BDC_CURSOR'

'MAKT-MAKTX'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_dynpro using 'SAPLMGMM' '0081'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-WERKS'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'RMMG1-WERKS'

record-werks.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP10'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'BDC_CURSOR'

'MARC-EKGRP'.

perform bdc_field using 'MARA-MEINS'

record-meins.

perform bdc_field using 'MARC-EKGRP'

record-ekgrp.

perform bdc_field using 'MARA-MATKL'

record-matkl.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP11'.

perform bdc_field using 'BDC_CURSOR'

'MAKT-MAKTX'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_dynpro using 'SAPLMGMM' '4040'.

perform bdc_field using 'BDC_OKCODE'

'=SP12'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_dynpro using 'SAPLMGMM' '0081'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-LGORT'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'RMMG1-LGORT'

record-lgort.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP13'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'MARA-MEINS'

record-meins.

perform bdc_field using 'MARC-EKGRP'

record-ekgrp.

perform bdc_field using 'MARC-DISMM'

record-dismm.

perform bdc_field using 'MARC-DISPO'

record-dispo.

perform bdc_field using 'BDC_CURSOR'

'MARC-DISLS'.

perform bdc_field using 'MARC-DISLS'

record-disls.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'SP14'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'MARC-BESKZ'

record-beskz.

perform bdc_field using 'BDC_CURSOR'

'MARC-FHORI'.

perform bdc_field using 'MARC-FHORI'

record-fhori.

perform bdc_field using 'MARC-DZEIT'

record-dzeit.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP15'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'MARC-PERKZ'

record-perkz.

perform bdc_field using 'BDC_CURSOR'

'MARC-MTVFP'.

perform bdc_field using 'MARC-MTVFP'

record-mtvfp.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP19'.

perform bdc_field using 'BDC_CURSOR'

'MAKT-MAKTX'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP20'.

perform bdc_field using 'BDC_CURSOR'

'MAKT-MAKTX'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'MARA-MEINS'

record-meins.

perform bdc_field using 'MARA-IPRKZ'

record-iprkz.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=SP23'.

perform bdc_field using 'BDC_CURSOR'

'MAKT-MAKTX'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_dynpro using 'SAPLMGMM' '4000'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'BDC_CURSOR'

'MAKT-MAKTX'.

perform bdc_field using 'MAKT-MAKTX'

record-maktx.

perform bdc_field using 'MARA-MEINS'

record-meins.

CALL TRANSACTION 'MM01' USING i_bdcdata MODE p_mode.

CLEAR I_BDCDATA[].

ENDLOOP.

ENDFORM. " BDC

FORM bdc_dynpro USING program dynpro.

CLEAR i_bdcdata.

i_bdcdata-program = program.

i_bdcdata-dynpro = dynpro.

i_bdcdata-dynbegin = 'X'.

APPEND i_bdcdata.

ENDFORM.

FORM bdc_field USING fnam fval.

CLEAR i_bdcdata.

i_bdcdata-fnam = fnam.

i_bdcdata-fval = fval.

APPEND i_bdcdata.

ENDFORM.

FORM ERROR_DOWNLOAD .

DATA: v_errorpath TYPE string.

v_errorpath = p_erfile.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

BIN_FILESIZE =

filename = v_errorpath

filetype = 'ASC'

APPEND = ' '

WRITE_FIELD_SEPARATOR = ' '

HEADER = '00'

TRUNC_TRAILING_BLANKS = ' '

WRITE_LF = 'X'

COL_SELECT = ' '

COL_SELECT_MASK = ' '

DAT_MODE = ' '

IMPORTING

FILELENGTH =

TABLES

data_tab = i_error

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

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.

2 REPLIES 2

MarcinPciak
Active Contributor
0 Kudos

Can't read your code, but what you need would be something like


CALL TRANSACTION ... USING bdcdata MESSAGES it_messages UPDATE ...

In messages you will have both succesfully performed steps (field MSGTYP = 'S' ) and the ones which failed (MSGTYP = 'E'),

so simply loop at that table and create error log based on that messages, then download it.

Regards

Marcin

former_member252723
Participant
0 Kudos

Solved by Myself