-
Notifications
You must be signed in to change notification settings - Fork 0
/
Z_J1B1_TESTE
752 lines (643 loc) · 23 KB
/
Z_J1B1_TESTE
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
*&---------------------------------------------------------------------*
*& Report Z_J1B1_TESTE
*& Eberton Sobreira - 14/10/2019
*& Criar nota fiscal por referência
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_J1B1_TESTE.
TABLES: j_1bnfdoc, j_1bnflin.
TYPES:
begin of ty_header,
branch like j_1bnfdoc-branch,
bukrs like j_1bnfdoc-bukrs,
docnum like j_1bnfdoc-docnum,
nfenum like j_1bnfdoc-nfenum, "Nr NF-e
docdat like j_1bnfdoc-docdat,
observat like j_1bnfdoc-observat,
nftype like j_1bnfdoc-nftype,
parid like j_1bnfdoc-parid,
parvw like j_1bnfdoc-parvw,
INCO1 like j_1bnfdoc-INCO1,
INCO2 like j_1bnfdoc-INCO2,
ANZPK like j_1bnfdoc-ANZPK,
SHPUNT like j_1bnfdoc-SHPUNT,
NTGEW like j_1bnfdoc-NTGEW,
BRGEW like j_1bnfdoc-BRGEW,
GEWEI like j_1bnfdoc-GEWEI,
end of ty_header,
begin of ty_itens,
ITMNUM LIKE J_1BDYLIN-ITMNUM,
ITMTYP LIKE J_1BDYLIN-ITMTYP,
MATNR LIKE J_1BDYLIN-MATNR,
WERKS LIKE J_1BDYLIN-WERKS,
MAKTX LIKE J_1BDYLIN-MAKTX,
MATKL LIKE J_1BDYLIN-MATKL,
MENGE LIKE J_1BDYLIN-MENGE,
MEINS LIKE J_1BDYLIN-MEINS,
NETPR LIKE J_1BDYLIN-NETPR,
CFOP LIKE J_1BDYLIN-CFOP,
TAXLW1 LIKE J_1BDYLIN-TAXLW1,
TAXLW2 LIKE J_1BDYLIN-TAXLW2,
MATORG LIKE J_1BDYLIN-MATORG,
MATUSE LIKE J_1BDYLIN-MATUSE,
NBM LIKE J_1BDYLIN-NBM,
TAXLW4 LIKE J_1BDYLIN-TAXLW4,
TAXLW5 LIKE J_1BDYLIN-TAXLW5,
DOCREF LIKE J_1BDYLIN-DOCREF,
ITMREF LIKE J_1BDYLIN-ITMREF,
COD_CTA LIKE J_1BDYLIN-COD_CTA,
END of ty_itens,
begin of ty_tax,
ITMNUM LIKE J_1BNFSTX-ITMNUM,
TAXTYP LIKE J_1BNFSTX-TAXTYP,
BASE LIKE J_1BNFSTX-BASE,
RATE LIKE J_1BNFSTX-RATE,
TAXVAL LIKE J_1BNFSTX-TAXVAL,
EXCBAS LIKE J_1BNFSTX-EXCBAS,
OTHBAS LIKE J_1BNFSTX-OTHBAS,
end of ty_tax,
begin of ty_msg,
SEQNUM LIKE J_1BNFFTX-SEQNUM,
MESSAGE LIKE J_1BNFFTX-MESSAGE,
end of ty_msg.
*Tabela Interna
DATA: ti_bdc TYPE TABLE OF bdcdata,
ti_message TYPE TABLE OF bdcmsgcoll,
ti_itens TYPE TABLE OF ty_itens,
ti_tax TYPE TABLE OF ty_tax,
ti_msg TYPE TABLE OF ty_msg.
*Work Area
DATA: wa_bdc TYPE bdcdata,
wa_params TYPE ctu_params,
WA_MESSAGE TYPE bdcmsgcoll,
WA_HEADER TYPE ty_header,
wa_item TYPE ty_itens,
WA_TAX TYPE ty_tax,
wa_msg TYPE ty_msg.
* Variáveis
DATA:
wx_idxTax type n value 0,
wx_countItens type i value 0,
wx_curItem type n value 0,
wx_curTax type n value 0,
wx_observacao type j_1bnfdoc-observat,
"wx_curdate(10) type c,
wx_refdocdate(10) type c,
wx_newdate(10) type c,
wx_numnfe(9) TYPE c," VALUE '1',
wx_ctanalit(10) type c,
wx_CFOP(7) type c,
"wx_dirICMS(4) type c,
"wx_dirIPI(4) type c,
"wx_dirCOFINS(4) type c,
"wx_dirPIS(4) type c,
wx_docref type j_1bnfdoc-docnum,
wx_itmnum type J_1BDYLIN-itmnum,
wx_QtTaxItem type i,
wx_QtMsgs type i,
wx_netpr(16) type c,
wx_menge(16) type c,
wx_bundle(1) type c value 'N'. "Pacote. Sobrescreve Taxas, CFOP, etc.
DATA: wx_bun_TAXLW1(3) type c, wx_bun_TAXLW2(3) type c, wx_bun_TAXLW4(3) type c, wx_bun_TAXLW5(3) type c.
selection-screen begin of block b1 with frame title text-t01.
parameters: P_DOCNUM TYPE j_1bnfdoc-docnum OBLIGATORY.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-t02.
parameters: P_PARVW TYPE J_1BDYDOC-PARVW,
P_PARID TYPE J_1BDYDOC-PARID,
P_PARID1 TYPE J_1BDYDOC-PARID.
selection-screen end of block b2.
selection-screen begin of block b3 with frame title text-t03.
parameters: P_NFTYPE TYPE j_1bnfdoc-NFTYPE, "Categoria NF
P_DOCDAT TYPE j_1bnfdoc-docdat OBLIGATORY, "Data do Documento
P_NVCFOP TYPE J_1BDYLIN-CFOP, "Novo CFOP
"P_NVICMS TYPE J_1BDYLIN-TAXLW1, "Novo Direito Fiscal ICMS
"P_NVIPI TYPE J_1BDYLIN-TAXLW2, "Novo Direito Fiscal IPI
"P_NVCOFI TYPE J_1BDYLIN-TAXLW4, "Novo Direito Fiscal COFINS
"P_NVPIS TYPE J_1BDYLIN-TAXLW5, "Novo Direito Fiscal PIS
P_CTANL TYPE J_1BDYLIN-COD_CTA, "Código Conta Analítica
P_OBSERV TYPE j_1bnfdoc-observat,
P_SAVREF AS CHECKBOX. "Gera na observação texto ref. a nf de origem e cria referência.
selection-screen end of block b3.
selection-screen begin of block b4 with frame title text-t04.
parameters: P_CFEIRA as checkbox. "NF de Entrada de Retorno de Feira/Exposição
"p_fmth6 as checkbox, "Indica que é pra exportar registros da Construção Civil.
selection-screen end of block b4.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* P_CFEIRA - NF de Entrada de Retorno de Feira/Exposição
* Ctg.NF - I0
* 50 (Suspenso) - Direito ICMS
* 49 (Outras) - Direito IPI
* 1914/2914 - CFOP
* OBSERVAÇÃO. REF NF 000XXX DE XX.XX.XXXX
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
INITIALIZATION.
p_docdat = sy-datum.
wx_bundle = 'N'.
START-OF-SELECTION.
IF P_CFEIRA EQ 'X'.
* Obrigar a informar o CFOP.
wx_bun_taxlw1 = '50'. "ICMS
wx_bun_taxlw2 = '49'. "IPI
wx_bun_taxlw4 = 'C08'. "COFINS
wx_bun_taxlw5 = 'P08'. "PIS
p_nvcfop = '1914/AA'. "Se ocorrer erro no CFOP a J1B1N vai chiar.
p_savref = 'X'.
wx_bundle = 'S'.
ENDIF.
"-- Primeiro Uso desta Aplicação:
" -- Dar entrada de Notas Fiscais de Remessa de Exporição/Feira (5914/6914) como (1914)
SELECT branch
bukrs
docnum
nfenum "Nr NFe
docdat "Data do Documento
observat
nftype
parid
parvw
INCO1
INCO2
ANZPK
SHPUNT
NTGEW
BRGEW
GEWEI
into corresponding fields of wa_header
from j_1bnfdoc
where bukrs eq 'BR30' and
docnum EQ p_docnum. "Nr Docto
"doctyp eq 1. "Nota fiscal
"direct eq 2. "Saída
ENDSELECT.
if sy-subrc ne 0.
message 'Documento não encontrado.' type 'I'.
stop.
endif.
*IF P_CFEIRA EQ 'X'.
*
*ENDIF.
* Data de Hoje
"write SY-DATUM to wx_curdate dd/mm/yyyy.
*replace all occurrences of '.' in wx_curdate with '/'.
* Data do Novo Documento
write p_docdat to wx_newdate dd/mm/yyyy.
replace all occurrences of '/' in wx_newdate with '.'.
* Data do Documento
write wa_header-docdat to wx_refdocdate dd/mm/yyyy.
*replace all occurrences of '.' in wx_refdocdate with '/'.
* NumNFe
"write wa_header-nfenum to wx_numnfe.
"wx_numnfe = '256856'.
data nfeformat(9) type n.
unpack wx_numnfe to nfeformat.
* Docto de Referência.
write wa_header-docnum to wx_docref.
* ************************
* HEADER DA NF
* ************************
data: wx_nftype(2) type c, wx_parid(10) type c, wx_parvw(2) type c.
IF P_NFTYPE IS INITIAL.
wx_nftype = wa_header-nftype.
ELSE.
wx_nftype = P_NFTYPE.
ENDIF.
IF P_PARID IS INITIAL.
wx_parid = wa_header-parid.
ELSE.
wx_parid = P_PARID.
"Se informou parceiro tem que informar a função.
IF P_PARVW IS INITIAL.
message 'Se informar o Parceiro tem que informar a Função do Parceiro.' TYPE 'I'.
stop.
ENDIF.
ENDIF.
IF P_PARVW IS INITIAL.
wx_parvw = wa_header-parvw.
ELSE.
wx_parvw = P_PARVW.
"Se informou função parceiro tem que informar parceiro.
IF P_PARID IS INITIAL.
message 'Se informar a Função do Parceiro, tem que informar o ID do Parceiro.' TYPE 'I'.
stop.
ENDIF.
ENDIF.
* TELA INICIAL
PERFORM f_load_bdcdata USING:
'X' 'SAPMJ1B1' '0900',
' ' 'J_1BDYDOC-NFTYPE' wx_nftype, "i0, i1, i8, etc...
' ' 'J_1BDYDOC-BUKRS' wa_header-bukrs,
' ' 'J_1BDYDOC-BRANCH' wa_header-branch,
' ' 'J_1BDYDOC-PARVW' wx_parvw,
' ' 'J_1BDYDOC-PARID' wx_parid,
' ' 'J_1BDYLIN-INCLTX' 'X'.
IF P_SAVREF EQ 'X'.
"REF NF 000123456 DE 01/01/2019'
wx_observacao = 'REF NF % DE & '.
REPLACE '%' IN wx_observacao WITH nfeformat.
REPLACE '&' IN wx_observacao WITH wx_refdocdate.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'J_1BDYDOC-DOCDAT' wx_newdate,
' ' 'J_1BDYDOC-OBSERVAT' wx_observacao,
' ' 'J_1BDYDOC-DOCREF' wa_header-docnum,
' ' 'BDC_OKCODE' '=ADIT'.
ELSE.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'J_1BDYDOC-DOCDAT' wx_newdate,
' ' 'J_1BDYDOC-OBSERVAT' p_observ,
' ' 'BDC_OKCODE' '=ADIT'.
ENDIF.
* ************************
* ITENS DA NF
* ************************
* Qtde Itens NF
SELECT COUNT( * )
INTO wx_countItens
FROM j_1bnflin
WHERE docnum EQ p_docnum.
* Obter Itens da NF
SELECT ITMNUM
ITMTYP
MATNR
WERKS
MAKTX
MATKL
MENGE
MEINS
NETPR
CFOP
TAXLW1
TAXLW2
MATORG
MATUSE
NBM
TAXLW4
TAXLW5
DOCREF
ITMREF
COD_CTA
INTO TABLE ti_itens
FROM j_1bnflin
WHERE docnum EQ p_docnum.
*IF p_nvicms IS INITIAL.
* wx_diricms = wa_item-taxlw1.
*ELSE.
* wx_diricms = p_nvicms.
*ENDIF.
*
*IF p_nvipi IS INITIAL.
* wx_diripi = wa_item-taxlw2.
*ELSE.
* wx_diripi = p_nvipi.
*ENDIF.
*
*IF p_nvcofi IS INITIAL.
* wx_dircofins = wa_item-taxlw4.
*ELSE.
* wx_dircofins = p_nvcofi.
*ENDIF.
*
*IF p_nvpis IS INITIAL.
* wx_dirpis = wa_item-taxlw5.
*ELSE.
* wx_dirpis = p_nvpis.
*ENDIF.
IF P_CTANL IS INITIAL.
wx_ctanalit = wa_item-COD_CTA.
ELSE.
wx_ctanalit = P_CTANL.
ENDIF.
LOOP AT ti_itens into wa_item.
wx_curItem = wx_curItem + 1.
wx_itmnum = 0.
IF P_SAVREF EQ 'X'.
wx_itmnum = wa_item-itmnum.
ENDIF.
data wx_newcfop(7) type c.
IF p_nvcfop IS INITIAL.
"Se não informado, copia.
wx_cfop = wa_item-cfop.
ELSE.
"Se informado, pega o novo.
wx_cfop = p_nvcfop.
ENDIF.
CONCATENATE wx_cfop(4) '/' wx_cfop+4 INTO wx_newcfop.
data wx_meins(3) type c.
write wa_item-MEINS to wx_meins.
write wa_item-NETPR to wx_netpr NO-ZERO.
write wa_item-MENGE to wx_menge NO-ZERO.
IF wx_bundle EQ 'S'.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '3000',
' ' 'J_1BDYLIN-ITMTYP' wa_item-itmtyp,
' ' 'J_1BDYLIN-MATNR' wa_item-MATNR,
' ' 'J_1BDYLIN-WERKS' wa_item-WERKS,
' ' 'J_1BDYLIN-MAKTX' wa_item-MAKTX,
' ' 'J_1BDYLIN-MATKL' wa_item-MATKL,
' ' 'J_1BDYLIN-MENGE' wx_menge,
' ' 'J_1BDYLIN-MEINS' wx_meins,
' ' 'J_1BDYLIN-NETPR' wx_netpr,
' ' 'J_1BDYLIN-CFOP' p_nvcfop,
' ' 'J_1BDYLIN-TAXLW1' wx_bun_TAXLW1, "Direitos ICMS
' ' 'J_1BDYLIN-TAXLW2' wx_bun_TAXLW2, "Direitos IPI
' ' 'J_1BDYLIN-MATORG' wa_item-MATORG,
' ' 'J_1BDYLIN-MATUSE' wa_item-MATUSE,
' ' 'J_1BDYLIN-NBM' wa_item-NBM,
' ' 'J_1BDYLIN-TAXLW4' wx_bun_TAXLW4, "Direitos COFINS
' ' 'J_1BDYLIN-TAXLW5' wx_bun_TAXLW5, "Direitos PIS
' ' 'J_1BDYLIN-DOCREF' wx_docref, "Nr Doc original
' ' 'J_1BDYLIN-ITMREF' wx_itmnum, "Item Doc Original
' ' 'J_1BDYLIN-COD_CTA' wx_ctanalit,
' ' 'BDC_OKCODE' '=TAX'.
ELSE.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '3000',
' ' 'J_1BDYLIN-ITMTYP' wa_item-itmtyp,
' ' 'J_1BDYLIN-MATNR' wa_item-MATNR,
' ' 'J_1BDYLIN-WERKS' wa_item-WERKS,
' ' 'J_1BDYLIN-MAKTX' wa_item-MAKTX,
' ' 'J_1BDYLIN-MATKL' wa_item-MATKL,
' ' 'J_1BDYLIN-MENGE' wx_menge,
' ' 'J_1BDYLIN-MEINS' wx_meins,
' ' 'J_1BDYLIN-NETPR' wx_netpr,
' ' 'J_1BDYLIN-CFOP' wx_newcfop,
' ' 'J_1BDYLIN-TAXLW1' wa_item-TAXLW1, "Direitos ICMS
' ' 'J_1BDYLIN-TAXLW2' wa_item-TAXLW2, "Direitos IPI
' ' 'J_1BDYLIN-MATORG' wa_item-MATORG,
' ' 'J_1BDYLIN-MATUSE' wa_item-MATUSE,
' ' 'J_1BDYLIN-NBM' wa_item-NBM,
' ' 'J_1BDYLIN-TAXLW4' wa_item-TAXLW4, "Direitos COFINS
' ' 'J_1BDYLIN-TAXLW5' wa_item-TAXLW5, "Direitos PIS
' ' 'J_1BDYLIN-DOCREF' wx_docref, "Nr Doc original
' ' 'J_1BDYLIN-ITMREF' wx_itmnum, "Item Doc Original
' ' 'J_1BDYLIN-COD_CTA' wx_ctanalit,
' ' 'BDC_OKCODE' '=TAX'.
ENDIF.
"Conta a qtde de impostos do item atual.
select count( * )
from j_1bnfstx
into wx_QtTaxItem
where DOCNUM EQ p_docnum AND
ITMNUM EQ wa_item-ITMNUM.
IF wx_qttaxitem > 4.
"if sy-subrc ne 0.
message 'Erro ao localizar os impostos. Condição não esperada' type 'W'.
stop.
"endif.
ENDIF.
"Seleciona os Impostos.
SELECT ITMNUM
TAXTYP
BASE
RATE
TAXVAL
EXCBAS
OTHBAS
INTO TABLE ti_tax
FROM j_1bnfstx
WHERE DOCNUM EQ p_docnum AND
ITMNUM EQ wa_item-ITMNUM.
wx_idxTax = 1.
DATA: TAXTYP_1(20) type c, BASE_1(20) type c, RATE_1(20) type c, TAXVAL_1(20) type c, EXCBAS_1(20) type c, OTHBAS_1(20) type c.
DATA: TAXTYP_2(20) type c, BASE_2(20) type c, RATE_2(20) type c, TAXVAL_2(20) type c, EXCBAS_2(20) type c, OTHBAS_2(20) type c.
DATA: TAXTYP_3(20) type c, BASE_3(20) type c, RATE_3(20) type c, TAXVAL_3(20) type c, EXCBAS_3(20) type c, OTHBAS_3(20) type c.
DATA: TAXTYP_4(20) type c, BASE_4(20) type c, RATE_4(20) type c, TAXVAL_4(20) type c, EXCBAS_4(20) type c, OTHBAS_4(20) type c.
" Loop nos Impostos para coletar.
" Está feio isso mas é o que tem pra hoje. =(
LOOP AT ti_tax INTO wa_tax.
DATA: wx_base(15) type c, wx_rate(6) type c, wx_taxval(15) type c, wx_excbas(15) type c, wx_othbas(15) type c.
write wa_tax-base to wx_base no-zero.
write wa_tax-rate to wx_rate no-zero.
write wa_tax-taxval to wx_taxval no-zero.
write wa_tax-excbas to wx_excbas no-zero.
write wa_tax-othbas to wx_othbas no-zero.
IF wx_idxtax EQ 1.
TAXTYP_1 = wa_tax-TAXTYP.
BASE_1 = wx_base.
RATE_1 = wx_rate.
TAXVAL_1 = wx_taxval.
EXCBAS_1 = wx_excbas.
OTHBAS_1 = wx_othbas.
ENDIF.
IF wx_idxtax EQ 2.
TAXTYP_2 = wa_tax-TAXTYP.
BASE_2 = wx_base.
RATE_2 = wx_rate.
TAXVAL_2 = wx_taxval.
EXCBAS_2 = wx_excbas.
OTHBAS_2 = wx_othbas.
ENDIF.
IF wx_idxtax EQ 3.
TAXTYP_3 = wa_tax-TAXTYP.
BASE_3 = wx_base.
RATE_3 = wx_rate.
TAXVAL_3 = wx_taxval.
EXCBAS_3 = wx_excbas.
OTHBAS_3 = wx_othbas.
ENDIF.
IF wx_idxtax EQ 4.
TAXTYP_4 = wa_tax-TAXTYP.
BASE_4 = wx_base.
RATE_4 = wx_rate.
TAXVAL_4 = wx_taxval.
EXCBAS_4 = wx_excbas.
OTHBAS_4 = wx_othbas.
ENDIF.
wx_idxTax = wx_idxTax + 1.
ENDLOOP.
"Salva os impostos
IF wx_qttaxitem EQ 1.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '3000',
' ' 'J_1BDYSTX-TAXTYP(01)' TAXTYP_1,
' ' 'J_1BDYSTX-BASE(01)' BASE_1,
' ' 'J_1BDYSTX-RATE(01)' RATE_1,
' ' 'J_1BDYSTX-TAXVAL(01)' TAXVAL_1,
' ' 'J_1BDYSTX-EXCBAS(01)' EXCBAS_1,
' ' 'J_1BDYSTX-OTHBAS(01)' OTHBAS_1,
' ' 'BDC_OKCODE' '=TAB1'.
ELSEIF wx_qttaxitem EQ 2.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '3000',
' ' 'J_1BDYSTX-TAXTYP(01)' TAXTYP_1,
' ' 'J_1BDYSTX-BASE(01)' BASE_1,
' ' 'J_1BDYSTX-RATE(01)' RATE_1,
' ' 'J_1BDYSTX-TAXVAL(01)' TAXVAL_1,
' ' 'J_1BDYSTX-EXCBAS(01)' EXCBAS_1,
' ' 'J_1BDYSTX-OTHBAS(01)' OTHBAS_1,
' ' 'J_1BDYSTX-TAXTYP(02)' TAXTYP_2,
' ' 'J_1BDYSTX-BASE(02)' BASE_2,
' ' 'J_1BDYSTX-RATE(02)' RATE_2,
' ' 'J_1BDYSTX-TAXVAL(02)' TAXVAL_2,
' ' 'J_1BDYSTX-EXCBAS(02)' EXCBAS_2,
' ' 'J_1BDYSTX-OTHBAS(02)' OTHBAS_2,
"' ' 'BDC_OKCODE' '/00'.
' ' 'BDC_OKCODE' '=TAB1'.
ELSEIF wx_qttaxitem EQ 3.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '3000',
' ' 'J_1BDYSTX-TAXTYP(01)' TAXTYP_1,
' ' 'J_1BDYSTX-BASE(01)' BASE_1,
' ' 'J_1BDYSTX-RATE(01)' RATE_1,
' ' 'J_1BDYSTX-TAXVAL(01)' TAXVAL_1,
' ' 'J_1BDYSTX-EXCBAS(01)' EXCBAS_1,
' ' 'J_1BDYSTX-OTHBAS(01)' OTHBAS_1,
' ' 'J_1BDYSTX-TAXTYP(02)' TAXTYP_2,
' ' 'J_1BDYSTX-BASE(02)' BASE_2,
' ' 'J_1BDYSTX-RATE(02)' RATE_2,
' ' 'J_1BDYSTX-TAXVAL(02)' TAXVAL_2,
' ' 'J_1BDYSTX-EXCBAS(02)' EXCBAS_2,
' ' 'J_1BDYSTX-OTHBAS(02)' OTHBAS_2,
' ' 'J_1BDYSTX-TAXTYP(03)' TAXTYP_3,
' ' 'J_1BDYSTX-BASE(03)' BASE_3,
' ' 'J_1BDYSTX-RATE(03)' RATE_3,
' ' 'J_1BDYSTX-TAXVAL(03)' TAXVAL_3,
' ' 'J_1BDYSTX-EXCBAS(03)' EXCBAS_3,
' ' 'J_1BDYSTX-OTHBAS(03)' OTHBAS_3,
' ' 'BDC_OKCODE' '=TAB1'.
ELSEIF wx_qttaxitem EQ 4.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '3000',
' ' 'J_1BDYSTX-TAXTYP(01)' TAXTYP_1,
' ' 'J_1BDYSTX-BASE(01)' BASE_1,
' ' 'J_1BDYSTX-RATE(01)' RATE_1,
' ' 'J_1BDYSTX-TAXVAL(01)' TAXVAL_1,
' ' 'J_1BDYSTX-EXCBAS(01)' EXCBAS_1,
' ' 'J_1BDYSTX-OTHBAS(01)' OTHBAS_1,
' ' 'J_1BDYSTX-TAXTYP(02)' TAXTYP_2,
' ' 'J_1BDYSTX-BASE(02)' BASE_2,
' ' 'J_1BDYSTX-RATE(02)' RATE_2,
' ' 'J_1BDYSTX-TAXVAL(02)' TAXVAL_2,
' ' 'J_1BDYSTX-EXCBAS(02)' EXCBAS_2,
' ' 'J_1BDYSTX-OTHBAS(02)' OTHBAS_2,
' ' 'J_1BDYSTX-TAXTYP(03)' TAXTYP_3,
' ' 'J_1BDYSTX-BASE(03)' BASE_3,
' ' 'J_1BDYSTX-RATE(03)' RATE_3,
' ' 'J_1BDYSTX-TAXVAL(03)' TAXVAL_3,
' ' 'J_1BDYSTX-EXCBAS(03)' EXCBAS_3,
' ' 'J_1BDYSTX-OTHBAS(03)' OTHBAS_3,
' ' 'J_1BDYSTX-TAXTYP(04)' TAXTYP_4,
' ' 'J_1BDYSTX-BASE(04)' BASE_4,
' ' 'J_1BDYSTX-RATE(04)' RATE_4,
' ' 'J_1BDYSTX-TAXVAL(04)' TAXVAL_4,
' ' 'J_1BDYSTX-EXCBAS(04)' EXCBAS_4,
' ' 'J_1BDYSTX-OTHBAS(04)' OTHBAS_4,
' ' 'BDC_OKCODE' '=TAB1'.
ENDIF.
"Se é o último item, tem que ir para o Tab3 de Parceiro.
IF wx_curitem EQ wx_countitens.
"Vai pra tela de Parceiros
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'BDC_OKCODE' '=TAB3'.
ELSE.
"Adiciona novo item.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'BDC_OKCODE' '=ADIT'.
ENDIF.
ENDLOOP.
* Parceiro 2300
IF p_parid1 IS INITIAL.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'J_1BDYNAD-PARVW(01)' P_PARVW,
' ' 'J_1BDYNAD-PARID(01)' p_parid,
' ' 'BDC_OKCODE' '=TAB4'. "Vai pra tela de Mensagens
ELSE.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'J_1BDYNAD-PARVW(01)' P_PARVW,
' ' 'J_1BDYNAD-PARID(01)' p_parid,
' ' 'J_1BDYNAD-PARVW(02)' 'SP',
' ' 'J_1BDYNAD-PARID(02)' p_parid1, "Parid do Transportador
' ' 'BDC_OKCODE' '=TAB4'. "Vai pra tela de Mensagens
ENDIF.
"Conta a qtde de msgs.
select count( * )
from J_1BNFFTX
into wx_qtmsgs
where DOCNUM EQ p_docnum.
SELECT SEQNUM MESSAGE
INTO TABLE ti_msg
FROM J_1BNFFTX
WHERE DOCNUM EQ p_docnum
ORDER BY SEQNUM.
DATA: fieldmsg(20) type c,
wx_idxMsg type n value 0,
wx_nextCODE(5) type c value '/00'.
"Se estiver na última msg tem que ir para Transporte.
LOOP AT ti_msg INTO wa_msg.
wx_idxMsg = wx_idxMsg + 1.
CONCATENATE 'J_1BDYFTX-MESSAGE(' wx_idxMsg ')' INTO fieldmsg.
IF wx_idxmsg EQ wx_qtmsgs.
wx_nextcode = '=TAB5'.
ENDIF.
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' fieldmsg wa_msg-message,
' ' 'BDC_OKCODE' wx_nextcode.
ENDLOOP.
data: wx_ANZPK(5) type c, wx_NTGEW(15) type c, wx_BRGEW(15) type c.
write wa_header-ANZPK to wx_anzpk NO-ZERO.
write wa_header-NTGEW to wx_NTGEW NO-ZERO.
write wa_header-BRGEW to wx_BRGEW NO-ZERO.
* Transporte
PERFORM f_load_bdcdata USING:
'X' 'SAPLJ1BB2' '2000',
' ' 'J_1BDYDOC-INCO1' wa_header-INCO1,
' ' 'J_1BDYDOC-INCO2' wa_header-INCO2,
' ' 'J_1BDYDOC-ANZPK' wa_header-ANZPK, "Qtde
' ' 'J_1BDYDOC-SHPUNT' wa_header-SHPUNT, "Volume
' ' 'J_1BDYDOC-NTGEW' wx_NTGEW, "Peso Líquido
' ' 'J_1BDYDOC-BRGEW' wx_BRGEW, "Peso Bruto
' ' 'J_1BDYDOC-GEWEI' wa_header-GEWEI, "Unidade de Peso
' ' 'BDC_OKCODE' '=TAB1'. "Vai pra Tela Inicial
*PERFORM f_load_bdcdata USING:
* 'X' 'SAPLJ1BB2' '2000',
* ' ' 'BDC_OKCODE' '=SAVE'.
wa_params-dismode = 'A'. " ( A - Visivel N - Background )
wa_params-racommit = 'X'.
CALL TRANSACTION 'J1B1N'
USING ti_bdc
MODE 'E' "Errors only
"OPTIONS FROM wa_params
MESSAGES INTO ti_message. "Retorno do sucesso ou fracasso do batch input.
"Message 'Cópia da NF concluída. CONFIRME OS DADOS ANTES DE SALVAR!!!' type 'S' DISPLAY LIKE 'E'.
"DATA VL_MSG TYPE STRING. "STRING É IGUAL CHAR, VAI AUTOMÁTICO DE ACORDO COM O TEXTO
*LOOP AT ti_message INTO wa_message.
*
*CALL FUNCTION 'MESSAGE_TEXT_BUILD'
* EXPORTING
* msgid = WA_MESSAGE-MSGID
* msgnr = WA_MESSAGE-MSGNR
* MSGV1 = WA_MESSAGE-MSGV1
* MSGV2 = WA_MESSAGE-MSGV2
* IMPORTING
* MESSAGE_TEXT_OUTPUT = VL_MSG.
*
*WRITE / VL_MSG.
*
*ENDLOOP.
*&---------------------------------------------------------------------*
*& Form F_LOAD_BDCDATA
*&---------------------------------------------------------------------*
FORM f_load_bdcdata USING p_x
p_2
p_3.
IF p_x = 'X'.
wa_bdc-program = p_2.
wa_bdc-dynpro = p_3.
wa_bdc-dynbegin = p_x.
APPEND wa_bdc TO ti_bdc.
ELSE.
wa_bdc-fnam = p_2.
wa_bdc-fval = p_3.
APPEND wa_bdc TO ti_bdc.
ENDIF.
CLEAR wa_bdc.
ENDFORM. " F_LOAD_BDCDATA