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: 

Session method

former_member201264
Active Contributor
0 Kudos
93

how to process a session with 500 records? For every 100 records i want create one session, so for 500 records i want create 5 sessions.

Is it possible in BDC?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
67

create an block in the selection screen ...


* BDC Options
selection-screen begin of block b_bdc with frame title text-b02.
parameters: p_uname  like sy-uname default sy-uname obligatory,
                                               "User Id
            p_sname(10) type c default 'DCDxx_' obligatory,
                                               "Session
            p_maxtrn(10) type n        default 5000.
"Max transaction Counter
selection-screen end of block b_bdc.

Then as per the maximun transations per data you can write the logic



* Delete duplicate rows from source data
  delete adjacent duplicates from i_src.

  describe table i_src lines l_count.

  if l_count gt 0.

*   Initialize the transaction couter and Create the initial BDC session
    clear: v_transcounter,
           l_subrc,
           i_bdc,
           l_tabix2,
           l_tabix3.
    refresh i_bdc.

    perform sub_openbdc using uname
                              sname
                        changing l_subrc.

    if l_subrc = 0.

* Add the appropriate BDC code to the current open BDC session for each
* record in the internal table.
      loop at i_src.
* Holds the current sy-tabix
        l_tabix2 = sy-tabix.

* For each combination of group and group counter

        at new  prgrp.

* Increment transaction counter
          v_transcounter = v_transcounter + 1.


* Clear the BDC table counter
          l_tabix = 0.

* Clear the flag.
          clear l_save_flag.

        endat.

        at end of meins.
          l_save_flag = c_check.
        endat.
        l_tabix = l_tabix + 1.
        l_tabix3 = l_tabix3 + 1.

*      To be implemented in the custom-code
        perform sub_generatebdc using i_src
                                      l_tabix
                                      l_tabix3
                                      l_save_flag.


*   Ensure the BDC data table is empty
* For the last record in same header insert the BDC table
        if l_save_flag = c_check.
          call function 'BDC_INSERT'
            exporting
              tcode            = tcode
            tables
              dynprotab        = i_bdc
            exceptions
              internal_error   = 1
              not_open         = 2
              queue_error      = 3
              tcode_invalid    = 4
              printing_invalid = 5
              posting_invalid  = 6
              others           = 7.

          if sy-subrc ne 0.
            clear wa_sessions.
            wa_sessions-sname = v_sname.
            wa_sessions-trans = v_transcounter.
            wa_sessions-status = c_check.
            wa_sessions-message = 'BDC record insert failed'(103).
            append wa_sessions to i_sessions.
          endif.
          refresh i_bdc.
          l_tabix = 0.
          l_tabix3 = 0.

*   Exceeded current BDC sessions transaction capacity. Close current
*   BDC session and create a new session.
          if v_transcounter = maxtrn
          or l_tabix2 = l_count.

            perform sub_closebdc.

*   When it is the last record in the table, do not open session
            if l_tabix2 ne l_count.
              perform sub_openbdc using    uname     "username
                                           sname     "session name
                                  changing l_subrc.  "sy-subrc
              if l_subrc ne 0.
                exit.
              endif.           " For l_subrc
            endif.             " For l_tabix2
          endif.               " For v_transcounter
        endif.
      endloop.
    endif.         " For l_count
  endif.


* Display summary report
  perform sub_stopclock.

  perform sub_displayuploadsummary tables i_sessions   "Session Details
                                   using  fname        "File Name
                                          l_count.     "Table index

5 REPLIES 5

Former Member
0 Kudos
67

hi Kancham,

Split the data into 5 internal table each with 100 records and loop through the tables and call BDC_INSERT in each loop and assign a unique session name ...

regards,

Santosh

Former Member
0 Kudos
67

in the program put the counter...for the input.then do like this..

loop a itab.

c = c + 1.

if c = 100 .

session name = 'test1'.

elseif c = 200.

session name = 'test2'.

endif.

endloop.

Former Member
0 Kudos
68

create an block in the selection screen ...


* BDC Options
selection-screen begin of block b_bdc with frame title text-b02.
parameters: p_uname  like sy-uname default sy-uname obligatory,
                                               "User Id
            p_sname(10) type c default 'DCDxx_' obligatory,
                                               "Session
            p_maxtrn(10) type n        default 5000.
"Max transaction Counter
selection-screen end of block b_bdc.

Then as per the maximun transations per data you can write the logic



* Delete duplicate rows from source data
  delete adjacent duplicates from i_src.

  describe table i_src lines l_count.

  if l_count gt 0.

*   Initialize the transaction couter and Create the initial BDC session
    clear: v_transcounter,
           l_subrc,
           i_bdc,
           l_tabix2,
           l_tabix3.
    refresh i_bdc.

    perform sub_openbdc using uname
                              sname
                        changing l_subrc.

    if l_subrc = 0.

* Add the appropriate BDC code to the current open BDC session for each
* record in the internal table.
      loop at i_src.
* Holds the current sy-tabix
        l_tabix2 = sy-tabix.

* For each combination of group and group counter

        at new  prgrp.

* Increment transaction counter
          v_transcounter = v_transcounter + 1.


* Clear the BDC table counter
          l_tabix = 0.

* Clear the flag.
          clear l_save_flag.

        endat.

        at end of meins.
          l_save_flag = c_check.
        endat.
        l_tabix = l_tabix + 1.
        l_tabix3 = l_tabix3 + 1.

*      To be implemented in the custom-code
        perform sub_generatebdc using i_src
                                      l_tabix
                                      l_tabix3
                                      l_save_flag.


*   Ensure the BDC data table is empty
* For the last record in same header insert the BDC table
        if l_save_flag = c_check.
          call function 'BDC_INSERT'
            exporting
              tcode            = tcode
            tables
              dynprotab        = i_bdc
            exceptions
              internal_error   = 1
              not_open         = 2
              queue_error      = 3
              tcode_invalid    = 4
              printing_invalid = 5
              posting_invalid  = 6
              others           = 7.

          if sy-subrc ne 0.
            clear wa_sessions.
            wa_sessions-sname = v_sname.
            wa_sessions-trans = v_transcounter.
            wa_sessions-status = c_check.
            wa_sessions-message = 'BDC record insert failed'(103).
            append wa_sessions to i_sessions.
          endif.
          refresh i_bdc.
          l_tabix = 0.
          l_tabix3 = 0.

*   Exceeded current BDC sessions transaction capacity. Close current
*   BDC session and create a new session.
          if v_transcounter = maxtrn
          or l_tabix2 = l_count.

            perform sub_closebdc.

*   When it is the last record in the table, do not open session
            if l_tabix2 ne l_count.
              perform sub_openbdc using    uname     "username
                                           sname     "session name
                                  changing l_subrc.  "sy-subrc
              if l_subrc ne 0.
                exit.
              endif.           " For l_subrc
            endif.             " For l_tabix2
          endif.               " For v_transcounter
        endif.
      endloop.
    endif.         " For l_count
  endif.


* Display summary report
  perform sub_stopclock.

  perform sub_displayuploadsummary tables i_sessions   "Session Details
                                   using  fname        "File Name
                                          l_count.     "Table index

Former Member
0 Kudos
67

Hi,

firstly you append your session names to an internal table.

As you already loop the records and for every 100th sy-tabix value and for every hundered records read that name internal table with index...

or when ever the modulous of the sy-tabix is 0 then read the session name internal table.

like...

100 / 100 = 1 is quotient. and remainder 0.

200 / 100 = 2.

300 / 100 = 3.

400 / 100 = 4.

500 / 100 = 5.

store that quotients in a variable and if mod is zero read the session name internal table with index of quotient variable...

Read table <session_name> into <work area> index <quotient variable>

Hope this would solve your problem

Regards,

Narin Nandivada.

Former Member
0 Kudos
67

Hi,

take a counter where you r loop the records and if counter eq 100 exit, say..

loop itab

bdc data......

add 1 to counter.

if counter = 0.

exit.

endif.

endloop.

with luck,

pritam.