Code: Alles auswählen.
FORM PRUEFEN_RLZ
using i_matnr like i_ve-matnr
wa_hu type c.
break joma.
types: BEGIN OF line,
User type c LENGTH 4,
HU type c LENGTH 22,
end of line.
data: lv_rlz type ALPFDBNUM,
lv_pkzrlz type EXDTF,
l_refdate type ALDATE,
lv_answer type char10,
ls_vepo like vepo,
lt_nums TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM,
lt_char TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR,
lt_curr TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR,
lt_return TYPE TABLE OF bapiret2,
ls_nums type BAPI1003_ALLOC_VALUES_NUM,
ls_char type BAPI1003_ALLOC_VALUES_CHAR,
lv_matnr type BAPI1003_KEY-OBJECT,
lv_fname type c value 'zscan_wa03' LENGTH 10,
lv_text1 type c LENGTH 25,
it_text1 type STANDARD TABLE OF line,
lv_HU type c LENGTH 21,
lv_len type i ,
lt_vekp TYPE STANDARD TABLE OF vekp.
lv_matnr = i_matnr.
SELECT single * FROM vepo
Into ls_vepo
Where venum = i_ve-venum
And vepos = i_ve-vepos.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_matnr
objecttable = 'MARA'
classnum = 'RESTLAUFZEIT_VERBR'
classtype = '001'
KEYDATE = SY-DATUM
* UNVALUATED_CHARS = ' '
LANGUAGE = SY-LANGU
* IMPORTING
* STATUS =
* STANDARDCLASS =
TABLES
allocvaluesnum = lt_nums
allocvalueschar = lt_char
allocvaluescurr = lt_curr
RETURN = lt_return
.
loop at lt_nums into ls_nums.
lv_rlz = ls_nums-value_from.
*ls_nums-VALUE_FROM
endloop.
loop at lt_char into ls_char.
lv_pkzrlz = ls_char-VALUE_NEUTRAL.
endloop.
CALL FUNCTION 'ZBC_CALC_DATE'
EXPORTING
in_rectype = lv_pkzrlz
in_nbr_dwxmqy = lv_rlz
in_date = sy-datum
IMPORTING
OUT_DATE = l_refdate
EXCEPTIONS
OTHER_ERROR = 1
OTHERS = 2
.
IF ls_vepo-vfdat < l_refdate.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
* DEFAULTOPTION = 'Y'
TEXTLINE1 = 'Restlaufzeit wurde unterschritten wollen sie denoch fortfahren?'
* TEXTLINE2 = ' '
TITEL = 'Restlaufzeit unterschritten'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
IMPORTING
ANSWER = lv_answer
.
endif.
lv_HU = wa_HU .
CONCATENATE sy-uname lv_HU INTO lv_text1 SEPARATED BY ' '.
lv_len = strlen( lv_text1 ).
IF lv_answer = 'N'.
return.
elseif lv_answer = 'J'.
APPEND lv_text1 to it_text1.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = BIN_FILESIZE
FILENAME = 'H:\zscan_wa03\Report.txt'
* FILETYPE = DAT
* APPEND = APPEND
* WRITE_FIELD_SEPARATOR = WRITE_FIELD_SEPARATOR
* HEADER = R
* TRUNC_TRAILING_BLANKS = TRUNC_TRAILING_BLANKS
* WRITE_LF = WRITE_LF
* COL_SELECT = COL_SELECT
* COL_SELECT_MASK = COL_SELECT_MASK
* DAT_MODE = DAT_MODE
* CONFIRM_OVERWRITE = CONFIRM_OVERWRITE
* NO_AUTH_CHECK = NO_AUTH_CHECK
* CODEPAGE = CODEPAGE
* IGNORE_CERR = IGNORE_CERR
* REPLACEMENT = REPLACEMENT
* WRITE_BOM = WRITE_BOM
* TRUNC_TRAILING_BLANKS_EOL = TRUNC_TRAILING_BLANKS_EOL
* WK1_N_FORMAT = WK1_N_FORMAT
* WK1_N_SIZE = WK1_N_SIZE
* WK1_T_FORMAT = WK1_T_FORMAT
* WK1_T_SIZE = WK1_T_SIZE
* SHOW_TRANSFER_STATUS = SHOW_TRANSFER_STATUS
* write_lf_after_last_line = write_lf_after_last_line
* VIRUS_SCAN_PROFILE = VIRUS_SCAN_PROFILE
IMPORTING
FILELENGTH = lv_len
TABLES
DATA_TAB = it_text1
* FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
IF SY-SUBRC <> 0.
case sy-subrc.
when 1.
RAISE FILE_WRITE_ERROR.
when 2.
RAISE NO_BATCH.
when 3.
RAISE GUI_REFUSE_FILETRANSFER.
when 4.
RAISE INVALID_TYPE .
when 5.
RAISE NO_AUTHORITY.
when 6.
RAISE UNKNOWN_ERROR.
when 7.
RAISE HEADER_NOT_ALLOWED.
when 8.
RAISE SEPARATOR_NOT_ALLOWED.
when 9.
RAISE FILESIZE_NOT_ALLOWED.
when 10.
RAISE HEADER_TOO_LONG.
when 11.
RAISE DP_ERROR_CREATE.
when 12.
RAISE DP_ERROR_SEND.
when 13.
RAISE DP_ERROR_WRITE.
when 14.
RAISE UNKNOWN_DP_ERROR.
when 15.
RAISE ACCESS_DENIED.
when 16.
RAISE DP_OUT_OF_MEMORY.
when 17.
RAISE DISK_FULL.
when 18.
RAISE DP_TIMEOUT.
when 19.
RAISE FILE_NOT_FOUND.
when 20.
RAISE DATAPROVIDER_EXCEPTION.
when 21.
RAISE CONTROL_FLUSH_ERROR.
when OTHERS.
RAISE UNKNOWN_ERROR.
endcase.
ENDIF.
else.
return.
ENDIF.
clear sy-msgno.
ENDFORM.
in dem Beispielcode war der Parameter auskommentiertjonas1996 hat geschrieben:...
Beim FB 'GUI_DOWNLOAD' den Exporting Parameter Append = 'X'
ich würde von globalen Variablen die Finger lassen. Wie wird sichergestellt, dass die an die Lieferung angehängte Textdatei nur die Protokollsätze zu der jeweiligen Lieferung enthält? Durch das APPEND und einen allgemeinen Dateinamen landen Protokollsätze aller Lieferungen in der gleichen Textdatei. Waum muss es überhaupt als Textdatei abgelegt (und angehängt) werden? Was spricht gegen eine eigene Protokolltabelle?jonas1996 hat geschrieben:...
Ich habe mir gedacht , dass ich die Liefernummer in eine Globale Variable schreibe und dann vor dem anhängen und dem schreiben in die Datei Prüfe ob die Liefernummer übereinstimmt.
auch ein IT-Lehrling sollte die Möglichkeit haben seine Aufgaben zu hinterfragen bzw. den Sinn dahinter zu erfragen. Die Anforderungen an einen Entwickler sind oft nur auf den ersten Blick logisch und es gibt fast immer mehrere verschiedene Wege das Ziel zu erreichen. Wenn es keinen speziellen Grund für genau diese Vorgehensweise gibt, so lässt sich vielleicht der Auftraggeber davon überzeugen, dass es auch elegantere Wege gibt...Leider muss ich es mit einer txt lösen.
Weil ich den Auftrag so bekommen habe.
da hat Tron Recht, zumindest beim Application Log könnte ich mir auch vorstellen wie das funktionieren würde. Wie bereits gesagt, es gibt immer mehr als nur den einen Weg! Der Ansatz mit der angehängten Datei/Notiz würde sich spätestens dann als nicht elegant erweisen, wenn man aufgefordert wird über die Protokolldaten eine Auswertung zu machen.Tron hat geschrieben:...
Protokollieren kann übrigens im Application Log, oder in einem simplen Textbaustein
ohne Z-Tabelle oder Global Memory Variable.
Folgende Benutzer bedankten sich beim Autor Alexander D. für den Beitrag:
jonas1996
Code: Alles auswählen.
FORM PRUEFEN_RLZ
using i_matnr like i_ve-matnr
wa_hu type c.
break joma.
types: BEGIN OF line,
User type c LENGTH 4,
HU type c LENGTH 22,
end of line.
data: lv_rlz type ALPFDBNUM,
lv_pkzrlz type EXDTF,
l_refdate type ALDATE,
lv_answer type char10,
ls_vepo like vepo,
lt_nums TYPE TABLE OF BAPI1003_ALLOC_VALUES_NUM,
lt_char TYPE TABLE OF BAPI1003_ALLOC_VALUES_CHAR,
lt_curr TYPE TABLE OF BAPI1003_ALLOC_VALUES_CURR,
lt_return TYPE TABLE OF bapiret2,
ls_nums type BAPI1003_ALLOC_VALUES_NUM,
ls_char type BAPI1003_ALLOC_VALUES_CHAR,
lv_matnr type BAPI1003_KEY-OBJECT,
lv_fname type c value 'zscan_wa03' LENGTH 10,
lv_text1 type c LENGTH 25,
it_text1 type STANDARD TABLE OF line,
lv_HU type c LENGTH 21,
lv_len type i,
lv_filename type string.
lv_matnr = i_matnr.
SELECT single * FROM vepo
Into ls_vepo
Where venum = i_ve-venum
And vepos = i_ve-vepos.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_matnr
objecttable = 'MARA'
classnum = 'RESTLAUFZEIT_VERBR'
classtype = '001'
KEYDATE = SY-DATUM
* UNVALUATED_CHARS = ' '
LANGUAGE = SY-LANGU
* IMPORTING
* STATUS =
* STANDARDCLASS =
TABLES
allocvaluesnum = lt_nums
allocvalueschar = lt_char
allocvaluescurr = lt_curr
RETURN = lt_return
.
loop at lt_nums into ls_nums.
lv_rlz = ls_nums-value_from.
*ls_nums-VALUE_FROM
endloop.
loop at lt_char into ls_char.
lv_pkzrlz = ls_char-VALUE_NEUTRAL.
endloop.
CALL FUNCTION 'ZBC_CALC_DATE'
EXPORTING
in_rectype = lv_pkzrlz
in_nbr_dwxmqy = lv_rlz
in_date = sy-datum
IMPORTING
OUT_DATE = l_refdate
EXCEPTIONS
OTHER_ERROR = 1
OTHERS = 2
.
IF ls_vepo-vfdat < l_refdate.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
* DEFAULTOPTION = 'Y'
TEXTLINE1 = 'Restlaufzeit wurde unterschritten wollen sie denoch fortfahren?'
* TEXTLINE2 = ' '
TITEL = 'Restlaufzeit unterschritten'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
IMPORTING
ANSWER = lv_answer
.
endif.
lv_HU = wa_HU .
CONCATENATE sy-uname lv_HU INTO lv_text1 SEPARATED BY ' '.
lv_len = strlen( lv_text1 ).
IF lv_answer = 'N'.
return.
elseif lv_answer = 'J'.
APPEND lv_text1 to it_text1.
lv_filename = 'H:\zscan_wa03\Report'.
CONCATENATE lv_filename '_' wa_vbeln '.txt' INTO lv_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE = BIN_FILESIZE
FILENAME = lv_filename
* FILETYPE = DAT
APPEND = 'X'
* WRITE_FIELD_SEPARATOR = WRITE_FIELD_SEPARATOR
* HEADER = R
* TRUNC_TRAILING_BLANKS = TRUNC_TRAILING_BLANKS
* WRITE_LF = WRITE_LF
* COL_SELECT =
* COL_SELECT_MASK = COL_SELECT_MASK
* DAT_MODE = DAT_MODE
* CONFIRM_OVERWRITE = CONFIRM_OVERWRITE
* NO_AUTH_CHECK = NO_AUTH_CHECK
* CODEPAGE = CODEPAGE
* IGNORE_CERR = IGNORE_CERR
* REPLACEMENT = REPLACEMENT
* WRITE_BOM = WRITE_BOM
* TRUNC_TRAILING_BLANKS_EOL = TRUNC_TRAILING_BLANKS_EOL
* WK1_N_FORMAT = WK1_N_FORMAT
* WK1_N_SIZE = WK1_N_SIZE
* WK1_T_FORMAT = WK1_T_FORMAT
* WK1_T_SIZE = WK1_T_SIZE
* SHOW_TRANSFER_STATUS = SHOW_TRANSFER_STATUS
* write_lf_after_last_line = write_lf_after_last_line
* VIRUS_SCAN_PROFILE = VIRUS_SCAN_PROFILE
IMPORTING
FILELENGTH = lv_len
TABLES
DATA_TAB = it_text1
* FIELDNAMES =
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
IF SY-SUBRC <> 0.
case sy-subrc.
when 1.
RAISE FILE_WRITE_ERROR.
when 2.
RAISE NO_BATCH.
when 3.
RAISE GUI_REFUSE_FILETRANSFER.
when 4.
RAISE INVALID_TYPE .
when 5.
RAISE NO_AUTHORITY.
when 6.
RAISE UNKNOWN_ERROR.
when 7.
RAISE HEADER_NOT_ALLOWED.
when 8.
RAISE SEPARATOR_NOT_ALLOWED.
when 9.
RAISE FILESIZE_NOT_ALLOWED.
when 10.
RAISE HEADER_TOO_LONG.
when 11.
RAISE DP_ERROR_CREATE.
when 12.
RAISE DP_ERROR_SEND.
when 13.
RAISE DP_ERROR_WRITE.
when 14.
RAISE UNKNOWN_DP_ERROR.
when 15.
RAISE ACCESS_DENIED.
when 16.
RAISE DP_OUT_OF_MEMORY.
when 17.
RAISE DISK_FULL.
when 18.
RAISE DP_TIMEOUT.
when 19.
RAISE FILE_NOT_FOUND.
when 20.
RAISE DATAPROVIDER_EXCEPTION.
when 21.
RAISE CONTROL_FLUSH_ERROR.
when OTHERS.
RAISE UNKNOWN_ERROR.
endcase.
ENDIF.
else.
return.
ENDIF.
clear sy-msgno.
ENDFORM. " PRUEFEN_RLZ