method CREATE_DELIVERY data lt_bapiret TYPE TABLE OF bapiret2 ls_bapir

  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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
method CREATE_DELIVERY .
data:
lt_bapiret TYPE TABLE OF bapiret2,
ls_bapiret LIKE LINE OF LT_BAPIRET,
ls_bapiret1 LIKE LINE OF LT_BAPIRET,
lt_alv1 TYPE TABLE OF ZSC_RFID_DS_ARRIVAL_SSF_ALV1,
lt_alv14 TYPE TABLE OF ZSC_RFID_DS_ARRIVAL_SSF_ALV14.
data: ls_alv1 like LINE OF lt_alv1,
ls_alv14 LIKE LINE OF LT_ALV14.
data: lo_nd_input TYPE REF TO IF_WD_CONTEXT_NODE,
lo_el_input TYPE REF TO IF_WD_CONTEXT_ELEMENT,
lo_nd_charg TYPE REF TO IF_WD_CONTEXT_NODE,
lo_el_charg TYPE REF TO IF_WD_CONTEXT_ELEMENT,
lo_nd_rfid TYPE REF TO IF_WD_CONTEXT_NODE,
lo_el_rfid TYPE REF TO IF_WD_CONTEXT_ELEMENT,
lo_nd_table TYPE REF TO IF_WD_CONTEXT_NODE,
lo_el_table TYPE REF TO IF_WD_CONTEXT_ELEMENT,
lo_nd_size TYPE REF TO IF_WD_CONTEXT_NODE,
lo_el_size TYPE REF TO IF_WD_CONTEXT_ELEMENT.
data: lt_charg TYPE wd_this->ELEMENTS_TABLE_CHARG,
ls_charg LIKE LINE OF LT_CHARG,
lt_rfid TYPE WD_THIS->ELEMENTS_TABLE_RFID,
ls_rfid LIKE LINE OF LT_RFID,
lt_table TYPE WD_THIS->ELEMENTS_TABLE,
ls_table LIKE LINE OF LT_table,
ls_input TYPE wd_this->ELEMENT_INPUT,
lt_size TYPE WD_THIS->ELEMENTS_TABLE_SIZE,
ls_size LIKE LINE OF LT_SIZE.
* data lv_meins TYPE c LENGTH 3.
data lv_post TYPE xfeld.
data: lv_has_error TYPE boolean,
lv_error_msg TYPE string.
FIELD-SYMBOLS: <fs_alv1> like LS_ALV1,
<fs_alv14> like LS_ALV14,
<fs_rfid> like LS_RFID,
<fs_charg> like LS_CHARG,
<fs_table> like LS_TABLE,
<fs_size> like LS_SIZE.
lv_post = IV_POST.
LO_ND_INPUT = WD_CONTEXT->GET_CHILD_NODE( NAME = wd_this->WDCTX_INPUT ).
LO_EL_INPUT = LO_ND_INPUT->GET_ELEMENT( ).
LO_EL_INPUT->GET_STATIC_ATTRIBUTES( IMPORTING STATIC_ATTRIBUTES = LS_INPUT ).
IF LV_HAS_ERROR is INITIAL.
LO_nd_RFID = WD_CONTEXT->GET_CHILD_NODE( NAME = wd_this->WDCTX_TABLE_RFID ).
LO_ND_RFID->GET_STATIC_ATTRIBUTES_TABLE( IMPORTING TABLE = LT_RFID ).
LOOP AT LT_RFID INTO LS_RFID.
"если для этой метки уже была создана поставка, то второй раз создавать ее не требуется
IF LS_RFID-VBELN is INITIAL.
MOVE-CORRESPONDING LS_RFID to LS_ALV14.
LS_ALV14-MEINS = LS_RFID-UOM.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = ls_alv14-MATNR
IMPORTING
output = ls_alv14-MATNR.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
INPUT = ls_alv14-MEINS
IMPORTING
OUTPUT = ls_alv14-MEINS
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
" todo: its a temporary decision for EBELN and EBELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* LS_ALV14-MATNR = LS_RFID-MATNR.
LS_ALV14-SEASON = ZCL_WD_ASSISTANCE=>GET_EN_SEASON( LS_RFID-SEASON ).
LS_ALV14-RSIZE = LS_RFID-SIZES.
* LS_ALV14-MEINS = LV_MEINS.
LS_ALV14-EBELN = LS_RFID-DOC46. "'4602599149'.
LS_ALV14-EBELP = LS_RFID-EBELP. "'00110'.
APPEND LS_ALV14 to LT_ALV14.
ENDIF.
ENDLOOP.
LO_ND_table = WD_CONTEXT->GET_CHILD_NODE( name = wd_this->WDCTX_TABLE ).
LO_ND_table->GET_STATIC_ATTRIBUTES_TABLE( IMPORTING TABLE = LT_TABLE ).
LOOP AT LT_TABLE INTO LS_TABLE.
MOVE-CORRESPONDING LS_TABLE to LS_ALV1.
ls_alv1-MEINS = LS_TABLE-MEINS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = ls_alv1-MATNR
IMPORTING
output = ls_alv1-MATNR.
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
INPUT = ls_alv1-MEINS
IMPORTING
OUTPUT = ls_alv1-MEINS.
" todo: its a temporary decision for EBELN and EBELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* LS_ALV1-MEINS = LV_MEINS.
LS_ALV1-WERKS = LS_INPUT-WERKS.
LS_ALV1-LGORT = LS_INPUT-LGORT.
LS_ALV1-QUAN_P = LS_TABLE-POD_KOLVO.
LS_ALV1-EBELN = LS_TABLE-EBELN. "'4602599149'.
LS_ALV1-EBELP = LS_TABLE-EBELP. "'00110'.
COLLECT ls_alv1 INTO LT_ALV1.
ENDLOOP.
*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Creation of VBELN + MBLNR if needed
data lv_res like sy-subrc.
data lv_dest_name TYPE string.
LV_DEST_NAME = ZCL_WD_ASSISTANCE=>GET_R3_DESTINATION( ).
* call FUNCTION 'RFC_CONNECTION_CLOSE' DESTINATION LV_DEST_NAME
* EXCEPTIONS
* OTHERS = 2.
*REFRESH LT_ALV1.
*REFRESH LT_ALV14.
*REFRESH LT_BAPIRET.
*wd_this->FILL_DDBI( ).
CALL FUNCTION 'ZBAPI_DELIVARY_CREATE' DESTINATION LV_DEST_NAME
EXPORTING "'03042013'
I_WERKS = LS_INPUT-WERKS "'6400'
I_LGORT = LS_INPUT-LGORT "'0003'
I_READER = '02'
I_OPER = '01'
I_DATAP_OM = LS_INPUT-BUDAT "'03042013'
I_DATAF_OM = LS_INPUT-BUDAT
I_POST = lv_post "LS_INPUT-POST
I_ZREIS = 'X' "LS_INPUT-ZREIS
I_ZZAGR = LS_INPUT-ZZAGR
I_ZCENTRE = LS_INPUT-ZCENTER
IMPORTING
et_dokum = WD_ASSIST->mt_material_key
TABLES
* ET_RETURN = LT_BAPIRET
* CT_ALV1 = LT_ALV1
* CT_ALV4 = LT_ALV14
CT_ALV1 = LT_ALV1
ct_alv4 = LT_ALV14
et_return = LT_BAPIRET
EXCEPTIONS
SYSTEM_FAILURE = 1
COMMUNICATION_FAILURE = 2
OTHERS = 3.
lv_res = sy-subrc.
ZCL_GUI_UTILS=>REPORT_DOC_CREATION( IR_MSG_MGR = wd_this->MSG_MGR IT_DOC = WD_ASSIST->mt_material_key ).
IF lv_res = 0.
READ TABLE lt_bapiret WITH KEY type = 'E' INTO LS_BAPIRET1.
IF sy-subrc IS INITIAL.
READ TABLE lt_bapiret WITH KEY type = 'S' INTO LS_BAPIRET.
IF sy-subrc is INITIAL and IV_POST is NOT INITIAL.
* WD_this->MSG_MGR->REPORT_SUCCESS( EXPORTING MESSAGE_TEXT = LS_BAPIRET-MESSAGE VIEW = 'MAIN' ).
WD_this->MSG_MGR->REPORT_ERROR_MESSAGE( EXPORTING MESSAGE_TEXT = LS_BAPIRET1-MESSAGE VIEW = 'MAIN' ).
DATA lv_msg_popup TYPE STRING.
lv_msg_popup = LS_BAPIRET1-MESSAGE.
* ZCL_GUI_UTILS=>show_error_popup( EXPORTING
* ir_component = WD_THIS->wd_get_api( )
* iv_win_name = 'APPROVE'
* iv_view_name = 'APPROVE_VIEW'
* iv_msg = lv_msg_popup
* IR_ASSISTANCE = WD_ASSIST ).
wd_this->GV_R3_HAS_PROBLEMS = abap_true.
* 12.05.2014 Set error flag in both variables
LV_HAS_ERROR = abap_true.
else.
LV_HAS_ERROR = abap_true.
LOOP AT LT_BAPIRET INTO LS_BAPIRET.
CONCATENATE LS_BAPIRET-MESSAGE LV_ERROR_MSG INTO LV_ERROR_MSG SEPARATED BY ', '.
ENDLOOP.
ENDIF.
endif.
IF LV_HAS_ERROR is INITIAL.
LO_ND_table = WD_CONTEXT->GET_CHILD_NODE( name = wd_this->WDCTX_TABLE ).
LO_ND_table->GET_STATIC_ATTRIBUTES_TABLE( IMPORTING TABLE = LT_TABLE ).
* everything is ok, updating current data
LOOP AT LT_ALV1 ASSIGNING <fs_alv1>.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <fs_alv1>-MATNR
IMPORTING
output = <fs_alv1>-MATNR.
LOOP AT LT_TABLE ASSIGNING <FS_TABLE> WHERE MATNR = <FS_ALV1>-MATNR and EBELN = <FS_ALV1>-EBELN.
* READ TABLE LT_TABLE ASSIGNING <FS_TABLE> with KEY matnr = <FS_ALV1>-MATNR.
* IF sy-subrc = 0.
<FS_TABLE>-MJAHR = <FS_ALV1>-MJAHR.
<FS_TABLE>-MBLNR = <FS_ALV1>-MBLNR.
<FS_TABLE>-VBELn = <FS_ALV1>-VBELN.
* <FS_TABLE>-EBELN = <FS_ALV1>-EBELN.
<FS_TABLE>-EBELP = <FS_ALV1>-EBELP.
* ENDIF.
ENDLOOP.
ENDLOOP.
LOOP AT LT_ALV14 ASSIGNING <FS_ALV14>.
READ TABLE LT_RFID ASSIGNING <fS_RFID> WITH KEY rfid = <FS_ALV14>-RFID.
IF sy-subrc = 0.
<FS_RFID>-CHARG = <FS_ALV14>-CHARG.
<FS_RFID>-VBELN = <FS_ALV14>-VBELN.
<FS_RFID>-POSNR = <FS_ALV14>-POSNR_VL.
<FS_RFID>-MBLNR = <FS_ALV14>-MBLNR_OM.
<FS_RFID>-MJAHR = <FS_ALV14>-MJAHR_OM.
<FS_RFID>-DOC46 = <FS_ALV14>-EBELN.
<FS_RFID>-EBELP = <FS_ALV14>-EBELP.
<fs_rfid>-CHARGH = <FS_ALV14>-CHARGH.
ENDIF.
ENDLOOP.
* set updated data
LO_ND_TABLE->BIND_TABLE( EXPORTING NEW_ITEMS = LT_TABLE ).
LO_ND_RFID->BIND_TABLE( EXPORTING NEW_ITEMS = LT_RFID ).
REFRESH_SECONDARY_ALVS( ).
IF LV_POST = abap_true.
* 12.05.2014 Fix saving othattrs. true->false
* For the case when it is neccessary to do posting while creating delivery
UPDATE_POBJ_OTHATTRS( EXPORTING IV_ONLY_DELIVERY = abap_false ).
ENDIF.
endif.
ELSE.
data lv_e TYPE string.
lv_e = lv_res.
CONCATENATE 'Поставка не была создана. Вызов RFC вернул код sy-subrc = ' lv_e ')' INTO LV_ERROR_MSG.
LV_HAS_ERROR = abap_true.
ENDIF.
ENDIF.
IF LV_HAS_ERROR is NOT INITIAL.
EV_MSG = LV_ERROR_MSG.
ENDIF.
endmethod.