Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem in uploading multiple line items while Creating sales order by BAPI

Hi experts , Im able to create sales order with one item while using this program, but the problem is when iam having multiple items or multiple sales order , iam not able to createthe line items , though its creating sales order header , Iam copy pasting my code , please add the additional code to my code to take more than 1 line items ,This is urgent requirement . Points will be rewarded for answers , Thanks in advance

&----


*& Report Z_SO_CREATE_BAPI

*&

&----


*&

*&

&----


REPORT Z_SO_CREATE_BAPI.

DATA: i_header TYPE bapisdhd1 occurs 0 with header line.

DATA: i_details TYPE bapisditm OCCURS 0 WITH HEADER LINE.

DATA: i_partner TYPE bapiparnr OCCURS 0 WITH HEADER LINE.

DATA: i_return1 TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: i_return2 TYPE bapiret2.

data : ORDER_HEADER_IN like BAPISDHD1.

data : ORDER_ITEMS_IN like BAPISDITM occurs 0 with HEADER LINE .

data : ORDER_ITEMS_INX Like BAPISDITMX 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 : ORDER_SCHEDULES_INX like BAPISCHDLX 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,

MATERIAL LIKE ORDER_ITEMS_IN-MATERIAL ,

  • PLANT LIKE ORDER_ITEMS_IN-PLANT,

  • TARGET_QTY LIKE ORDER_ITEMS_IN-TARGET_QTY,

  • ITM_NUMBERX like ORDER_ITEMS_INX-ITM_NUMBER ,

  • MATERIALX LIKE ORDER_ITEMS_INX-MATERIAL ,

    • CUST_MAT22 LIKE ORDER_ITEMS_IN-CUST_MAT22,

  • PLANTX LIKE ORDER_ITEMS_INX-PLANT,

  • TARGET_QTYX LIKE ORDER_ITEMS_INX-TARGET_QTY,

  • ITM_NUMBER LIKE ORDER_ITEMS_IN-ITM_NUMBER,

  • MATERIAL LIKE ORDER_ITEMS_IN-MATERIAL ,

PARTN_ROLE LIKE ORDER_PARTNERS-PARTN_ROLE,

PARTN_NUMB LIKE ORDER_PARTNERS-PARTN_NUMB,

END OF TAB.

DATA: v_vbeln TYPE bapivbeln-vbeln.

selection-screen begin of block b1 with frame.

skip 3.

parameter:p_infile like rlgrap-filename obligatory.

skip 3.

selection-screen end of block b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.

PERFORM value_help.

*

start-of-selection.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p_infile

FILETYPE = 'DAT'

  • HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = tab.

  • EXCEPTIONS

  • FILE_OPEN_ERROR = 1

  • FILE_READ_ERROR = 2

  • NO_BATCH = 3

  • GUI_REFUSE_FILETRANSFER = 4

  • INVALID_TYPE = 5

  • NO_AUTHORITY = 6

  • UNKNOWN_ERROR = 7

  • BAD_DATA_FORMAT = 8

  • HEADER_NOT_ALLOWED = 9

  • SEPARATOR_NOT_ALLOWED = 10

  • HEADER_TOO_LONG = 11

  • UNKNOWN_DP_ERROR = 12

  • ACCESS_DENIED = 13

  • DP_OUT_OF_MEMORY = 14

  • DISK_FULL = 15

  • DP_TIMEOUT = 16

  • OTHERS = 17

IF sy-subrc <> 0.

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

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

ENDIF.

**Validation for the Create SO screen

*AT SELECTION-SCREEN ON BLOCK na_create.

*

*

Loop at Tab.

i_header-doc_type = TAB-DOC_TYPE .

i_header-sales_org = TAB-SALES_ORG.

i_header-distr_chan = TAB-DISTR_CHAN .

i_header-division = TAB-DIVISION .

append i_header.

*endloop.

i_partner-partn_role = TAB-PARTN_ROLE .

i_partner-partn_numb = TAB-PARTN_NUMB.

APPEND i_partner.

i_details-material = TAB-MATERIAL .

APPEND i_details.

endloop.

*Bapi for Creating SO

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

  • SALESDOCUMENTIN = v_vbeln

order_header_in = i_header

  • ORDER_HEADER_INX =

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

  • CONVERT = ' '

IMPORTING

SALESDOCUMENT = v_vbeln

tables

RETURN = i_return1

ORDER_ITEMS_IN = i_details

ORDER_ITEMS_INX = ORDER_ITEMS_INX

order_partners = i_partner .

  • 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 =

  • EXTENSIONIN =

  • PARTNERADDRESSES =

IF NOT v_vbeln IS INITIAL.

*Bapi Commit Work

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

IMPORTING

return = i_return2

.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

  • IMPORTING

  • RETURN =

.

ENDIF.

LOOP AT i_return1 . "INTO wa_return1.

WRITE:/ i_return1-message.

ENDLOOP.

FORM value_help .

CALL FUNCTION 'DSVAS_DOC_WS_FILENAME_GET_50'

EXPORTING

DEF_FILENAME = ' '

DEF_PATH = ' '

MASK = ',.,..'

MODE = 'O'

TITLE = ' '

IMPORTING

FILENAME = p_infile

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

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.

________________________________________________________________________________________________________________________________________

txt file data

order type salesorg distch divison materialno parter role

TA PB01 01 00 000000000000000852 WE

Partner no

8101000000

Former Member
Not what you were looking for? View more on this topic or Ask a question