Skip to Content
0
Former Member
Jan 22, 2008 at 09:04 AM

help with SE37 code needed - create sales order

100 Views

Hi Guurus,

Can you please help? I finally finished with function creation (I just adopted the function, which I found in the system and it works ok, YEAH!!!)

BUT!!! 😊 It is working just for the sales order creation with one item.

Is it a big deal if you adopt my code that the function will have possibility to add more then one item?

Thanks in advance

Sašo

Here is the code:

*FUNCTION Z_RFC_SD_SIMO_SALES_ORDER2.

**"----


*-

*""Local interface:

**" IMPORTING

**" VALUE(P_AUART) TYPE AUART DEFAULT 'zhp'

**" VALUE(P_VKORG) TYPE VKORG DEFAULT 0001

**" VALUE(P_VTWEG) TYPE VTWEG DEFAULT 07

**" VALUE(P_SPART) TYPE SPART DEFAULT 01

**" VALUE(P_AUGRU) TYPE AUGRU DEFAULT 001

**" VALUE(P_BSTKD) TYPE BSTKD DEFAULT 'test si order avtom'

**" VALUE(P_SOLD) TYPE KUNNR DEFAULT 21000069

**" VALUE(P_SHIP) TYPE KUNNR DEFAULT 21000069

**" VALUE(P_MATNR) TYPE MATNR DEFAULT 'SIOBRACUN'

**" VALUE(P_MENGE) TYPE KWMENG DEFAULT 1

**" VALUE(P_PLANT) TYPE WERKS_D DEFAULT 0001

**" VALUE(P_ITCAT) TYPE PSTYV DEFAULT 'ZG2W'

**" VALUE(P_LGORT) TYPE LGORT_D DEFAULT 0001

**" EXPORTING

**" VALUE(V_VBELN) TYPE VBELN

**" VALUE(RESULT) TYPE CHAR01

**"----


*-

*

  • DATA DECLARATIONS.

**DATA: v_vbeln LIKE vbak-vbeln.

*DATA: header LIKE bapisdhead1.

*DATA: headerx LIKE bapisdhead1x.

*DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.

*DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.

*DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.

*DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

*DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx

*WITH HEADER LINE.

*DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl

*WITH HEADER LINE.

*

  • HEADER DATA

*header-doc_type = p_auart.

*headerx-doc_type = 'X'.

*

*header-sales_org = p_vkorg.

*headerx-sales_org = 'X'.

*

*header-distr_chan = p_vtweg.

*headerx-distr_chan = 'X'.

*

*header-division = p_spart.

*headerx-division = 'X'.

**order reason

*header-ord_reason = p_augru.

*headerx-ord_reason = 'X'.

**PO number from MAX

*header-PURCH_NO_C = p_BSTKD.

*headerx-PURCH_NO_C = 'X'.

*

*headerx-updateflag = 'I'.

*

  • PARTNER DATA

*partner-partn_role = 'AG'.

*partner-partn_numb = p_sold.

*APPEND partner.

*

*partner-partn_role = 'WE'.

*partner-partn_numb = p_ship.

*APPEND partner.

*

  • ITEM DATA

*itemx-updateflag = 'I'.

*

*item-itm_number = '000010'.

*itemx-itm_number = 'X'.

*

*

*item-material = p_matnr.

*itemx-material = 'X'.

*

*item-plant = p_plant.

*itemx-plant = 'X'.

*

*item-target_qty = p_menge.

*itemx-target_qty = 'X'.

*

*item-target_qu = ' '.

*itemx-target_qu = 'X'.

*

*item-item_categ = p_itcat.

*itemx-item_categ = 'X'.

*

**item-STORE_LOC = p_LGORT.

**itemx-STORE_LOC = 'X'.

*

*

*

*APPEND item.

*APPEND itemx.

*

  • Fill schedule lines

*lt_schedules_in-itm_number = '000010'.

*lt_schedules_in-sched_line = '0001'.

*lt_schedules_in-req_qty = p_menge.

*APPEND lt_schedules_in.

*

  • Fill schedule line flags

*lt_schedules_inx-itm_number = '000010'.

*lt_schedules_inx-sched_line = '0001'.

*lt_schedules_inx-updateflag = 'X'.

*lt_schedules_inx-req_qty = 'X'.

*APPEND lt_schedules_inx.

*

  • Call the BAPI

*CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'

*EXPORTING

*sales_header_in = header

*sales_header_inx = headerx

*IMPORTING

*salesdocument_ex = v_vbeln

*TABLES

*return = return

*sales_items_in = item

*sales_items_inx = itemx

*sales_schedules_in = lt_schedules_in

*sales_schedules_inx = lt_schedules_inx

*sales_partners = partner.

*

  • Check the return table.

*LOOP AT return WHERE type = 'E' OR type = 'A'.

*EXIT.

*ENDLOOP.

*

*

*

*IF sy-subrc = 0.

*

*result = 'E'.

*

*ELSE.

*

*COMMIT WORK AND WAIT.

*

*result = 'S'.

*ENDIF.

*

*

*

*

*

*ENDFUNCTION.

Edited by: Saso Poljansek on Jan 22, 2008 10:23 AM