06-06-2007 6:11 AM
Dear Experts,
I am running an BDC for the transaction ME2L where I enter the material, plant and vendor combination and get the Result.
Can the result of the transaction be stored in an internal table through BDC. Suppose there are 20 combinations in the file, the resultant internal table should contain the result for all the 20 combination.
My client wants the result of the 20 combinations into an Excel sheet for review. Please suggest if storing the result into an internal table is possible? If yes, how do i go about it?
Thanks in Advance
Regards,
Prashant Kamat
06-06-2007 6:14 AM
check sy-subrc after call transaction.
Then add the internal table data into one more internal table call result. After finishing the BDC download the result table data.
06-06-2007 6:19 AM
please got through this. any doubt revert back.
Text Elements
001 : Select Options
002 : C:\SD\Error\Discount-ZSWD
003 : Error Download Path
004 : C:\SD\Error\Discount-ZSWD - DDMMYYYY HH:MM:SS.txt
***********************************************************************
REPORT ZSD_CONDREC_DISCOUNT_ZSWD
MESSAGE-ID 00.
*include bdcrecx1.
TABLES : t100.
************************************************************************
Internal table declaration *
************************************************************************
DATA : BEGIN OF it_price OCCURS 0,
index(4), "Index
kschl(4), "Condition type
vkorg(4), "Sales organization
vtweg(2), "distribution channel
spart(2), "Division
matnr(18), "Material no
kbetr(11), "Rate
konwa(5), "Rate unit (currency or percentage)
kmein(3), "Condition unit
krech(1), "Calculation type for condition
datab(10), "Validity start date
datbi(10), "Validity end date
er_message(100),
END OF it_price.
************************************************************************
Internal table to get the error data *
************************************************************************
DATA : it_error LIKE it_price OCCURS 0 WITH HEADER LINE.
DATA : bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA : i_msgtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
************************************************************************
Internal table to find the error from the legacy data *
************************************************************************
DATA : BEGIN OF it_erfind OCCURS 0,
index(4), "Index
er_message(100), "For Error Message
END OF it_erfind.
************************************************************************
Variables declaration *
************************************************************************
DATA : g_message(200),
time(10),
date(10) ,
v_error_filename LIKE rlgrap-filename.
date = sy-datum.
time = sy-uzeit.
************************************************************************
Initialization
************************************************************************
INITIALIZATION.
Generating Error file name with date and time.
PERFORM make_file_name.
************************************************************************
Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER: p_file LIKE ibipparms-path OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) text-003.
SELECTION-SCREEN COMMENT 33(79) text-004.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN:END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .
PERFORM get_filename.
************************************************************************
Start of selection
************************************************************************
START-OF-SELECTION.
PERFORM upload_data.
PERFORM fill_data.
END-OF-SELECTION.
&----
*& Form fill_data
&----
text
----
FORM fill_data.
LOOP AT it_price.
*Start of Screen 1
PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV13A-KSCHL'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ANTA'.
PERFORM bdc_field USING 'RV13A-KSCHL'
it_price-kschl.
***********************************************************************
Key Combination: Sales org / Dist. channel / Division / Material
***********************************************************************
PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV130-SELKZ(03)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=WEIT'.
PERFORM bdc_field USING 'RV130-SELKZ(03)'
'X'.
*Start of Screen 2
PERFORM bdc_dynpro USING 'SAPMV13A' '1800'.
PERFORM bdc_field USING 'KOMG-VKORG'
it_price-vkorg.
PERFORM bdc_field USING 'KOMG-VTWEG'
it_price-vtweg.
PERFORM bdc_field USING 'KOMG-SPART'
it_price-spart.
PERFORM bdc_field USING 'KOMG-MATNR(01)'
it_price-matnr.
PERFORM bdc_field USING 'KONP-KBETR(01)'
it_price-kbetr.
PERFORM bdc_field USING 'KONP-KONWA(01)'
it_price-konwa.
PERFORM bdc_field USING 'KONP-KMEIN(01)'
it_price-kmein.
PERFORM bdc_field USING 'RV13A-KRECH(01)'
it_price-krech.
PERFORM bdc_field USING 'RV13A-DATAB(01)'
it_price-datab.
PERFORM bdc_field USING 'RV13A-DATBI(01)'
it_price-datbi.
perform bdc_dynpro using 'SAPMV13A' '1821'.
perform bdc_field using 'BDC_CURSOR'
'KOMG-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SICH'. "Save the entry
PERFORM bdc_transaction TABLES i_msgtab USING 'VK11' 'N' 'L'.
************************************************************************
*To fetch the error message from the standard error table
************************************************************************
SELECT SINGLE * FROM t100 WHERE sprsl = 'E'
AND arbgb = sy-msgid
AND msgnr = sy-msgno.
g_message = t100-text.
***********************************************************************
*subroutine to change the error message for every document number
***********************************************************************
PERFORM replace_parameters USING sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4
CHANGING g_message.
WRITE: / 'System variables:'.
SKIP.
WRITE: / ' Sy-msgty:', sy-msgty.
WRITE: / ' Sy-msgid:', sy-msgid.
WRITE: / ' Sy-msgno:', sy-msgno.
WRITE: / ' Sy-msgv1:', sy-msgv1.
WRITE: / ' Sy-msgv2:', sy-msgv2.
WRITE: / ' Sy-msgv3:', sy-msgv3.
WRITE: / ' Sy-msgv4:', sy-msgv4.
SKIP.
WRITE: / 'Message:'.
SKIP.
WRITE: / sy-msgty, g_message.
************************************************************************
*To find out the error in the legacy data if there is anything and pass
*the document no with error message to the seperate internal table
*called it_erfind
************************************************************************
IF sy-msgty = 'E'.
it_erfind-index = it_price-index.
it_erfind-er_message = g_message.
APPEND it_erfind.
ENDIF.
*Finally we are segregating the error and downloading the error data.
----
AT LAST.
*To segregate the error
----
PERFORM segregate_error.
*To download the error from it_error internal table with err mesg
----
PERFORM error_download.
PERFORM display_message.
ENDAT.
ENDLOOP.
perform close_group.
CLEAR it_price.
ENDFORM. "fill_data
*Subrotine to replace the parameters
----
FORM replace_parameters USING p_par_1 p_par_2 p_par_3
p_par_4 CHANGING p_message.
erst mal pruefen, ob numerierte Parameter verwendet wurden
----
DO.
REPLACE '&1' WITH p_par_1 INTO p_message.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH p_par_2 INTO p_message.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH p_par_3 INTO p_message.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH p_par_4 INTO p_message.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDDO.
falls keine numerierten Parameter vorh., ersetzen wie gehabt
----
REPLACE '&' WITH p_par_1 INTO p_message.
CONDENSE p_message.
IF sy-subrc EQ 0.
REPLACE '&' WITH p_par_2 INTO p_message.
CONDENSE p_message.
IF sy-subrc EQ 0.
REPLACE '&' WITH p_par_3 INTO p_message.
CONDENSE p_message.
IF sy-subrc EQ 0.
REPLACE '&' WITH p_par_4 INTO p_message.
CONDENSE p_message.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. "REPLACE_PARAMETERS
*Subroutine to segregate the error data from the legacy data
----
FORM segregate_error.
LOOP AT it_erfind.
LOOP AT it_price WHERE index = it_erfind-index.
MOVE-CORRESPONDING it_price TO it_error.
it_error-er_message = it_erfind-er_message.
APPEND it_error.
ENDLOOP.
ENDLOOP.
ENDFORM. "segregate_error
********************************************************************
*Subroutine to download the error data from the it_error table.
********************************************************************
FORM error_download.
IF it_error[] IS NOT INITIAL.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
codepage = 'IBM'
filename = v_error_filename
filetype = 'DAT'
TABLES
data_tab = it_error.
ENDIF.
ENDFORM. "error_download
----
Start new screen *
----
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "BDC_DYNPRO
----
Insert field *
----
FORM bdc_field USING fnam fval.
IF FVAL <> NODATA.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
&----
*& Form bdc_transaction
&----
text
----
-->MESSTAB text
-->TCODE text
-->CTUMODE text
-->CUPDATE text
----
FORM bdc_transaction TABLES messtab USING tcode ctumode cupdate .
CALL TRANSACTION tcode USING bdcdata
MODE ctumode
UPDATE cupdate
MESSAGES INTO messtab.
REFRESH bdcdata.
CLEAR bdcdata.
ENDFORM. " bdc_transaction
********************************************************************
Uploading data file to internal table. *
********************************************************************
FORM upload_data.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = p_file
CODEPAGE = 'IBM '
filetype = 'DAT'
TABLES
data_tab = it_price
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. "upload_data
&----
*& Form display_message
&----
FORM display_message .
IF it_error[] IS INITIAL.
MESSAGE i019(zmsg). "Success
ELSE.
MESSAGE e020(zmsg). "Failed
ENDIF.
ENDFORM. " display_message
&----
*& Form get_filename
&----
text
----
--> p1 text
<-- p2 text
----
FORM get_filename .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
FIELD_NAME = p_file
IMPORTING
file_name = p_file .
IF sy-subrc NE 0 .
WRITE : / 'Enter File Name'.
ENDIF.
ENDFORM. " get_filename
&----
*& Form make_file_name
&----
FORM make_file_name .
WRITE sy-datum TO date MM/DD/YYYY.
WRITE sy-uzeit TO time USING EDIT MASK ' __ __ __'.
CONCATENATE text-002 date time '.txt'
INTO v_error_filename.
ENDFORM. " make_file_name
regards
prabhu
06-06-2007 6:22 AM
Hi,
ME2L is a report. You dont need to do a BDC. Use Submit statement and pass the selection screen values. Results can be exported to memory using the same statement.
SUBMIT <program name> USING SELECTION-SCREEN '1000'
WITH <parameter Values> EXPORTING LIST TO MEMORY
AND RETURN.
Then you can FM LIST_FROM_MEMORY and import results. This can then be downloaded to XL.
Regards,
Ram