Application Development and Automation 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: 
Read only

BDC call by session

Former Member
0 Likes
1,208

Hi

we have to create sales order through BDC using session method but the problem is that, we have to create sales order not more than 300 line item as there is a check on accounting entries of bills of not more than 300 line items.

So how would I create sales order of not more than 300 items from a text files which can containg 500 line items.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,182

Hi Suchender,

I also had similar requirement as yours. Please find the below logic. It will work for you :


READ TABLE itab.
recs = sy-tfill.
a = recs DIV 300.
b = recs MOD 300.

s1 = 1.
s2 = 300.

DO a TIMES.
  sno = sy-index.
  CONDENSE sno.
  CONCATENATE 'SESSION' sno INTO ses_nam SEPARATED BY '_'.
  PERFORM session USING ses_nam s1 s2.
  s1 = s1 + 300.
  IF sy-index <> a.
    s2 = s2 + 300.
  ENDIF.
ENDDO.

IF b <> 0.
  s2 = s2 + b.
  sno = sno + 1.
  CONDENSE sno.
  CONCATENATE 'SESSION' sno INTO ses_nam SEPARATED BY '_'.
  PERFORM session USING ses_nam s1 s2.
ENDIF.

*&---------------------------------------------------------------------*
*&      Form  session
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->SES_NAM    text
*      -->S1         text
*      -->S2         text
*----------------------------------------------------------------------*
FORM session USING ses_nam s1 s2.
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      group               = ses_nam
      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 <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  LOOP AT itab FROM s1 TO s2.
    REFRESH bdcdata.
    PERFORM mapping.

    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        tcode     = 'MM01'
      TABLES
        dynprotab = bdcdata.
  ENDLOOP.

  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.
  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.                    "session

Cheers

VJ

Hi

we have to create sales order through BDC using session method but the problem is that, we have to create sales order not more than 300 line item as there is a check on accounting entries of bills of not more than 300 line items.

So how would I create sales order of not more than 300 items from a text files which can containg 500 line items.

7 REPLIES 7
Read only

Former Member
0 Likes
1,182

Hi,

Its purely business requirement on whether to split the line items at 300 and then create a new sales order...Please check the same with your functional consultant.

Hope this helps

Regards

Shiva

Read only

0 Likes
1,182

I want to know how to do it as all the data is stored in BDC Session than how would i do that.

Read only

Former Member
0 Likes
1,182

While reading the items put a check before bdc_insert, not to exceed 300 lines and ask your functional consultant what to do incase items are more than 300.

Read only

0 Likes
1,182

Tahnks Arjun

but how can we do that if all the 5000 records have come to BDC Sessions tahn how will we insert only 300 in first time . We have to create 1 sale order for 300 line items and another SO for next 300 line items and so on.

Do we have to call form open group for 300 line items only and again for next 300 items or any other metod is there.

Read only

0 Likes
1,182

Do we have to call form open group for 300 line items only and again for next 300 items or any other metod is there

Yes you have to .

Read only

Former Member
0 Likes
1,182

find the common field which have same data so that it can come into one sales order by this we can reduce the number of sales orders

Read only

Former Member
0 Likes
1,183

Hi Suchender,

I also had similar requirement as yours. Please find the below logic. It will work for you :


READ TABLE itab.
recs = sy-tfill.
a = recs DIV 300.
b = recs MOD 300.

s1 = 1.
s2 = 300.

DO a TIMES.
  sno = sy-index.
  CONDENSE sno.
  CONCATENATE 'SESSION' sno INTO ses_nam SEPARATED BY '_'.
  PERFORM session USING ses_nam s1 s2.
  s1 = s1 + 300.
  IF sy-index <> a.
    s2 = s2 + 300.
  ENDIF.
ENDDO.

IF b <> 0.
  s2 = s2 + b.
  sno = sno + 1.
  CONDENSE sno.
  CONCATENATE 'SESSION' sno INTO ses_nam SEPARATED BY '_'.
  PERFORM session USING ses_nam s1 s2.
ENDIF.

*&---------------------------------------------------------------------*
*&      Form  session
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->SES_NAM    text
*      -->S1         text
*      -->S2         text
*----------------------------------------------------------------------*
FORM session USING ses_nam s1 s2.
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      group               = ses_nam
      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 <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  LOOP AT itab FROM s1 TO s2.
    REFRESH bdcdata.
    PERFORM mapping.

    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        tcode     = 'MM01'
      TABLES
        dynprotab = bdcdata.
  ENDLOOP.

  CALL FUNCTION 'BDC_CLOSE_GROUP'
    EXCEPTIONS
      not_open    = 1
      queue_error = 2
      OTHERS      = 3.
  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.                    "session

Cheers

VJ