SAP ABAP DELIVERY REPORT.
READ MORE BDC DETAILS
REPORT ZSW_DEL_1 NO STANDARD PAGE HEADING LINE-COUNT 37(3).
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 : IT_VBAK TYPE TABLE OF TY_VBAK,
WA_VBAK TYPE TY_VBAK.
DATA : IT_VBAP TYPE TABLE OF TY_VBAP,
WA_VBAP TYPE TY_VBAP.
DATA : IT_LIKP TYPE TABLE OF TY_LIKP,
WA_LIKP TYPE TY_LIKP.
DATA : IT_LIPS TYPE TABLE OF TY_LIPS,
WA_LIPS TYPE TY_LIPS.
DATA : IT_VBFA TYPE TABLE OF TY_VBFA,
WA_VBFA TYPE TY_VBFA.
DATA : IT_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 = 'THIS IS 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 THE 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 'THIS IS 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 'THIS IS 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 'THIS IS 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 'THIS IS INVALID DIVISION' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_DIVISION
***********************************
* READ MORE BDC DETAILS *
***********************************
FORM GET_DATA .
SELECT VBELN
VKORG
VTWEG
SPART
FROM VBAK
INTO TABLE IT_VBAK
WHERE VBELN IN S_VBELN
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART.
IF IT_VBAK IS NOT INITIAL.
SELECT VBELN
POSNR
MATNR
ZMENG
NETPR
FROM VBAP
INTO TABLE IT_VBAP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
SELECT VBELV
POSNV
VBELN
POSNN
VBTYP_N
FROM VBFA
INTO TABLE IT_VBFA
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELV = IT_VBAP-VBELN
AND VBTYP_N = 'J'.
SELECT VBELN
FROM LIKP
INTO TABLE IT_LIKP
FOR ALL ENTRIES IN IT_VBFA
WHERE VBELN = IT_VBFA-VBELN.
SELECT VBELN
POSNR
LFIMG
NETPR
FROM LIPS
INTO TABLE IT_LIPS
FOR ALL ENTRIES IN IT_LIKP
WHERE VBELN = IT_LIKP-VBELN.
SORT IT_VBAP.
SORT IT_LIPS.
LOOP AT IT_VBFA INTO WA_VBFA.
READ TABLE IT_LIPS INTO WA_LIPS WITH KEY VBELN = WA_VBFA-VBELN
POSNR = WA_VBFA-POSNN
BINARY SEARCH.
READ TABLE IT_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 IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
LOOP AT IT_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 = IT_FINAL.
IF SY-SUBRC = 0.
MESSAGE '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 'IBM'.
WRITE: SY-ULINE.
ENDFORM. " DISPLAY_FOOTER
READ MORE BDC DETAILS.........
READ MORE BDC DETAILS
REPORT ZSW_DEL_1 NO STANDARD PAGE HEADING LINE-COUNT 37(3).
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 : IT_VBAK TYPE TABLE OF TY_VBAK,
WA_VBAK TYPE TY_VBAK.
DATA : IT_VBAP TYPE TABLE OF TY_VBAP,
WA_VBAP TYPE TY_VBAP.
DATA : IT_LIKP TYPE TABLE OF TY_LIKP,
WA_LIKP TYPE TY_LIKP.
DATA : IT_LIPS TYPE TABLE OF TY_LIPS,
WA_LIPS TYPE TY_LIPS.
DATA : IT_VBFA TYPE TABLE OF TY_VBFA,
WA_VBFA TYPE TY_VBFA.
DATA : IT_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 = 'THIS IS 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 THE 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 'THIS IS 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 'THIS IS 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 'THIS IS 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 'THIS IS INVALID DIVISION' TYPE 'I'.
ENDIF.
ENDFORM. " VALIDATE_DIVISION
***********************************
* READ MORE BDC DETAILS *
***********************************
FORM GET_DATA .
SELECT VBELN
VKORG
VTWEG
SPART
FROM VBAK
INTO TABLE IT_VBAK
WHERE VBELN IN S_VBELN
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART.
IF IT_VBAK IS NOT INITIAL.
SELECT VBELN
POSNR
MATNR
ZMENG
NETPR
FROM VBAP
INTO TABLE IT_VBAP
FOR ALL ENTRIES IN IT_VBAK
WHERE VBELN = IT_VBAK-VBELN.
SELECT VBELV
POSNV
VBELN
POSNN
VBTYP_N
FROM VBFA
INTO TABLE IT_VBFA
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELV = IT_VBAP-VBELN
AND VBTYP_N = 'J'.
SELECT VBELN
FROM LIKP
INTO TABLE IT_LIKP
FOR ALL ENTRIES IN IT_VBFA
WHERE VBELN = IT_VBFA-VBELN.
SELECT VBELN
POSNR
LFIMG
NETPR
FROM LIPS
INTO TABLE IT_LIPS
FOR ALL ENTRIES IN IT_LIKP
WHERE VBELN = IT_LIKP-VBELN.
SORT IT_VBAP.
SORT IT_LIPS.
LOOP AT IT_VBFA INTO WA_VBFA.
READ TABLE IT_LIPS INTO WA_LIPS WITH KEY VBELN = WA_VBFA-VBELN
POSNR = WA_VBFA-POSNN
BINARY SEARCH.
READ TABLE IT_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 IT_FINAL.
CLEAR WA_FINAL.
ENDLOOP.
ENDIF.
ENDFORM. " GET_DATA
FORM DISPLAY_DATA .
LOOP AT IT_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 = IT_FINAL.
IF SY-SUBRC = 0.
MESSAGE '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 'IBM'.
WRITE: SY-ULINE.
ENDFORM. " DISPLAY_FOOTER
READ MORE BDC DETAILS.........
No comments:
Post a Comment