*&---------------------------------------------------------------------*
*& Report ZSW_DOWNLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSW_DOWNLOAD.
TABLES : VBAK,VBAP,VBFA,LIKP,LIPS.
TYPES: BEGIN OF TY_VBAK,
VBELN TYPE VBAK-VBELN,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
END OF TY_VBAK.
TYPES: BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
END OF TY_VBAP.
TYPES: BEGIN OF TY_LIKP,
VBELN TYPE LIKP-VBELN,
END OF TY_LIKP.
TYPES: BEGIN OF TY_LIPS,
VBELN TYPE LIPS-VBELN,
POSNR TYPE LIPS-POSNR,
LFIMG TYPE LIPS-LFIMG,
NETPR TYPE LIPS-NETPR,
END OF TY_LIPS.
TYPES: BEGIN OF TY_VBFA,
VBELV TYPE VBFA-VBELV,
POSNV TYPE VBFA-POSNV,
VBELN TYPE VBFA-VBELN,
POSNN TYPE VBFA-POSNN,
VBTYP_N TYPE VBFA-VBTYP_N,
END OF TY_VBFA.
TYPES: BEGIN OF TY_FINAL,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
VBELN1 TYPE LIPS-VBELN,
POSNR1 TYPE LIPS-POSNR,
LFIMG TYPE LIPS-LFIMG,
NETPR1 TYPE LIPS-NETPR,
END OF TY_FINAL.
DATA : I_VBAK TYPE TABLE OF TY_VBAK,WA_VBAK TYPE TY_VBAK.
DATA : I_VBAP TYPE TABLE OF TY_VBAP,WA_VBAP TYPE TY_VBAP.
DATA : I_LIKP TYPE TABLE OF TY_LIKP,WA_LIKP TYPE TY_LIKP.
DATA : I_LIPS TYPE TABLE OF TY_LIPS,WA_LIPS TYPE TY_LIPS.
DATA : I_VBFA TYPE TABLE OF TY_VBFA,WA_VBFA TYPE TY_VBFA.
DATA : I_FINAL TYPE TABLE OF TY_FINAL,WA_FINAL TYPE TY_FINAL.
DATA : V_TITLE TYPE STRING.
DATA : V_FNAME TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN NO-EXTENSION.
SELECT-OPTIONS : S_VKORG FOR VBAK-VKORG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS : S_VTWEG FOR VBAK-VTWEG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS : S_SPART FOR VBAK-SPART NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN SKIP.
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
PARAMETERS : DOWNLOAD AS CHECKBOX.
INITIALIZATION.
V_TITLE = 'SALES DOCUMENT:ITEM DATA AND DELIVERY DETAILS'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILE_PATH.
AT SELECTION-SCREEN ON HELP-REQUEST FOR P_FILE.
PERFORM GET_HELP_FOR_FILE_PATH.
AT SELECTION-SCREEN.
PERFORM VALIDATE_SALESDOCUMENT.
PERFORM VALIDATE_SALESORGANIZATION.
PERFORM VALIDATE_DISTRIBUTIONCHANNEL.
PERFORM VALIDATE_DIVISION.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
PERFORM DOWNLOAD_DATA.
END-OF-SELECTION.
TOP-OF-PAGE.
PERFORM DISPLAY_HEADING.
END-OF-PAGE.
PERFORM DISPLAY_FOOTER.
FORM GET_FILE_PATH .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = P_FILE
CHANGING
FILE_NAME = P_FILE.
ENDFORM. " GET_FILE_PATH
FORM GET_HELP_FOR_FILE_PATH .
MESSAGE 'PLEASE SELECT FILE PATH' TYPE 'I'.
ENDFORM. " GET_HELP_FOR_FILE_PATH
FORM VALIDATE_SALESDOCUMENT .
SELECT SINGLE VBELN FROM VBAK INTO WA_VBAK WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID SALES DOCUMENT NO' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_SALESDOCUMENT
FORM VALIDATE_SALESORGANIZATION .
SELECT VKORG FROM VBAK INTO WA_VBAK UP TO 1 ROWS WHERE VKORG IN S_VKORG.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID SALES ORGANIZATION' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_SALESORGANIZATION
FORM VALIDATE_DISTRIBUTIONCHANNEL.
SELECT VTWEG FROM VBAK INTO WA_VBAK UP TO 1 ROWS WHERE VTWEG IN S_VTWEG.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID DISTRIBUTION CHANNEL' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_DISTRIBUTIONCHANNEL
FORM VALIDATE_DIVISION .
SELECT SPART FROM VBAK INTO WA_VBAK UP TO 1 ROWS WHERE SPART IN S_SPART.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID DIVISION' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_DIVISION
FORM GET_DATA .
SELECT VBELN VKORG VTWEG SPART FROM VBAK INTO TABLE I_VBAK WHERE VBELN IN S_VBELN AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG AND SPART IN S_SPART.
IF I_VBAK IS NOT INITIAL.
SELECT VBELN POSNR MATNR ZMENG NETPR FROM VBAP INTO TABLE I_VBAP FOR ALL ENTRIES IN I_VBAK
WHERE VBELN = I_VBAK-VBELN.
SELECT VBELV POSNV VBELN POSNN VBTYP_N FROM VBFA INTO TABLE I_VBFA FOR ALL ENTRIES IN I_VBAP
WHERE VBELV = I_VBAP-VBELN AND VBTYP_N = 'J'.
SELECT VBELN FROM LIKP INTO TABLE I_LIKP FOR ALL ENTRIES IN I_VBFA WHERE VBELN = I_VBFA-VBELN.
SELECT VBELN POSNR LFIMG NETPR FROM LIPS INTO TABLE I_LIPS FOR ALL ENTRIES IN I_LIKP
WHERE VBELN = I_LIKP-VBELN.
SORT I_VBAP.
SORT I_LIPS.
LOOP AT I_VBFA INTO WA_VBFA.
READ TABLE I_LIPS INTO WA_LIPS WITH KEY VBELN = WA_VBFA-VBELN POSNR = WA_VBFA-POSNN BINARY SEARCH.
READ TABLE I_VBAP INTO WA_VBAP WITH KEY VBELN = WA_VBFA-VBELV POSNR = WA_VBFA-POSNV BINARY SEARCH.
WA_FINAL-VBELN = WA_VBAP-VBELN.
WA_FINAL-POSNR = WA_VBAP-POSNR.
WA_FINAL-MATNR = WA_VBAP-MATNR.
WA_FINAL-ZMENG = WA_VBAP-ZMENG.
WA_FINAL-NETPR = WA_VBAP-NETPR.
WA_FINAL-VBELN1 = WA_LIPS-VBELN.
WA_FINAL-POSNR1 = WA_LIPS-POSNR.
WA_FINAL-LFIMG = WA_LIPS-LFIMG.
WA_FINAL-NETPR1 = WA_LIPS-NETPR.
APPEND WA_FINAL TO I_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
LOOP AT I_FINAL INTO WA_FINAL.
WRITE : / WA_FINAL-VBELN,WA_FINAL-POSNR,WA_FINAL-MATNR,WA_FINAL-ZMENG,WA_FINAL-NETPR,
WA_FINAL-VBELN1,WA_FINAL-POSNR1,WA_FINAL-LFIMG,WA_FINAL-NETPR.
ENDLOOP.
ENDFORM. " DISPLAY_DATA
FORM DOWNLOAD_DATA .
IF DOWNLOAD = 'X'.
V_FNAME = P_FILE.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = V_FNAME
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FINAL.
IF SY-SUBRC = 0.
MESSAGE 'DATA SUCCESSFULLY DOWNLOADED' TYPE 'I'.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_DATA
FORM DISPLAY_HEADING .
WRITE: SY-ULINE.
WRITE :/45 V_TITLE.
WRITE: SY-ULINE.
ENDFORM. " DISPLAY_HEADING
FORM DISPLAY_FOOTER .
WRITE: SY-ULINE.
WRITE :/45 'INTEL GROUP OF COMPANIES'.
WRITE: SY-ULINE.
ENDFORM. " DISPLAY_FOOTER
*& Report ZSW_DOWNLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSW_DOWNLOAD.
TABLES : VBAK,VBAP,VBFA,LIKP,LIPS.
TYPES: BEGIN OF TY_VBAK,
VBELN TYPE VBAK-VBELN,
VKORG TYPE VBAK-VKORG,
VTWEG TYPE VBAK-VTWEG,
SPART TYPE VBAK-SPART,
END OF TY_VBAK.
TYPES: BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
END OF TY_VBAP.
TYPES: BEGIN OF TY_LIKP,
VBELN TYPE LIKP-VBELN,
END OF TY_LIKP.
TYPES: BEGIN OF TY_LIPS,
VBELN TYPE LIPS-VBELN,
POSNR TYPE LIPS-POSNR,
LFIMG TYPE LIPS-LFIMG,
NETPR TYPE LIPS-NETPR,
END OF TY_LIPS.
TYPES: BEGIN OF TY_VBFA,
VBELV TYPE VBFA-VBELV,
POSNV TYPE VBFA-POSNV,
VBELN TYPE VBFA-VBELN,
POSNN TYPE VBFA-POSNN,
VBTYP_N TYPE VBFA-VBTYP_N,
END OF TY_VBFA.
TYPES: BEGIN OF TY_FINAL,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,
ZMENG TYPE VBAP-ZMENG,
NETPR TYPE VBAP-NETPR,
VBELN1 TYPE LIPS-VBELN,
POSNR1 TYPE LIPS-POSNR,
LFIMG TYPE LIPS-LFIMG,
NETPR1 TYPE LIPS-NETPR,
END OF TY_FINAL.
DATA : I_VBAK TYPE TABLE OF TY_VBAK,WA_VBAK TYPE TY_VBAK.
DATA : I_VBAP TYPE TABLE OF TY_VBAP,WA_VBAP TYPE TY_VBAP.
DATA : I_LIKP TYPE TABLE OF TY_LIKP,WA_LIKP TYPE TY_LIKP.
DATA : I_LIPS TYPE TABLE OF TY_LIPS,WA_LIPS TYPE TY_LIPS.
DATA : I_VBFA TYPE TABLE OF TY_VBFA,WA_VBFA TYPE TY_VBFA.
DATA : I_FINAL TYPE TABLE OF TY_FINAL,WA_FINAL TYPE TY_FINAL.
DATA : V_TITLE TYPE STRING.
DATA : V_FNAME TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_VBELN FOR VBAK-VBELN NO-EXTENSION.
SELECT-OPTIONS : S_VKORG FOR VBAK-VKORG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS : S_VTWEG FOR VBAK-VTWEG NO INTERVALS NO-EXTENSION.
SELECT-OPTIONS : S_SPART FOR VBAK-SPART NO INTERVALS NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN SKIP.
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
PARAMETERS : DOWNLOAD AS CHECKBOX.
INITIALIZATION.
V_TITLE = 'SALES DOCUMENT:ITEM DATA AND DELIVERY DETAILS'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILE_PATH.
AT SELECTION-SCREEN ON HELP-REQUEST FOR P_FILE.
PERFORM GET_HELP_FOR_FILE_PATH.
AT SELECTION-SCREEN.
PERFORM VALIDATE_SALESDOCUMENT.
PERFORM VALIDATE_SALESORGANIZATION.
PERFORM VALIDATE_DISTRIBUTIONCHANNEL.
PERFORM VALIDATE_DIVISION.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
PERFORM DOWNLOAD_DATA.
END-OF-SELECTION.
TOP-OF-PAGE.
PERFORM DISPLAY_HEADING.
END-OF-PAGE.
PERFORM DISPLAY_FOOTER.
FORM GET_FILE_PATH .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = P_FILE
CHANGING
FILE_NAME = P_FILE.
ENDFORM. " GET_FILE_PATH
FORM GET_HELP_FOR_FILE_PATH .
MESSAGE 'PLEASE SELECT FILE PATH' TYPE 'I'.
ENDFORM. " GET_HELP_FOR_FILE_PATH
FORM VALIDATE_SALESDOCUMENT .
SELECT SINGLE VBELN FROM VBAK INTO WA_VBAK WHERE VBELN IN S_VBELN.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID SALES DOCUMENT NO' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_SALESDOCUMENT
FORM VALIDATE_SALESORGANIZATION .
SELECT VKORG FROM VBAK INTO WA_VBAK UP TO 1 ROWS WHERE VKORG IN S_VKORG.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID SALES ORGANIZATION' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_SALESORGANIZATION
FORM VALIDATE_DISTRIBUTIONCHANNEL.
SELECT VTWEG FROM VBAK INTO WA_VBAK UP TO 1 ROWS WHERE VTWEG IN S_VTWEG.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID DISTRIBUTION CHANNEL' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_DISTRIBUTIONCHANNEL
FORM VALIDATE_DIVISION .
SELECT SPART FROM VBAK INTO WA_VBAK UP TO 1 ROWS WHERE SPART IN S_SPART.
ENDSELECT.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID DIVISION' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_DIVISION
FORM GET_DATA .
SELECT VBELN VKORG VTWEG SPART FROM VBAK INTO TABLE I_VBAK WHERE VBELN IN S_VBELN AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG AND SPART IN S_SPART.
IF I_VBAK IS NOT INITIAL.
SELECT VBELN POSNR MATNR ZMENG NETPR FROM VBAP INTO TABLE I_VBAP FOR ALL ENTRIES IN I_VBAK
WHERE VBELN = I_VBAK-VBELN.
SELECT VBELV POSNV VBELN POSNN VBTYP_N FROM VBFA INTO TABLE I_VBFA FOR ALL ENTRIES IN I_VBAP
WHERE VBELV = I_VBAP-VBELN AND VBTYP_N = 'J'.
SELECT VBELN FROM LIKP INTO TABLE I_LIKP FOR ALL ENTRIES IN I_VBFA WHERE VBELN = I_VBFA-VBELN.
SELECT VBELN POSNR LFIMG NETPR FROM LIPS INTO TABLE I_LIPS FOR ALL ENTRIES IN I_LIKP
WHERE VBELN = I_LIKP-VBELN.
SORT I_VBAP.
SORT I_LIPS.
LOOP AT I_VBFA INTO WA_VBFA.
READ TABLE I_LIPS INTO WA_LIPS WITH KEY VBELN = WA_VBFA-VBELN POSNR = WA_VBFA-POSNN BINARY SEARCH.
READ TABLE I_VBAP INTO WA_VBAP WITH KEY VBELN = WA_VBFA-VBELV POSNR = WA_VBFA-POSNV BINARY SEARCH.
WA_FINAL-VBELN = WA_VBAP-VBELN.
WA_FINAL-POSNR = WA_VBAP-POSNR.
WA_FINAL-MATNR = WA_VBAP-MATNR.
WA_FINAL-ZMENG = WA_VBAP-ZMENG.
WA_FINAL-NETPR = WA_VBAP-NETPR.
WA_FINAL-VBELN1 = WA_LIPS-VBELN.
WA_FINAL-POSNR1 = WA_LIPS-POSNR.
WA_FINAL-LFIMG = WA_LIPS-LFIMG.
WA_FINAL-NETPR1 = WA_LIPS-NETPR.
APPEND WA_FINAL TO I_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
LOOP AT I_FINAL INTO WA_FINAL.
WRITE : / WA_FINAL-VBELN,WA_FINAL-POSNR,WA_FINAL-MATNR,WA_FINAL-ZMENG,WA_FINAL-NETPR,
WA_FINAL-VBELN1,WA_FINAL-POSNR1,WA_FINAL-LFIMG,WA_FINAL-NETPR.
ENDLOOP.
ENDFORM. " DISPLAY_DATA
FORM DOWNLOAD_DATA .
IF DOWNLOAD = 'X'.
V_FNAME = P_FILE.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = V_FNAME
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FINAL.
IF SY-SUBRC = 0.
MESSAGE 'DATA SUCCESSFULLY DOWNLOADED' TYPE 'I'.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_DATA
FORM DISPLAY_HEADING .
WRITE: SY-ULINE.
WRITE :/45 V_TITLE.
WRITE: SY-ULINE.
ENDFORM. " DISPLAY_HEADING
FORM DISPLAY_FOOTER .
WRITE: SY-ULINE.
WRITE :/45 'INTEL GROUP OF COMPANIES'.
WRITE: SY-ULINE.
ENDFORM. " DISPLAY_FOOTER
No comments:
Post a Comment