VA02 释放行项目计划行确认数量

标准功能操作事物代码VA02

 

 

 

 

 

 

 

操作后计划行被删除

需求是:实现批量操作,用户不需要一个一个的点,程序批量释放

参考地址:http://www.abapcookbook.com/sap-abap-code-sample/function-module-change-cancel-confirmed-quantity/

调用function : CALL FUNCTION 'SD_BACKORDER_UPDATE'

 

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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
REPORT ztestfmconfirmedquantity.
*&--------------------------------------------------------------------&*
*& Program Description:                                               &*
*& -----------------------                                            &*
*& This demo program will update the confirmed quantity in a          &*
*& sales order.                                                       &*
*&                                                                    &*
*& The program demonstrate the use of the FM 'SD_BACKORDER_UPDATE'.   &*
*&                                                                    &*
*& Author:  ABAPCOOKBOOK                                              &*
*& Website: www.abapcookbook.com                                      &*
************************************************************************
 
************************************************************************
* DATA DECLARATIONS                                                    *
************************************************************************
*Tables:
TABLES:
  vbap,
  vbep.
 
*Internal tables:
DATA:
  gt_vbap               TYPE STANDARD TABLE OF vbap,
  gt_vbep               TYPE STANDARD TABLE OF vbep,
  gt_kortab             TYPE STANDARD TABLE OF mdvu,
  gt_return             TYPE STANDARD TABLE OF bapiret2.
 
*Field Symbols:
FIELD-SYMBOLS:
  <fs_vbap>             TYPE vbap,
  <fs_vbep>             TYPE vbep.
 
*Structures:
DATA:
  gst_kortab            TYPE mdvu.
 
*Variables:
DATA:
  gv_msg                TYPE string,
  gv_tabix              TYPE sy-tabix.
 
*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,
 
* Confirm Quantity.
  p_bmeng TYPE vbep-bmeng 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.
 
* Rules 'For All Entries'.
* Not necessary as 'VBELN' and 'POSNR' is already primary key, this logic
* just to demonstrate 'For All Entries' rule.
  SORT gt_vbap BY vbeln posnr.
  DELETE ADJACENT DUPLICATES FROM gt_vbap COMPARING vbeln posnr.
 
* Retrieving schedule lines entries.
  SELECT *
    FROM vbep
   INTO TABLE gt_vbep
 FOR ALL ENTRIES IN gt_vbap
   WHERE vbeln EQ gt_vbap-vbeln
     AND posnr EQ gt_vbap-posnr.
 
  IF sy-subrc EQ 0.
 
*   Sorting for binary search.
    SORT gt_vbep BY vbeln posnr.
 
    LOOP AT gt_vbap ASSIGNING <fs_vbap>.
 
*     ........................
*     FM Data for updating the confirm quantity.
*     ........................
*     Adding the schedule lines items.
      READ TABLE gt_vbep TRANSPORTING NO FIELDS
      WITH KEY  vbeln = <fs_vbap>-vbeln
                posnr = <fs_vbap>-posnr
                BINARY SEARCH.
 
      IF sy-subrc EQ 0.
 
        gv_tabix = sy-tabix.
 
*       Index looping for better performance.
        LOOP AT gt_vbep ASSIGNING <fs_vbep> FROM gv_tabix.
 
          IF  <fs_vbep>-vbeln EQ <fs_vbap>-vbeln
          AND <fs_vbep>-posnr EQ <fs_vbap>-posnr.
 
*           Current item of the sales order for the current
*           availability date.
            gst_kortab-vbeln = <fs_vbep>-vbeln.
            gst_kortab-posnr = <fs_vbep>-posnr.
            gst_kortab-mbdat = <fs_vbep>-mbdat.
 
*           Setting the confirm quantity. Please note that
*           setting this value to '0' will cancel the confirm quantity
*           in the sales order on all schedule lines.
            gst_kortab-vmeng = p_bmeng.
 
            APPEND gst_kortab TO gt_kortab.
 
          ELSE.
 
*           Clear index
            CLEAR gv_tabix.
 
*           Move out of the loop.
            EXIT.
 
          ENDIF.
 
*         Clearing of work areas.
          CLEAR:
            gst_kortab.
 
        ENDLOOP.
 
      ENDIF.
 
*     Calling function module to update confirm quantity. The ATP check is
*     also generated using this function module.
*     Please Note: The drawback of this FM is that it automatically commit
*     changes to database even if a sales order is in edit mode and
*     it don't look that much perfomant.
      CALL FUNCTION 'SD_BACKORDER_UPDATE'
        TABLES
          kortab    = gt_kortab
          et_return = gt_return.
 
*     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 FM. 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.
 
*       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.
 
*       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,
        gv_tabix.
 
*     Refreshing internal tables:
      REFRESH:
        gt_kortab,
        gt_return.
 
    ENDLOOP.
 
  ENDIF.
 
ENDIF.

  

 

posted on   TorranceZhao  阅读(1872)  评论(0编辑  收藏  举报

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示