*&---------------------------------------------------------------------*
*& Report ZMM_FIFO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMM_FIFO NO STANDARD PAGE HEADING.
TYPES: BEGIN OF TY_FINAL,
MATNR TYPE MATNR, " Material Number
WERKS TYPE WERKS_D, " Plant
LGORT TYPE LGORT_D, " Storage Location
CHARG TYPE CHARG_D, " Batch Number
CLABS TYPE STRING, " Valuated Unrestricted-Use Stock
MEINS TYPE MEINS, " Base Unit of Measure
MAKTX TYPE MAKTX, " Material Description (Short Text)
END OF TY_FINAL,
BEGIN OF TY_MARA,
MATNR TYPE MATNR, " Material Number
MEINS TYPE MEINS, " Base Unit of Measure
END OF TY_MARA,
BEGIN OF TY_MAKT,
MATNR TYPE MATNR, " Material Number
SPRAS TYPE SPRAS, " Language Key
MAKTX TYPE MAKTX, " Material Description (Short Text)
END OF TY_MAKT,
BEGIN OF TY_MCHB,
MATNR TYPE MATNR, " Material Number
WERKS TYPE WERKS_D, " Plant
LGORT TYPE LGORT_D, " Storage Location
CHARG TYPE CHARG_D, " Batch Number
CLABS TYPE LABST, " Valuated Unrestricted-Use Stock
END OF TY_MCHB,
BEGIN OF LT_ERROR,
TIME(8),
DATE(8),
MSG1(50),
MSG2(50),
MSG3(50),
MSG4(50),
TEXT(220),
END OF LT_ERROR.
DATA: IT_FINAL TYPE TABLE OF TY_FINAL,
IT_FINAL1 TYPE TABLE OF TY_FINAL,
IT_MARA TYPE TABLE OF TY_MARA,
IT_MAKT TYPE TABLE OF TY_MAKT,
IT_MCHB TYPE TABLE OF TY_MCHB,
WA_FINAL1 TYPE TY_FINAL,
WA_FINAL TYPE TY_FINAL,
WA_MARA TYPE TY_MARA,
WA_MAKT TYPE TY_MAKT,
WA_MCHB TYPE TY_MCHB.
*
*DATA: IT_TAB TYPE STANDARD TABLE OF TY_FINAL,
* WA_TAB TYPE ALSMEX_TABLINE.
DATA: P_FILE TYPE STRING,
E_FILE TYPE STRING,
FV_TEXT TYPE STRING,
SV_TEXT TYPE STRING,
TEXT TYPE STRING.
DATA: V_DIR_PATH LIKE EPSF-EPSDIRNAM VALUE '\\192.168.0.22\TUBECUTTING\GRIN\UPLOAD',
E_DIR_PATH LIKE EPSF-EPSDIRNAM VALUE '\\192.168.0.22\TUBECUTTING\GRIN\UPLOAD',
V_DIR_NAME LIKE EPSF-EPSDIRNAM,
V_FILE_COUNTER LIKE EPSF-EPSFILSIZ,
V_ERROR_COUNTER LIKE EPSF-EPSFILSIZ,
T_DIR_LIST LIKE TABLE OF EPSFILI,
W_DIR_LIST TYPE EPSFILI,
LV0TEXT TYPE STRING.
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS : P_WERKS TYPE MCHB-WERKS,
P_LGORT TYPE MCHB-LGORT.
SELECTION-SCREEN: END OF BLOCK B1.
START-OF-SELECTION.
PERFORM GET_DATA.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT MATNR
WERKS
LGORT
CHARG
CLABS
FROM MCHB
INTO TABLE IT_MCHB
WHERE WERKS EQ P_WERKS
AND LGORT EQ P_LGORT
AND CLABS IS NOT NULL.
IF SY-SUBRC EQ 0.
SELECT MATNR
MEINS
FROM MARA
INTO TABLE IT_MARA
FOR ALL ENTRIES IN IT_MCHB
WHERE MATNR EQ IT_MCHB-MATNR.
IF SY-SUBRC EQ 0.
ENDIF.
SELECT MATNR
SPRAS
MAKTX
FROM MAKT
INTO TABLE IT_MAKT
FOR ALL ENTRIES IN IT_MCHB
WHERE MATNR EQ IT_MCHB-MATNR
AND SPRAS EQ 'EN'.
IF SY-SUBRC EQ 0.
ENDIF.
ENDIF.
IF IT_MCHB IS NOT INITIAL.
LOOP AT IT_MCHB INTO WA_MCHB.
WA_FINAL-MATNR = WA_MCHB-MATNR. "Material Number
WA_FINAL-WERKS = WA_MCHB-WERKS. "Plant
WA_FINAL-LGORT = WA_MCHB-LGORT. "Storage Location
WA_FINAL-CHARG = WA_MCHB-CHARG. "Batch Number
WA_FINAL-CLABS = WA_MCHB-CLABS. "Valuated Unrestricted-Use Stock
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = WA_MCHB-MATNR.
IF SY-SUBRC EQ 0.
WA_FINAL-MEINS = WA_MARA-MEINS. "Base Unit of Measure
ENDIF.
READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MCHB-MATNR.
IF SY-SUBRC EQ 0.
WA_FINAL-MAKTX = WA_MAKT-MAKTX. "Material Description (Short Text)
ENDIF.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL, WA_MAKT, WA_MARA, WA_MCHB.
ENDLOOP.
ENDIF.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
DIR_NAME = V_DIR_PATH
IMPORTING
DIR_NAME = V_DIR_NAME
FILE_COUNTER = V_FILE_COUNTER
ERROR_COUNTER = V_ERROR_COUNTER
TABLES
DIR_LIST = T_DIR_LIST
EXCEPTIONS
INVALID_EPS_SUBDIR = 1
SAPGPARAM_FAILED = 2
BUILD_DIRECTORY_FAILED = 3
NO_AUTHORIZATION = 4
READ_DIRECTORY_FAILED = 5
TOO_MANY_READ_ERRORS = 6
EMPTY_DIRECTORY_LIST = 7
OTHERS = 8.
FV_TEXT = SY-DATUM.
CONCATENATE FV_TEXT 'TEST' '.csv' INTO FV_TEXT.
READ TABLE T_DIR_LIST INTO W_DIR_LIST WITH KEY NAME = FV_TEXT.
IF SY-SUBRC EQ 0.
CONCATENATE V_DIR_PATH '\' W_DIR_LIST-NAME INTO P_FILE.
OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'error' TYPE 'E'.
EXIT.
ELSE.
DO.
READ DATASET P_FILE INTO LV0TEXT.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
IF SY-TABIX NE 1.
SPLIT LV0TEXT AT ',' INTO WA_FINAL-MATNR
WA_FINAL-WERKS
WA_FINAL-LGORT
WA_FINAL-CHARG
WA_FINAL-CLABS
WA_FINAL-MEINS
WA_FINAL-MAKTX.
APPEND WA_FINAL TO IT_FINAL.
ENDIF.
ENDIF.
ENDDO.
CLEAR WA_FINAL.
ENDIF.
CLOSE DATASET P_FILE.
CONCATENATE V_DIR_PATH '\' FV_TEXT INTO P_FILE.
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
LOOP AT IT_FINAL INTO WA_FINAL.
CONCATENATE WA_FINAL-MATNR
WA_FINAL-WERKS
WA_FINAL-LGORT
WA_FINAL-CHARG
WA_FINAL-CLABS
WA_FINAL-MEINS
WA_FINAL-MAKTX
INTO LV0TEXT SEPARATED BY ','.
TRANSFER LV0TEXT TO P_FILE.
CLEAR: WA_FINAL,
LV0TEXT.
ENDLOOP.
ENDIF.
CLOSE DATASET P_FILE.
ELSE.
CONCATENATE V_DIR_PATH '\' FV_TEXT INTO P_FILE.
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
CONCATENATE 'Material Number'
'Plant'
'Storage Location'
'Batch Number'
'Valuated Unrestricted-Use Stock'
'Base Unit of Measure'
'Material Description'
INTO LV0TEXT SEPARATED BY ','.
TRANSFER LV0TEXT TO P_FILE.
CLEAR LV0TEXT.
LOOP AT IT_FINAL INTO WA_FINAL.
CONCATENATE WA_FINAL-MATNR
WA_FINAL-WERKS
WA_FINAL-LGORT
WA_FINAL-CHARG
WA_FINAL-CLABS
WA_FINAL-MEINS
WA_FINAL-MAKTX
INTO LV0TEXT SEPARATED BY ','.
TRANSFER LV0TEXT TO P_FILE.
CLEAR: WA_FINAL,
LV0TEXT.
ENDLOOP.
ENDIF.
CLOSE DATASET P_FILE.
ENDIF.
ENDFORM. " GET_DATA
*& Report ZMM_FIFO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZMM_FIFO NO STANDARD PAGE HEADING.
TYPES: BEGIN OF TY_FINAL,
MATNR TYPE MATNR, " Material Number
WERKS TYPE WERKS_D, " Plant
LGORT TYPE LGORT_D, " Storage Location
CHARG TYPE CHARG_D, " Batch Number
CLABS TYPE STRING, " Valuated Unrestricted-Use Stock
MEINS TYPE MEINS, " Base Unit of Measure
MAKTX TYPE MAKTX, " Material Description (Short Text)
END OF TY_FINAL,
BEGIN OF TY_MARA,
MATNR TYPE MATNR, " Material Number
MEINS TYPE MEINS, " Base Unit of Measure
END OF TY_MARA,
BEGIN OF TY_MAKT,
MATNR TYPE MATNR, " Material Number
SPRAS TYPE SPRAS, " Language Key
MAKTX TYPE MAKTX, " Material Description (Short Text)
END OF TY_MAKT,
BEGIN OF TY_MCHB,
MATNR TYPE MATNR, " Material Number
WERKS TYPE WERKS_D, " Plant
LGORT TYPE LGORT_D, " Storage Location
CHARG TYPE CHARG_D, " Batch Number
CLABS TYPE LABST, " Valuated Unrestricted-Use Stock
END OF TY_MCHB,
BEGIN OF LT_ERROR,
TIME(8),
DATE(8),
MSG1(50),
MSG2(50),
MSG3(50),
MSG4(50),
TEXT(220),
END OF LT_ERROR.
DATA: IT_FINAL TYPE TABLE OF TY_FINAL,
IT_FINAL1 TYPE TABLE OF TY_FINAL,
IT_MARA TYPE TABLE OF TY_MARA,
IT_MAKT TYPE TABLE OF TY_MAKT,
IT_MCHB TYPE TABLE OF TY_MCHB,
WA_FINAL1 TYPE TY_FINAL,
WA_FINAL TYPE TY_FINAL,
WA_MARA TYPE TY_MARA,
WA_MAKT TYPE TY_MAKT,
WA_MCHB TYPE TY_MCHB.
*
*DATA: IT_TAB TYPE STANDARD TABLE OF TY_FINAL,
* WA_TAB TYPE ALSMEX_TABLINE.
DATA: P_FILE TYPE STRING,
E_FILE TYPE STRING,
FV_TEXT TYPE STRING,
SV_TEXT TYPE STRING,
TEXT TYPE STRING.
DATA: V_DIR_PATH LIKE EPSF-EPSDIRNAM VALUE '\\192.168.0.22\TUBECUTTING\GRIN\UPLOAD',
E_DIR_PATH LIKE EPSF-EPSDIRNAM VALUE '\\192.168.0.22\TUBECUTTING\GRIN\UPLOAD',
V_DIR_NAME LIKE EPSF-EPSDIRNAM,
V_FILE_COUNTER LIKE EPSF-EPSFILSIZ,
V_ERROR_COUNTER LIKE EPSF-EPSFILSIZ,
T_DIR_LIST LIKE TABLE OF EPSFILI,
W_DIR_LIST TYPE EPSFILI,
LV0TEXT TYPE STRING.
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS : P_WERKS TYPE MCHB-WERKS,
P_LGORT TYPE MCHB-LGORT.
SELECTION-SCREEN: END OF BLOCK B1.
START-OF-SELECTION.
PERFORM GET_DATA.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
SELECT MATNR
WERKS
LGORT
CHARG
CLABS
FROM MCHB
INTO TABLE IT_MCHB
WHERE WERKS EQ P_WERKS
AND LGORT EQ P_LGORT
AND CLABS IS NOT NULL.
IF SY-SUBRC EQ 0.
SELECT MATNR
MEINS
FROM MARA
INTO TABLE IT_MARA
FOR ALL ENTRIES IN IT_MCHB
WHERE MATNR EQ IT_MCHB-MATNR.
IF SY-SUBRC EQ 0.
ENDIF.
SELECT MATNR
SPRAS
MAKTX
FROM MAKT
INTO TABLE IT_MAKT
FOR ALL ENTRIES IN IT_MCHB
WHERE MATNR EQ IT_MCHB-MATNR
AND SPRAS EQ 'EN'.
IF SY-SUBRC EQ 0.
ENDIF.
ENDIF.
IF IT_MCHB IS NOT INITIAL.
LOOP AT IT_MCHB INTO WA_MCHB.
WA_FINAL-MATNR = WA_MCHB-MATNR. "Material Number
WA_FINAL-WERKS = WA_MCHB-WERKS. "Plant
WA_FINAL-LGORT = WA_MCHB-LGORT. "Storage Location
WA_FINAL-CHARG = WA_MCHB-CHARG. "Batch Number
WA_FINAL-CLABS = WA_MCHB-CLABS. "Valuated Unrestricted-Use Stock
READ TABLE IT_MARA INTO WA_MARA WITH KEY MATNR = WA_MCHB-MATNR.
IF SY-SUBRC EQ 0.
WA_FINAL-MEINS = WA_MARA-MEINS. "Base Unit of Measure
ENDIF.
READ TABLE IT_MAKT INTO WA_MAKT WITH KEY MATNR = WA_MCHB-MATNR.
IF SY-SUBRC EQ 0.
WA_FINAL-MAKTX = WA_MAKT-MAKTX. "Material Description (Short Text)
ENDIF.
APPEND WA_FINAL TO IT_FINAL.
CLEAR: WA_FINAL, WA_MAKT, WA_MARA, WA_MCHB.
ENDLOOP.
ENDIF.
CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
EXPORTING
DIR_NAME = V_DIR_PATH
IMPORTING
DIR_NAME = V_DIR_NAME
FILE_COUNTER = V_FILE_COUNTER
ERROR_COUNTER = V_ERROR_COUNTER
TABLES
DIR_LIST = T_DIR_LIST
EXCEPTIONS
INVALID_EPS_SUBDIR = 1
SAPGPARAM_FAILED = 2
BUILD_DIRECTORY_FAILED = 3
NO_AUTHORIZATION = 4
READ_DIRECTORY_FAILED = 5
TOO_MANY_READ_ERRORS = 6
EMPTY_DIRECTORY_LIST = 7
OTHERS = 8.
FV_TEXT = SY-DATUM.
CONCATENATE FV_TEXT 'TEST' '.csv' INTO FV_TEXT.
READ TABLE T_DIR_LIST INTO W_DIR_LIST WITH KEY NAME = FV_TEXT.
IF SY-SUBRC EQ 0.
CONCATENATE V_DIR_PATH '\' W_DIR_LIST-NAME INTO P_FILE.
OPEN DATASET P_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'error' TYPE 'E'.
EXIT.
ELSE.
DO.
READ DATASET P_FILE INTO LV0TEXT.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
IF SY-TABIX NE 1.
SPLIT LV0TEXT AT ',' INTO WA_FINAL-MATNR
WA_FINAL-WERKS
WA_FINAL-LGORT
WA_FINAL-CHARG
WA_FINAL-CLABS
WA_FINAL-MEINS
WA_FINAL-MAKTX.
APPEND WA_FINAL TO IT_FINAL.
ENDIF.
ENDIF.
ENDDO.
CLEAR WA_FINAL.
ENDIF.
CLOSE DATASET P_FILE.
CONCATENATE V_DIR_PATH '\' FV_TEXT INTO P_FILE.
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
LOOP AT IT_FINAL INTO WA_FINAL.
CONCATENATE WA_FINAL-MATNR
WA_FINAL-WERKS
WA_FINAL-LGORT
WA_FINAL-CHARG
WA_FINAL-CLABS
WA_FINAL-MEINS
WA_FINAL-MAKTX
INTO LV0TEXT SEPARATED BY ','.
TRANSFER LV0TEXT TO P_FILE.
CLEAR: WA_FINAL,
LV0TEXT.
ENDLOOP.
ENDIF.
CLOSE DATASET P_FILE.
ELSE.
CONCATENATE V_DIR_PATH '\' FV_TEXT INTO P_FILE.
OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
CONCATENATE 'Material Number'
'Plant'
'Storage Location'
'Batch Number'
'Valuated Unrestricted-Use Stock'
'Base Unit of Measure'
'Material Description'
INTO LV0TEXT SEPARATED BY ','.
TRANSFER LV0TEXT TO P_FILE.
CLEAR LV0TEXT.
LOOP AT IT_FINAL INTO WA_FINAL.
CONCATENATE WA_FINAL-MATNR
WA_FINAL-WERKS
WA_FINAL-LGORT
WA_FINAL-CHARG
WA_FINAL-CLABS
WA_FINAL-MEINS
WA_FINAL-MAKTX
INTO LV0TEXT SEPARATED BY ','.
TRANSFER LV0TEXT TO P_FILE.
CLEAR: WA_FINAL,
LV0TEXT.
ENDLOOP.
ENDIF.
CLOSE DATASET P_FILE.
ENDIF.
ENDFORM. " GET_DATA