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 for sales order

Former Member
0 Kudos
196

Hi to all,

i had used the bapi BAPI_SALESORDER_CREATEFROMDAT1 for sales order creation.

but iam getting a message the document type does not exit.

I had executed in debugging mode but what i found is the table ORDER_HEADER_IN is initial even though the pass the data thru an intenal table.

could any one help me out.

Thanks & Regards,

satish

3 REPLIES 3

Former Member
0 Kudos
111

Hi!

In the newer versions of SAP, BAPI_SALESORDER_CREATEFROMDAT1 is obsolete.

Use BAPI_SALESORDER_CREATEFROMDAT2 instead of 1.

Regards

Tamá

Former Member
0 Kudos
111

Hi,

i think you are passing only the header to that function module, seee the below example program and pass the fields accordingly

*&---------------------------------------------------------------------* 
*& Report  ZMMC2_CREATE_ORDER                                          * 
*&                                                                     * 
*&---------------------------------------------------------------------* 
*&                                                                     * 
*&    This report will execute the actual ZMMC2 sales order creations. * 
*&    It will create a ZORI order with blocked code 99.                * 
*&    It can be called from ZMMC2 or ran in background.                * 
*&                                                                     * 
*&    The original report was written in release 4.0B, but now, in 4.7 * 
*&    as much batch input code as possible is replaced by BAPI's.      * 
*&                                                                     * 
*&                                                                     * 
*&---------------------------------------------------------------------* 

REPORT  zmmc2_create_order LINE-SIZE 132. 


**********DATA DECLARATION*************** 

TABLES: zrt01, 
        zrt03, 
        zrtmsg, 
        vbap, 
        mvke,                                               " 
        mast.                          " routing allocation 


DATA: BEGIN OF sel_zrt01 OCCURS 0. 
        INCLUDE STRUCTURE zrt01. 
DATA: END OF sel_zrt01. 

DATA: BEGIN OF sel_zrt02 OCCURS 0. 
        INCLUDE STRUCTURE zrt02. 
DATA: END OF sel_zrt02. 

DATA: BEGIN OF msg OCCURS 0. 
        INCLUDE STRUCTURE bdcmsgcoll. 
DATA: END OF msg. 

data: i_header type BAPISDHEAD, 
      i_partner type BAPIPARTNR occurs 0 with header line, 
      i_items type BAPIITEMIN occurs 0 with header line, 
      result type BAPIRETURN1, 
      sales_doc like BAPIVBELN-VBELN. 

DATA: BEGIN OF message_log OCCURS 0, 
        tcode  LIKE sy-tcode, 
        msgtyp, 
        msgid(20), 
        msgnr(3), 
        var1(50), 
        var2(50), 
        var3(50), 
        var4(50), 
      END OF message_log. 


DATA: wrkcnt TYPE i. 

DATA: BEGIN OF BDCDATA OCCURS 0. 
        INCLUDE STRUCTURE BDCDATA. 
DATA: END OF BDCDATA. 

**************SELECTION SCREEN****************** 

SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME. 
  SELECT-OPTIONS slimtnbr FOR zrt03-imtnbr. 
*  PARAMETER wrk_mode TYPE c DEFAULT 'N'. 
  PARAMETER pchkonly AS CHECKBOX DEFAULT ' '. 
  PARAMETER plistcre AS CHECKBOX DEFAULT ' '. 
  PARAMETER pmaxcnt TYPE i DEFAULT 2. 
SELECTION-SCREEN END OF BLOCK sel1. 


************************************************ 
START-OF-SELECTION. 
************************************************ 

  wrkcnt = 0. 


*Get Material Master* 

  PERFORM read_orders_to_create. 

  IF wrkcnt > 0. 
    PERFORM process_orders_to_create. 
  ENDIF. 

*********************************************** 
END-OF-SELECTION. 
*********************************************** 
SET PF-STATUS '100'. 

AT USER-COMMAND. 
  IF SY-UCOMM = 'SUBMIT'. 
    SUBMIT ZMMCD_CREATE_ORDER 
      WITH SLIMTNBR IN SLIMTNBR 
      WITH PCHKONLY = ' ' 
      WITH PLISTCRE = PLISTCRE 
      WITH PMAXCNT = PMAXCNT 
      AND RETURN. 
  ENDIF. 



*&---------------------------------------------------------------------* 
*&      Form  READ_ORDERS_TO_CREATE 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*----------------------------------------------------------------------* 
FORM read_orders_to_create . 

  DATA: wrk_matnr LIKE mvke-matnr. 

  FREE sel_zrt01. 
  CLEAR sel_zrt01. 

*************Select BOM's to create************* 
  SELECT * FROM zrt01 WHERE imtnbr IN slimtnbr 
                      AND expcrea = 'X'. 

    wrk_matnr = zrt01-imtnbr. 

    SELECT SINGLE * FROM mvke WHERE matnr = wrk_matnr 
                               AND  vkorg = zrt01-expvkorg 
                               AND  vtweg = zrt01-expvtweg. 
    CHECK sy-subrc = 0. 

    MOVE-CORRESPONDING zrt01 TO sel_zrt01. 
    APPEND sel_zrt01. 
    wrkcnt = wrkcnt + 1. 
    IF wrkcnt >= pmaxcnt. 
      EXIT. 
    ENDIF. 

  ENDSELECT. 

  IF pchkonly = 'X' OR plistcre = 'X'. 
    SKIP. 
    WRITE: /  'Number of Orders to create:' , wrkcnt. 
    SKIP. 

  ENDIF. 

ENDFORM.                    " READ_ORDERS_TO_CREATE 
*&---------------------------------------------------------------------* 
*&      Form  PROCESS_ORDERS_TO_CREATE 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*----------------------------------------------------------------------* 
FORM process_orders_to_create . 

  LOOP AT sel_zrt01. 
    IF PCHKONLY <> 'X'. 
      MOVE-CORRESPONDING SEL_ZRT01 TO ZRT01. 
* 
      PERFORM INSERT_ORDER_IN_FILE. 
* 
      SELECT SINGLE *  FROM VBAP 
                       WHERE MATNR = SEL_ZRT01-IMTNBR. 
* 
      IF SY-SUBRC = 0. 
        MOVE 'Y' TO ZRT01-EXPCREA. 
        UPDATE ZRT01. 
      ELSE. 
        MOVE 'E' TO ZRT01-EXPCREA. 
        UPDATE ZRT01. 
      ENDIF. 
* 
    ENDIF. 
* 
    IF PLISTCRE = 'X' OR PCHKONLY = 'X'. 
      WRITE: /  SEL_ZRT01-IMTNBR, 
                SEL_ZRT01-EXPVKORG, 
                SEL_ZRT01-EXPVTWEG, 
                SEL_ZRT01-CUST, 
                SEL_ZRT01-NAMECUST, 
                SEL_ZRT01-PONBR, 
                SEL_ZRT01-EXPQTY, 
                SEL_ZRT01-EXPUNI, 
                'Order:', 
                VBAP-VBELN. 
    ENDIF. 
  ENDLOOP. 

ENDFORM.                    " PROCESS_ORDERS_TO_CREATE 
*&---------------------------------------------------------------------* 
*&      Form  INSERT_ORDER_IN_FILE 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*----------------------------------------------------------------------* 
form INSERT_ORDER_IN_FILE . 

  data: WRK_EXPPRICE(10) type c. 
  clear i_header. 

  clear: i_partner, i_items. 
  free: i_partner, i_items. 

  IF ZRT01-AUART IS INITIAL. 
    i_header-doc_type = 'ZORI'. 
  ELSE. 
    i_header-doc_type = zrt01-auart. 
  ENDIF. 

  i_header-sales_org = ZRT01-EXPVKORG. 
  i_header-distr_chan = ZRT01-EXPVTWEG. 
  i_header-division = 'AL'. 

  i_header-purch_no = ZRT01-PONBR. 

*Customer data********* 
  i_partner-partn_numb = ZRT01-CUST. 
  i_partner-partn_role = 'AG'. 
* 
  IF NOT ZRT01-EXPDLDT IS INITIAL. 
    i_header-req_date_h = zrt01-expdldt. 
  ENDIF. 

  i_header-dlv_block = 99. 

*Items***************** 
  i_items-material = zrt01-imtnbr. 
  i_items-req_qty = ZRT01-EXPQTY * 1000. 
  i_items-target_qu = ZRT01-EXPUNI. 
  i_items-sales_unit = ZRT01-EXPUNI. 
  i_items-plant = ZRT01-ZZPLNWERKS. 
  i_items-cond_type = 'ZPR0'. 
  i_items-cond_value = ZRT01-EXPPRICE. 


  append: i_partner, i_items. 

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1' 
        EXPORTING 
          order_header_in           = i_header 
*         WITHOUT_COMMIT            = ' ' 
*         CONVERT_PARVW_AUART       = ' ' 
       IMPORTING 
          SALESDOCUMENT             = sales_doc 
*         SOLD_TO_PARTY             = 
*         SHIP_TO_PARTY             = 
*         BILLING_PARTY             = 
         RETURN                    = result 
        tables 
          order_items_in            = i_items 
          order_partners            = i_partner 
*         ORDER_ITEMS_OUT           = 
*         ORDER_CFGS_REF            = i_conf_data 
*         ORDER_CFGS_INST           = 
*         ORDER_CFGS_PART_OF        = 
*         ORDER_CFGS_VALUE          = i_config 
*         ORDER_CCARD               = 
*         ORDER_CFGS_BLOB           = 
*         ORDER_SCHEDULE_EX         = 
                  . 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. 

write: / sales_doc. 
PERFORM savmsg. 

*First screen to enter sales document number 
perform BDC_FILL using 'SAPMV45A' '0102' 'X'. 
perform bdc_fill using 'VBAK-VBELN' sales_doc ' '. 
perform bdc_fill using 'BDC_OKCODE' '/00' ' '. 

*Second screen to select material and go to config and back. 
perform bdc_fill using 'SAPMV45A' '4001' 'X'. 

perform bdc_fill using 'RV45A-VBAP_SELKZ(01)' 'X' ' '. 
perform bdc_fill using 'BDC_OKCODE' '=POCO' ' '. 
*This is where it goes wrong. This okcode is suppose to let the 
*prog jump to the config screen but it doesnt do it and when i 
*execute the batchinput part seperatly it works fine. I 
*think it has something to do with the bapi call before the batch input 

*Go to config 
perform bdc_fill using 'SAPLCEI0' '0109' 'X'. 
perform bdc_fill using 'BDC_OKCODE' '=BACK' ' '. 

*Go back 
perform bdc_fill using 'SAPMV45A' '4001' 'X'. 
perform bdc_fill using 'BDC_OKCODE' '=SICH' ' '. 

CALL TRANSACTION 'VA02'  USING  BDCDATA 
                           MODE 'A' 
                           UPDATE 'A'. 
*                           MESSAGES INTO MSG. 

endform.                    " INSERT_ORDER_IN_FILE 
*&---------------------------------------------------------------------* 
*&      Form  savmsg 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*  -->  p1        text 
*  <--  p2        text 
*----------------------------------------------------------------------* 
form savmsg . 

DATA: text(150). 

if result-type = 'E'. 
  move: result-type to message_log-msgtyp, 
        result-id to message_log-msgid, 
        result-number to message_log-msgnr, 
        result-message_v1 to message_log-var1, 
        result-message_v2 to message_log-var2, 
        result-message_v3 to message_log-var3. 
  message_log-tcode = 'VA01'. 
  APPEND message_log. 

  CLEAR text. 
    CALL FUNCTION 'MESSAGE_TEXT_BUILD' 
      EXPORTING 
        msgid               = message_log-msgid 
        msgnr               = message_log-msgnr 
        msgv1               = message_log-var1 
        msgv2               = message_log-var2 
        msgv3               = message_log-var3 
        msgv4               = message_log-var4 
      IMPORTING 
        message_text_output = text. 

   MOVE: zrt01-imtnbr TO zrtmsg-imtnbr, 
          sy-uname     TO zrtmsg-userid, 
          sy-datum     TO zrtmsg-creadat, 
          sy-uzeit     TO zrtmsg-creatim. 
    zrtmsg-counter = zrtmsg-counter + 1. 
    MOVE-CORRESPONDING message_log TO zrtmsg. 

    MOVE: zrt01-imtnbr TO zrtmsg-matnr, 
          ZRT01-ZZPLNWERKS TO zrtmsg-werks, 
          ZRT01-EXPVKORG  TO zrtmsg-vkorg, 
          ZRT01-EXPVTWEG TO zrtmsg-vtweg, 
          text         TO zrtmsg-text. 
    INSERT  zrtmsg . 

    CLEAR: message_log, result. 
    FREE:  message_log. 

endif. 

endform.                    " savmsg 
*&---------------------------------------------------------------------* 
*&      Form  BDC_FILL 
*&---------------------------------------------------------------------* 
*       text 
*----------------------------------------------------------------------* 
*      -->P_0504   text 
*      -->P_0505   text 
*      -->P_0506   text 
*----------------------------------------------------------------------* 
form BDC_FILL  using VALUE_A VALUE_B CHECK. 
clear bdcdata. 
if check = 'X'. 
  bdcdata-program = value_a. 
  bdcdata-dynpro = value_b. 
  bdcdata-dynbegin = 'X'. 
else. 
  bdcdata-fnam = value_a. 
  bdcdata-fval = value_b. 
endif. 
append bdcdata. 
endform.                    " BDC_FILL 

Regards

Sudheer

0 Kudos
111

hi Sudheer,

I had written the following code could you check.

PARAMETERS:P_FPATH LIKE RLGRAP-FILENAME.

PARAMETERS:B AS CHECKBOX .

*internal table to hold header data.

DATA: BEGIN OF IT_VA01 occurs 0,

AUART(4),

KUNNR(10),

BSTKD(35),

BSTDK(10),

TEXT(100),

END OF IT_VA01.

*internal table to hold line items data.

DATA:BEGIN OF IT_ITEM OCCURS 0,

POSNR LIKE VBAP-POSNR,

MATNR LIKE VBAP-MATNR,

KWMENG(15),

WERKS LIKE VBAP-WERKS,

KBETR(11) ,

END OF IT_ITEM.

*internal table to hold error messages.

DATA: BEGIN OF it_error OCCURS 100,

msg LIKE BAPIRET2-message, "Error message

END OF it_error.

DATA:V_VKORG(4) VALUE '5031'.

DATA:V_VTWEG(2) VALUE '50'.

DATA:V_SPART(2) VALUE '73'.

data:v_date LIKE SY-DATUM.

data:v_prole(2) value 'SP'.

data:v_sonum like BAPIVBELN-VBELN.

data:msg(255) TYPE c.

DATA:V_COND_TYPE(4) VALUE 'ZPR'.

data:it_header like bapisdhead occurs 0 with header line.

data:it_BAPIITEMIN like BAPIITEMIN occurs 0 with header line.

data:it_BAPIPARTNR like BAPIPARNR occurs 0 with header line.

data:it_return like standard table of BAPIRETURN1 with header line.

INITIALIZATION.

clear v_date.

v_date = sy-datum.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FPATH.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FPATH'

IMPORTING

FILE_NAME = P_FPATH.

START-OF-SELECTION.

clear it_return.

PERFORM GET_DATA.

perform upload.

&----


*& Form GET_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_DATA .

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

  • CODEPAGE = ' '

FILENAME = p_fpath

FILETYPE = 'DAT'

  • HEADLEN = ' '

  • LINE_EXIT = ' '

  • TRUNCLEN = ' '

  • USER_FORM = ' '

  • USER_PROG = ' '

  • DAT_D_FORMAT = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = it_va01.

  • EXCEPTIONS

  • CONVERSION_ERROR = 1

  • FILE_OPEN_ERROR = 2

  • FILE_READ_ERROR = 3

  • INVALID_TYPE = 4

  • NO_BATCH = 5

  • UNKNOWN_ERROR = 6

  • INVALID_TABLE_WIDTH = 7

  • GUI_REFUSE_FILETRANSFER = 8

  • CUSTOMER_ERROR = 9

  • NO_AUTHORITY = 10

  • OTHERS = 11

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " GET_DATA

&----


*& Form upload

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM upload .

LOOP AT IT_VA01.

SPLIT IT_VA01-TEXT AT ',' INTO IT_item-posnr IT_item-MATNR

IT_item-KWMENG IT_item-WERKS IT_item-KBETR.

APPEND it_item.

CLEAR it_item.

ENDLOOP.

*SD_ORDER_HEADER

LOOP AT IT_VA01.

  • CALL FUNCTION 'CONVERSION_EXIT_AUART_INPUT'

  • EXPORTING

  • INPUT = IT_VA01-AUART

  • IMPORTING

  • OUTPUT = IT_VA01-AUART.

it_header-DOC_TYPE = IT_VA01-AUART.

it_header-SALES_ORG = V_VKORG.

it_header-DISTR_CHAN = V_VTWEG.

it_header-DIVISION = V_SPART.

it_header-PURCH_NO = IT_VA01-BSTKD.

CALL FUNCTION 'CONVERSION_EXIT_IDATE_INPUT'

EXPORTING

INPUT = IT_VA01-BSTDK

IMPORTING

OUTPUT = IT_VA01-BSTDK.

it_header-PURCH_DATE = IT_VA01-BSTDK.

it_header-REQ_DATE_H = v_date.

append it_header.

clear it_header.

endloop.

  • SD_ORDER_ITEMS_IN

LOOP AT IT_ITEM.

it_BAPIITEMIN-ITM_NUMBER = IT_item-posnr.

it_BAPIITEMIN-MATERIAL = IT_item-MATNR.

it_BAPIITEMIN-PLANT = IT_item-WERKS.

it_BAPIITEMIN-req_QTY = IT_item-KWMENG.

it_BAPIITEMIN-COND_TYPE = V_COND_TYPE.

it_BAPIITEMIN-COND_VALUE = IT_item-KBETR.

append it_BAPIITEMIN.

clear it_BAPIITEMIN.

ENDLOOP.

*SD_ORDER_PARTNERS

loop at it_va01.

it_BAPIPARTNR-PARTN_ROLE = V_PROLE.

it_BAPIPARTNR-PARTN_NUMB = it_va01-kunnr.

append it_BAPIPARTNR.

clear it_BAPIPARTNR.

endloop.

IF B = 'X'.

CLEAR V_SONUM.

  • CREATE_ORDER

clear it_return.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'

EXPORTING

ORDER_HEADER_IN = it_header

  • WITHOUT_COMMIT = 'X'

  • CONVERT_PARVW_AUART = 'X'

IMPORTING

SALESDOCUMENT = v_sonum

  • SOLD_TO_PARTY =

  • SHIP_TO_PARTY =

  • BILLING_PARTY =

RETURN = it_return

TABLES

ORDER_ITEMS_IN = it_BAPIITEMIN

ORDER_PARTNERS = it_BAPIPARTNR.

LOOP AT it_return WHERE type EQ 'E' OR type EQ 'A'.

IF it_return-type EQ 'E'.

it_error-msg = it_return-message.

APPEND it_error.

CLEAR it_error.

ENDIF.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .

EXIT.

ENDLOOP.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ENDIF.

IF sy-subrc EQ 0.

WRITE:/ v_sonum , '* PROCESSED OK *'.

else.

loop at it_error.

write:/ it_error-msg.

endloop.

endif.

endif.

thanks & Regards,

satish