Skip to Content

There’s no real documentation on this BAPI or on BAPI_QUOTATION_CREATEFROMDATA2. Had a lot of trouble with it considering that there was no test data in the development box. As a result I thought I’d share this.


This sample uses Conditions and Characteristics, which turned out to be very difficult to find working information on. Unfortunately no clue on how the sub-items work as it wasn’t part of my requirement.


A very useful transaction to analyze any errors with is CUTRC which I never knew about. Definitely going to start using it more.


Another interesting thing that I figured out is dynamically assigning table structures to FieldSymbols. I had heard that you couldn’t pass a dynamically assigned field symbol (table) to a function but mine works perfectly.


*&———————————————————————*
*& Report  ZUPL_QUOTATION
*&
*&———————————————————————*
*&
*&
*& Should’ve used the second BAPI. More info around on it.
*&———————————————————————*

REPORT zupl_quotation.
“Parameters for screen
SELECTION-SCREEN BEGIN OF BLOCK c1  WITH FRAME TITLE text002.
* Sold-to-party, ship-to-party, Sales Organization, Distribution Channel, Division and a Sales office
PARAMETERS: p_sld_p TYPE vbakkunnr,
             p_shp_p TYPE vbpakunnr,
             p_slorg TYPE vbakvkorg,
             p_distr TYPE vbakvtweg,
             p_div   TYPE vbakspart,
             p_sloff TYPE vbakvkbur,
             p_dfrom TYPE datum,
             p_dto   TYPE datum.

SELECTION-SCREEN END OF BLOCK c1.

SELECTION-SCREEN BEGIN OF BLOCK b1  WITH FRAME TITLE text001.
PARAMETERS: r_sect RADIOBUTTON GROUP rad1 DEFAULT ‘X’,
             r_plat RADIOBUTTON GROUP rad1.
PARAMETERS: p_file TYPE ibipparmspath.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

   CALL FUNCTION ‘F4_FILENAME’
     IMPORTING
       file_name = p_file.

END-OF-SELECTION.
   “Section table
   TYPES: BEGIN OF t_datatab_s,
             quan              TYPE string,
             vc                TYPE string,
             su                TYPE string,
             ch_cu_quality     TYPE string,
             ch_cu_size        TYPE string,
             ch_cu_component   TYPE string,
             ch_zz_length      TYPE string,
             ch_zz_scrap       TYPE string,
             ch_cu_prc_opt     TYPE string,
             ch_drawing_number TYPE string,
             ch_mark_number    TYPE string,
             ch_zz_bundle_size TYPE string,
             ch_cu_time        TYPE string,
             kbetr             TYPE string,
             kpein             TYPE string,
             kmein             TYPE string,
          END OF t_datatab_s.

   “Plates table
   TYPES: BEGIN OF t_datatab_p,
             quan              TYPE string,
             vc                TYPE string,
             su                TYPE string,
             ch_ps_quality     TYPE string,
             ch_ps_size        TYPE string,
             ch_ps_component   TYPE string,
             ch_zz_length      TYPE string,
             ch_zz_width       TYPE string,
             ch_zz_scrap       TYPE string,
             ch_pl_prc_opt     TYPE string,
             ch_drawing_number TYPE string,
             ch_mark_number    TYPE string,
             ch_zz_bundle_size TYPE string,
             ch_mass_item_sn   TYPE string,
             ch_cu_time        TYPE string,
             kbetr             TYPE string,
             kpein             TYPE string,
             kmein             TYPE string,
          END OF t_datatab_p.

   “Excel Variables
   DATA: lt_filestable TYPE STANDARD TABLE OF t_datatab_s,
         lt_fileptable TYPE STANDARD TABLE OF t_datatab_p,
         ls_file_s LIKE LINE OF lt_filestable,
         ls_file_p LIKE LINE OF lt_fileptable,
         lv_file TYPE string,
         lv_rc TYPE sysubrc,
         lv_path TYPE char255,
         it_raw TYPE truxs_t_text_data.
   “Quoatation Variables
   DATA: order_header_in TYPE bapisdhead,
         salesdocument   TYPE bapivbelnvbeln,
         sold_to_party   TYPE bapisoldto,
         ship_to_party   TYPE bapishipto,
         billing_party   TYPE bapipayer,
         order_items_in  TYPE STANDARD TABLE OF bapiitemin WITH HEADER LINE,
         order_partners  TYPE STANDARD TABLE OF bapipartnr WITH HEADER LINE,
         order_items_out TYPE STANDARD TABLE OF bapiitemex WITH HEADER LINE,
         order_cfgs_ref  TYPE STANDARD TABLE OF bapicucfg WITH HEADER LINE,
         order_cfgs_inst TYPE STANDARD TABLE OF bapicuins WITH HEADER LINE,
         order_cfgs_part_of TYPE STANDARD TABLE OF bapicuprt WITH HEADER LINE,
         order_cfgs_value TYPE STANDARD TABLE OF bapicuval WITH HEADER LINE,
         lv_instid TYPE cu_inst_id,
         lv_itemid TYPE posnr_va,
         lv_configid TYPE cux_cfg_id.

   DATA: BEGIN OF li_return OCCURS 1.
           INCLUDE STRUCTURE bapiret1.
   DATA: END OF li_return.

   FIELD-SYMBOLS: <f_table> TYPE STANDARD TABLE,
                  <f_wa>    TYPE any,
                  <field>   TYPE any.
   DATA: it_knvp TYPE TABLE OF knvp,
         lv_parvw TYPE parvw.
   TABLES: knvp.

   lv_parvw = ‘SP’.

   CALL FUNCTION ‘CONVERSION_EXIT_PARVW_INPUT’
     EXPORTING
       input         = lv_parvw
     IMPORTING
       OUTPUT        = lv_parvw.

   SELECT * FROM knvp
            WHERE kunnr = p_sld_p
              AND kunn2 = p_shp_p
              AND parvw = lv_parvw.
   ENDSELECT.
   IF sysubrc = 4.
     MESSAGE E000(ZATS_MSG) WITH ‘The Ship-to-Party is not linked’ ‘to the selected Sold-to-Party’.
   ENDIF.
   “Radio buttons
   IF r_sect = ‘X’. “Sections File
     ASSIGN lt_filestable TO <f_table>.
     ASSIGN ls_file_s TO <f_wa>.
   ELSE. “Plates File
     ASSIGN lt_fileptable TO <f_table>.
     ASSIGN ls_file_p TO <f_wa>.
   ENDIF.

   “Initialize values.
   lv_itemid = ‘000010’.
   lv_configid = ‘000001’.
   lv_instid = ‘00000001’.

   “Import data
   CALL FUNCTION ‘TEXT_CONVERT_XLS_TO_SAP’
     EXPORTING
       i_line_header        = ‘X’
       i_tab_raw_data       = it_raw
      i_filename           = p_file
     TABLES
       i_tab_converted_data = <f_table>
     EXCEPTIONS
       conversion_failed    = 1
       OTHERS               = 2.

   IF sysubrc <> 0.
     MESSAGE ID symsgid TYPE symsgty NUMBER symsgno
             WITH symsgv1 symsgv2 symsgv3 symsgv4.
   ENDIF.

   “Mapping section from Excel file to Quoatation data.
   order_header_indoc_type = ‘ZQT1’.
   order_header_insales_org = p_slorg.
   order_header_indistr_chan = p_distr.
   order_header_indivision p_div.
*  order_header_in-ref_1 = ‘Your Reference Number’.
   order_header_inqt_valid_f = p_dfrom“Quotation start date
   order_header_inqt_valid_t = p_dto.   “Quotation end date

   order_partnerspartn_role = ‘SP’.
   order_partnerspartn_numb = p_sld_p. “Sold to party
   CALL FUNCTION ‘CONVERSION_EXIT_PARVW_INPUT’ “Required as the data is stored different on the database.
     EXPORTING
       input  = order_partnerspartn_role
     IMPORTING
       output = order_partnerspartn_role.
   APPEND order_partners.

   order_partnerspartn_role = ‘SH’. “Ship to party
   order_partnerspartn_numb = p_shp_p.
   CALL FUNCTION ‘CONVERSION_EXIT_PARVW_INPUT’ Required as the data is stored different on the database.
     EXPORTING
       input  = order_partnerspartn_role
     IMPORTING
       output = order_partnerspartn_role.
   APPEND order_partners.

   LOOP AT <f_table> INTO <f_wa>.
     order_items_initm_number = lv_itemid. “Item Number
     order_items_inpo_itm_no = lv_itemid. “Points to the Characteristics… Without it none are populated.
     “Don’t exist in this structure.
*    ORDER_ITEMS_IN-CONFIG_ID = lv_configid.
*    ORDER_ITEMS_IN-INST_ID = lv_instid.

     ASSIGN COMPONENT ‘VC’ OF STRUCTURE <f_wa> TO <field>.
     order_items_inmaterial = <field>. “Material Number
     CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
       EXPORTING
         input  = order_items_inmaterial
       IMPORTING
         output = order_items_inmaterial.

     ASSIGN COMPONENT ‘QUAN’ OF STRUCTURE <f_wa> TO <field>.
     order_items_inreq_qty = <field>. “Quantity
     MULTIPLY order_items_inreq_qty BY 1000.
     ASSIGN COMPONENT ‘SU’ OF STRUCTURE <f_wa> TO <field>.
     order_items_intarget_qu = <field>. “Measurement

     order_items_inCOND_TYPE = ‘ZPRM’. “Should this be hardcoded to work?? Apparently so.
     ASSIGN COMPONENT ‘KBETR’ OF STRUCTURE <f_wa> TO <field>.
     order_items_incond_value = <field>. “Rate
     DIVIDE order_items_incond_value BY 10.
     ASSIGN COMPONENT ‘KPEIN’ OF STRUCTURE <f_wa> TO <field>.
     order_items_incond_p_unt = <field>. “Condition Pricing Unit
     ASSIGN COMPONENT ‘KMEIN’ OF STRUCTURE <f_wa> TO <field>.
     order_items_incond_d_unt = <field>. “Condition Unit

     APPEND order_items_in.

     “Header texts section.
     order_cfgs_valueconfig_id = lv_configid.
     order_cfgs_valueinst_id = lv_instid.
     order_cfgs_valuecharc = ‘CH_ZZ_LENGTH’.
     ASSIGN COMPONENT ‘CH_ZZ_LENGTH’ OF STRUCTURE <f_wa> TO <field>.
     order_cfgs_valuevalue = <field>.
     APPEND order_cfgs_value.

     order_cfgs_valueconfig_id = lv_configid.
     order_cfgs_valueinst_id = lv_instid.
     order_cfgs_valuecharc = ‘CH_ZZ_SCRAP’.
     ASSIGN COMPONENT ‘CH_ZZ_SCRAP’ OF STRUCTURE <f_wa> TO <field>.
     order_cfgs_valuevalue = <field>.
     APPEND order_cfgs_value.

     order_cfgs_valueconfig_id = lv_configid.
     order_cfgs_valueinst_id = lv_instid.
     order_cfgs_valuecharc = ‘CH_DRAWING_NUMBER’.
     ASSIGN COMPONENT ‘CH_DRAWING_NUMBER’ OF STRUCTURE <f_wa> TO <field>.
     order_cfgs_valuevalue = <field>.
     APPEND order_cfgs_value.

     order_cfgs_valueconfig_id = lv_configid.
     order_cfgs_valueinst_id = lv_instid.
     order_cfgs_valuecharc = ‘CH_MARK_NUMBER’.
     ASSIGN COMPONENT ‘CH_MARK_NUMBER’ OF STRUCTURE <f_wa> TO <field>.
     order_cfgs_valuevalue = <field>.
     APPEND order_cfgs_value.

     order_cfgs_valueconfig_id = lv_configid.
     order_cfgs_valueinst_id = lv_instid.
     order_cfgs_valuecharc = ‘CH_ZZ_BUNDLE_SIZE’.
     ASSIGN COMPONENT ‘CH_ZZ_BUNDLE_SIZE’ OF STRUCTURE <f_wa> TO <field>.
     order_cfgs_valuevalue = <field>.
     APPEND order_cfgs_value.

     order_cfgs_valueconfig_id = lv_configid.
     order_cfgs_valueinst_id = lv_instid.
     order_cfgs_valuecharc = ‘CH_CU_TIME’.
     ASSIGN COMPONENT ‘CH_CU_TIME’ OF STRUCTURE <f_wa> TO <field>.
     order_cfgs_valuevalue = <field>.
     APPEND order_cfgs_value.

     IF r_sect = ‘X’. “Section File
       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_CU_COMPONENT’.
       ASSIGN COMPONENT ‘CH_CU_COMPONENT’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_CU_PRC_OPT’.
       ASSIGN COMPONENT ‘CH_CU_PRC_OPT’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_CU_QUALITY’.
       ASSIGN COMPONENT ‘CH_CU_QUALITY’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_CU_SIZE’.
       ASSIGN COMPONENT ‘CH_CU_SIZE’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

     ELSEIF r_plat = ‘X’. “Plates File
       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_PS_COMPONENT’.
       ASSIGN COMPONENT ‘CH_PS_COMPONENT’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_PL_PRC_OPT’.
       ASSIGN COMPONENT ‘CH_PL_PRC_OPT’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_PS_QUALITY’.
       ASSIGN COMPONENT ‘CH_PS_QUALITY’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valueconfig_id = lv_configid.
       order_cfgs_valueinst_id = lv_instid.
       order_cfgs_valuecharc = ‘CH_PS_SIZE’.
       ASSIGN COMPONENT ‘CH_PS_SIZE’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valuecharc = ‘CH_ZZ_WIDTH’.
       ASSIGN COMPONENT ‘CH_ZZ_WIDTH’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.

       order_cfgs_valuecharc = ‘CH_MASS_ITEM_SN’.
       ASSIGN COMPONENT ‘CH_MASS_ITEM_SN’ OF STRUCTURE <f_wa> TO <field>.
       order_cfgs_valuevalue = <field>.
       APPEND order_cfgs_value.
     ENDIF.
     “End of texts (Characteristics)

     “Need to fill in order_cfgs_ref & order_cfgs_inst and possibly order_cfgs_part_of too.
     “Got the information from an example using BAPI_QUOTATION_GETDETAILBOS
     order_cfgs_refposex  = lv_itemid.
     order_cfgs_refconfig_id = lv_configid.
     order_cfgs_refroot_id = lv_instid. “The type is inst_id.
     APPEND order_cfgs_ref.

     order_cfgs_instconfig_id = lv_configid.
     order_cfgs_instinst_id  = lv_instid.
     order_cfgs_instobj_type = ‘MARA’.
     order_cfgs_instclass_type = ‘300’.
     order_cfgs_instobj_key = order_items_inmaterial.
     order_cfgs_instquantity = order_items_intarget_qty.
     APPEND order_cfgs_inst.

     “Only for configurable sub-items..
*    order_cfgs_part_of-config_id = lv_configid.
*    order_cfgs_part_of-parent_id = lv_itemid.
*    order_cfgs_part_of-inst_id = lv_instid.
*    order_cfgs_part_of-class_type = ‘300’.
*    order_cfgs_part_of-obj_type = ‘MARA’.
*    order_cfgs_part_of-obj_key = order_items_in-material.
*    APPEND order_cfgs_part_of.

     ADD 10 TO lv_itemid. “Items count in tens. Will be derived though if left open apparently.
     ADD 1 TO lv_configid. “Appears to increase per line item.
     CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
       EXPORTING
         input  = lv_itemid
       IMPORTING
         output = lv_itemid.

     CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
       EXPORTING
         input  = lv_configid
       IMPORTING
         output = lv_configid.

*    lv_instid = lv_instid + 1. “Apparently this stays 1 as per the GETDETAILBOS example.
   ENDLOOP.

   CALL FUNCTION ‘BAPI_QUOTATION_CREATEFROMDATA’
     EXPORTING
       order_header_in     = order_header_in
*     without_commit      = ‘ ‘
*     convert_parvw_auart = ‘ ‘
     IMPORTING
       salesdocument       = salesdocument
       sold_to_party       = sold_to_party
       ship_to_party       = ship_to_party
*     billing_party       =
       return              = li_return
     TABLES
       order_items_in      = order_items_in
       order_partners      = order_partners
       order_items_out     = order_items_out
       order_cfgs_ref      = order_cfgs_ref
       order_cfgs_inst     = order_cfgs_inst
       order_cfgs_part_of  = order_cfgs_part_of
       order_cfgs_value    = order_cfgs_value.

   IF NOT li_return IS INITIAL.
     WRITE:/ li_returntype,
             li_returnmessage.
   ELSE.
     WRITE:/ ‘Quotation ‘, salesdocument, ‘ created successfully.’.
   ENDIF.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply