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

SD_SALESDOCUMENT_CREATE with Pricing Condition

I try to use the function 'SD_SALESDOCUMENT_CREATE' to create a sales order. However, I encouter a problem in maintaining the pricing condition. When I maintain fields in the input table 'SALES_CONDITIONS_IN' and 'SALES_CONDITIONS_INX', the new conditions are added but not update the old values.

Have anyone ever used this function and can maintain the pricing condition? Help me please!!!!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • Posted on Dec 13, 2005 at 04:59 AM

    are you setting these falgs before calling the FM.

    SALES_CONDITIONS_IN-COND_UPDAT  = 'X'.
    SALES_CONDITIONS_INX-UPDATEFLAG = 'X'.

    if not do that and try...

    vijay.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 13, 2005 at 05:01 AM

    You need to set the Update flag for all conditions records.

    i hope this will solve your problem...

    regards

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2005 at 05:30 AM

    Hi,

    I think instead of using above FM, which is SAP's internal FM, use of BAPI - BAPI_SALESORDER_CREATEFROMDAT2

    should be done for creating the sales order.

    Here if you pass corrrect related info about condition type , it will get created when creating Sales Order.

    Let meknow if you need any clarifiaction on the same.

    Regards,

    Akshay

    Note: Pls. reward with points if you feel answer was helpful.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2005 at 06:33 AM

    I follow your advice, but it doesn't work. Well, I would like to list all values I maintain in the input tables.

    In the table 'ORDER_CONDITIONS_IN', I maintain:

    ITM_NUMBER = 000010

    COND_TYPE = ZN99

    COND_VALUE = 42,000

    COND_UPDATE = 'X'

    In the table 'ORDER_CONDITIONS_INX', I maintain

    ITM_NUMBER = 000010

    COND_TYPE = ZN99

    UPDATE_FLAG = U or X

    Is there any other fields I should maintain to update the old pricing condition record?

    In the BAPI 'BAPI_SALESORDER_CREATEFROMDAT2', it also call the same function module inside. Therefore, could you please give me some informtation about maintaining the pricing condition?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 13, 2005 at 06:45 AM

    i feel you are changing the old values to the existing one. then you are using wrong FM i believe.

    instead use <b>SD_SALESDOCUMENT_CHANGE</b> if you are trying to change the conditions for already existing ones...

    the one which you are using will create new records...

    vijay

    Add a comment
    10|10000 characters needed characters exceeded

    • HI Vijay Sir

      My materials have maintained values for condition 'ZPR0'.

      I want my bapi to pick new values which i pass instead of already saved values.

      i am using BAPI_SALESORDER_CREATEFROMDAT2 to create sale order.

      Currently it is picking both new and old values.

      Plz help me in this concern.

      thanks

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2005 at 07:06 AM

    First of all, I really appreciate your contribution. You are very generous!

    I have to create a sales document by using the function 'SD_SALESDOCUMENT_CREATE'. (As mentioned, the problem is that pricing condition is not updated but added)

    Therefore, is it possible to use the function 'SD_SALESDOCUMENT_CREATE' to create a sales doc and then use the function 'SD_SALESDOCUMENT_CHANGE' to delete the old pricing condition record? Do you have any suggestion or the fields that should be maintained to delete the old record?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2005 at 08:50 AM

    My requirement is really simple. I want to create a sales order by calling a function module. Everything goes well, but unfortunately I encounter a problem in pricing condition.

    I would like to know which fields should be maintained to delete the old pricing condition record by using the function SD_SALESDOCUMENT_CHANGE.

    I sincerely appreciate your immediate response.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2005 at 10:09 AM

    Your source code really help me. However, I would like to know the assigned values of each input field.

    I used to maintain the following fields, but it doesn't work

    salesdocument = 'salesdoc_no'

    ORDER_HEADER_INX-UPDATEFLAG = 'U'

    ITEM_IN-ITM_NUMBER = '000010'

    ITEM_INX-UPDATEFLAG = 'U'

    CONDITIONS_IN-ITM_NUMBER = '000010'

    CONDITIONS_IN-COND_COUNT = '01'

    CONDITIONS_IN-COND_TYPE = 'ZN99'

    CONDITIONS_INX-ITM_NUMBER = '000010'

    CONDITIONS_INX-COND_COUNT = '01'

    CONDITIONS_INX-COND_TYPE = 'ZN99'

    CONDITIONS_INX-UPDATEFLAG = 'D'

    Did I input any fields wrong?

    Add a comment
    10|10000 characters needed characters exceeded

    • I got the code check it, there is little change

      I used BAPI_SALESORDER_CHANGE. try and get back ..

      REPORT zcost_update MESSAGE-ID id.
      
      *---------------------------------------------------------------------*
      * DESCRIPTION     : Update pricing conditions on the salesorder       *
      *---------------------------------------------------------------------*
      *---------------------------------------------------------------------*
      *---------------------------------------------------------------------*
      *          Type pools
      *---------------------------------------------------------------------*
      TYPE-POOLS : slis.
      *---------------------------------------------------------------------*
      *          Tables
      *---------------------------------------------------------------------*
      TABLES: t616u ,
              vbpa  ,
              vbap  ,
              vbak  ,
              mara  ,
              t005t ,
              t604t .
      *---------------------------------------------------------------------*
      *          Internal Tables
      *---------------------------------------------------------------------*
      * To store first line contents of report
      DATA : BEGIN OF it_output OCCURS 0,
               vbeln      LIKE vbap-vbeln,           " Sales order number
               posnr      LIKE vbap-posnr,           " Sales order line+
               werks      LIKE vbap-werks,           " Plant
               matnr      LIKE vbap-matnr,           " Material Number
               arktx      LIKE vbap-arktx,           " Description of material
               faksp      LIKE vbap-faksp,           " Bill block
               kbetr      LIKE konv-kbetr,           " Condition value
               knumv      LIKE konv-knumv,           " Condition number
               check,                                " Check box for selection
               line_color(4),                        " Line color
               vbpos(17),
             END OF it_output.
      * To store second line contents of report
      DATA: BEGIN OF it_output2 OCCURS 0,
               kbetr      LIKE konv-kbetr,           " Condition value
               vbpos(17),
              END OF it_output2.
      * Internal table to store details of sales order
      DATA : BEGIN OF it_material OCCURS 0,
               vbeln      LIKE vbap-vbeln,           " Sales order number
               posnr      LIKE vbap-posnr,           " Sales order line
               uepos      LIKE vbap-uepos,           " Trim
               werks      LIKE vbap-werks,
               matnr      LIKE vbap-matnr,           " Material Number
      *         werks      LIKE vbap-werks,           " Plant
               arktx      LIKE vbap-arktx,           " Description of material
               faksp      LIKE vbap-faksp,           " Billing Block
               knumv      LIKE vbak-knumv,           " Condition number
             END OF it_material.
      * Internal table to store error messages
      DATA : BEGIN OF it_errmsgs OCCURS 0,
               vbeln       LIKE vbap-vbeln,           " Sales order number
               posnr       LIKE vbap-posnr,           " Sales order line
               message(100) TYPE c,                   " Error Message
             END OF it_errmsgs.
      
      * WORKING STORAGE FOR BAPI INTERFACE
      DATA: BEGIN OF it_bapiparex OCCURS 0.
              INCLUDE STRUCTURE bapiparex.                        "1710
      DATA: END OF it_bapiparex.
      DATA: BEGIN OF it_bape.
      DATA: structure LIKE bapiparex-structure.                   "len 30
              INCLUDE STRUCTURE bape_vbap.                        "len 261
      DATA:       filler(1419) TYPE c.                            "len 1419
      DATA: END OF it_bape.
      
      DATA: BEGIN OF it_bapex.
      DATA: structure LIKE bapiparex-structure.                   "len 30
              INCLUDE STRUCTURE bape_vbapx.                       "len 22
      DATA:       filler(1658) TYPE c.
      DATA: END OF it_bapex.
      
      *Internal Tables to capture BapirETURN messages
      DATA: it_bapireturn1 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
            it_bapireturn2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
      
      DATA: x_orderitemx LIKE bapisdh1x.
      DATA: v_export TYPE c.
      DATA: BEGIN OF itmupd OCCURS 0.
              INCLUDE STRUCTURE bapisditmx.
      DATA: END OF itmupd.
      DATA: BEGIN OF itmfld OCCURS 0.
              INCLUDE STRUCTURE bapisditm.
      DATA: END OF itmfld.
      * Internal table for field catalog
      DATA : it_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      * Internal table for Events
             it_events   TYPE slis_t_event WITH HEADER LINE.
      *---------------------------------------------------------------------*
      *         Global Variables
      *---------------------------------------------------------------------*
      DATA:    v_tabix         LIKE  sy-tabix,          " Line index
               v_repid         LIKE  sy-repid,          " Program name
               x_layout        TYPE  slis_layout_alv,   " Output layout
               v_kbetr(9).
      *---------------------------------------------------------------------*
      *          Selection Screen
      *---------------------------------------------------------------------*
      SELECTION-SCREEN  : BEGIN OF BLOCK blk3
                              WITH FRAME TITLE text-003." Further Doc.Data
      SELECT-OPTIONS :
      * Created on
      s_erdat    FOR vbak-erdat.
      
      *-Start of changes - stc00002
      SELECTION-SCREEN :BEGIN OF LINE.
      *-Sales document Radiobutton - Select-Option
      PARAMETERS : r_select  RADIOBUTTON GROUP grp1 .
      SELECTION-SCREEN COMMENT 4(25) text-015 FOR FIELD r_select.
      *-Select Option for Sales Order
      SELECT-OPTIONS : s_vbeln  FOR vbap-vbeln.
      SELECTION-SCREEN :END OF LINE.
      
      SELECTION-SCREEN :BEGIN OF LINE.
      *-Sales document Radiobutton - Parameter
      PARAMETERS : r_parmtr  RADIOBUTTON GROUP grp1 .
      SELECTION-SCREEN COMMENT 4(28) text-015 FOR FIELD r_parmtr.
      PARAMETERS: p_vbeln LIKE vbak-vbeln.
      SELECTION-SCREEN :END OF LINE.
      
      SELECTION-SCREEN :BEGIN OF LINE.
      *-Item
      SELECTION-SCREEN COMMENT 3(26) text-016 FOR FIELD s_posnr.
      SELECT-OPTIONS: s_posnr FOR vbap-posnr.
      SELECTION-SCREEN :END OF LINE.
      *-End of changes - stc00002
      SELECTION-SCREEN  : END OF BLOCK blk3.
      
      
      SELECTION-SCREEN BEGIN OF BLOCK blk4 WITH FRAME .
      *To Display error record only
      PARAMETERS p_errors AS CHECKBOX .
      
      SELECTION-SCREEN END OF BLOCK blk4.
      *---------------------------------------------------------------------*
      *          Start of Selection
      *---------------------------------------------------------------------*
      START-OF-SELECTION.
      * Selecting data depending on selection criteria
        PERFORM select_data.
      
      *---------------------------------------------------------------------*
      *          End of Selection
      *---------------------------------------------------------------------*
      END-OF-SELECTION.
      *Display report output
        PERFORM display_output.
      
      *&---------------------------------------------------------------------*
      *&      Form  SELECT_DATA
      *&---------------------------------------------------------------------*
      *        Select data based on selection criteria
      *----------------------------------------------------------------------*
      FORM select_data.
      *Refresh & clear internal tables before populating data
        REFRESH : it_output ,
                  it_output2,
                  it_material.
        CLEAR   : it_output,
                  it_material,
                  it_output2.
      *Fetching data from VBAP
      *-Sales Order - Select-Option
        IF r_select = 'X'.                                        
          SELECT vbap~vbeln
                 vbap~posnr
                 vbap~uepos
                 vbap~werks
                 vbap~matnr
                 vbap~arktx
                 vbap~faksp
                 vbak~knumv
                  INTO TABLE it_material
                 FROM vbap JOIN vbak
                 ON vbap~vbeln = vbak~vbeln
      *                     JOIN konv
      *           ON vbak~knumv = konv~knumv AND
      *              vbap~posnr = konv~kposn
                 WHERE vbak~vbeln IN s_vbeln.
      *             AND konv~kschl =  c_zek2.
      *-Sales Order - Parameter & Item - Select-Option
        ELSEIF r_parmtr = 'X'.                                    
          SELECT vbap~vbeln
                 vbap~posnr
                 vbap~uepos
                 vbap~werks
                 vbap~matnr
                 vbap~arktx
                 vbap~faksp
                 vbak~knumv
                  INTO TABLE it_material
                 FROM vbap JOIN vbak
                 ON vbap~vbeln = vbak~vbeln
      *                     JOIN konv
      *           ON vbak~knumv = konv~knumv AND
      *              vbap~posnr = konv~kposn
                 WHERE vbak~vbeln = p_vbeln
                   AND vbap~posnr IN s_posnr.
      *             AND konv~kschl =  c_zek2.
        ENDIF.                                                    
      * If sy-subrc is not equal to zero exit
        IF sy-subrc <> 0 .
          EXIT.
        ENDIF.
        DELETE it_material WHERE uepos = '000000'.
        LOOP AT it_material.
      * If Errors Only Check Box is checked.
          IF p_errors = 'X'.
            IF it_material-faksp = 'ZL' OR it_material-faksp = 'ZY'.
            ELSE.
              DELETE it_material.
              CONTINUE.
            ENDIF.
          ENDIF.
      
      * Populating IT_OUTPUT from IT_MATERIAL.
          SELECT kbetr FROM konv
                      INTO it_output-kbetr
            WHERE knumv = it_material-knumv
              AND kposn = it_material-posnr
              AND kschl = 'ZEK2'.
          ENDSELECT.
      
          MOVE-CORRESPONDING it_material TO it_output.
          SHIFT it_material-vbeln LEFT DELETING LEADING '0'.
          CONCATENATE it_material-vbeln
                      it_material-posnr
                 INTO it_output-vbpos
                 SEPARATED BY '/'.
      
          APPEND it_output.
          CLEAR it_output.
        ENDLOOP.
      ENDFORM.                    " SELECT_DATA
      *&---------------------------------------------------------------------*
      *&      Form  DISPLAY_OUTPUT
      *&---------------------------------------------------------------------*
      *        Display Report
      *----------------------------------------------------------------------*
      FORM display_output.
      
        DATA : l_pf_formname   TYPE slis_formname VALUE 'PF_STATUS',
               l_user_formname TYPE slis_formname VALUE 'USER_COMMAND',
               keyinfo TYPE slis_keyinfo_alv.
      
        v_repid = sy-repid.
      * populate fieldcatalog
        PERFORM build_fieldcatalog.
      * Populate events internal table
        PERFORM build_events.
      * Layout initialization.
        PERFORM layout USING x_layout.
        x_layout-info_fieldname    = 'LINE_COLOR'.
      * Specifying KeyFields for List.
        keyinfo-header01 = 'VBPOS'.
        keyinfo-item01   = 'VBPOS'.
      *  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
          EXPORTING
            i_callback_program       = v_repid
            i_callback_pf_status_set = l_pf_formname
            i_callback_user_command  = l_user_formname
            is_layout                = x_layout
            it_fieldcat              = it_fieldcat[]
            it_events                = it_events[]
            i_tabname_header         = 'IT_OUTPUT'
            i_tabname_item           = 'IT_OUTPUT2'
            is_keyinfo               = keyinfo
          TABLES
      *      t_outtab                 = it_output
            t_outtab_header          = it_output
            t_outtab_item            = it_output2
          EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.
      ENDFORM.                    " DISPLAY_OUTPUT
      *&---------------------------------------------------------------------*
      *&      Form  TOP-OF-LIST
      *&---------------------------------------------------------------------*
      *        For Top of list
      *----------------------------------------------------------------------*
      FORM top-of-list.
      * Display Steelcase header
        CALL FUNCTION 'Z_STEELCASE_HEADER'.
      ENDFORM.                    " TOP-OF-LIST
      
      
      *---------------------------------------------------------------------*
      *       FORM LAYOUT                                                   *
      *---------------------------------------------------------------------*
      FORM layout USING l_layout TYPE slis_layout_alv.
        l_layout-box_fieldname      = 'CHECK'.
        l_layout-box_tabname        = 'IT_OUTPUT'.
        l_layout-colwidth_optimize  = 'X'.
      ENDFORM.                    "layout
      *---------------------------------------------------------------------*
      *&      Form  USER_COMMAND
      *&---------------------------------------------------------------------*
      *      Processing User command
      *----------------------------------------------------------------------*
      *      -->P_UCOMM     Screens, function code triggered by PAI
      *      -->P_SELFIELD  information cursor position ALV
      *----------------------------------------------------------------------*
      FORM user_command USING    p_ucomm    LIKE sy-ucomm
                                 p_selfield TYPE slis_selfield.
      
        DATA : l_index LIKE sy-tabix,
               lt_output  LIKE it_output OCCURS 0 WITH HEADER LINE,
               lt_process LIKE it_output OCCURS 0 WITH HEADER LINE.
        l_index = p_selfield-tabindex.
        CASE p_ucomm.
          WHEN 'SAVE'.
            PERFORM validate_input.
            REFRESH   it_errmsgs.
            CLEAR     it_errmsgs.
            lt_output[] = it_output[].
            SORT lt_output BY vbeln.
            DELETE ADJACENT DUPLICATES FROM lt_output COMPARING vbeln.
            LOOP AT lt_output.
              LOOP AT it_output WHERE vbeln = lt_output-vbeln.
                lt_process = it_output.
                APPEND lt_process.
              ENDLOOP.
              PERFORM save_sales_docu TABLES lt_process.
              CLEAR lt_process[].
            ENDLOOP.
            p_selfield-refresh = 'X'.
      *Display Messages
            IF it_errmsgs[] IS INITIAL.
              MESSAGE s899 WITH 'Record(s) Successfully Updated'.
            ELSE.
              PERFORM display_errors.
            ENDIF.
          WHEN '&IC1'.
      * On Double click display the sales order.
            READ TABLE it_output INDEX l_index.
            SET PARAMETER  ID 'AUN' FIELD it_output-vbeln.
            CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
        ENDCASE.
      ENDFORM.                    " USER_COMMAND
      *---------------------------------------------------------------------*
      *       FORM pf_status                                                *
      *---------------------------------------------------------------------*
      *       Set pf status
      *----------------------------------------------------------------------*
      *  -->  p_extab    excluding Fcode table
      *---------------------------------------------------------------------*
      FORM pf_status USING    p_extab TYPE slis_t_extab.
        DATA : l_extab TYPE slis_extab.
        SET PF-STATUS 'STANDARD' EXCLUDING p_extab.
      ENDFORM.                    " PF_STATUS_SET
      
      *&---------------------------------------------------------------------*
      *&      Form  SAVE_SALES_DOCU
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *  -->  p1        text
      *  <--  p2        text
      *----------------------------------------------------------------------*
      FORM save_sales_docu TABLES pt_output STRUCTURE it_output.
        DATA: initem        LIKE bapisditm  OCCURS 0 WITH HEADER LINE,
              initemx       LIKE bapisditmx OCCURS 0 WITH HEADER LINE.
      
        DATA: BEGIN OF p_cond OCCURS 0.
                INCLUDE STRUCTURE bapicond.
        DATA: END OF p_cond.
      
        DATA: BEGIN OF p_updates OCCURS 0.
                INCLUDE STRUCTURE bapicondx.
        DATA: END OF p_updates.
      
        DATA: v_tabix LIKE sy-tabix,
             lv_werks LIKE vbap-werks,
             lv_waerk LIKE vbak-waerk.
      
      **Setting the flag field as update
        REFRESH : it_bapireturn1,
                   it_bapireturn2,
                   it_bapiparex,
                   itmfld,
                   itmupd.
        CLEAR   : it_bapireturn1,
                  it_bapireturn2,
                  it_bapiparex,
                  itmfld,
                  itmupd,
                  it_bape,
                  it_bapex.
        CLEAR: initem[],
                initemx[],
                p_cond[],
                p_updates[].
      
        x_orderitemx-updateflag = 'U'.
        LOOP AT pt_output.
          v_tabix = sy-tabix.
          IF pt_output-check = ' '.
            CONTINUE.
          ENDIF.
      *If the sales order is checked, clear billing block on salesorder
      * Load item process information.
          initem-itm_number = pt_output-posnr.
          initem-bill_block = ' '.
          APPEND initem.                                    " Item Values
      * Load Item process indicators
          CLEAR initemx.
          initemx-itm_number = pt_output-posnr.
          initemx-updateflag = 'U'.
          initemx-bill_block = 'X'.
          APPEND initemx.                                   " Item Indicators
          CLEAR: lv_werks, lv_waerk.
          SELECT SINGLE werks FROM vbap INTO lv_werks
            WHERE vbeln = pt_output-vbeln AND posnr = pt_output-posnr.
      
          IF lv_werks = '0500'.
            lv_waerk = 'CAD'.
          ELSE.
            lv_waerk = 'USD'.
          ENDIF.
      
          p_cond-itm_number = pt_output-posnr.
          p_cond-cond_value = pt_output-kbetr.
          p_cond-cond_type = 'ZEK2'.
          p_cond-currency  = lv_waerk.
          APPEND p_cond.
      
          p_updates-itm_number = p_cond-itm_number.
          p_updates-cond_type  = p_cond-cond_type.
          p_updates-updateflag = 'U'.
          p_updates-cond_value = 'X'.
          p_updates-currency   = 'X'.
          APPEND p_updates.
        ENDLOOP.
        CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
          EXPORTING
            salesdocument    = pt_output-vbeln
            order_header_inx = x_orderitemx
          TABLES
            return           = it_bapireturn1
            order_item_in    = initem
            order_item_inx   = initemx
            conditions_in    = p_cond
            conditions_inx   = p_updates.
      
      *Store the error messages in internal table
        LOOP AT it_bapireturn1 WHERE type = 'E'.
          LOOP AT pt_output WHERE check > space.
            it_errmsgs-vbeln = pt_output-vbeln.
            it_errmsgs-posnr = pt_output-posnr.
            it_errmsgs-message = it_bapireturn1-message.
            APPEND it_errmsgs.
            CLEAR it_errmsgs.
          ENDLOOP.
        ENDLOOP.
      *Commit the bapi transaction if no error messages are there.
        IF sy-subrc <> 0.
          REFRESH it_bapireturn2.
          CLEAR it_bapireturn2.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait   = 'X'
            IMPORTING
              return = it_bapireturn2.
      *If commit is not succesful capture the error messages.
          IF  NOT it_bapireturn2 IS  INITIAL.
            LOOP AT pt_output WHERE check > space.
              it_errmsgs-vbeln = pt_output-vbeln.
              it_errmsgs-posnr = pt_output-posnr.
              it_errmsgs-message = it_bapireturn2-message.
              APPEND it_errmsgs.
              CLEAR it_errmsgs.
            ENDLOOP.
          ENDIF.
        ENDIF.
        LOOP AT it_output WHERE check > space.
      *If line was not included in this update go to top of loop
          READ TABLE pt_output WITH KEY posnr = it_output-posnr.
          IF sy-subrc NE 0.
            CONTINUE.
          ENDIF.
      *If errors occurred, flag the line
          READ TABLE it_errmsgs WITH KEY posnr = it_output-posnr.
          IF sy-subrc = 0.
            it_output-line_color = 'C600'.
          ELSE.
      *If salesOrder is updated refresh the data from the database.
            it_output-line_color = ' '.
            SELECT kbetr
                  FROM konv
                  INTO it_output-kbetr
                  WHERE knumv = it_output-knumv AND
                        kposn = it_output-posnr AND
                        kschl = 'ZEK2'.
            ENDSELECT.
      * Make the checkboxes unchecked after updating the salesorder.
            it_output-check = ' '.
          ENDIF.
          MODIFY it_output.
        ENDLOOP.
      ENDFORM.                    " SAVE_SALES_DOCU
      *&---------------------------------------------------------------------*
      *&      Form  VALIDATE_INPUT
      *&---------------------------------------------------------------------*
      *      To Validate Input Fields
      *----------------------------------------------------------------------*
      FORM validate_input.
        DATA: l_kschl LIKE konv-kschl.
        LOOP AT it_output WHERE check NE space.
        ENDLOOP.
        IF sy-subrc NE 0.
          MESSAGE e899 WITH 'At least one item must be selected' ' '.
        ENDIF.
        LOOP AT it_output WHERE check NE space.
          v_tabix = sy-tabix.
      * check for duplicate pricing conditions.
          SELECT SINGLE kschl
                        FROM konv
                        INTO l_kschl
                        WHERE knumv = it_output-knumv AND
                              kposn = it_output-posnr AND
                              kschl = 'Z071'.
          IF sy-subrc EQ 0.
            MESSAGE e899 WITH it_output-vbpos text-011 .
            EXIT.
          ENDIF.
        ENDLOOP.
      ENDFORM.                    " VALIDATE_INPUT
      *&---------------------------------------------------------------------*
      *&      Form  DISPLAY_ERRORS
      *&---------------------------------------------------------------------*
      *       Display PopUp Messages
      *----------------------------------------------------------------------*
      FORM display_errors.
      *variables
        DATA : l_pos(1) TYPE n VALUE 1. " Field pos
      * Fieldcatalog for popup
        DATA : it_fieldcat_pop TYPE slis_t_fieldcat_alv WITH HEADER LINE.
      * Sales Order #
        it_fieldcat_pop-fieldname         = 'VBELN'.
        it_fieldcat_pop-tabname           = 'IT_ERRMSGS'.
        it_fieldcat_pop-col_pos           = l_pos.
        it_fieldcat_pop-seltext_m         = 'Sales Order# '.
        it_fieldcat_pop-ddictxt           = 'M'.
        it_fieldcat_pop-outputlen         = 10.
        it_fieldcat_pop-no_zero           = 'X'.
        APPEND it_fieldcat_pop.
        CLEAR  it_fieldcat_pop.
        l_pos                              = l_pos + 1.
      * Message
        it_fieldcat_pop-fieldname         = 'MESSAGE'.
        it_fieldcat_pop-tabname           = 'IT_ERRMSGS'.
        it_fieldcat_pop-col_pos           = l_pos.
        it_fieldcat_pop-seltext_m         = 'Message'.
        it_fieldcat_pop-ddictxt           = 'M'.
        it_fieldcat_pop-outputlen         = 255.
        it_fieldcat_pop-no_zero           = 'X'.
        APPEND it_fieldcat_pop.
        CLEAR  it_fieldcat_pop.
      
        CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
          EXPORTING
            i_title       = 'Errors'
            i_tabname     = 'IT_ERRMSGS'
            it_fieldcat   = it_fieldcat_pop[]
          TABLES
            t_outtab      = it_errmsgs
          EXCEPTIONS
            program_error = 1
            OTHERS        = 2.
      ENDFORM.                    " DISPLAY_ERRORS
      
      *&---------------------------------------------------------------------*
      *&      Form  BUILD_FIELDCATALOG
      *&---------------------------------------------------------------------*
      *      Builds FieldCatalog
      *----------------------------------------------------------------------*
      FORM build_fieldcatalog.
        DATA : l_pos(2) TYPE n VALUE 1.
        REFRESH it_fieldcat.
        CLEAR   it_fieldcat.
        l_pos = 1.
      * Order/Line
        it_fieldcat-fieldname = 'VBPOS'.
        it_fieldcat-tabname   = 'IT_OUTPUT'.
        it_fieldcat-col_pos   = l_pos.
        it_fieldcat-outputlen = 17.
        it_fieldcat-seltext_m =  text-013.   "Order/Line
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
        l_pos = l_pos + 1.
      * pLANT
        it_fieldcat-fieldname = 'WERKS'.
        it_fieldcat-tabname   = 'IT_OUTPUT'.
        it_fieldcat-col_pos   = l_pos.
        it_fieldcat-outputlen = 4.
        it_fieldcat-seltext_m =  'Plnt'.   "Plant
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
        l_pos = l_pos + 1.
      * Material#
        it_fieldcat-fieldname  = 'MATNR'.
        it_fieldcat-tabname   = 'IT_OUTPUT'.
        it_fieldcat-col_pos   = l_pos.
        it_fieldcat-outputlen = 18.
        it_fieldcat-seltext_m =  text-006.   "Material#
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
        l_pos = l_pos + 1.
      * Material Desc
        it_fieldcat-fieldname   = 'ARKTX'.
        it_fieldcat-tabname   = 'IT_OUTPUT'.
        it_fieldcat-col_pos   = l_pos.
        it_fieldcat-outputlen = 40.
        it_fieldcat-seltext_m =  text-007.   "Material Desc
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
        l_pos = l_pos + 1.
      * Bill Block
        it_fieldcat-fieldname   = 'FAKSP'.
        it_fieldcat-tabname   = 'IT_OUTPUT'.
      *  it_fieldcat-input     = 'X'.
        it_fieldcat-col_pos   = l_pos.
        it_fieldcat-outputlen =  2.
        it_fieldcat-seltext_m =  text-017.   "Bl Bk
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
        l_pos = l_pos + 1.
      * Cost
        it_fieldcat-fieldname   = 'KBETR'.
        it_fieldcat-tabname   = 'IT_OUTPUT'.
        it_fieldcat-input     = 'X'.
        it_fieldcat-col_pos   = l_pos.
      *  it_fieldcat-outputlen =  9.
        it_fieldcat-seltext_m =  text-018.   "Cost
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
        l_pos = l_pos + 1.
      
      ** Field Catalog for second line in Output.
        l_pos = 1.
      * Cost
        it_fieldcat-fieldname   = 'KBETR'.
        it_fieldcat-tabname   = 'IT_OUTPUT2'.
      *  it_fieldcat-input     = 'X'.
        it_fieldcat-col_pos   = l_pos.
        it_fieldcat-outputlen =  9.
        it_fieldcat-seltext_m =  text-099.   "Cost
        APPEND it_fieldcat.
        CLEAR  it_fieldcat.
      
      *  l_pos = l_pos + 1.
      ** HTS Code
      *  it_fieldcat-fieldname = 'STAWN'.
      *  it_fieldcat-tabname   = 'IT_OUTPUT2'.
      *  it_fieldcat-col_pos   = '2'.
      *  it_fieldcat-outputlen = 17.
      *  it_fieldcat-seltext_m =  text-010.   "HTS Code
      *  APPEND it_fieldcat.
      *  CLEAR  it_fieldcat.
      ENDFORM.                    " BUILD_FIELDCATALOG
      *&---------------------------------------------------------------------*
      *&      Form  BUILD_EVENTS
      *&---------------------------------------------------------------------*
      *       Populate Events Table
      *----------------------------------------------------------------------*
      FORM build_events.
        REFRESH it_events.
        CLEAR   it_events.
      *ADD Top of Page event.
        it_events-name = 'TOP_OF_PAGE'.
        it_events-form = 'TOP_OF_PAGE'.
        APPEND it_events.
        CLEAR  it_events.
      *ADD Top of LIST event.
        it_events-name = 'TOP_OF_LIST'.
        it_events-form = 'TOP-OF-LIST'.
        APPEND it_events.
        CLEAR  it_events.
      ENDFORM.                    " BUILD_EVENTS

      don't forget to reward....

  • author's profile photo Former Member
    Former Member
    Posted on Dec 13, 2005 at 10:46 AM

    My source code is like this. Did I do something wrong?

    l_order_header_inx-updateflag = 'U'.
    
    lw_item_in-itm_number      = '000010'.
    append lw_item_in to lt_item_in.
    
    lw_item_inx-itm_number     = '000010'.
    lw_item_inx-updateflag    = 'U'.
    append lw_item_inx to lt_item_inx.
    
    lw_cond_in-itm_number      = '000010'.
    lw_cond_in-cond_count      = '01'.
    lw_cond_in-cond_type       = 'ZN99'.
    append lw_cond_in to lt_cond_in.
    
    lw_cond_inx-itm_number      = '000010'.
    lw_cond_inx-cond_count      = '01'.
    lw_cond_inx-cond_type       = 'ZN99'.
    lw_cond_inx-updateflag     = 'D'.
    append lw_cond_inx to lt_cond_inx.
    
    CALL FUNCTION 'SD_SALESDOCUMENT_CHANGE'
      EXPORTING
       SALESDOCUMENT               = '0027900417'
       ORDER_HEADER_INX            = l_order_header_inx
      TABLES
        RETURN                     = lt_return
        ITEM_IN                    = lt_item_in
        ITEM_INX                   = lt_item_inx
        CONDITIONS_IN              = lt_cond_in
        CONDITIONS_INX             = lt_cond_inx   .
    
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 24, 2015 at 07:55 PM

    Hi Vijay...

    Greetings from Venezuela,

    I have a pretty good looking scenario with this FM SD_SALESDOCUMENT_CREATE, in productive system is working fine, the source code for this program is the same in productive and develepment system, but in development area the return table is given me a hard time beacause it returns two lines well executed and the rest is error, i describe the return table for you:

    1.- MESSAGE - SALES_HEADER_IN SUCEESFULLY PROCESSED - TYPE "S"

    2.- SALES_ITEM_IN SUCEESFULLY PROCESSED - TYPE "S"

    3.- MISSING CONDITION PB00 IN PRICING SQUEMA A V - TYPE "E"

    4.- SALES DOCUMENT STILL INCOMPLETE PLEASE COMPLETE - TYPE "W"

    5.- SALES DOCUMENT NOT MODIFIED - TYPE "E"

    I've review the internet and don't get a clu in this matter... i think this has to be functional area more than ABAP area, but the SD consultant told me that no change has been made in the system... how can this be happening???

    the source code for the FM is the following:

    *-*-*-*-*-*-*-*-*-*-*-*-****-*-*-*-*-*-*-*-*-*-*-*-****-*-*-*-*-*-*-*-*-*-*-*-***

    CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
    EXPORTING
    sales_header_in = it_bapi_header
    business_object = us_objtype
    IMPORTING
    salesdocument_ex = it_bapi_salesdocument
    TABLES
    return = it_bapi_return
    sales_items_in = it_bapi_items_in
    sales_partners = it_bapi_order_partners
    sales_schedules_in = it_bapi_order_schedules_in
    sales_conditions_in = it_order_conditions_in.

    *-*-*-*-*-*-*-*-*-*-*-*-****-*-*-*-*-*-*-*-*-*-*-*-****-*-*-*-*-*-*-*-*-*-*-*-***


    The source reprt is a claim customer program that's the reason they used this FM. Thanks in advice

    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.