Code: Alles auswählen.
REPORT ZCASA_BI_SD_FAKTURA_STORNO_EX .
TABLES: VBRK.
DATA: BEGIN OF BDCDATA OCCURS 0.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCDATA.
*-DATA
DATA: FILENAME LIKE RLGRAP-FILENAME.
DATA: DATEI LIKE RLGRAP-FILENAME.
DATA: SUBRC LIKE SY-SUBRC.
DATA DELIM.
DATA: REPORTS LIKE TRDIR-NAME OCCURS 0 WITH HEADER LINE.
DATA V_ZIPLANG(1) TYPE I.
DATA: ANSWER,
JOB TYPE TBTCJOB-JOBNAME,
JOB1 TYPE TBTCJOB-JOBNAME,
NUM1 TYPE RSJOBINFO-JOBNUMB,
NUM TYPE RSJOBINFO-JOBNUMB.
*--------------
*-Data's
DATA: GROUP(12),
USER(12),
KEEP(1) VALUE ' ',
HOLDDATE LIKE SY-DATUM,
ANZAHL(6) TYPE N.
* Mappenzähler
DATA AS_ZAHL TYPE I.
DATA MP_ZAHL(2) TYPE N VALUE 1.
DATA: BEGIN OF TAB1 OCCURS 0,
VBELN LIKE VBAK-VBELN,
END OF TAB1.
DATA V_LINES TYPE I.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBRK-VBELN,
END OF ITAB.
PARAMETER:
P_PFAD LIKE RLGRAP-FILENAME DEFAULT 'C:\' OBLIGATORY,
P_FILET LIKE RLGRAP-FILETYPE DEFAULT 'DAT',
*-Mappe
P_GROUP LIKE GROUP OBLIGATORY,
P_ANZAHL(5) DEFAULT '10000',
CH_BATCH AS CHECKBOX DEFAULT 'X'.
START-OF-SELECTION.
PERFORM UPDATE.
PERFORM LISTE.
PERFORM BATCH.
END-OF-SELECTION.
*-Pfad finden-----------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_PFAD.
GET CURSOR FIELD P_PFAD VALUE P_PFAD.
FILENAME = P_PFAD.
PERFORM FILEFINDER.
LEAVE TO SCREEN 1000.
*&---------------------------------------------------------------------*
*& Form FILEFINDER
*&---------------------------------------------------------------------*
FORM FILEFINDER.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = P_PFAD
MASK = ',*.*,*.*.'
mode = 'O'
IMPORTING
filename = datei
EXCEPTIONS
inv_winsys = 1
no_batch = 2
SELECTION_CANCEL = 3
selection_error = 4
OTHERS = 5.
MOVE DATEI TO P_PFAD.
ENDFORM. " FILEFINDER
*&---------------------------------------------------------------------*
*& Form UPDATE
*&---------------------------------------------------------------------*
FORM UPDATE.
REFRESH: TAB1,ITAB.
CLEAR: ITAB,TAB1.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = P_PFAD
FILETYPE = P_FILET
TABLES
DATA_TAB = TAB1
EXCEPTIONS
OTHERS = 1.
DESCRIBE TABLE TAB1 LINES V_LINES.
ENDFORM. " UPDATE
*&---------------------------------------------------------------------*
*& Form LISTE
*&---------------------------------------------------------------------*
FORM LISTE.
WRITE: / 'Anzahl Fakturen im Upload File',V_LINES.
SORT TAB1 BY VBELN.
LOOP AT TAB1.
SELECT SINGLE * FROM VBRK WHERE VBELN EQ TAB1-VBELN.
IF SY-SUBRC = 0.
WRITE: / VBRK-VBELN,VBRK-FKSTO.
MOVE VBRK-VBELN TO ITAB-VBELN.
APPEND ITAB.
ELSE.
WRITE: / TAB1-VBELN,'gibt es nicht bitte Kontrollieren'.
DELETE TAB1.
ENDIF.
ENDLOOP.
ENDFORM. " LISTE
*&---------------------------------------------------------------------*
*& Form BATCH
*&---------------------------------------------------------------------*
FORM BATCH.
IF CH_BATCH EQ 'X'.
PERFORM OPEN_GROUP.
REFRESH BDCDATA.
CLEAR BDCDATA.
ENDIF.
LOOP AT ITAB.
IF CH_BATCH EQ 'X'.
* - externe Nummernvergabe.
PERFORM ZBDC_DYNPRO USING:
'X' 'SAPMV60A' '0102',
' ' 'BDC_CURSOR' 'KOMFK-VBELN(01)',
' ' 'BDC_OKCODE' '=SICH',
' ' 'KOMFK-VBELN(01)' ITAB-VBELN.
PERFORM ZBDC_DYNPRO USING:
'X' 'SAPMV60A' '0102',
' ' 'BDC_CURSOR' 'KOMFK-VBELN(01)',
' ' 'BDC_OKCODE' '=BACK'.
*-Transaktion
PERFORM BDC_TRANSACTION USING 'VF11'.
PERFORM BDC_REFRESH.
* --- Mappengröße beachten
AS_ZAHL = AS_ZAHL + 1.
IF AS_ZAHL = P_ANZAHL.
PERFORM CLOSE_GROUP.
MP_ZAHL = MP_ZAHL + 1.
MOVE MP_ZAHL TO P_GROUP+10(2).
PERFORM OPEN_GROUP.
AS_ZAHL = 0.
ENDIF.
ENDIF.
ENDLOOP.
IF CH_BATCH EQ 'X'.
PERFORM CLOSE_GROUP.
ENDIF.
ENDFORM. " BATCH
*&---------------------------------------------------------------------*
*& Form OPEN_GROUP
*&---------------------------------------------------------------------*
FORM OPEN_GROUP.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = P_GROUP
USER = SY-UNAME
KEEP = KEEP
HOLDDATE = HOLDDATE.
ENDFORM. " OPEN_GROUP
*-----------------------------------------------------------------------
*- Kopf Batch
*-----------------------------------------------------------------------
FORM ZBDC_DYNPRO USING BEGIN FNAM FVAL.
CLEAR BDCDATA.
IF BEGIN = 'X'.
BDCDATA-PROGRAM = FNAM.
BDCDATA-DYNPRO = FVAL.
BDCDATA-DYNBEGIN = 'X'.
ELSE.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
ENDIF.
APPEND BDCDATA.
ENDFORM.
*-Transaktion-----------------------------------------------------------
FORM BDC_TRANSACTION USING TCODE TYPE C.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = TCODE
TABLES
DYNPROTAB = BDCDATA.
ENDFORM.
*-Löschen---------------------------------------------------------------
FORM BDC_REFRESH.
CLEAR BDCDATA. REFRESH BDCDATA.
ENDFORM.
*-Mappe schliessen------------------------------------------------------
FORM CLOSE_GROUP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
CLEAR BDCDATA.
REFRESH BDCDATA.
ENDFORM.