1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
REPORT ztestbapiso1. *&--------------------------------------------------------------------&* *& Program Description: &* *& ----------------------- &* *& This demo program will update the reason for rejection for all &* *& items in a selected sales order. &* *& &* *& The program demonstrate the use of the 'BAPI_SALESORDER_CHANGE'. &* *& &* *& Author: ABAPCOOKBOOK &* *& Website: www.abapcookbook.com &* ************************************************************************ ************************************************************************ * DATA DECLARATIONS * ************************************************************************ *Tables: TABLES: vbap. *Internal tables: DATA: gt_vbap TYPE STANDARD TABLE OF vbap, gt_item_in TYPE STANDARD TABLE OF bapisditm, gt_item_inx TYPE STANDARD TABLE OF bapisditmx, gt_return TYPE STANDARD TABLE OF bapiret2. *Field Symbols: FIELD-SYMBOLS: <fs_vbap> TYPE vbap. *Structures: DATA: gst_item_hedx TYPE bapisdh1x, gst_item_in TYPE bapisditm, gst_item_inx TYPE bapisditmx. *Variables: DATA: gv_msg TYPE string. *Constants: CONSTANTS: gc_error TYPE string VALUE ': An error occured, no change done to the sales order.', gc_success TYPE string VALUE ': Sales order changed successfully.'. ************************************************************************ * SELECTION SCREEN * ************************************************************************ SELECT-OPTIONS: * Sales Order Number. s_vbeln FOR vbap-vbeln OBLIGATORY. PARAMETERS: * Reason for Rejection. p_abgru TYPE vbap-abgru OBLIGATORY. ************************************************************************ * CODE LOGIC * ************************************************************************ *Select sales order data from table VBAP. SELECT * FROM vbap INTO TABLE gt_vbap WHERE vbeln IN s_vbeln. IF sy-subrc EQ 0. LOOP AT gt_vbap ASSIGNING <fs_vbap>. * (Order Header Level) * Setting the update flag at order header level to update mode. gst_item_hedx-updateflag = 'U'. * (Order Item Level) * Setting of the material number(MATNR) at order item level. gst_item_in-material = <fs_vbap>-matnr. * Setting of the item number(POSNR) at order item level. gst_item_in-itm_number = <fs_vbap>-posnr. gst_item_inx-itm_number = <fs_vbap>-posnr. * Setting of the reason for rejection(ABGRU) at order item level. gst_item_in-reason_rej = p_abgru. gst_item_inx-reason_rej = 'X'. * Setting the update flag at order item level to update mode. gst_item_inx-updateflag = 'U'. * BAPI items level tables: APPEND: gst_item_in TO gt_item_in, gst_item_inx TO gt_item_inx. * Calling BAPI to update reason for rejection in the selected sales order. CALL FUNCTION 'BAPI_SALESORDER_CHANGE' EXPORTING salesdocument = <fs_vbap>-vbeln order_header_inx = gst_item_hedx TABLES return = gt_return order_item_in = gt_item_in order_item_inx = gt_item_inx. * Preparing the result message. CONCATENATE <fs_vbap>-vbeln " Sales Order Number <fs_vbap>-posnr " Item Number INTO gv_msg " Message SEPARATED BY space. " Space * Check if at least one error was raised by the BAPI. Loop inside * loop is not advise, however, the return table will contains small * amount of entries. We can use that for our demo. LOOP AT gt_return TRANSPORTING NO FIELDS WHERE type EQ 'E' OR type EQ 'A'. * Exit and rollback changes. EXIT. ENDLOOP. * If error found, rollback database changes. IF sy-subrc EQ 0. * Rollback changes. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. * Preparing error message. CONCATENATE gv_msg "Sales Order and Item Number gc_error "Error Message INTO gv_msg SEPARATED BY space. * Output message. WRITE / gv_msg. * Else, no error found, commit database changes. ELSE. * Commit changes. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true. * Preparing success message. CONCATENATE gv_msg "Sales Order and Item Number gc_success "Success Message INTO gv_msg SEPARATED BY space. * Output message. WRITE / gv_msg. ENDIF. * Write a line after each sales order. AT END OF vbeln. WRITE: sy-uline. ENDAT. * Clearing of variables and structures: CLEAR: * Variables: gv_msg, * Structures: gst_item_hedx, gst_item_in, gst_item_inx. * Refreshing internal tables: REFRESH: gt_item_in, gt_item_inx, gt_return. ENDLOOP. ENDIF. |
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/1667.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。
评论列表(2条)
出自:http://www.abapcookbook.com/bapi/bapi-update-sales-order-reason-rejection/
You can use BAPI_SALESORDER_CHANGE to do this. Set field REASON_REJ in the item table.