‎2006 Jan 31 3:08 PM
Hi All,
I have one typical BDC problem. If the number of records in file are crossing 80,my bdc is giving problem .So I need to split total records into sets of 80 and submit them. So I need to create the session name dynamically, pass the data dynamically. IF you have example code or know the procedure as how to proceed kindly inform me
Regards
Praveen
‎2006 Jan 31 3:16 PM
Hi Praveen,
Set a counter for no of records in your internal table.
When the count reaches 80 ,close the current session and insert new session.
Your session name should be dyanamic .concatenate with a counter at the end of the session name and pass it to function module.
loop at i_file.
i_cnt = i_cnt + 1.
if i_cnt = 80.
clear i_cnt.
call function 'BDC_CLOSE_GROUP'.
Open new session with new group
v_group = groupname and counter
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt
group = v_group
endif.
endloop.
endloop.
Hope this helps.
Regards,
Sudheer
‎2006 Jan 31 3:16 PM
Hi Praveen,
Set a counter for no of records in your internal table.
When the count reaches 80 ,close the current session and insert new session.
Your session name should be dyanamic .concatenate with a counter at the end of the session name and pass it to function module.
loop at i_file.
i_cnt = i_cnt + 1.
if i_cnt = 80.
clear i_cnt.
call function 'BDC_CLOSE_GROUP'.
Open new session with new group
v_group = groupname and counter
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt
group = v_group
endif.
endloop.
endloop.
Hope this helps.
Regards,
Sudheer
‎2006 Jan 31 5:25 PM
There should be no problem creating a session with more than 80 records. Or are you creating a header record with more than 80 detail lines?
Rob
‎2006 Feb 01 7:53 AM
Hi Bob,
I'm doing BDC for KB31N tcode,where i have two items in header(doc date, posting date).Multiple line items(each line item should consists of 4 fields namely cost center,statistical key figure,total qty,text).
When i'm sending more than 80 rec records i'm being populated an error message "BDC_Close_group, session not opened"
Kindly advice me how to handle this
‎2006 Feb 01 2:16 PM
I think the problem is in the logic of looping through your data and creating the BDC session - not the number of records being passed. May we please see your code?
Rob
‎2006 Feb 01 8:07 AM
Try using report RSBDCSUB to start BDC session I guess you will not face this 80 restriction problem wid that...
Else you can also use report RSBDCSUB to open multiple sessions of 80 records each ...
the solution using BDC_CLOSE_GROUP AND OPEN_GROUP has already been suggested to u.
regards,
Sumeet Mishra
‎2006 Feb 01 3:10 PM
Hi Rob,
Please find my code below..
Part of the variables are in Polish since the original developer is a polish guy..
Praveen
Code.
*&----
*
*& Report ZCO_I025_WSKAZNIKI_STAT_DEV *
*& *
*&----
*
*& *
*& Interfejs wczytywania wskaźników statystycznych *
*& *
*&----
*
REPORT zco_i025_wskazniki_stat_dev .
TYPES:
BEGIN OF l_tab_dane,
indic LIKE rk23f-stagr,
quant LIKE rk23f-mbgbtr,
mpk LIKE rk23f-ekostl,
order LIKE rk23f-eaufnr,
text LIKE rk23f-sgtxt,
END OF l_tab_dane.
DATA:
it_excel TYPE TABLE OF alsmex_tabline,
wa_excel TYPE alsmex_tabline,
it_data TYPE TABLE OF l_tab_dane,
wa_data TYPE l_tab_dane,
error TYPE C,
msg TYPE string.
DATA:
iv_pole TYPE string,
ddatum(10),
kdatum(10),
*Inserted By satyam Developer
filelist TYPE filetable,
rc TYPE i.
DATA: BEGIN OF bdctab OCCURS 5.
INCLUDE STRUCTURE bdcdata.
DATA: END OF bdctab.
SELECTION-SCREEN BEGIN OF BLOCK p1 WITH FRAME TITLE text-001.
PARAMETERS:
p_zakla LIKE tka01-kokrs DEFAULT '1000',
p_ddate LIKE sy-datum DEFAULT sy-datum,
p_kdate LIKE sy-datum DEFAULT sy-datum.
SELECTION-SCREEN ULINE.
PARAMETERS:
p_fname LIKE rlgrap-filename. " DEFAULT 'd:dane.xls'.
SELECTION-SCREEN END OF BLOCK p1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
file_filter = cl_gui_frontend_services=>filetype_excel
multiselection = 'X'
CHANGING
file_table = filelist
rc = rc.
IF LINES( filelist ) IS INITIAL.
EXIT.
ENDIF.
READ TABLE filelist INDEX 1 INTO p_fname.
START-OF-SELECTION.
AUTHORITY-CHECK OBJECT 'TKA01'
ID 'KOKRS' FIELD p_zakla.
CONCATENATE p_ddate6(2) '.' p_ddate4(2) '.' p_ddate(4) INTO ddatum.
CONCATENATE p_kdate6(2) '.' p_kdate4(2) '.' p_kdate(4) INTO kdatum.
error = '0'.
PERFORM wczytaj_dane.
IF error = '0'.
PERFORM utworz_sesje.
PERFORM wprowadz_dane.
PERFORM zamknij_sesje. "comment by prav
ENDIF.
PERFORM zamknij_sesje. "add by prav
IF error = '1'.
WRITE: msg, /.
ENDIF.
WRITE: 'Wykonano', /.
*&----
*
*& Form wczytaj_dane
*&----
*
text
*----
*
FORM wczytaj_dane.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = 1
i_begin_row = 1
i_end_col = 8
i_end_row = 65000
TABLES
intern = it_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / 'Bład importu pliku wejsciowego: ', p_fname, ' - ',
sy-subrc.
ELSE.
SORT it_excel BY row col.
LOOP AT it_excel INTO wa_excel.
IF wa_excel-row = 1.
CONTINUE.
ENDIF.
iv_pole = wa_excel-value.
CASE wa_excel-col.
WHEN 1. wa_data-indic = iv_pole.
WHEN 2.
REPLACE ',' WITH '.' INTO iv_pole.
wa_data-quant = iv_pole.
WHEN 3. wa_data-mpk = iv_pole.
WHEN 4. wa_data-order = iv_pole.
WHEN 5. wa_data-text = iv_pole.
ENDCASE.
AT END OF row.
IF wa_data-mpk IS INITIAL AND wa_data-order IS INITIAL.
error = '1'.
WRITE:
'Musi być podane Stanowisko kosztów lub Zlecenie wewnętrzne. Rekord: ',
wa_excel-row, /.
EXIT.
ENDIF.
IF wa_data-mpk IS NOT INITIAL AND wa_data-order IS NOT INITIAL.
error = '1'.
WRITE:
'Musi być podane Stanowisko kosztów lub Zlecenie wewnętrzne. Rekord: ',
wa_excel-row, /.
EXIT.
ENDIF.
IF wa_data-indic IS INITIAL.
error = '1'.
WRITE: 'Brak identyfikatora wskaźnika. Rekord: ', wa_excel-row
, /.
EXIT.
ENDIF.
IF wa_data-quant IS INITIAL.
error = '1'.
WRITE: 'Brak informacji o ilości. Rekord: ', wa_excel-row, /.
EXIT.
ENDIF.
APPEND wa_data TO it_data.
CLEAR wa_data.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. "wczytaj_dane
*&----
*
*& Form wprowadz_dane
*&----
*
text
*----
*
FORM wprowadz_dane.
DATA:
licznik TYPE i,
l_txt TYPE string,
pole(30) TYPE c,
liczba(15) TYPE c.
***********************************************************************
*****
LOOP AT it_data into wa_data.
PERFORM bdc_dynpro USING 'SAPLSPO4' '0300'.
PERFORM bdc_field USING 'BDC_CURSOR' 'SVALD-VALUE(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=FURT'.
PERFORM bdc_field USING 'SVALD-VALUE(01)' p_zakla.
***********************************************************************
*****
PERFORM bdc_dynpro USING 'SAPLK23F1' '1200'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM bdc_field USING 'COHEADER-SEND_REC_REL' '03SAP'.
PERFORM bdc_field USING 'RK23F-STATUS' 'L'.
PERFORM bdc_field USING 'COHEADER-BLDAT' ddatum.
PERFORM bdc_field USING 'COHEADER-BUDAT' kdatum.
PERFORM bdc_field USING 'BDC_CURSOR' 'EKOSTL(1)'.
licznik = 0.
************************************************************************
******
LOOP AT it_data into wa_data.
ADD 1 TO licznik.
l_txt = licznik.
CONCATENATE 'EL4(' l_txt ')' INTO pole.
condense pole no-gaps.
PERFORM bdc_field USING pole wa_data-indic.
CONCATENATE 'ELR1(' l_txt ')' INTO pole.
condense pole no-gaps.
liczba = wa_data-quant.
if liczba < 0.
shift liczba circular left up to '-'.
endif.
condense liczba no-gaps.
PERFORM bdc_field USING pole liczba.
IF NOT wa_data-mpk IS INITIAL.
CONCATENATE 'EL2(' l_txt ')' INTO pole.
condense pole no-gaps.
PERFORM bdc_field USING pole wa_data-mpk.
ENDIF.
IF NOT wa_data-order IS INITIAL.
CONCATENATE 'EL3(' l_txt ')' INTO pole.
condense pole no-gaps.
PERFORM bdc_field USING pole wa_data-order.
ENDIF.
CONCATENATE 'EL8(' l_txt ')' INTO pole.
condense pole no-gaps.
PERFORM bdc_field USING pole wa_data-text.
call transaction 'KB31N' using bdctab mode 'A'.
refresh:bdctab.
clear bdctab.
ENDLOOP.
************************************************************************
******
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'KB31N'
TABLES
dynprotab = bdctab
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.
WRITE: / text-010 .
ENDIF.
call transaction 'KB31N' using bdctab mode 'A'.
************************************************************************
*******
REFRESH bdctab.
clear:bdctab. "by praveen
ENDFORM. "wprowadz_dane
*&----
*
*& Form bdc_dynpro
*&----
*
text
*----
*
-->PROGRAM text
-->DYNPRO text
*----
*
FORM bdc_dynpro USING program dynpro.
CLEAR bdctab.
MOVE:
program TO bdctab-program,
dynpro TO bdctab-dynpro,
'X' TO bdctab-dynbegin.
APPEND bdctab.
ENDFORM. "bdc_dynpro
*&----
*
*& Form bdc_field
*&----
*
text
*----
*
-->POLE text
-->WARTOSC text
*----
*
FORM bdc_field USING pole wartosc.
CLEAR bdctab.
MOVE:
pole TO bdctab-fnam,
wartosc TO bdctab-fval.
APPEND bdctab.
ENDFORM. "bdc_field
*&----
*
*& Form utworz_sesje
*&----
*
text
*----
*
FORM utworz_sesje.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = 'WSKASTAT'
user = sy-uname
keep = 'X'.
**begin of praveen
*if sy-subrc ne 0.
write 'hai'.
endif.
**end of praveen
ENDFORM. "utworz_sesje
*&----
*
*& Form zamknij_sesje
*&----
*
text
*----
*
FORM zamknij_sesje.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
IF sy-subrc NE 0.
WRITE: /, 'Bład podczas zamykania sesji'.
EXIT.
ENDIF.
ENDFORM. "zamknij_sesje
‎2009 Jan 19 2:17 PM
run in background mode. go to se38->Program( menu)->execute->background.