2008 Apr 05 4:19 AM
Hi All,
My requirement is to capture the error record and download the error record to a flat file .
I have done recording for MM01 transaction .
I am getting a problem like no error records are downloaded into the flat file .It is downloading only the empty records.
Pls see the below code which i developed & modify it for any changes .Its an urgent .Pls provide me the solution ASAP.
My Flat file
M FERT X MATL105 KG
X FERT X MATL106 KG
In the above flat file 'X' is an Industry sector which doesnot exists which is an error record that has to be captured and download it into the flat file .
Source code :
report Z_MM01_MSG_F MESSAGE-ID MSG1
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record occurs 0,
* data element: MBRSH
MBRSH_001(001),
* data element: MTART
MTART_002(004),
* data element: XFELD
KZSEL_01_003(001),
* data element: MAKTX
MAKTX_004(040),
* data element: MEINS
MEINS_005(003),
* data element: MTPOS_MARA
MTPOS_MARA_006(004),
end of record.
*-----------------------------------------------------------------
*DECLARATION OF BDCDATA STRUCTURE
*-----------------------------------------------------------------
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE .
*-----------------------------------------------------------------
*declaration to store the message
*------------------------------------------------------------------
DATA: IT_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE .
*-----------------------------------------------------------------
*DECLARATION TO STORE THE MESSAGE
*-----------------------------------------------------------------
DATA: BEGIN OF IT_STORE_MSG OCCURS 0,
STORE(1000),
END OF IT_STORE_MSG.
*-----------------------------------------------------------------
*declaration SUCCESS MESG
*------------------------------------------------------------------
DATA: BEGIN OF IT_SUCCESS OCCURS 0,
SUCCESS_REC(10),
MBRSH(10),
TABIX LIKE SY-TABIX,
END OF IT_SUCCESS.
*-----------------------------------------------------------------
*declaration ERROR MESSAGE
*------------------------------------------------------------------
DATA: BEGIN OF IT_ERROR OCCURS 0,
ERROR_REC(10),
MBRSH(10),
TABIX LIKE SY-TABIX,
END OF IT_ERROR.
DATA:TABIX LIKE SY-TABIX.
*------------------------------------------------------------------
*validating Material type(mtart) field data with table T134
*------------------------------------------------------------------
data : v_type like T134-mtart.
DATA: V_INDSECT LIKE MARA-MBRSH.
*** End generated data section ***
start-of-selection.
CALL FUNCTION 'UPLOAD'
* EXPORTING
* CODEPAGE = ' '
* FILENAME = ' '
* FILETYPE = ' '
* ITEM = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* LINE_EXIT = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* SILENT = 'S'
* IMPORTING
* FILESIZE =
* CANCEL =
* ACT_FILENAME =
* ACT_FILETYPE =
TABLES
data_tab = record
* 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.
*perform open_dataset using dataset.
perform open_group.
LOOP AT RECORD.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
*---------------------------------------------------------------
*- Validating industry sector(MBRSH) from the master table(MARA)
*---------------------------------------------------------------
select single MBRSH from T137 into V_INDSECT where MBRSH eq
record-MBRSH_001.
IF SY-SUBRC EQ 0.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_001.
*endif.
perform bdc_field using 'RMMG1-MTART'
record-MTART_002.
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)'
record-KZSEL_01_003.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_004.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
record-MEINS_005.
perform bdc_field using 'MARA-MTPOS_MARA'
record-MTPOS_MARA_006.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM01'.
*ELSE.
*message E000 WITH 'Industry sector does not Exist' .
*endif.
LOOP AT MESSTAB.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = MESSTAB-MSGID
LANG = MESSTAB-MSGSPRA
NO = MESSTAB-MSGNR
V1 = MESSTAB-MSGV1
V2 = MESSTAB-MSGV2
* V3 = SY-MSGV3
* V4 = SY-MSGV4
IMPORTING
MSG = IT_STORE_MSG-STORE
EXCEPTIONS
* NOT_FOUND = 1
OTHERS = 0.
IF MESSTAB-MSGTYP = 'S'.
IT_SUCCESS-SUCCESS_REC = IT_STORE_MSG-STORE.
IT_SUCCESS-MBRSH = record-MBRSH_001.
IT_SUCCESS-TABIX = TABIX.
APPEND IT_SUCCESS.
ELSEIF MESSTAB-MSGTYP = 'E'.
IT_ERROR-ERROR_REC = IT_STORE_MSG-STORE.
IT_ERROR-MBRSH = record-MBRSH_001.
IT_ERROR-TABIX = TABIX.
APPEND IT_ERROR.
ENDIF.
endloop.
endif.
ENDLOOP.
CALL FUNCTION 'DOWNLOAD'
TABLES
DATA_TAB = IT_error
* FIELDNAMES =
* EXCEPTIONS
* INVALID_FILESIZE = 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.
perform close_group.
*perform close_dataset using dataset.
Code Formatted by: Alvaro Tejada Galindo on Apr 9, 2008 5:05 PM
2008 Apr 09 7:06 PM
Hi,
DATA: IT_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE .
CALL FUNCTION 'DOWNLOAD'
TABLES
DATA_TAB = IT_error
FIELDNAMES =
EXCEPTIONS
INVALID_FILESIZE = 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.
instead of using IT_error ion tables use IT_MESSTAB.
<REMOVED BY MODERATOR>
Code Formatted by: Alvaro Tejada Galindo on Apr 9, 2008 5:07 PM
Hi All,
My requirement is to capture the error record and download the error record to a flat file .
I have done recording for MM01 transaction .
I am getting a problem like no error records are downloaded into the flat file .It is downloading only the empty records.
Pls see the below code which i developed & modify it for any changes .Its an urgent .Pls provide me the solution ASAP.
My Flat file
M FERT X MATL105 KG
X FERT X MATL106 KG
In the above flat file 'X' is an Industry sector which doesnot exists which is an error record that has to be captured and download it into the flat file .
Source code :
report Z_MM01_MSG_F MESSAGE-ID MSG1
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record occurs 0,
* data element: MBRSH
MBRSH_001(001),
* data element: MTART
MTART_002(004),
* data element: XFELD
KZSEL_01_003(001),
* data element: MAKTX
MAKTX_004(040),
* data element: MEINS
MEINS_005(003),
* data element: MTPOS_MARA
MTPOS_MARA_006(004),
end of record.
*-----------------------------------------------------------------
*DECLARATION OF BDCDATA STRUCTURE
*-----------------------------------------------------------------
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE .
*-----------------------------------------------------------------
*declaration to store the message
*------------------------------------------------------------------
DATA: IT_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE .
*-----------------------------------------------------------------
*DECLARATION TO STORE THE MESSAGE
*-----------------------------------------------------------------
DATA: BEGIN OF IT_STORE_MSG OCCURS 0,
STORE(1000),
END OF IT_STORE_MSG.
*-----------------------------------------------------------------
*declaration SUCCESS MESG
*------------------------------------------------------------------
DATA: BEGIN OF IT_SUCCESS OCCURS 0,
SUCCESS_REC(10),
MBRSH(10),
TABIX LIKE SY-TABIX,
END OF IT_SUCCESS.
*-----------------------------------------------------------------
*declaration ERROR MESSAGE
*------------------------------------------------------------------
DATA: BEGIN OF IT_ERROR OCCURS 0,
ERROR_REC(10),
MBRSH(10),
TABIX LIKE SY-TABIX,
END OF IT_ERROR.
DATA:TABIX LIKE SY-TABIX.
*------------------------------------------------------------------
*validating Material type(mtart) field data with table T134
*------------------------------------------------------------------
data : v_type like T134-mtart.
DATA: V_INDSECT LIKE MARA-MBRSH.
*** End generated data section ***
start-of-selection.
CALL FUNCTION 'UPLOAD'
* EXPORTING
* CODEPAGE = ' '
* FILENAME = ' '
* FILETYPE = ' '
* ITEM = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* LINE_EXIT = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* SILENT = 'S'
* IMPORTING
* FILESIZE =
* CANCEL =
* ACT_FILENAME =
* ACT_FILETYPE =
TABLES
data_tab = record
* 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.
*perform open_dataset using dataset.
perform open_group.
LOOP AT RECORD.
perform bdc_dynpro using 'SAPLMGMM' '0060'.
perform bdc_field using 'BDC_CURSOR'
'RMMG1-MATNR'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
*---------------------------------------------------------------
*- Validating industry sector(MBRSH) from the master table(MARA)
*---------------------------------------------------------------
select single MBRSH from T137 into V_INDSECT where MBRSH eq
record-MBRSH_001.
IF SY-SUBRC EQ 0.
perform bdc_field using 'RMMG1-MBRSH'
record-MBRSH_001.
*endif.
perform bdc_field using 'RMMG1-MTART'
record-MTART_002.
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)'
record-KZSEL_01_003.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_004.
perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
perform bdc_field using 'MARA-MEINS'
record-MEINS_005.
perform bdc_field using 'MARA-MTPOS_MARA'
record-MTPOS_MARA_006.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
perform bdc_transaction using 'MM01'.
*ELSE.
*message E000 WITH 'Industry sector does not Exist' .
*endif.
LOOP AT MESSTAB.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = MESSTAB-MSGID
LANG = MESSTAB-MSGSPRA
NO = MESSTAB-MSGNR
V1 = MESSTAB-MSGV1
V2 = MESSTAB-MSGV2
* V3 = SY-MSGV3
* V4 = SY-MSGV4
IMPORTING
MSG = IT_STORE_MSG-STORE
EXCEPTIONS
* NOT_FOUND = 1
OTHERS = 0.
IF MESSTAB-MSGTYP = 'S'.
IT_SUCCESS-SUCCESS_REC = IT_STORE_MSG-STORE.
IT_SUCCESS-MBRSH = record-MBRSH_001.
IT_SUCCESS-TABIX = TABIX.
APPEND IT_SUCCESS.
ELSEIF MESSTAB-MSGTYP = 'E'.
IT_ERROR-ERROR_REC = IT_STORE_MSG-STORE.
IT_ERROR-MBRSH = record-MBRSH_001.
IT_ERROR-TABIX = TABIX.
APPEND IT_ERROR.
ENDIF.
endloop.
endif.
ENDLOOP.
CALL FUNCTION 'DOWNLOAD'
TABLES
DATA_TAB = IT_error
* FIELDNAMES =
* EXCEPTIONS
* INVALID_FILESIZE = 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.
perform close_group.
*perform close_dataset using dataset.
Code Formatted by: Alvaro Tejada Galindo on Apr 9, 2008 5:05 PM
2008 Apr 09 7:06 PM
Hi,
DATA: IT_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE .
CALL FUNCTION 'DOWNLOAD'
TABLES
DATA_TAB = IT_error
FIELDNAMES =
EXCEPTIONS
INVALID_FILESIZE = 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.
instead of using IT_error ion tables use IT_MESSTAB.
<REMOVED BY MODERATOR>
Code Formatted by: Alvaro Tejada Galindo on Apr 9, 2008 5:07 PM