Code: Alles auswählen.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_mappe
user = sy-uname
keep = 'X'.
CLEAR: gt_itab_order,
pos.
LOOP AT gt_itab_order.
*-- Neuer Kunde
AT NEW kunnr.
REFRESH bdc_table.
CLEAR bdc_table.
*-- Auftrag
PERFORM dynpro USING:
'X' 'SAPMV45A' '0101',
' ' 'VBAK-AUART' 'ZTA', "Auftrag Online
' ' 'VBAK-VKORG' '3000',
' ' 'VBAK-VTWEG' '30',
' ' 'VBAK-VKBUR' '3010',
' ' 'VBAK-VKGRP' '400', "Verkäufergruppe für Onlineaufträge
' ' 'BDC_OKCODE' '/0'.
*-- Kunde und Datum
PERFORM get_next_business_day.
WRITE: date2+6(2) TO lv_datum,
date2+4(2) TO lv_datum+2,
date2(4) TO lv_datum+4.
PERFORM dynpro USING:
'X' 'SAPMV45A' '4001',
' ' 'KUAGV-KUNNR' gt_itab_order-kunnr,
' ' 'RV45A-KETDAT' lv_datum, "von File lesen
' ' 'VBAK-LIFSK' '50',
' ' 'BDC_OKCODE' '/0'.
MOVE: 1 TO lv_line,
1 TO pos.
NEW-LINE.
WRITE: / 'Neuer Auftrag mit Auftraggeber: ', gt_itab_order-kunnr.
SKIP 1.
ENDAT.
*--
IF lv_line = 18.
lv_line = 2.
ENDIF.
IF lv_line < 10.
CONCATENATE 'RV45A-MABNR(0' lv_line ')' INTO lv_matnr.
CONCATENATE 'RV45A-KWMENG(0' lv_line ')' INTO lv_menge.
ELSE.
CONCATENATE 'RV45A-MABNR(' lv_line ')' INTO lv_matnr.
CONCATENATE 'RV45A-KWMENG(' lv_line ')' INTO lv_menge.
ENDIF.
PERFORM dynpro USING:
'X' 'SAPMV45A' '4001',
' ' lv_matnr gt_itab_order-matnr,
' ' lv_menge gt_itab_order-menge,
' ' 'BDC_OKCODE' '/0'.
WRITE: /3 pos LEFT-JUSTIFIED,
10 gt_itab_order-matnr,
29 gt_itab_order-menge.
ADD 1 TO lv_line.
ADD 1 TO pos.
*--
IF LINES( it_text ) > 0 AND lv_txt <> 'X'.
CLEAR lv_kunnr.
WRITE gt_itab_order-kunnr TO lv_kunnr+5 RIGHT-JUSTIFIED.
OVERLAY lv_kunnr WITH '0000000000'.
SELECT SINGLE * FROM kna1 WHERE kunnr = lv_kunnr.
PERFORM dynpro USING:
" 'X' 'SAPMV45A' '4001',
" ' ' 'KUAGV-KUNNR' gt_itab_order-kunnr,
" ' ' 'RV45A-KETDAT' '25.02.2012', "von File lesen
' ' 'BDC_OKCODE' '=KTEX_SUB'.
*-- kopftext
PERFORM dynpro USING:
'X' 'SAPMV45A' '4002',
' ' 'BDC_OKCODE' 'TP_NEXT',
'X' 'SAPMV45A' '4002',
' ' 'LV70T-SPRAS' kna1-spras,
' ' 'BDC_OKCODE' '=TP_DETAIL'.
PERFORM dynpro USING:
'X' 'SAPLSTXX' '1100'.
LOOP AT it_text TO 20. "maximal 20 Zeilen - Formularanhangtext
MOVE sy-tabix TO c_num.
ADD 1 TO c_num.
IF sy-tabix < 10.
CONCATENATE 'RSTXT-TXLINE(0' c_num ')' INTO c_field.
CONCATENATE 'RSTXT-TXPARGRAPH(0' c_num ')' INTO c_field2.
ELSE.
CONCATENATE 'RSTXT-TXLINE(' c_num ')' INTO c_field.
CONCATENATE 'RSTXT-TXPARGRAPH(0' c_num ')' INTO c_field2.
ENDIF.
PERFORM dynpro USING:
' ' c_field2 '*',
' ' c_field it_text-line,
' ' 'BDC_OKCODE' '/0'.
CLEAR c_field.
ENDLOOP.
PERFORM dynpro USING:
' ' 'BDC_OKCODE' '=TXVB'.
PERFORM dynpro USING:
'X' 'SAPLSTXX' '1100',
' ' 'BDC_OKCODE' '=TXBA'.
PERFORM dynpro USING:
'X' 'SAPMV45A' '4002',
' ' 'BDC_OKCODE' '/EBACK'.
MOVE 'X' TO lv_txt.
CLEAR it_text.
REFRESH it_text.
ENDIF.
ENDLOOP.
*--
PERFORM dynpro USING:
'X' 'SAPMV45A' '4001',
' ' 'BDC_OKCODE' '/11'.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'VA01'
TABLES
dynprotab = bdc_table.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
*-- Email senden
"gf_document_data-obj_name = 'Ordine Online'.
"gf_document_data-obj_descr = 'Ordine Online'.
"gf_document_data-obj_langu = kna1-spras. "sy-langu.
"gf_document_data-obj_prio = '1'.
"WRITE 'Soeben ist ein neuer Online Auftrag auf dem Crystal Server eingegangen.' TO gt_object_content-line.
"APPEND gt_object_content.
"PERFORM send_mail.
*-- get output file
CLEAR file_out.
CONCATENATE '\\saptest\users\crystal\bkp\' dir_list-name INTO file_out.
PERFORM copy_file USING filename file_out.
DELETE DATASET filename.
FORM dynpro USING dynbegin name value.
CLEAR bdc_table.
IF dynbegin = 'X'.
MOVE: name TO bdc_table-program,
value TO bdc_table-dynpro,
'X' TO bdc_table-dynbegin.
APPEND bdc_table.
ELSE.
MOVE: name TO bdc_table-fnam,
value TO bdc_table-fval.
APPEND bdc_table.
ENDIF.
ENDFORM. "dynpro