Skip to Content

Sometimes the task is not to create order through Bapi, because in this case it will be saved,
if not error occured. If you need to go into a standard transaction, passing
with some header information and items. Here are fragments of programs that
make it easy to do this:

1) Purchase Order.

  Imagine, you have
an ALV report with output table gt_outtab and columns banfn and bnfpo –
purchase requisition no and item. no.

  DATA : header                        LIKE mepoheader,
       mepo_doc       
TYPE mepo_document,
       requisitions   
TYPE  mereq_t_eban_mem,
       wa_requisitions
LIKE LINE OF requisitions,
       items          
LIKE  mepoitem OCCURS 0 WITH HEADER LINE .
DATAlr_selections   TYPE REF TO cl_salv_selections,
       lt_rows        
TYPE salv_t_row,
       ls_row         
LIKE LINE OF  lt_rows.


  lr_selections
= gr_table->get_selections( ).
  lt_rows
= lr_selections->get_selected_rows( ).
 
IF lt_rows IS INITIAL .
   
MESSAGE s001 WITH ‘select any line’ .
   
EXIT .
 
ENDIF.
 
CLEAR : items , items[]  .
 
LOOP AT lt_rows INTO l_row.
   
READ TABLE gt_outtab INDEX l_row .
   
CHECK gt_outtabebeln IS INITIAL .
   
ADD 10 TO itemsebelp .
    items
banfn = gt_outtabbanfn .
    items
bnfpo = gt_outtabbnfpo .
   
APPEND items.
 
ENDLOOP .

* call me21n
 
CALL FUNCTION ‘WB2_PO_PROCESS_START’
   
EXPORTING
      im_ekko              
= header
      im_aktyp             
= ‘H’
   
IMPORTING
      ch_requisitions      
= requisitions
   
TABLES
      cht_items            
= items
   
CHANGING
      ch_document          
= mepo_doc
   
EXCEPTIONS
      invalid_call         
= 1
      invalid_activity_type
= 2
      done                 
= 3
      error                
= 4
     
OTHERS                = 5.

  IF sysubrc <> 0.
* Implement suitable error handling here
 
ENDIF.

2)Sales order basis on previous sales document. Vbeln – number of previous sales document.

  SELECT SINGLE * FROM vbak INTO wa_vbak
        
WHERE vbeln = vbeln.

CALL FUNCTION ‘Z_MAP_VBAKKOM_2_HDRIN’ ” code of FM below
   
EXPORTING
      i_vbakkom      
= vbakkom
   
IMPORTING
      order_header_in
= sales_header_in.

  CLEAR : sales_partners , sales_partners[].

  DATA t_vbpa     LIKE vbpa OCCURS 0 WITH HEADER LINE  .
 
SELECT * FROM vbpa INTO TABLE t_vbpa WHERE vbeln = wa_vbakvbeln .
 
LOOP AT t_vbpa .
    sales_partners
partn_role = t_vbpaparvw.
   
IF NOT t_vbpakunnr IS INITIAL   .
      sales_partners
partn_numb = t_vbpakunnr.
   
ELSEIF NOT t_vbpapernr IS INITIAL   .
      sales_partners
partn_numb = t_vbpapernr .
   
ENDIF .
    sales_partners
itm_number = t_vbpaposnr .
   
APPEND sales_partners.
 
ENDLOOP.

* items
 
CLEAR : sales_items_in[] ,      sales_items_in,
          sales_schedules_in[]
sales_schedules_in,
          sales_conditions_in[]
, sales_conditions_in,
          tab_root_instances[]
root_instances.

    SELECT * FROM vbap INTO wa_vbap WHERE vbeln = vbeln.

     sales_items_initm_number     = wa_vbapposnr .
    sales_items_in
material       = wa_vbapmatnr .
    sales_items_in
reason_rej     = wa_vbapabgru .
    sales_items_in
ref_doc        = wa_vbapvbeln .
    sales_items_in
ref_doc_it     = wa_vbapposnr .
    sales_items_in
ref_doc_ca     = wa_vbak-vbtyp .
    sales_items_in
plant          = wa_vbapwerks .
    sales_items_in
store_loc      = wa_vbaplgort .
    sales_items_in
po_itm_no      = sales_items_initm_number .
   
IF vbtyp_v = ‘B’. ” next doc is contract
      sales_items_in
target_qty     wa_vbaporfmng  .
   
ELSE .
      sales_schedules_in
itm_number     = sales_items_initm_number .
      sales_schedules_in
sched_line     = 1 .
      sales_schedules_in
req_qty        = wa_vbaporfmng   .
     
APPEND sales_schedules_in .
   
ENDIF .
   
APPEND sales_items_in.

* conditions
   
DATA amount_external LIKE  bapicurrbapicurr .
   
SELECT        * FROM  konv INTO wa_konv
                   
WHERE  knumv  = wa_vbakknumv
                     
AND  kposn  = wa_vbapposnr
                     
AND  kherk  = ‘C’.    ” manual conditions
     
IF wa_konvkrech = ‘A’ .   ” 
        wa_konv
kbetr = wa_konvkbetr / 10 .
     
ENDIF .
     
MOVE-CORRESPONDING wa_konv TO komv.
     
CALL FUNCTION ‘MAP2E_KOMV_TO_BAPISDCOND’
       
EXPORTING
          komv      
= komv
       
CHANGING
          bapisdcond
= bapisdcond.

      MOVE-CORRESPONDING bapisdcond TO sales_conditions_in .
     
IF bapisdcondcurrency IS NOT INITIAL .
       
CALL FUNCTION ‘BAPI_CURRENCY_CONV_TO_EXTERNAL’
         
EXPORTING
           
currency        = bapisdcondcurrency
            amount_internal
= bapisdcondcond_value
         
IMPORTING
            amount_external
= amount_external.
        sales_conditions_in
cond_value = amount_external.
     
ENDIF .

      sales_conditions_initm_number = sales_items_initm_number .
     
APPEND sales_conditions_in .
   
ENDSELECT.

    IF tc = ‘X’  .   ” configuration if vehicle, variable tc is flag – material is vehicle

       root_instancesinstance_no = wa_vbapcuobj .
      root_instances
posex  = sales_items_inpo_itm_no  .   
     
APPEND  root_instances TO tab_root_instances .
   
ENDIF .

  ENDSELECT .

   IF tc = ‘X’  .   ” read configuration of previous doc. if it is vehicle
   
CALL FUNCTION ‘CUXI_GET_MULTI_CONFIGURATION’
     
EXPORTING
        i_tab_root_instances        
= tab_root_instances
     
TABLES
        e_tab_cfg_headers           
= e_tab_cfg_headers
        e_tab_instances             
= e_tab_instances
        e_tab_part_of               
= e_tab_part_of
        e_tab_values                
= e_tab_values
        e_tab_var_keys              
= e_tab_var_keys
     
EXCEPTIONS
        invalid_instance            
= 1
        instance_is_a_classification
= 2
        no_root_instance            
= 3
        internal_error              
= 4
        invalid_data                
= 5
       
OTHERS                       = 6.

** clear some fields
   
LOOP AT e_tab_cfg_headers INTO  cfg_headers .
     
CLEAR :   cfg_headerssce ,
                cfg_headers
kbname,
                cfg_headers
kbversion,
                cfg_headers
complete,
                cfg_headers
consistent,
                cfg_headers
cfginfo,
                cfg_headers
kbprofile,
                cfg_headers
kblanguage,
                cfg_headers
cbase_id,
                cfg_headers
cbase_id_type .
     
MODIFY e_tab_cfg_headers  FROM cfg_headers.
   
ENDLOOP .

    LOOP AT e_tab_instances INTO  instances .
     
CLEAR : instancesobj_txt ,
              instances
quantity ,
              instances
author ,
              instances
quantity_unit ,
              instances
complete ,
              instances
consistent ,
              instances
object_guid ,
              instances
persist_id ,
              instances
persist_id_type .
     
MODIFY e_tab_instances FROM instances .
   
ENDLOOP .

    LOOP AT e_tab_values INTO values.
     
CLEAR  valuesvalcode .
     
MODIFY e_tab_values FROM  values .
   
ENDLOOP.
 
ENDIF .

* header conditions
 
SELECT        * FROM  konv INTO wa_konv
                 
WHERE  knumv  = wa_vbakknumv
                   
AND  kposn  = ‘000000’
                   
AND  kherk  = ‘C’.    ” manual
   
IF wa_konvkrech = ‘A’ .   ”       

      wa_konvkbetr = wa_konvkbetr / 10 .
   
ENDIF .
   
MOVE-CORRESPONDING wa_konv TO komv.
   
CALL FUNCTION ‘MAP2E_KOMV_TO_BAPISDCOND’
     
EXPORTING
        komv      
= komv
     
CHANGING
        bapisdcond
= bapisdcond.

    MOVE-CORRESPONDING bapisdcond TO sales_conditions_in .
    sales_conditions_in
itm_number = ‘000000’ .
   
APPEND sales_conditions_in .
 
ENDSELECT.

CALL FUNCTION ‘BAPI_SALESDOCU_CREATEWITHDIA’
 
EXPORTING
    sales_header_in              
= sales_header_in

   synchronous                   = ‘X’

   IMPORTING
   salesdocument_ex             
= vbeln_so
TABLES
  
return                        = return
   sales_items_in               
= sales_items_in

    sales_partners                = sales_partners
   sales_schedules_in           
= sales_schedules_in
   sales_conditions_in          
= sales_conditions_in
   sales_cfgs_ref               
= e_tab_cfg_headers
   sales_cfgs_inst              
= e_tab_instances
   sales_cfgs_value             
= e_tab_values .

  FUNCTION Z_MAP_VBAKKOM_2_HDRIN.
*”———————————————————————-
*”*”Локальный интерфейс:
*”  IMPORTING
*”     REFERENCE(I_VBAKKOM) TYPE  VBAKKOM
*”  EXPORTING
*”     REFERENCE(ORDER_HEADER_IN) TYPE  BAPISDHEAD1
*”———————————————————————-
 
MOVE i_vbakkomauart TO order_header_indoc_type        .
 
MOVE i_vbakkomsubmi TO order_header_incollect_no      .
 
MOVE i_vbakkomvkorg TO order_header_insales_org       .
 
MOVE i_vbakkomvtweg TO order_header_indistr_chan      .
 
MOVE i_vbakkomspart TO order_header_indivision        .
 
MOVE i_vbakkomvkgrp TO order_header_insales_grp       .
 
MOVE i_vbakkomvkbur TO order_header_insales_off       .
 
MOVE i_vbakkomvdatu TO order_header_inreq_date_h      .
 
MOVE i_vbakkomvprgr TO order_header_indate_type       .
 
MOVE i_vbakkombsark TO order_header_inpo_method       .
 
MOVE i_vbakkombstdk TO order_header_inpurch_date      .
 
MOVE i_vbakkombstzd TO order_header_inpo_supplem      .
 
MOVE i_vbakkomihrez TO order_header_inref_1           .
 
MOVE i_vbakkombname TO order_header_inname            .
 
MOVE i_vbakkomtelf1 TO order_header_intelephone       .
 
MOVE i_vbakkomkonda TO order_header_inprice_grp       .
 
MOVE i_vbakkomkdgrp TO order_header_incust_group      .
 
MOVE i_vbakkombzirk TO order_header_insales_dist      .
 
MOVE i_vbakkompltyp TO order_header_inprice_list      .
 
MOVE i_vbakkominco1 TO order_header_inincoterms1      .
 
MOVE i_vbakkominco2 TO order_header_inincoterms2      .
 
MOVE i_vbakkomzterm TO order_header_inpmnttrms        .
 
MOVE i_vbakkomlifsk TO order_header_indlv_block       .
 
MOVE i_vbakkomfaksk TO order_header_inbill_block      .
 
MOVE i_vbakkomaugru TO order_header_inord_reason      .
 
MOVE i_vbakkomautlf TO order_header_incompl_dlv       .
 
MOVE i_vbakkomprsdt TO order_header_inprice_date      .
 
MOVE i_vbakkomangdt TO order_header_inqt_valid_f      .
 
MOVE i_vbakkombnddt TO order_header_inqt_valid_t      .
 
MOVE i_vbakkomguebg TO order_header_inct_valid_f      .
 
MOVE i_vbakkomgueen TO order_header_inct_valid_t      .
 
MOVE i_vbakkomkvgr1 TO order_header_incust_grp1       .
 
MOVE i_vbakkomkvgr2 TO order_header_incust_grp2       .
 
MOVE i_vbakkomkvgr3 TO order_header_incust_grp3       .
 
MOVE i_vbakkomkvgr4 TO order_header_incust_grp4       .
 
MOVE i_vbakkomkvgr5 TO order_header_incust_grp5       .
 
MOVE i_vbakkombstkd TO order_header_inpurch_no_c      .
 
MOVE i_vbakkombstkd_e TO order_header_inpurch_no_s      .
 
MOVE i_vbakkombstdk_e TO order_header_inpo_dat_s        .
 
MOVE i_vbakkombsark_e TO order_header_inpo_meth_s       .
 
MOVE i_vbakkomihrez_e TO order_header_inref_1_s         .
 
MOVE i_vbakkomaudat TO order_header_indoc_date        .
 
MOVE i_vbakkomgwldt TO order_header_inwar_date        .
 
MOVE i_vbakkomvsbed TO order_header_inship_cond       .
 
MOVE i_vbakkomktext TO order_header_inpp_search       .
 
MOVE i_vbakkommahza TO order_header_indun_count       .
 
MOVE i_vbakkommahdt TO order_header_indun_date        .
 
MOVE i_vbakkomabrvw TO order_header_indlvscheduse     .
 
MOVE i_vbakkomabdis TO order_header_inplan_dlv_schtype.
 
MOVE i_vbakkomvgbel TO order_header_inref_doc         .
 
MOVE i_vbakkombukrs_vf TO order_header_incomp_code_b     .
 
MOVE i_vbakkomtaxk1 TO order_header_inalt_tax_class   .
 
MOVE i_vbakkomtaxk2 TO order_header_intax_class2      .
 
MOVE i_vbakkomtaxk3 TO order_header_intax_class3      .
 
MOVE i_vbakkomtaxk4 TO order_header_intax_class4      .
 
MOVE i_vbakkomtaxk5 TO order_header_intax_class5      .
 
MOVE i_vbakkomtaxk6 TO order_header_intax_class6      .
 
MOVE i_vbakkomtaxk7 TO order_header_intax_class7      .
 
MOVE i_vbakkomtaxk8 TO order_header_intax_class8      .
 
MOVE i_vbakkomtaxk9 TO order_header_intax_class9      .
 
MOVE i_vbakkomxblnr TO order_header_inref_doc_l       .
 
MOVE i_vbakkomzuonr TO order_header_in***_number      .
 
MOVE i_vbakkomvgtyp TO order_header_inref_doc_cat     .
 
MOVE i_vbakkomkzazu TO order_header_inord_comb_in     .
 
MOVE i_vbakkomperfk TO order_header_inbill_sched      .
 
MOVE i_vbakkomperrl TO order_header_ininvo_sched      .
 
MOVE i_vbakkommrnkz TO order_header_inmn_invoice      .
 
MOVE i_vbakkomkurrf TO order_header_inexch_rate_fi    .
 
MOVE i_vbakkomvaltg TO order_header_inadd_val_dy      .
 
MOVE i_vbakkomvaldt TO order_header_infix_val_dy      .
 
MOVE i_vbakkomzlsch TO order_header_inpymt_meth       .
 
MOVE i_vbakkomktgrd TO order_header_inaccnt_asgn      .
 
MOVE i_vbakkomkursk TO order_header_inexchg_rate      .
 
MOVE i_vbakkomfkdat TO order_header_inbill_date       .
 
MOVE i_vbakkomfbuda TO order_header_inserv_date       .
 
MOVE i_vbakkommschl TO order_header_indunn_key        .
 
MOVE i_vbakkommansp TO order_header_indunn_block      .
 
MOVE i_vbakkomabssc TO order_header_inpymt_gar_proc   .
 
MOVE i_vbakkomabtnr TO order_header_indepartment_no   .
 
MOVE i_vbakkomempst TO order_header_inrec_point       .
 
MOVE i_vbakkomlcnum TO order_header_indoc_num_fi      .
 
MOVE i_vbakkomkdkg1 TO order_header_incust_cond_grp1  .
 
MOVE i_vbakkomkdkg2 TO order_header_incust_cond_grp2  .
 
MOVE i_vbakkomkdkg3 TO order_header_incust_cond_grp3  .
 
MOVE i_vbakkomkdkg4 TO order_header_incust_cond_grp4  .
 
MOVE i_vbakkomkdkg5 TO order_header_incust_cond_grp5  .
 
MOVE i_vbakkomdelco TO order_header_indlv_time        .
 
MOVE i_vbakkomwaerk TO order_header_inCURRENCY        .
 
MOVE i_vbakkomernam TO order_header_increated_by      .
 
MOVE i_vbakkomlandtx TO order_header_intax_depart_cty  .
 
MOVE i_vbakkomstceg_l TO order_header_intax_dest_cty    .
 
MOVE i_vbakkomxegdr TO order_header_ineu_triang_deal  .
 
MOVE i_vbakkomvbeln_grp TO order_header_inmaster_contr    .
 
MOVE i_vbakkomscheme_grp TO order_header_inref_proc        .
 
MOVE i_vbakkomabruf_part TO order_header_incheck_partn_auth.
 
MOVE i_vbakkomdat_fzau TO order_header_incml_qty_date    .
 
MOVE i_vbakkomvsnmr_v TO order_header_inversion         .
 
MOVE i_vbakkomqmnum TO order_header_innotif_no        .
 
MOVE i_vbakkomvkont TO order_header_infkk_conacct     .

ENDFUNCTION.

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