Skip to Content

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

How to pass Itab to "BAPI_SALESORDER_CHANGE"

Requirment : We cancel sales order that have been created but not fulfilled within 7 days.

At present, we do this manually. Can we configure to have the system auto cancel the sales order

after the said period?

selection screen

u2022 Sales organization (P_VKORG like ZSD_REJECT-VKORG)

u2022 Sales office (S_VKBUR for ZSD_REJECT-VKBUR)

u2022 Plant (S_WERKS for ZSD_REJECT-WERKS)

u2022 Sales order type (S_AUART for ZSD_REJECT-AUART)

u2022 Sales order no. (S_VBELN for ZSD_REJECT-VBELN)

u2022 Customer no. (S_KUNNR for ZSD_REJECT-KUNNR)

u2022 Rejection date (S_REJDTE for ZSD_REJECT-REJDATE)

Report format/columns should be as follows:

1. Sales organization (ZSD_REJECT-VKORG)

2. Sales office (ZSD_REJECT-VKBUR)

3. Plant (ZSD_REJECT-WERKS)

4. Customer no. (ZSD_REJECT-KUNNR)

5. Customer name (KNA1-NAME1)

6. Sales order no. (ZSD_REJECT-VBELN)

7. Sales order item (ZSD_REJECT-POSNR)

8. Material no. (VBAP-MATNR)

9. Material description (VBAP-ARKTX)

10. Order quantity (VBAP-KWMENG)

11. Rejected quantity (ZSD_REJECT-REJQTY)

12. Unit of measure (VBAP-VRKME)

13. Rejected net value (ZSD_REJECT-REJVAL)

14. Currency (VBAK-WAERK)

15. Rejection date (ZSD_REJECT-REJDATE)

16. Rejection time (ZSD_REJECT-REJTIME)

17. Rejection user (ZSD_REJECT-REJUSER)

Program : I have created one report & calling bapi BAPI_SALESORDER_CHANGE

TYPES: BEGIN OF t_tab,

vkorg TYPE zsd_reject-vkorg ,

vkbur TYPE zsd_reject-vkbur ,

auart TYPE zsd_reject-auart ,

END OF t_tab.

TYPES: BEGIN OF t_vbak,

vbeln TYPE vbak-vbeln ,

erdat TYPE vbak-erdat ,

waerk TYPE vbak-waerk,

vbtyp TYPE vbak-vbtyp,

auart TYPE vbak-auart,

vkorg TYPE vbak-vkorg ,

vkbur TYPE vbak-vkbur ,

kunnr TYPE vbak-kunnr ,

cmfre TYPE vbak-cmfre ,

  • gbsta type vpup-gbsta,

costa TYPE vbuk-costa ,

fkstk TYPE vbuk-fkstk,

END OF t_vbak.

TYPES: BEGIN OF t_data,

vbeln TYPE vbak-vbeln ,

waerk TYPE vbak-waerk,

auart TYPE vbak-auart,

vkorg TYPE vbak-vkorg ,

vkbur TYPE vbak-vkbur ,

kunnr TYPE vbak-kunnr ,

cmfre TYPE vbak-cmfre ,

END OF t_data.

TYPES: BEGIN OF t_vbap,

matnr TYPE vbap-matnr ,

vbeln TYPE vbap-vbeln ,

posnr TYPE vbap-posnr,

arktx TYPE vbap-arktx ,

pstyv TYPE vbap-pstyv,

abgru TYPE vbap-abgru,

kwmeng TYPE vbap-kwmeng,

werks TYPE vbap-werks ,

END OF t_vbap.

----


  • TABLES *

----


TABLES : zsd_reject.

----


  • INTERNAL TABLES, STRUCTURES & WORK AREAS *

----


DATA: it_vbak TYPE STANDARD TABLE OF t_vbak WITH HEADER LINE,

it_data TYPE STANDARD TABLE OF t_data WITH HEADER LINE ,

it_vbap TYPE STANDARD TABLE OF t_vbap ,

wa_vbak TYPE t_vbak ,

wa_vbap TYPE t_vbap ,

wa_data TYPE t_data.

----


  • PARAMETERS & SELECT-OPTIONS *

----


    • DUE TO AN SAP LIMITATION WITH CREATING / CHANGING VARIANTS,

  • selection screen fields over 45 characters in length should be avoided

SELECTION-SCREEN: BEGIN OF BLOCK a01 WITH FRAME TITLE text-001.

PARAMETERS: p_vkorg LIKE zsd_reject-vkorg.

SELECT-OPTIONS: s_vkbur FOR zsd_reject-vkbur,

s_werks FOR zsd_reject-werks,

s_auart FOR zsd_reject-auart,

s_vbeln FOR zsd_reject-vbeln,

s_kunnr FOR zsd_reject-kunnr,

s_rejdte FOR zsd_reject-rejdate.

SELECTION-SCREEN: END OF BLOCK a01.

DATA : p_days TYPE i VALUE 7,

l_checkdate LIKE sy-datum.

START-OF-SELECTION.

l_checkdate = sy-datum - p_days.

SELECT vbak~vbeln

vbak~erdat

vbak~waerk

vbak~vbtyp

vbak~auart

vbak~vkorg

vbak~vkbur

vbak~kunnr

vbak~cmfre

  • vbup~gbsta

vbuk~costa

vbuk~fkstk

INTO TABLE it_vbak

FROM vbak INNER JOIN vbuk

ON vbakvbeln = vbukvbeln

WHERE vbak~vkorg = p_vkorg

AND vbak~vkbur IN s_vkbur

AND vbak~auart IN s_auart

AND vbak~vbtyp = 'C'

AND vbuk~gbstk NE 'C'.

Requirment :

This checking is only for those order were previously blocked and has been released, which means credit release date not equal to 00.00.0000 and hence program will check rejection logic based on credit release date vs system date > 7 calendar days. For those orders which holding credit release date equals to 00.00.0000 will go through rejection checking

based on order creation date vs system date > 7 calendar days respectively.

LOOP AT it_vbak INTO wa_vbak.

IF NOT wa_vbak-cmfre IS INITIAL.

IF wa_vbak-cmfre > l_checkdate.

DELETE it_vbak FROM wa_vbak.

ENDIF.

ELSE.

IF wa_vbak-erdat > l_checkdate.

DELETE it_vbak FROM wa_vbak.

ENDIF.

ENDIF.

ENDLOOP.

SELECT vbapmatnr vbapvbeln vbapposnr vbaparktx vbap~pstyv

vbapabgru vbapkwmeng vbap~werks INTO TABLE it_vbap

FROM vbap INNER JOIN vbup ON

vbapvbeln = vbupvbeln AND vbapposnr = vbupposnr

FOR ALL entries

IN it_vbak WHERE vbap~vbeln = it_vbak-vbeln AND

gbsta NE 'C'.

I have taken the records in two internal table for header & item it_vbak & it_vbap

now I need to call the BAPI_SALESORDER_CHANGE and pass the internal table to Bapi .

Can anyone please let me know how to pass this into Bapi?

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument =

  • ORDER_HEADER_IN =

order_header_inx =

  • SIMULATION =

  • BEHAVE_WHEN_ERROR = ' '

  • INT_NUMBER_ASSIGNMENT = ' '

  • LOGIC_SWITCH =

  • tables

  • return =

  • ORDER_ITEM_IN =

  • ORDER_ITEM_INX =

  • PARTNERS =

  • PARTNERCHANGES =

  • PARTNERADDRESSES =

  • ORDER_CFGS_REF =

  • ORDER_CFGS_INST =

  • ORDER_CFGS_PART_OF =

  • ORDER_CFGS_VALUE =

  • ORDER_CFGS_BLOB =

  • ORDER_CFGS_VK =

  • ORDER_CFGS_REFINST =

  • SCHEDULE_LINES =

  • SCHEDULE_LINESX =

  • ORDER_TEXT =

  • ORDER_KEYS =

  • CONDITIONS_IN =

  • CONDITIONS_INX =

  • EXTENSIONIN =

.

Thanks in advance

Regards

Rahul

Tags:
Former Member
Former Member replied

Hi,

you delete the table entry like this :

if wa_vbak-erdat > l_checkdate.
delete table it_vbak from wa_vbak.
continue.
endif.

Kostas

0 View this answer in context

Helpful Answer

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