Skip to Content
author's profile photo Former Member
Former Member

BAPI_SALESORDER_CHANGE

I was trying to update VBEP-LIFSP to ' ' using BAPI_SALESORDER_CHANGE. everything is going fine, but VBEP-LIFSP is not updated.

Please Help. Thank You.

DATA: LT_SDH1  TYPE TABLE OF BAPISDH1   WITH HEADER LINE, 
      LT_SDH1X TYPE TABLE OF BAPISDH1X  WITH HEADER LINE, 
      LT_SCHDL  TYPE TABLE OF BAPISCHDL  WITH HEADER LINE, 
      LT_SCHDLX TYPE TABLE OF BAPISCHDLX WITH HEADER LINE, 
      LT_RETURN TYPE TABLE OF BAPIRET2   WITH HEADER LINE, 
      LS_RETURN TYPE TABLE OF BAPIRET2   WITH HEADER LINE. 

SELECT  A~VBELN 
          A~ERDAT 
          A~AUART 
          A~VKORG 
          A~VTWEG 
          A~KUNNR 
          B~POSNR 
          B~MATNR 
          B~WERKS 
          B~LGORT 
          C~WMENG 
          C~LIFSP    FROM VBAK AS A INNER JOIN VBAP AS B ON 
                                          A~VBELN = B~VBELN 
                                    INNER JOIN VBEP AS C ON 
                                          C~VBELN = A~VBELN  AND 
                                          C~POSNR = B~POSNR 
                     INTO TABLE IT_BLOCK 
                     WHERE A~VBELN  IN S_VBELN 
                       AND A~ERDAT  IN S_ERDAT 
                       AND A~AUART  IN S_AUART 
                       AND A~VKORG  IN S_VKORG 
                       AND A~VTWEG  IN S_VTWEG 
                       AND A~KUNNR  IN S_KUNNR 
                       AND B~MATNR  IN S_MATNR 
                       AND B~WERKS  IN S_WERKS 
                       AND B~LGORT  IN S_LGORT 
                       AND C~LIFSP  IN S_LIFSP 
                       AND C~ETTYP  =  'DN' 
                       AND B~PSTYV  =  'ZREN' . 

  SORT IT_BLOCK BY VBELN. 

 LOOP AT IT_BLOCK. 

      CLEAR   : LT_SCHDL, LT_SCHDLX, LS_RETURN. 
      REFRESH : LT_RETURN. 

      MOVE 'U' TO LT_SDH1X-UPDATEFLAG. 
      MOVE 'U' TO LT_SCHDLX-UPDATEFLAG. 

      IF IT_BLOCK-LIFSP <> ''. 
          MOVE : '' TO LT_SCHDL-REQ_DLV_BL, 
                 'X' TO LT_SCHDLX-REQ_DLV_BL. 
      ENDIF. 


      CALL FUNCTION 'BAPI_SALESORDER_CHANGE' 
        EXPORTING 
          SALESDOCUMENT               = IT_BLOCK-VBELN 
          ORDER_HEADER_IN             = LT_SDH1 
          ORDER_HEADER_INX            = LT_SDH1X 
*         SIMULATION                  = 
*         BEHAVE_WHEN_ERROR           = ' ' 
*         INT_NUMBER_ASSIGNMENT       = ' ' 
*         LOGIC_SWITCH                = 
        TABLES 
          RETURN                      = LS_RETURN 
*         ORDER_ITEM_IN               = 
*         ORDER_ITEM_INX              = 
*         PARTNERS                    = 
*         PARTNERCHANGES              = 
*         PARTNERADDRESSES            = 
*         ORDER_CFGS_REF              = 
*         ORDER_CFGS_INST             = 
*         ORDER_CFGS_PART_OF          = 
*         ORDER_CFGS_VALUE            = 
*         ORDER_CFGS_BLOB             = 
*         ORDER_CFGS_VK               = 
*         ORDER_CFGS_REFINST          = 
         SCHEDULE_LINES              = LT_SCHDL 
         SCHEDULE_LINESX             = LT_SCHDLX . 
*         ORDER_TEXT                  = 
*         ORDER_KEYS                  = 
*         CONDITIONS_IN               = 
*         CONDITIONS_INX              = 
*         EXTENSIONIN                 = 


      LOOP AT LS_RETURN. 
         MOVE-CORRESPONDING LS_RETURN TO LT_RETURN. 
         APPEND LT_RETURN. 
         CLEAR  LT_RETURN. 
      ENDLOOP. 

  ENDLOOP. 

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 
       EXPORTING 
         WAIT          = 'X' 
       IMPORTING 
         RETURN        = LS_RETURN. 

      MOVE-CORRESPONDING LS_RETURN TO LT_RETURN. 
      APPEND LT_RETURN. 
      CLEAR  LT_RETURN. 

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Sep 05, 2006 at 06:48 PM

    You need to populate ITM_NUMBER and SCHED_LINE in LT_SCHDL and LT_SCHDLX and you need to include append statements for each.

    Also, you can build the schedule line internal table for all schedule lines on one order then call the update BAPI after the last record of each order is processed.

    Try something like this:

    DATA: LT_SDH1 TYPE TABLE OF BAPISDH1 WITH HEADER LINE,

    LT_SDH1X TYPE TABLE OF BAPISDH1X WITH HEADER LINE,

    LT_SCHDL TYPE TABLE OF BAPISCHDL WITH HEADER LINE,

    LT_SCHDLX TYPE TABLE OF BAPISCHDLX WITH HEADER LINE,

    LT_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE,

    LS_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.

    DATA: BEGIN OF IT_BLOCK OCCURS 0,

    VBELN LIKE VBAK-VBELN,

    ERDAT LIKE VBAK-ERDAT,

    AUART LIKE VBAK-AUART,

    VKORG LIKE VBAK-VKORG,

    VTWEG LIKE VBAK-VTWEG,

    KUNNR LIKE VBAK-KUNNR,

    POSNR LIKE VBAP-POSNR,

    MATNR LIKE VBAP-MATNR,

    WERKS LIKE VBAP-WERKS,

    LGORT LIKE VBAP-LGORT,

    WMENG LIKE VBEP-WMENG,

    LIFSP LIKE VBEP-LIFSP,

    ETENR LIKE VBEP-ETENR,

    END OF IT_BLOCK.

    SELECT A~VBELN

    A~ERDAT

    A~AUART

    A~VKORG

    A~VTWEG

    A~KUNNR

    B~POSNR

    B~MATNR

    B~WERKS

    B~LGORT

    C~WMENG

    C~LIFSP

    C~ETENR FROM VBAK AS A INNER JOIN VBAP AS B ON

    AVBELN = BVBELN

    INNER JOIN VBEP AS C ON

    CVBELN = AVBELN AND

    CPOSNR = BPOSNR

    INTO TABLE IT_BLOCK

    WHERE A~VBELN IN S_VBELN

    AND A~ERDAT IN S_ERDAT

    AND A~AUART IN S_AUART

    AND A~VKORG IN S_VKORG

    AND A~VTWEG IN S_VTWEG

    AND A~KUNNR IN S_KUNNR

    AND B~MATNR IN S_MATNR

    AND B~WERKS IN S_WERKS

    AND B~LGORT IN S_LGORT

    AND C~LIFSP IN S_LIFSP

    AND C~ETTYP = 'DN'

    AND B~PSTYV = 'ZREN' .

    SORT IT_BLOCK BY VBELN.

    LOOP AT IT_BLOCK.

    CLEAR : LT_SCHDL, LT_SCHDLX, LS_RETURN.

    REFRESH : LT_RETURN.

    MOVE 'U' TO LT_SDH1X-UPDATEFLAG.

    MOVE 'U' TO LT_SCHDLX-UPDATEFLAG.

    IF IT_BLOCK-LIFSP <> ''.

    MOVE : IT_BLOCK-POSNR to LT_SCHDL-ITM_NUMBER,

    IT_BLOCK-POSNR to LT_SCHDLX-ITM_NUMBER,

    IT_BLOCK-ETENR to LT_SCHDL-SCHED_LINE,

    IT_BLOCK-ETENR to LT_SCHDLX-SCHED_LINE,

    '' TO LT_SCHDL-REQ_DLV_BL,

    'X' TO LT_SCHDLX-REQ_DLV_BL.

    APPEND: LT_SCHDL,

    LT_SCHDLX.

    ENDIF.

    AT END OF VBELN.

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

    EXPORTING

    SALESDOCUMENT = IT_BLOCK-VBELN

    ORDER_HEADER_IN = LT_SDH1

    ORDER_HEADER_INX = LT_SDH1X

    • SIMULATION =

    • BEHAVE_WHEN_ERROR = ' '

    • INT_NUMBER_ASSIGNMENT = ' '

    • LOGIC_SWITCH =

    TABLES

    RETURN = LS_RETURN

    • ORDER_ITEM_IN =

    • ORDER_ITEM_INX =

    • PARTNERS =

    • PARTNERCHANGES =

    • PARTNERADDRESSES =

    • ORDER_CFGS_REF =

    • ORDER_CFGS_INST =

    • ORDER_CFGS_PART_OF =

    • ORDER_CFGS_VALUE =

    • ORDER_CFGS_BLOB =

    • ORDER_CFGS_VK =

    • ORDER_CFGS_REFINST =

    SCHEDULE_LINES = LT_SCHDL

    SCHEDULE_LINESX = LT_SCHDLX .

    • ORDER_TEXT =

    • ORDER_KEYS =

    • CONDITIONS_IN =

    • CONDITIONS_INX =

    • EXTENSIONIN =

    LOOP AT LS_RETURN.

    MOVE-CORRESPONDING LS_RETURN TO LT_RETURN.

    APPEND LT_RETURN.

    CLEAR LT_RETURN.

    ENDLOOP.

    ENDAT.

    ENDLOOP.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = LS_RETURN.

    MOVE-CORRESPONDING LS_RETURN TO LT_RETURN.

    APPEND LT_RETURN.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.