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: 

BDC Report

Former Member
0 Kudos

Hi,

After executing my BDC Prgram, im getting a result screen..

insted of this i need to save the report in my sys..

how can i do it.. please lettme know any sample code..

Thanks

Hema

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Hema,

You can use my program ....You need to change the following in my program

Change the structure of an Internal Table and use your structure of Flat file.

Change the recording, Transcation code and the Write message ...

IF SY-SUBRC <> 0.

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

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

WRITE : / 'MATERIAL DSC: ', W_UPLOAD-MAKTX , L_MSG .

This will answer your question

report Z24_CALL_TRANS_MM01

no standard page heading line-size 255.

&----


&

*& STRUCTURE DECLARATION SOURCE INTERNAL TABLE

&----


&

TYPES : BEGIN OF TY_UPLOAD ,

MBRSH TYPE RMMG1-MBRSH ,

MTART TYPE RMMG1-MTART ,

MAKTX TYPE MAKT-MAKTX ,

MEINS TYPE MARA-MEINS ,

END OF TY_UPLOAD .

&----


&

*& DECLARATION OF INTERNAL TABLE

&----


&

DATA :T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD INITIAL SIZE 0 ,

T_BDCDATA TYPE STANDARD TABLE OF BDCDATA INITIAL SIZE 0 ,

  • INTERNAL TABEL; ERROR HANDLING

T_BDCMSG TYPE STANDARD TABLE OF BDCMSGCOLL ,

T_ERROR TYPE STANDARD TABLE OF TY_UPLOAD INITIAL SIZE 0 ,

&----


&

*& DECLARATION OF WORK AREA

&----


&

W_UPLOAD TYPE TY_UPLOAD ,

W_BDCDATA TYPE BDCDATA ,

W_BDCMSG TYPE BDCMSGCOLL .

&----


&

*& DECLARATION OF SELECTION-SCREEN .

&----


&

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

PARAMETERS : P_FNAME TYPE FILENAME .

SELECTION-SCREEN END OF BLOCK B1 .

&----


&

*& START-OF-SELECTION

&----


&

START-OF-SELECTION .

  • UPLOAD THE DATA

PERFORM SUB_UPLOAD_DATA .

  • POPULATE BDCDATA

PERFORM SUB_POPULATE_BDC .

  • PROCESSING ERROR RECORDS

PERFORM SUB_ERROR_REC .

&----


*& Form SUB_UPLOAD_DATA

&----


  • THIS IS SUB-ROUTINE USED TO UPLOAD THE DATA TO INTERNAL TABLE

----


FORM SUB_UPLOAD_DATA .

DATA : L_FNAME TYPE STRING .

L_FNAME = P_FNAME .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = L_FNAME

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_UPLOAD

.

IF SY-SUBRC <> 0.

ENDIF.

ENDFORM. " SUB_UPLOAD_DATA

&----


*& Form SUB_POPULATE_BDC

&----


  • THIS IS SUB-ROUTINE IS USED TO POPULATE THE DATA IN BDC

----


DATA : L_MSG TYPE STRING .

FORM SUB_POPULATE_BDC .

LOOP AT T_UPLOAD INTO W_UPLOAD .

REFRESH T_BDCDATA .

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RMMG1-MBRSH'

W_UPLOAD-MBRSH.

perform bdc_field using 'RMMG1-MTART'

W_UPLOAD-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'

'/00'.

perform bdc_field using 'MAKT-MAKTX'

W_UPLOAD-MAKTX.

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

W_UPLOAD-MEINS.

perform bdc_field using 'MARA-MTPOS_MARA'

'ZMUS'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

CALL TRANSACTION 'MM01' USING T_BDCDATA

MODE 'N'

MESSAGES INTO T_BDCMSG .

IF SY-SUBRC <> 0 .

APPEND W_UPLOAD TO T_ERROR .

ENDIF .

READ TABLE T_BDCMSG INTO W_BDCMSG INDEX 1 .

CLEAR : L_MSG .

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = W_BDCMSG-MSGID

LANG = SY-LANGU

NO = W_BDCMSG-MSGNR

V1 = W_BDCMSG-MSGV1

V2 = W_BDCMSG-MSGV2

V3 = W_BDCMSG-MSGV3

V4 = W_BDCMSG-MSGV4

IMPORTING

MSG = L_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.

WRITE : / 'MATERIAL DSC: ', W_UPLOAD-MAKTX , L_MSG .

ENDIF.

ENDLOOP .

ENDFORM. " SUB_POPULATE_BDC

----


  • Start new screen *

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR W_BDCDATA.

W_BDCDATA-PROGRAM = PROGRAM.

W_BDCDATA-DYNPRO = DYNPRO.

W_BDCDATA-DYNBEGIN = 'X'.

APPEND W_BDCDATA TO T_BDCDATA.

ENDFORM.

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

CLEAR W_BDCDATA.

W_BDCDATA-FNAM = FNAM.

W_BDCDATA-FVAL = FVAL.

APPEND W_BDCDATA TO T_BDCDATA .

ENDFORM.

&----


*& Form SUB_ERROR_REC

&----


  • text

----


FORM SUB_ERROR_REC .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:/ERROR-ME.TXT'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_ERROR

.

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

Hope the information provided was very helpful...

Thanks & Regards,

Kittu

7 REPLIES 7

praveen_kumar132
Participant
0 Kudos

Hema,

What result do you want in your system, you mean uploaded or dowloaded files. explain your requirement more clear.

Regards,

Praveen.

0 Kudos

Hi,

Actually after upload fetched up, i need a seperate report file

for uploaded and error records in text file.

thanks

Hema

0 Kudos

Hello Hema,

U need to capture the errors into a file.. right?

Using BDCMSGCOLL structure the errors can be captured.

declare one interanal table <ITAB> with this structure. and

give the <CALL TRANSACTION stmt... >like this.

CALL TRANSACTION <TCODE> USING<BDCDATA> MODE < > MESSAGES INTO <ITAB>.

after processing all records if any errors are there in your flat file those are captured into ITAB.

loop at ITAB. to know the errors.

and using FM GUI_DOWNLOAD you can download the errors into local file.

hope this will help you.

Regards

Sekhar

Edited by: sekhar on Nov 27, 2008 9:29 AM

0 Kudos

Hi ,

define the one error file internal table and collect the all error records and use the GUI_download and get the file in the desktop .

Regards,

Bharani

Former Member
0 Kudos

Hi Hema,

u mean to handle error.

Use BDC Msgcall structure.

Call FM 'format_message'.

Former Member
0 Kudos

Hello Hema,

You can use my program ....You need to change the following in my program

Change the structure of an Internal Table and use your structure of Flat file.

Change the recording, Transcation code and the Write message ...

IF SY-SUBRC <> 0.

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

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

WRITE : / 'MATERIAL DSC: ', W_UPLOAD-MAKTX , L_MSG .

This will answer your question

report Z24_CALL_TRANS_MM01

no standard page heading line-size 255.

&----


&

*& STRUCTURE DECLARATION SOURCE INTERNAL TABLE

&----


&

TYPES : BEGIN OF TY_UPLOAD ,

MBRSH TYPE RMMG1-MBRSH ,

MTART TYPE RMMG1-MTART ,

MAKTX TYPE MAKT-MAKTX ,

MEINS TYPE MARA-MEINS ,

END OF TY_UPLOAD .

&----


&

*& DECLARATION OF INTERNAL TABLE

&----


&

DATA :T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD INITIAL SIZE 0 ,

T_BDCDATA TYPE STANDARD TABLE OF BDCDATA INITIAL SIZE 0 ,

  • INTERNAL TABEL; ERROR HANDLING

T_BDCMSG TYPE STANDARD TABLE OF BDCMSGCOLL ,

T_ERROR TYPE STANDARD TABLE OF TY_UPLOAD INITIAL SIZE 0 ,

&----


&

*& DECLARATION OF WORK AREA

&----


&

W_UPLOAD TYPE TY_UPLOAD ,

W_BDCDATA TYPE BDCDATA ,

W_BDCMSG TYPE BDCMSGCOLL .

&----


&

*& DECLARATION OF SELECTION-SCREEN .

&----


&

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

PARAMETERS : P_FNAME TYPE FILENAME .

SELECTION-SCREEN END OF BLOCK B1 .

&----


&

*& START-OF-SELECTION

&----


&

START-OF-SELECTION .

  • UPLOAD THE DATA

PERFORM SUB_UPLOAD_DATA .

  • POPULATE BDCDATA

PERFORM SUB_POPULATE_BDC .

  • PROCESSING ERROR RECORDS

PERFORM SUB_ERROR_REC .

&----


*& Form SUB_UPLOAD_DATA

&----


  • THIS IS SUB-ROUTINE USED TO UPLOAD THE DATA TO INTERNAL TABLE

----


FORM SUB_UPLOAD_DATA .

DATA : L_FNAME TYPE STRING .

L_FNAME = P_FNAME .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = L_FNAME

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_UPLOAD

.

IF SY-SUBRC <> 0.

ENDIF.

ENDFORM. " SUB_UPLOAD_DATA

&----


*& Form SUB_POPULATE_BDC

&----


  • THIS IS SUB-ROUTINE IS USED TO POPULATE THE DATA IN BDC

----


DATA : L_MSG TYPE STRING .

FORM SUB_POPULATE_BDC .

LOOP AT T_UPLOAD INTO W_UPLOAD .

REFRESH T_BDCDATA .

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RMMG1-MBRSH'

W_UPLOAD-MBRSH.

perform bdc_field using 'RMMG1-MTART'

W_UPLOAD-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'

'/00'.

perform bdc_field using 'MAKT-MAKTX'

W_UPLOAD-MAKTX.

perform bdc_field using 'BDC_CURSOR'

'MARA-MEINS'.

perform bdc_field using 'MARA-MEINS'

W_UPLOAD-MEINS.

perform bdc_field using 'MARA-MTPOS_MARA'

'ZMUS'.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=YES'.

CALL TRANSACTION 'MM01' USING T_BDCDATA

MODE 'N'

MESSAGES INTO T_BDCMSG .

IF SY-SUBRC <> 0 .

APPEND W_UPLOAD TO T_ERROR .

ENDIF .

READ TABLE T_BDCMSG INTO W_BDCMSG INDEX 1 .

CLEAR : L_MSG .

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = W_BDCMSG-MSGID

LANG = SY-LANGU

NO = W_BDCMSG-MSGNR

V1 = W_BDCMSG-MSGV1

V2 = W_BDCMSG-MSGV2

V3 = W_BDCMSG-MSGV3

V4 = W_BDCMSG-MSGV4

IMPORTING

MSG = L_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.

WRITE : / 'MATERIAL DSC: ', W_UPLOAD-MAKTX , L_MSG .

ENDIF.

ENDLOOP .

ENDFORM. " SUB_POPULATE_BDC

----


  • Start new screen *

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR W_BDCDATA.

W_BDCDATA-PROGRAM = PROGRAM.

W_BDCDATA-DYNPRO = DYNPRO.

W_BDCDATA-DYNBEGIN = 'X'.

APPEND W_BDCDATA TO T_BDCDATA.

ENDFORM.

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

CLEAR W_BDCDATA.

W_BDCDATA-FNAM = FNAM.

W_BDCDATA-FVAL = FVAL.

APPEND W_BDCDATA TO T_BDCDATA .

ENDFORM.

&----


*& Form SUB_ERROR_REC

&----


  • text

----


FORM SUB_ERROR_REC .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:/ERROR-ME.TXT'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_ERROR

.

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

Hope the information provided was very helpful...

Thanks & Regards,

Kittu

Former Member
0 Kudos

Hi,

In call transaction method, if record goes for error, CALL TRANSACTION statement returns sy-subrc other than 0. Based on this, you can create another internal table with same structure of data table and add error records to this table. Later, you could use error table directly without any changing the structure because of its same structure of data table. BDCMSGCOLL table collects all messages generated during processing of that particular record. BDCMSGCOLL table data could be used to track the error description.

In session method, each record status and the messages appeared during execution can be tracked completely from SM35 transaction. You can simply download the log if required. But in this technique, you could not get error records automatically.

Hope answered your questions.

Regards,

Prasanth