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: 

Handling sessions in BDC

Former Member
0 Kudos

Hi all,

What do we code to create a new session in BDC Call transaction method.

Let me explain the situation in brief.

I have an issue where in i need to upload 5000 records. As per requirement i am supposed to upload only 1000 per session. Please let me know how to create new session dynamically and move the processed data to sessions. And also let me know how to handle the errors in those records after processing 500 records.

I know that Message_format is the FM to know to errors but I need to handle them dynamically.

Guess we need to go by session method to handle errors but how to do that dynamically.

Thanks and Regards

Amit.

4 REPLIES 4

Former Member
0 Kudos

Guys am still waiting. Please reply.

Amit

Former Member
0 Kudos

Amit,

You will have to implement logic in your loop that you genernate a BDC session for every 1000 records. So, have a counter and when it reaches 1000, do a CALL TRANSACITON. Keep accumulating your messages a in separate table.

Now, refresh the BDCDATA table and repeat the process agian.

Regards,

Ravi

Note : Please mark the helpful answers

former_member184569
Active Contributor
0 Kudos

Hi Amit,

Suppose all your records are in table infile.

Keep a counter such that when each record in the table is processed, the counter is incremented.

When 1000 records are processed, call the insert bdc function. Reset the function.

Thus dynamically you create 5 sessions if there are five records.

In the following table, I am creating bdc sessions for the transaction FBV1. It has two screens.

1000 for the first screen(header details) and 3000 for all other records(line item details)

LOOP AT infile.

PERFORM create_bdc.

ENDLOOP.

IF abend_job = false.

PERFORM format_scrn_0300_last.

PERFORM insert_bdcdata.

ENDIF.

*----


form create_bdc.

sy-subrc = 0.

IF new_bdc EQ true.

PERFORM open_bdc.

IF abend_job = true.

EXIT.

ENDIF.

ENDIF.

IF first_time = true.

CLEAR ba_cnt_tab.

PERFORM format_scrn_0100. /* to process first screen

PERFORM format_break_fields.

ELSEIF detail_rec_cnt = 999. /* When the number of records is 999 process the last record and insert the session

PERFORM format_scrn_0300_last.

PERFORM insert_bdcdata.

IF abend_job = false.

MOVE: true TO bdc_tab_created.

PERFORM format_scrn_0100. /* Again call the header screen and put the header details.

PERFORM format_break_fields.

ENDIF.

ELSE.

PERFORM format_scrn_0300_detail. /* Processing of Details records otherwise.

PERFORM format_break_fields.

ENDIF.

IF abend_job = false.

IF first_time = true.

MOVE: true TO bdc_tab_created,

false TO first_time.

ENDIF.

ELSE.

EXIT.

ENDIF.

ENDFORM.

*----


************************************************************************

  • Format Break Fields

FORM format_break_fields.

*----


  • This form format fields necessary for breaking logic and postions

  • the BA_CNT_TAB at the Business Area being processed.

MOVE: infile-cost_center TO prev_cost_center,

infile-business_area TO prev_business_area,

infile-amount TO prev_amount,

infile-dollar_amt TO prev_dollar_amt,

infile-order+2(12) TO prev_order,

infile-wbs_element TO prev_wbs_element,

infile-text TO prev_text,

infile-due_on_date TO prev_due_on_date.

SHIFT prev_order LEFT DELETING LEADING space.

ENDFORM.

************************************************************************

  • format screen 0100

FORM format_scrn_0100.

*----


  • This form contains the logic to create screen 0100

sy-subrc = 0.

IF ba_cnt_tab-business_area NE infile-business_area.

  • Position BA_CNT_TAB at business area currently processing.

LOOP AT ba_cnt_tab.

IF ba_cnt_tab-business_area = infile-business_area.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

PERFORM dynpro_saplf040_0100 USING infile-post_key infile-accnt.

ENDFORM.

************************************************************************

  • FORMAT SCREEN 0300 FOR LAST DETAIL

FORM format_scrn_0300_last.

*----


  • This form formats the last detail screen 0300 and a phantom entry

  • if needed. Screen 0002 is also formatted for each 0300.

ADD: prev_dollar_amt TO phantom_accum,

1 TO detail_rec_cnt.

IF prev_dollar_amt GT 0.

ADD: prev_dollar_amt TO amt_debit_added.

ELSE.

ADD: prev_dollar_amt TO amt_credit_added.

ENDIF.

IF detail_rec_cnt LT ba_cnt_tab-rec_cnt.

IF phantom_accum LT 0.

  • Reverse posting key since being posted as an offset to the accumulated

  • Amount.

MOVE debit_pk TO posting_key.

num_data = phantom_accum * -1.

ELSE.

MOVE credit_pk TO posting_key.

num_data = phantom_accum.

ENDIF.

PERFORM dynpro_saplf040_0300 USING prev_amount prev_text

prev_due_on_date posting_key phantom_accnt.

PERFORM dynpro_saplkacb_0002 USING prev_cost_center

prev_business_area prev_order prev_wbs_element.

MOVE num_data TO char_data.

PERFORM dynpro_saplf040_0300 USING char_data '' '' '' ''.

PERFORM bdc_value USING 'BDC_OKCODE' post.

PERFORM dynpro_saplkacb_0002 USING ' ' prev_business_area ' ' ' '.

ELSE.

PERFORM dynpro_saplf040_0300 USING prev_amount prev_text

prev_due_on_date '' ''.

PERFORM bdc_value USING 'BDC_OKCODE' post.

PERFORM dynpro_saplkacb_0002 USING prev_cost_center

prev_business_area prev_order prev_wbs_element.

ENDIF.

CLEAR: detail_rec_cnt,

phantom_accum.

ENDFORM.

************************************************************************

  • FORMAT DETAIL FOR SCREEN 0300

FORM format_scrn_0300_detail.

*----


  • This FORM formats screen 0300 for a detail record along with its

  • screen 0002

ADD: prev_dollar_amt TO phantom_accum.

PERFORM dynpro_saplf040_0300 USING prev_amount prev_text

prev_due_on_date infile-post_key infile-accnt.

PERFORM dynpro_saplkacb_0002 USING prev_cost_center

prev_business_area prev_order prev_wbs_element.

IF prev_dollar_amt LT 0.

ADD: prev_dollar_amt TO amt_credit_added.

ELSE.

ADD: prev_dollar_amt TO amt_debit_added.

ENDIF.

ADD: 1 TO detail_rec_cnt.

ENDFORM.

************************************************************************

  • Dynpro for program SAPMF05A Screen 0100

FORM dynpro_saplf040_0100 USING post_key post_accnt.

*----


  • This FORM formats SCREEN 0100

*----


  • This PERFORM is done once for each screen.

PERFORM bdc_dynpro USING 'SAPLF040' '0100'.

  • This PERFORM is done as many times as there are fields to be

  • populated for the screen being processed.

PERFORM bdc_value USING 'BKPF-BLDAT' header-doc_mdy.

PERFORM bdc_value USING 'BKPF-BUDAT' header-post_mdy.

PERFORM bdc_value USING 'BKPF-BLART' header-doc_type.

PERFORM bdc_value USING 'BKPF-BUKRS' header-company_code.

PERFORM bdc_value USING 'BKPF-MONAT' header-period.

PERFORM bdc_value USING 'BKPF-WAERS' header-currency.

PERFORM bdc_value USING 'BKPF-XBLNR' header-reference_doc.

PERFORM bdc_value USING 'BKPF-BKTXT' header-text.

*Begin of change by Priya Vasudevan for including checkbox

  • PERFORM BDC_VALUE USING 'VBKPF-XBWAE' CONTROL.

*End of change

IF header-rate NE space.

PERFORM bdc_value USING 'BKPF-KURSF' header-rate.

ENDIF.

IF header-translation_date NE space.

PERFORM bdc_value USING 'BKPF-WWERT' header-translation_date.

ENDIF.

PERFORM bdc_value USING 'RF05V-NEWBS' post_key.

PERFORM bdc_value USING 'RF05V-NEWKO' post_accnt.

ENDFORM.

************************************************************************

  • Dynpro for program SAPLF040 Screen 0300

FORM dynpro_saplf040_0300 USING amount text due_on_date

post_key post_accnt.

*----


  • This FORM formats SCREEN 0300

*----


  • This PERFORM is done once for each screen.

PERFORM bdc_dynpro USING 'SAPLF040' '0300'.

  • This PERFORM is done as many times as there are fields to be

  • populated for the screen being processed.

PERFORM bdc_value USING 'BSEG-WRBTR' amount.

*Begin of change by Priya Vasudevan for addition of assign no and tax .

  • PERFORM BDC_VALUE USING 'BSEG-ZUONR' ASSIGNMENT_NUMBER.

  • PERFORM BDC_VALUE USING 'BKPF-XMWST' TAX_CALCULATE.

*End of change

PERFORM bdc_value USING 'RF05V-NEWBS' post_key.

PERFORM bdc_value USING 'RF05V-NEWKO' post_accnt.

IF due_on_date NE space.

PERFORM bdc_value USING 'BSEG-ZFBDT' due_on_date.

ENDIF.

IF text NE space.

PERFORM bdc_value USING 'BSEG-SGTXT' text.

ENDIF.

ENDFORM.

************************************************************************

  • Dynpro for program SAPLKACB Screen 0002

FORM dynpro_saplkacb_0002 USING cost_center business_area order wbs.

*----


  • This FORM formats SCREEN 0002 WHICH IS A POP-UP SCREEN

  • THAT DOES NOT APPEAR DURING ON-LINE PROCESSING

*----


  • This PERFORM is done once for each screen.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

  • This PERFORM is done as many times as there are fields to be

  • populated for the screen being processed.

IF cost_center NE space.

PERFORM bdc_value USING 'COBL-KOSTL' cost_center.

ENDIF.

IF business_area NE space.

PERFORM bdc_value USING 'COBL-GSBER' business_area.

ENDIF.

IF order NE space.

PERFORM bdc_value USING 'COBL-AUFNR' order.

ENDIF.

IF wbs NE space.

PERFORM bdc_value USING 'COBL-PS_PSP_PNR' wbs.

ENDIF.

ENDFORM.

************************************************************************

  • BDC Dynpro

FORM bdc_dynpro USING pgm scrn.

*----


  • This FORM formats the transaction that tells the BDC which screen is

  • to be populated.

*----


CLEAR bdc_tab.

MOVE: pgm TO bdc_tab-program,

scrn TO bdc_tab-dynpro,

begin TO bdc_tab-dynbegin.

APPEND bdc_tab.

ENDFORM.

************************************************************************

  • BDC Value

FORM bdc_value USING field val.

*----


  • This FORM tells the BDC which field is to be populated and the value

  • to use.

*----


CLEAR bdc_tab.

MOVE: field TO bdc_tab-fnam,

val TO bdc_tab-fval.

APPEND bdc_tab.

ENDFORM.

************************************************************************

FORM open_bdc.

*----


  • This routine opens the BDC data file

*----


sy-subrc = 0.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

client = sy-mandt

group = group_name

keep = 'X'

user = sy-uname

EXCEPTIONS

client_invalid = 1

destination_invalid = 2

group_invalid = 3

group_is_locked = 4

holddate_invalid = 5

internal_error = 6

queue_error = 7

running = 8

system_lock_error = 9

user_invalid = 10

OTHERS = 11.

IF sy-subrc NE 0.

MOVE: true TO abend_job.

CASE sy-subrc.

WHEN 01.

PERFORM process_msg USING '109' sy-mandt 'BDC OPEN' ''.

WHEN 02.

PERFORM process_msg USING '109' 'BDC OPEN' '' ''.

WHEN 03.

PERFORM process_msg USING '111' 'BDC OPEN' '' ''.

WHEN 04.

PERFORM process_msg USING '124' 'BDC OPEN' '' ''.

WHEN 05.

PERFORM process_msg USING '112' 'BDC OPEN' '' ''.

WHEN 06.

PERFORM process_msg USING '113' 'BDC OPEN' '' ''.

WHEN 07.

PERFORM process_msg USING '114' 'BDC OPEN' '' ''.

WHEN 08.

PERFORM process_msg USING '115' 'BDC OPEN' '' ''.

WHEN 09.

PERFORM process_msg USING '125' 'BDC OPEN' '' ''.

WHEN 10.

PERFORM process_msg USING '116' 'BDC OPEN' '' ''.

WHEN 11.

PERFORM process_msg USING '126' 'BDC OPEN' '' ''.

ENDCASE.

ELSE.

MOVE: true TO bdc_openned,

false TO new_bdc.

ENDIF.

ENDFORM.

************************************************************************

  • Insert BDC data

FORM insert_bdcdata.

*----


  • This routine inserts a scenario into the BDC batch session.

  • Add the actual value of the particular Transaction code relevant

  • to the scenario being processed for the constant TRANS_CODE.

*----


sy-subrc = 0.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

tcode = trans_code

TABLES

dynprotab = bdc_tab

EXCEPTIONS

internal_error = 1

not_open = 2

queue_error = 3

tcode_invalid = 4

OTHERS = 5.

IF sy-subrc NE 0.

MOVE: true TO abend_job.

CASE sy-subrc.

WHEN 01.

PERFORM process_msg USING '113' 'BDC INSERT' '' ''.

WHEN 02.

PERFORM process_msg USING '117' 'BDC INSERT' '' ''.

WHEN 03.

PERFORM process_msg USING '114' 'BDC INSERT' '' ''.

WHEN 04.

PERFORM process_msg USING '118' 'BDC INSERT' '' ''.

WHEN 05.

PERFORM process_msg USING '126' 'BDC INSERT' '' ''.

ENDCASE.

ELSE.

bdc_trans_cnt = bdc_trans_cnt + 1.

ENDIF.

  • Initialize table after inserting the processed BDC Transactions

  • for one scenario

REFRESH bdc_tab.

ENDFORM.

************************************************************************

  • End of Job Routine

FORM eoj_routine.

IF bdc_openned = true.

PERFORM close_bdc.

IF bdc_tab_created = true AND

abend_job = false.

TRANSLATE submit TO UPPER CASE.

IF submit = 'X'.

PERFORM submit_bdc_to_batch.

ELSE.

CLEAR : msg1, msg2, msg3.

CONCATENATE 'Session' group_name INTO msg1 SEPARATED BY space.

msg2 = 'has been created. '.

msg3 = 'Please use SM35 to process the session.'.

MESSAGE i150 WITH msg1 msg2 msg3 .

ENDIF.

IF abend_job = false.

PERFORM update_date_control_file.

ENDIF.

ENDIF.

ENDIF.

IF abend_job = true.

PERFORM abend_job.

PERFORM alert_check.

ELSE.

  • These writes are an example of control totals that would be included

  • on a control report.

PERFORM: process_msg USING '174' total_recs '' 'NC',

process_msg USING '176' bdc_trans_cnt '' 'NC',

process_msg USING '148' tot_debit '' 'NC',

process_msg USING '149' tot_credit '' 'NC',

process_msg USING '173' interface_id '' ''.

  • WRITE: /1 ' End of Job Run'.

TRANSLATE temp_unix_name TO LOWER CASE.

SHIFT full_fil_name UP TO temp_unix_name+0(9).

SUBMIT zuxmv WITH filename EQ full_fil_name

WITH frompath EQ temp_unix_path

WITH to_path EQ temp_arc_path

exporting list to memory

AND RETURN.

ENDIF.

SUBMIT zuxlp WITH filename = temp_log_name

WITH path = temp_log_path

WITH printer = temp_printer

exporting list to memory

AND RETURN.

IF abend_job = true.

IF execution = 'ONLINE'.

PERFORM process_msg USING '100' in_trailer-interface_id '' ''.

MESSAGE a100 WITH in_trailer-interface_id.

ENDIF.

ENDIF.

CLOSE DATASET logfile.

ENDFORM.

  • Close BDC data

FORM close_bdc.

*----


  • This routine closes the BDC batch session.

*----


sy-subrc = 0.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

not_open = 1

queue_error = 2

OTHERS = 3.

IF sy-subrc NE 0.

MOVE: true TO abend_job.

CASE sy-subrc.

WHEN 01.

PERFORM process_msg USING '117' 'BDC CLOSE' '' ''.

WHEN 02.

PERFORM process_msg USING '114' 'BDC CLOSE' '' ''.

WHEN 03.

PERFORM process_msg USING '126' 'BDC CLOSE' '' ''.

ENDCASE.

ENDIF.

ENDFORM.

************************************************************************

  • Submit BDC to Batch

FORM submit_bdc_to_batch.

*----


  • This FORM submits the completed BDC Table to Batch to be processed

  • for all the transactions processed from the Interface input file.

*----


  • Changes made by sthomas on 11.16.2005

SUBMIT rsbdcsub WITH mappe EQ group_name

with Z_VERARB EQ 'X'

*Code inserted by sthomas on 16.11.2005

WITH fehler EQ ' '

EXPORTING LIST TO MEMORY

AND RETURN.

WAIT UP TO 2 SECONDS.

SELECT * UP TO 1 ROWS INTO TABLE i_apqi

FROM apqi

WHERE groupid = group_name

AND credate <= sy-datum

AND cretime <= sy-uzeit

ORDER BY cretime DESCENDING.

READ TABLE i_apqi INDEX 1.

clear : msg1, msg2, msg3.

concatenate 'Session' group_name into msg1 SEPARATED BY SPACE.

IF i_apqi-qstate = 'F'.

msg2 = 'has been successfully processed'.

MESSAGE i150 WITH msg1 msg2.

ELSEIF i_apqi-qstate = 'E'.

msg2 = 'has been processed with errors.'.

msg3 = 'Please use SM35 to view the errors'.

MESSAGE i150 WITH msg1 msg2 msg3 .

ELSE.

msg2 = 'has been transferred to the background for'.

msg3 = 'processing. Please use SM35 to view the status'.

MESSAGE i150 WITH msg1 msg2 msg3.

ENDIF.

  • End of code.

  • End of change

ENDFORM.

************************************************************************

  • Update date control file

FORM update_date_control_file.

*----


  • This routine will update the Interface Date/Time Control File with

  • the Date/Time Stamp of the current file just processed successfully.

  • The parameter FILE_OPERATION indicates that the control file is to

  • be updated with the new stamp and the status of the Interface/file

  • will be set to 'C' for complete.

*----


CALL FUNCTION 'Z_PROCESS_INTERFACE_CTL_TABLE'

EXPORTING

file_id = in_trailer-interface_id

file_name = in_trailer-file_name

file_date = in_trailer-date

file_time = in_trailer-time

file_operation = '2'

EXCEPTIONS

dup_file_error = 1

file_id_not_found = 2

table_not_updated = 3

OTHERS = 4.

IF sy-subrc NE 0.

MOVE: true TO abend_job.

CASE sy-subrc.

WHEN 01.

PERFORM process_msg USING '127' in_trailer-interface_id

in_trailer-file_name 'OPERATION 2'.

WHEN 02.

PERFORM process_msg USING '128' in_trailer-interface_id

in_trailer-file_name 'OPERATION 2'.

WHEN 03.

PERFORM process_msg USING '129' 'ZTAG' '' ''.

WHEN 04.

PERFORM process_msg USING '126' 'OPERATION 2' '' ''.

ENDCASE.

ENDIF.

ENDFORM.

*----


  • Abend Job

FORM abend_job.

*----


  • This form updates the Interface Date/Time Control File with a status

  • of 'A' to indicate that this Interface has abended. The Date/Time

  • stamp on the Control file will not be updated with the date/time

  • from the current file. The parameter FILE_OPERATION OF '3' initiates

  • this process. Any time Operation '3' is used with the

  • Date/Time Control File, the calling program must abend using an 'A'

  • Message. A generic abend message of 100 has been set up in the

  • T100 table.

*----


CALL FUNCTION 'Z_PROCESS_INTERFACE_CTL_TABLE'

EXPORTING

file_id = in_trailer-interface_id

file_name = in_trailer-file_name

file_date = in_trailer-date

file_time = in_trailer-time

file_operation = '3'

EXCEPTIONS

dup_file_error = 1

file_id_not_found = 2

table_not_updated = 3

OTHERS = 4.

IF sy-subrc NE 0.

CASE sy-subrc.

WHEN 01.

PERFORM process_msg USING '127' in_trailer-interface_id

in_trailer-file_name 'OPERATION 3'.

WHEN 02.

PERFORM process_msg USING '128' in_trailer-interface_id

in_trailer-file_name 'OPERATION 3'.

WHEN 03.

PERFORM process_msg USING '129' 'ZTAG' 'OPERATION 3' ''.

WHEN 04.

PERFORM process_msg USING '126' 'OPERATION 3' '' ''.

ENDCASE.

ENDIF.

PERFORM process_msg USING '100' in_trailer-interface_id '' ''.

ENDFORM.

INCLUDE zi000002.

Feel free to ask any doubt in this logic.

Regards,

Susmitha

Former Member
0 Kudos

Hi,

I have a file which has six records, i need to pass it in different sessions, ( 3 records in one session )

can u help me on this.

Geff