Application Development and Automation 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: 
Read only

Adding text to SO using BAPI

Former Member
0 Likes
2,067

HI ,

I am using BAPI to create sales order BAPI_SALESORDER_CREATEFROMDAT2.

While creating i want to add text in the line items.

Is it possible?

There is a structure ORDER_TEXT, shud i use this?

But it asks for sales order number, which is not yet created until the BAPI is processed.

Isnt it possible to add the text while creating the SO using this BAPI?if yes then how

thanks

Points will be rewarded

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,588

Hi Kantheri,

Yes you can add the text while creating the salesorder it self.Check the Pseudo code.


* Populate texts
  refresh bapisdtext_itab.
  clear   bapisdtext_itab.
  if not text1 is initial.
    bapisdtext_itab-itm_number = gc_header_item.
    bapisdtext_itab-text_id    = gc_ship_instr.
    bapisdtext_itab-langu      = sy-langu.
    bapisdtext_itab-text_line  = text1.
    append bapisdtext_itab.
    clear  bapisdtext_itab.
  endif.
  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
       EXPORTING
            ORDER_HEADER_IN    = bapisdhd1
       IMPORTING
            SALESDOCUMENT      = vbak-vbeln
       TABLES
            RETURN             = BAPIRET2_itab
            ORDER_ITEMS_IN     = BAPISDITM_itab
            ORDER_PARTNERS     = BAPIPARNR_itab
            ORDER_SCHEDULES_IN = BAPISCHDL_itab
            ORDER_TEXT         = BAPISDTEXT_itab.

Try to simulate the code with your changes.

Regards,

Raghav

4 REPLIES 4
Read only

Former Member
0 Likes
1,589

Hi Kantheri,

Yes you can add the text while creating the salesorder it self.Check the Pseudo code.


* Populate texts
  refresh bapisdtext_itab.
  clear   bapisdtext_itab.
  if not text1 is initial.
    bapisdtext_itab-itm_number = gc_header_item.
    bapisdtext_itab-text_id    = gc_ship_instr.
    bapisdtext_itab-langu      = sy-langu.
    bapisdtext_itab-text_line  = text1.
    append bapisdtext_itab.
    clear  bapisdtext_itab.
  endif.
  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
       EXPORTING
            ORDER_HEADER_IN    = bapisdhd1
       IMPORTING
            SALESDOCUMENT      = vbak-vbeln
       TABLES
            RETURN             = BAPIRET2_itab
            ORDER_ITEMS_IN     = BAPISDITM_itab
            ORDER_PARTNERS     = BAPIPARNR_itab
            ORDER_SCHEDULES_IN = BAPISCHDL_itab
            ORDER_TEXT         = BAPISDTEXT_itab.

Try to simulate the code with your changes.

Regards,

Raghav

Read only

0 Likes
1,588

Hi Raghvendra, what should be the gc_ship_instr value or how do i determine it? Is it the same id 0002 etc which can be seen throug goto>header.

Read only

0 Likes
1,588

hi Kantheri,

It is the text-id value which you need to create a text for it.

The value what i am passing is this.

gc_ship_instr like ttxid-tdid value '0012'

Regards,

Raghav

Read only

Former Member
0 Likes
1,588

Hi,

yes text can be entered while creating sales order

just check FM PIA_CSO_BAPI_SORDER_CREATE2 which

calls BAPI_SALESORDER_CREATEFROMDAT2.

fill structure order_text with sales text.

use below code

REFRESH T_SDTEXT.

CLEAR SDTEXT.

CALL FUNCTION 'CSO_P_TEXT_GET'

EXPORTING

PI_MODE_GET_COMPL = C_ACTIVE

IMPORTING

PE_RETURN = RETURN

TABLES

PE_T_TEXT = T_TEXT.

IF NOT RETURN IS INITIAL.

MOVE-CORRESPONDING RETURN TO PE_RETURN1.

EXIT.

ENDIF.

LOOP AT T_TEXT INTO TEXT.

MOVE-CORRESPONDING TEXT TO SDTEXT.

APPEND SDTEXT TO T_SDTEXT.

ENDLOOP.

  • OSS note begin 552438

PERFORM BAPI_TEXTS_ASCII_ITF_CONV TABLES T_SDTEXT

USING 'ASC'.

  • OSS note end 552438

  • Salesorder create

CLEAR LOGIC_SWITCH.

LOGIC_SWITCH-PRICING = C_PRICING_STRAT_KEEP_PRICES.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

ORDER_HEADER_IN = SDHD1

INT_NUMBER_ASSIGNMENT = 'X'

LOGIC_SWITCH = LOGIC_SWITCH

IMPORTING

SALESDOCUMENT = DOC_NUMBER

TABLES

RETURN = T_RET2

ORDER_ITEMS_IN = T_SDITM

ORDER_PARTNERS = T_PARNR

ORDER_SCHEDULES_IN = T_SCHDL

ORDER_CONDITIONS_IN = T_CND

ORDER_CCARD = T_CCARD

<b> ORDER_TEXT = T_SDTEXT.</b> LOOP AT T_RET2 INTO RET2.

IF RET2-TYPE = C_MESSAGE_TYPE_ERROR OR

RET2-TYPE = C_MESSAGE_TYPE_ABORT.

MOVE-CORRESPONDING RET2 TO PE_RETURN1.

EXIT.

ENDIF.

ENDLOOP.

Regards

amole