*&---------------------------------------------------------------------*
*& Report ZTOOLMAT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTOOLMAT_DU.
DATA: LT_PTAB TYPE ABAP_FUNC_PARMBIND_TAB,
LS_PTAB TYPE ABAP_FUNC_PARMBIND.
TYPES: BEGIN OF TYP_DAT,
LINE TYPE STRING, " UP/DOWNLOAD行データ
END OF TYP_DAT.
TYPES: BEGIN OF TYP_HASHTABLE,
KEY TYPE STRING,
INX TYPE I,
END OF TYP_HASHTABLE.
TYPES: BEGIN OF TYP_RESULT,
INX TYPE I,
CODE TYPE MARA-MATNR,
RESULT TYPE STRING,
RESULT_TEXT TYPE STRING,
END OF TYP_RESULT.
* 内部テーブル
DATA:LT_HASH TYPE HASHED TABLE OF TYP_HASHTABLE WITH UNIQUE KEY KEY ,
L_HASH TYPE TYP_HASHTABLE.
DATA:TBL_DAT TYPE TABLE OF TYP_DAT.
DATA:LINE_DAT TYPE TYP_DAT.
DATA:TBL_STRING TYPE TABLE OF STRING.
DATA:L_VALUE TYPE STRING.
DATA:RE TYPE ABAP_FUNC_PARMBIND,
RE_MSG TYPE ABAP_FUNC_PARMBIND.
DATA L_RE TYPE YERESULTSIGN.
DATA L_MSG TYPE NATXT.
DATA:NORL_COUNT TYPE I VALUE 0,
ER_COUNT TYPE I VALUE 0.
DATA L_H_TBL_RETURN TYPE BAPIRET2.
DATA ER_FLG TYPE C.
DATA:LT_RESULT TYPE TABLE OF TYP_RESULT,
LH_RESULT TYPE TYP_RESULT.
FIELD-SYMBOLS : <FS_STRC> TYPE ABAP_FUNC_PARMBIND,
<FS_VALUE> TYPE ANY,
<FS2> TYPE ANY,
<FS_RET> TYPE YERESULTSIGN,
<FS_REMSG> TYPE NATXT.
DATA OREF TYPE REF TO CX_ROOT.
*画面項目
SELECTION-SCREEN BEGIN OF BLOCK BL1 WITH FRAME TITLE TEXT-001.
PARAMETERS P_FILEU1 TYPE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS P_CKBOX AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(40) TEXT-002.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BL1.
*ファイル項目
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILEU1.
PERFORM GET_FILENAME CHANGING P_FILEU1.
INITIALIZATION.
*実行処理
START-OF-SELECTION.
*
* ファイル入力
PERFORM UPLOAD_FILE USING P_FILEU1 TBL_DAT.
PERFORM F_MAIN_PROC CHANGING LT_RESULT.
END-OF-SELECTION.
IF ER_FLG IS NOT INITIAL.
RETURN.
ENDIF.
WRITE: 'No' ,
5(20) '品目コード' ,
25(15) '結果サイン' ,
40 'メッセージテキスト' ,
/.
LOOP AT LT_RESULT INTO LH_RESULT .
WRITE:/(4) LH_RESULT-INX,
5(20) LH_RESULT-CODE ,
25(15) LH_RESULT-RESULT ,
40 LH_RESULT-RESULT_TEXT.
IF LH_RESULT-RESULT = 'ER:エラー' .
ADD 1 TO ER_COUNT .
ELSEIF LH_RESULT-RESULT = 'CR:登録' OR LH_RESULT-RESULT = 'CH:変更' OR LH_RESULT-RESULT = 'EX:拡張登録' .
ADD 1 TO NORL_COUNT .
ENDIF.
ENDLOOP.
WRITE: /'正常件数:', NORL_COUNT,'件' , 'エラー件数:', ER_COUNT,'件' .
*&---------------------------------------------------------------------*
*& Form GET_FILENAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->EX_FILE text
*----------------------------------------------------------------------*
FORM GET_FILENAME CHANGING EX_FILE TYPE RLGRAP-FILENAME.
* ローカル定義
DATA :
L_TITLE TYPE STRING, " ダイアログの表題
L_FILTER TYPE STRING, " ファイル拡張フィルタストリング
L_RC TYPE SY-SUBRC, " リターンコード
L_I_FILE TYPE FILETABLE. " 選択されたファイル
* テキスト設定
L_TITLE = 'TAB区切りファイル指定'.
L_FILTER = 'TAB区切りファイル (*.txt)|*.txt'.
* ファイルを開くダイアログを表示
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
WINDOW_TITLE = L_TITLE
FILE_FILTER = L_FILTER
CHANGING
FILE_TABLE = L_I_FILE
RC = L_RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
NOT_SUPPORTED_BY_GUI = 4
OTHERS = 5.
IF SY-SUBRC = 0.
READ TABLE L_I_FILE INDEX 1 INTO EX_FILE.
ENDIF.
ENDFORM. " GET_FILENAME
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->IM_FILE text
* -->IM_TABLE text
*----------------------------------------------------------------------*
FORM UPLOAD_FILE USING IM_FILE TYPE RLGRAP-FILENAME
IM_TABLE TYPE STANDARD TABLE.
* ローカル定義
DATA :
L_FILENAME TYPE STRING. "ファイル名
* ファイルパス設定
L_FILENAME = IM_FILE.
* UPLOADファイル
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ''
TABLES
DATA_TAB = IM_TABLE
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form F_MAIN_PROC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM F_MAIN_PROC CHANGING INPUT LIKE LT_RESULT.
DATA: LT_INTERFACE TYPE RSFBINTFV,
LS_IMPORT_PARA TYPE RSFBPARA,
REF_WA TYPE REF TO DATA,
REF_WB TYPE REF TO DATA,
L_MATERIAL_CD TYPE STRING.
CLEAR LT_RESULT.
*->呼び出す先モジュールのIMPORT パラメータ情報取得
CALL METHOD CL_FB_FUNCTION_UTILITY=>METH_GET_INTERFACE
EXPORTING
IM_NAME = 'Y_MD_UPDATE_MAT_MASTER' "FM name
IMPORTING
EX_INTERFACE = LT_INTERFACE
EXCEPTIONS
ERROR_OCCURED = 1
OBJECT_NOT_EXISTING = 2
OTHERS = 3.
*->2行目の項目IDを取得する
LOOP AT TBL_DAT INTO LINE_DAT FROM 2 TO 2.
SPLIT LINE_DAT-LINE AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE TBL_STRING.
LOOP AT TBL_STRING INTO L_VALUE .
*->IMPORT パラメータ情報に入力ファイル内項目の存在チェック
READ TABLE LT_INTERFACE-IMPORT INTO LS_IMPORT_PARA WITH KEY PARAMETER = L_VALUE.
IF SY-SUBRC <> 0.
WRITE : /'項目ID「',L_VALUE,'」がインポートパラメータにありません。'.
ER_FLG = 'X'.
ENDIF.
*->IMPORTパラーメタテーブルに項目属性を追加する
CLEAR: LS_PTAB,L_HASH.
MOVE L_VALUE TO LS_PTAB-NAME.
MOVE ABAP_FUNC_EXPORTING TO LS_PTAB-KIND.
INSERT LS_PTAB INTO TABLE LT_PTAB.
*->入力ファイル内項目に対応する値のINDEXをハッシュテーブルに格納する
MOVE L_VALUE TO L_HASH-KEY.
MOVE SY-TABIX TO L_HASH-INX.
INSERT L_HASH INTO TABLE LT_HASH.
ENDLOOP.
*->項目エラーが場合、リターンする
IF ER_FLG = 'X'.
RETURN.
ENDIF.
ENDLOOP.
*->呼び出す先モジュールのEXPORTパラメータを追加する
MOVE 'E_RESULT' TO LS_PTAB-NAME.
MOVE ABAP_FUNC_IMPORTING TO LS_PTAB-KIND.
GET REFERENCE OF L_RE INTO LS_PTAB-VALUE.
INSERT LS_PTAB INTO TABLE LT_PTAB.
*
MOVE 'E_ERMSG' TO LS_PTAB-NAME.
MOVE ABAP_FUNC_IMPORTING TO LS_PTAB-KIND.
GET REFERENCE OF L_MSG INTO LS_PTAB-VALUE.
INSERT LS_PTAB INTO TABLE LT_PTAB.
CLEAR: LS_PTAB,TBL_STRING.
*->汎用パラメータテーブルに値を格納する
LOOP AT TBL_DAT INTO LINE_DAT FROM 3.
SPLIT LINE_DAT-LINE AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE TBL_STRING.
LOOP AT LT_PTAB ASSIGNING <FS_STRC> .
CLEAR L_HASH.
READ TABLE LT_HASH INTO L_HASH WITH TABLE KEY KEY = <FS_STRC>-NAME.
IF SY-SUBRC <> 0 .
CONTINUE.
ENDIF.
READ TABLE LT_INTERFACE-IMPORT INTO LS_IMPORT_PARA WITH KEY PARAMETER = <FS_STRC>-NAME.
CREATE DATA REF_WA TYPE (LS_IMPORT_PARA-STRUCTURE).
ASSIGN REF_WA->* TO <FS2>.
READ TABLE TBL_STRING ASSIGNING <FS_VALUE> INDEX L_HASH-INX .
<FS2> = <FS_VALUE>.
UNASSIGN <FS2>.
IF <FS_STRC>-NAME = 'I_MATERIAL'.
L_MATERIAL_CD = <FS_VALUE>.
ENDIF.
*品目コード
IF SY-SUBRC = 0 AND REF_WA IS NOT INITIAL .
<FS_STRC>-VALUE = REF_WA.
ELSE.
GET REFERENCE OF SPACE INTO <FS_STRC>-VALUE.
ENDIF.
ENDLOOP.
TRY.
*FUNCTIONを呼び出し
CALL FUNCTION 'Y_MD_UPDATE_MAT_MASTER'
PARAMETER-TABLE LT_PTAB.
LH_RESULT-CODE = L_MATERIAL_CD.
*リターン結果
READ TABLE LT_PTAB INTO RE WITH KEY NAME = 'E_RESULT'.
ASSIGN RE-VALUE->* TO <FS_RET>.
CASE <FS_RET>.
WHEN 'CR'.
LH_RESULT-RESULT = 'CR:登録'.
WHEN 'CH'.
LH_RESULT-RESULT = 'CH:変更'.
WHEN 'EX'.
LH_RESULT-RESULT = 'EX:拡張登録'.
WHEN 'ER'.
LH_RESULT-RESULT = 'ER:エラー'.
WHEN 'NO'.
LH_RESULT-RESULT = 'NO:変更なし'.
WHEN ''.
LH_RESULT-RESULT = '他(想定なし)'.
ENDCASE.
*ERメッセージ
READ TABLE LT_PTAB INTO RE_MSG WITH KEY NAME = 'E_ERMSG'.
ASSIGN RE_MSG-VALUE->* TO <FS_REMSG>.
LH_RESULT-RESULT_TEXT = <FS_REMSG>.
*INDEX
LH_RESULT-INX = LH_RESULT-INX + 1.
APPEND LH_RESULT TO LT_RESULT.
CATCH CX_ROOT INTO OREF.
CONTINUE.
ENDTRY.
IF P_CKBOX IS INITIAL.
**-> Commit work
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = L_H_TBL_RETURN.
ELSE.
** -> Rollback work
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDLOOP.
ENDFORM.
2019年3月16日星期六
订阅:
博文 (Atom)
Customer Characteristic
Characteristic Descriptions are stored in the table - CABNT - Language - SPRAS - Characteristic description - ATBEZ Characteristic Values ...
-
REPORT ZBPADD2 . DATA : L_PARTN_CAT TYPE BAPIBUS1006_HEAD - PARTN_CAT , LS_CENTRAL TYPE BAPIBUS1006_CENTRAL , ...
-
HEADER: ADD Customer Fields to structure of IMKPF and BAPI_TE_XMKPF. Items: ADD Customer Fields to structure of IMSEG and BAPI_TE_XMSEG....
-
FUNCTION:SD_SALESDOCUMENT_CREATE Append fiels to Structure below. BAPE_VBAP BAPE_VBAPX VBAPKOZ VBAPKOZX No need to append fields to Struc...