Application Development 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: 

BAPI_SALESORDER_CREATEFROMDAT2

Former Member
0 Kudos

I have requirement that when purchase order is created. I have to automatically create sales order in ECC System. My problem is when i pass data to BAPI(BAPI_SALESORDER_CREATEFROMDAT2). The Output comes blank no error message. Please help me.

Thanks,

Arun

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Check the RETURN table in the BAPI for any messages.

17 REPLIES 17

prakashjasti
Contributor
0 Kudos

Hi,

Have you used BAPI_TRANSACTION_COMMIT after the BAPI_SALESORDER_CREATEFROMDAT2.

Regards,

Prakash.

Prakash J

0 Kudos

No i have not. Can you tell me the use of it. and how to do. I am new to this

Thanks,

Arun

0 Kudos

Hi,

I searched the net and found some info about (BAPI_TRANSACTION_COMMIT)and applied it. But i am still getting blank.

Is this how to use it.

    call function 'BAPI_TRANSACTION_COMMIT'
  
exporting
    
wait          = 'X'.

Thanks,

Arun

Former Member
0 Kudos

Check the RETURN table in the BAPI for any messages.

0 Kudos

Hi,

I have Error Message saying Sales document type EC is not defined. what would have caused this and how to solve this.

Thanks,

Arun

0 Kudos

It is saying about wrong Sales Document type. But when I see your code, you are sending "OR' as the Document type which is a valid one. Are you still getting the error ( Sales document type EC is not defined)?

0 Kudos

Hi,

i followed the advice of 'sabyasachi karforma' and implied it. now i am getting two types of Errors.

i passed data to order_header_inx and item, schedule. Also i did  order_header_in-doc_type= 'TA'. i am getting

Error : Sales order was not changed

Error : No customer master record exists for customer 0

But when i pass order_header_in-doc-type = 'OR'. I am getting

Error : sales document type OR is not defined

Thanks,

Arun

0 Kudos

Sales Document type TA is fine. It is the output version of order type OR. The error related to partners might be due to you are not sending ship to information in the table ORDER_PARTNERS. Try passing Ship to along with Sold to as  same number as sold to ( Ship to  PARTN_ROLE  = 'WE' ).

Former Member
0 Kudos

Hi,

after the FM BAPI_SALESORDER_CREATEFROMDAT2

you can submit this FM in this way:

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

Regards

Ivan

uppu_narayan
Active Participant
0 Kudos

Hi Arun,

      can you plz post your code............so that you get the solution..

thanks and regards,

narayan

0 Kudos

Hi,

This is a test code.

data : ORDER_HEADER_IN like BAPISDHD1.
data : ORDER_ITEMS_IN like BAPISDITM occurs 0 with
header line.
data : RETURN like BAPIRET2 occurs 0 with header line.
data : ORDER_PARTNERS like BAPIPARNR occurs 0 with
header line.
DATA : ORDER_KEYS LIKE BAPISDKEY OCCURS 0 WITH HEADER
LINE.
data : ORDER_SCHEDULES_IN like BAPISCHDL occurs 0 with
header line.


data : BEGIN OF TAB OCCURS 0,
        SRNO(4),
        DOC_TYPE like ORDER_HEADER_IN-dOC_TYPE,
        SALES_ORG LIKE ORDER_HEADER_IN-SALES_ORG,
        DISTR_CHAN LIKE ORDER_HEADER_IN-DISTR_CHAN,
        DIVISION like ORDER_HEADER_IN-DIVISION,
*        REQ_DATE_H(10),
        PURCH_DATE(10),
        PMNTTRMS LIKE ORDER_HEADER_IN-PMNTTRMS,
        PURCH_NO_C LIKE ORDER_HEADER_IN-PURCH_NO_C,
        ITM_NUMBER like BAPISDITM-ITM_NUMBER,
        CUST_MAT22 LIKE ORDER_ITEMS_IN-CUST_MAT22,
        PLANT LIKE ORDER_ITEMS_IN-PLANT,
        TARGET_QTY LIKE ORDER_ITEMS_IN-TARGET_QTY,
        PARTN_ROLE LIKE ORDER_PARTNERS-PARTN_ROLE,
        PARTN_NUMB LIKE ORDER_PARTNERS-PARTN_NUMB,
      END OF TAB.

data: itab1 like alsmex_tabline occurs 0 with header
line.
DATA: gd_currentrow type i.


data : PURCHASEORDER like ekko-ebeln.


Data: tot_rec type i,     "Total Records
         gd_update type i,   "Main Table Increement Counter
         gd_lines type i,    "Success Table increement Counter
         w_textout like t100-text. "VARIABLE TO GET ERRORLOG


data : begin of it_success occurs 0,
        SALESDOCUMENT LIKE BAPIVBELN-VBELN,  "PROJECT
      end of it_success.

data : begin of it_error occurs 0,
        srno(4),
        err_msg(73) TYPE c,    "TO RETREIVE ERROR MESSAGES
       end of it_error.
data : srno(4).
DATA : SALESDOCUMENT LIKE  BAPIVBELN-VBELN.

data : begin of inttab,
        EBELN TYPE EKKO-EBELN,
        AEDAT TYPE EKKO-AEDAT,
        BSART TYPE EKKO-BSART,
        EKORG TYPE EKKO-EKORG,
        EKGRP TYPE EKKO-EKORG,
        EBELP TYPE EKPO-EBELP,
        TXZ01 TYPE EKPO-TXZ01,
        MATNR TYPE EKPO-MATNR, "MATERIAL NO
        NETPR TYPE string, "NETPRICE
        WERKS type ekpo-WERKS,
        MENGE TYPE EKPO-MENGE,
       end of inttab.

data : gen_segment like edidd-segnam value 'ZIDOC'.

DATA : BEGIN OF INTTAB1,
        CARRID(1000) TYPE C,
       END OF INTTAB1.

data : control_dat like edidc,
          gen_data like inttab1.

data : int_edidd like edidd occurs 0 with header line,
       int_edidc like edidc occurs 0 with header line,
       lit_tab   like inttab occurs 0 with header line.


data : lit_ekko TYPE ekko occurs 0 with header line,
          lit_ekpo TYPE ekpo occurs 0 with header line,
          lit_purchase_check type zpurchase_check occurs 0 with header line.

select * from ekko
   into table lit_ekko
  where aedat = '20020722'.

select * from ekpo
   into table lit_ekpo
        where aedat = '20020722'.

     select * from zpurchase_check
    into table lit_purchase_check
    where aedat = '20020722'.

    if sy-subrc eq 0.

       LOOP AT LIT_EKKO.

       read table lit_ekpo with key ebeln = lit_ekko-ebeln aedat = lit_ekko-aedat.

        LIT_TAB-EBELN = LIT_EKKO-EBELN.
        LIT_TAB-AEDAT = LIT_EKKO-AEDAT.
        LIT_TAB-BSART = LIT_EKKO-BSART.
        LIT_TAB-EKORG = LIT_EKKO-EKORG.
        LIT_TAB-EKGRP = LIT_EKKO-EKGRP.
        LIT_TAB-EBELP = LIT_EKPO-EBELP.
        LIT_TAB-TXZ01 = LIT_EKPO-TXZ01.
        LIT_TAB-MATNR = LIT_EKPO-MATNR.
        LIT_TAB-NETPR = LIT_EKPO-NETPR.
        LIT_TAB-WERKS = LIT_EKPO-WERKS.
        LIT_TAB-MENGE = LIT_EKPO-MENGE.
        APPEND LIT_TAB.

        ENDLOOP.

loop at lit_tab.


order_header_in-doc_type   = 'OR'.
order_header_in-purch_no_c = lit_tab-ebeln.
order_header_in-purch_date = lit_tab-aedat.
ORDER_HEADER_IN-DISTR_CHAN = '20'.
ORDER_HEADER_IN-PURCH_NO_C = '10000001'.
ORDER_HEADER_IN-DIVISION  = '01'.
order_items_in-ITM_NUMBER  = lit_tab-ebelp.
order_items_in-material    = lit_tab-matnr.
*order_items_in-netpr      = lit_tab-netpr.
order_items_in-plant       = lit_tab-WERKS.
append order_items_in.

order_partners-PARTN_ROLE = 'AG'.
order_partners-PARTN_NUMB = '0000001000'.
APPEND ORDER_PARTNERS.

order_schedules_in-itm_number = lit_tab-ebelp.
order_schedules_in-req_qty    = lit_tab-menge.
append order_schedules_in.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
        EXPORTING
*            SALESDOCUMENTIN               =
             ORDER_HEADER_IN               = ORDER_HEADER_IN
*            ORDER_HEADER_INX              =
*            SENDER                        =
*            BINARY_RELATIONSHIPTYPE       =
*            INT_NUMBER_ASSIGNMENT         =
*            BEHAVE_WHEN_ERROR             =
*            LOGIC_SWITCH                  =
*            TESTRUN                       =
*            CONVERT                       = ' '
       IMPORTING
         SALESDOCUMENT                 = SALESDOCUMENT
        TABLES
         RETURN                        = RETURN
             ORDER_ITEMS_IN                = ORDER_ITEMS_IN
*            ORDER_ITEMS_INX               =
             ORDER_PARTNERS                = ORDER_PARTNERS
             ORDER_SCHEDULES_IN            = ORDER_SCHEDULES_IN
*            ORDER_SCHEDULES_INX           =
*            ORDER_CONDITIONS_IN           =
*            ORDER_CONDITIONS_INX          =
*            ORDER_CFGS_REF                =
*            ORDER_CFGS_INST               =
*            ORDER_CFGS_PART_OF            =
*            ORDER_CFGS_VALUE              =
*            ORDER_CFGS_BLOB               =
*            ORDER_CFGS_VK                 =
*            ORDER_CFGS_REFINST            =
*            ORDER_CCARD                   =
*            ORDER_TEXT                    =
         ORDER_KEYS                    = ORDER_KEYS
*            EXTENSIONIN                   =
*            PARTNERADDRESSES              =
.

*   endif.
    call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait          = 'X'.


endloop.

endif.

0 Kudos

Read documentation of BAPI. I think you need to fill in " ORDER_HEADER_INX " , " ORDER_ITEMS_INX" and "ORDER_SCHEDULES_INX". The fields in them are single character. you need to enter "I" or "U" for insert / update. Go through documentation and fill these accordingly.

0 Kudos

Hi,

you have to pass order_header_inx and order_item_inx and order_schedule_inx.

order_header_inx-doc_type   = 'X'.

you have to fill header, item and schedule using above process.

in case of, order_header_in you pass value in some field. in case of order_header_inX you have to pass 'X' to the same field.

i think

order_header_in-doc_type   = 'TA'. you have to use fm coversion_exit_alpha_input.

check message type through RETURN type bapiret2. if all are success message then only use BAPI_TRANSACTION_COMMIT FM.

Thanks

Sabyasachi

0 Kudos

Hi,

i passed data to order_header_inx and item, schedule. Also i did  order_header_in-doc_type= 'TA'. But now i am getting

Error : Sales order was not changed

Error : No customer master record exists for customer 0

Thanks,

Arun

Former Member
0 Kudos

HI All,

Thanks for the support. Solved the issue.

Thanks,

Arun

Former Member
0 Kudos

Hi,

Still you did not get nay solution then try to execute the BAPI manually(SE37) and check the return messages.

Regards,

Shaiksha Vali.

Former Member
0 Kudos

Hello Arun,

BAPI performs a functionality of a transaction or some part of functionality of transaction where data can be posted/created without user continuous interaction or without screens.

I would suggest you if you are planning to use a BAPI, then understand the functionality:

You may go through the documentation completely, identify the transaction which is used for same process and interpret the same by using it or provide inputs to it. You will have better and proper understanding of the functionality and will come to know mandatory fields, the different error messages you would get. In your case try using transaction VA01 and check it out.

Also in BAPI's mostly for creation/change of data or some document, you need to pass flags such as 'X' or 'U' or 'I' for it to be executed completely in tables ending with X eg.order_header_inx[].

Hope it is helpful in some way.

Thanks.