SALES REPORT DISPLAYING CUSTOMAR WIZE
*&---------------------------------------------------------------------*
*& Report ZSD_R_RDDL002_S_CUST_REP_RK28
*&
*&---------------------------------------------------------------------*
*& AUTHOR: KRANTHI.
*& REPORT NAME: SALES REPORT DISPLAYING CUSTOMAR WIZE.
*& PURPOSE: TO DISPLAY ALL CUSTOMARS AND PLANTS BASED ON SALES ORDER
*& REQUEST NO:SMPK 900987.
*& VERSION:V1.
*& SPEC : 01.
*&
*&---------------------------------------------------------------------*
*& MODIFICATION LOG:
*& MOD1:I ADDED TWO NEW FIELDS KUNNR AND POSNR.
*&---------------------------------------------------------------------*
REPORT ZSD_R_RDDL002_S_CUST_REP_RK28 NO STANDARD PAGE HEADING LINE-SIZE 100.
*&---------------------------------------------------------------------*
*& Structores declaration
*&---------------------------------------------------------------------*
*structor declaration for sales order header.
TYPES:BEGIN OF TY_VBAK ,
VBELN TYPE VBELN_VA, "sales document
ERDAT TYPE ERDAT , "date on which record was created
AUDAT TYPE AUDAT , "document date
VKORG TYPE VKORG , "sales organization
VTWEG TYPE VTWEG , "distribution chennel
VKGRP TYPE VKGRP , "distribution group
KUNNR TYPE KUNAG , "sold-to party
END OF TY_VBAK ,
*structor declaration for sales order item.
BEGIN OF TY_VBAP ,
VBELN TYPE VBELN_VA, "sales document
POSNR TYPE POSNR_VA, "sales document item
MATNR TYPE MATNR , "meterial no
MATKL TYPE MATKL , "meterial group
ARKTX TYPE ARKTX , "shart text for sales order item
PSTYV TYPE PSTYV , "sales document item category
NETWR TYPE NETWR , "net value of order item
WERKS TYPE WERKS_EXT, "plant(own or external)
END OF TY_VBAP ,
*structor declaration for customar.
BEGIN OF TY_KNA1 ,
KUNNR TYPE KUNNR , "customar no1
NAME1 TYPE NAME1_GP, "name1
ORT01 TYPE ORT01_GP, "city
PSTLZ TYPE PSTLZ , "postal code
REGIO TYPE REGIO , "region(state)
END OF TY_KNA1 ,
*structor declaration for plants/branches.
BEGIN OF TY_T001W ,
WERKS TYPE WERKS_D , "plant
NAME1 TYPE NAME1 , "name
ORT01 TYPE ORT01 , "city
END OF TY_T001W ,
*structor declaration for final output for sales order wize.
BEGIN OF TY_OUTPUT_S,
KUNNR_C TYPE KUNNR , "customar no1
NAME1 TYPE NAME1_GP, "name1
ORT01 TYPE ORT01_GP, "city
PSTLZ TYPE PSTLZ , "postal code
REGIO TYPE REGIO , "region(state)
VBELN TYPE VBELN_VA, "sales document
ERDAT TYPE ERDAT , "date on which record was created
AUDAT TYPE AUDAT , "document date
VKORG TYPE VKORG , "sales organization
VTWEG TYPE VTWEG , "distribution chennel
VKGRP TYPE VKGRP , "distribution group
KUNNR TYPE KUNAG , "sold-to party
* VBELN TYPE VBELN_VA, "sales document
POSNR TYPE POSNR_VA, "sales document item
MATNR TYPE MATNR , "meterial no
MATKL TYPE MATKL , "meterial group
ARKTX TYPE ARKTX , "shart text for sales order item
PSTYV TYPE PSTYV , "sales document item category
NETWR TYPE NETWR , "net value of order item
* WERKS_o TYPE WERKS_EXT, "plant(own or external)
WERKS TYPE WERKS_D , "plant
* NAME1 TYPE NAME1 , "name
* ORT01 TYPE ORT01 , "city
END OF TY_OUTPUT_S .
*&---------------------------------------------------------------------*
*& internal tables declaration
*&---------------------------------------------------------------------*
*itab declaration for sales order header.
DATA:T_VBAK TYPE STANDARD TABLE OF TY_VBAK,
*itab declaration for sales order item.
T_VBAP TYPE STANDARD TABLE OF TY_VBAP,
*itab declaration for customar.
T_KNA1 TYPE STANDARD TABLE OF TY_KNA1,
*itab declaration for plants/branches.
T_T001W TYPE STANDARD TABLE OF TY_T001W,
*itab declaration for final output.
T_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT_S,
*&---------------------------------------------------------------------*
*& workareas declaration
*&---------------------------------------------------------------------*
*workarea declaration for sales order header.
W_VBAK TYPE TY_VBAK,
*workarea declaration for sales order item.
W_VBAP TYPE TY_VBAP,
*workarea declaration for customar.
W_KNA1 TYPE TY_KNA1,
*workarea declaration for plants/branches.
W_T001W TYPE TY_T001W,
*workarea declaration for final output.
W_OUTPUT TYPE TY_OUTPUT_S,
W_OUTPUT1 TYPE TY_OUTPUT_S,
*&---------------------------------------------------------------------
*& global variable declaration.
*&---------------------------------------------------------------------*
G_kunnr TYPE VBAK-kunnr.
*&---------------------------------------------------------------------*
*& selection screen declaration.
*&---------------------------------------------------------------------*
SELECTION-SCREEN:BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:S_kunnr FOR G_kunnr.
SELECTION-SCREEN:END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& initilization event declaration
*&---------------------------------------------------------------------*
INITIALIZATION.
*clearing workareas
CLEAR:W_VBAK,
W_VBAP,
W_KNA1,
W_T001W,
W_OUTPUT.
*refreshing internal table
REFRESH:T_VBAK,
T_VBAP,
T_KNA1,
T_T001W,
T_OUTPUT.
*&---------------------------------------------------------------------*
*& at selection screen event declaration
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*validating sales order number
DATA:L_kunnr TYPE kunnr.
SELECT SINGLE
kunnr
INTO
L_kunnr
FROM
kna1
WHERE kunnr IN S_kunnr.
IF SY-SUBRC <> 0 .
MESSAGE:E002(YNRK_MESS) WITH 'no data found from' S_KUNNR-LOW 'to' S_KUNNR-HIGH
.
ENDIF.
*&---------------------------------------------------------------------*
*& start of selection event declaration
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*get vbak data.
PERFORM SUB_GET_VBAK.
*get vbap data.
PERFORM SUB_GET_VBAP.
*get kna1 data.
PERFORM SUB_GET_KNA1.
*get t001w data.
PERFORM SUB_GET_T001W.
*&---------------------------------------------------------------------*
*& top of page event declaration
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
*displaying the report heading.
WRITE:/40 'SALESORDER REPORT'.
ULINE.
*displaying the header column headings
WRITE:/2 'customar no', 20 'name1' , 30 'document date' , 40 'sales organization',
50 'distribution chennel' ,
60 'distribution group' , 70'sold-to party' , 80 'postal code' , 90
'region',100 'city'.
ULINE.
*displaying the item column headings.
WRITE:/2 'sales item' , 20 'meterial no' , 30 'meterial group', 40 'shart text' ,
50 'item catagory' ,
60 'city' , 70 'net value'.
*&---------------------------------------------------------------------*
*& end of selection event declaration
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*populating data into final output internal table.
PERFORM SUB_POPULATE_DATA_FINAL_OUTPUT.
*displaying the final output.
PERFORM SUB_DISPLAY_OUTPUT.
*&---------------------------------------------------------------------*
*& Form sub_get_vbak
*&---------------------------------------------------------------------*
* this routine is used to get the sales order header data from database.
*----------------------------------------------------------------------*
FORM SUB_GET_VBAK .
SELECT VBELN "sales document
ERDAT "date on which record was created
AUDAT "document date
VKORG "sales organization
VTWEG "distribution chennel
VKGRP "distribution group
KUNNR "sold-to party
FROM
VBAK
INTO TABLE T_VBAK
WHERE kunnr IN S_kunnr.
IF SY-SUBRC <> 0.
MESSAGE:I003(YNRK_MESS) WITH 'no data found in the given range'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_get_vbak
*&---------------------------------------------------------------------*
*& Form sub_get_vbap
*&---------------------------------------------------------------------*
* this routine is used to get sales order item data.
*----------------------------------------------------------------------*
FORM SUB_GET_VBAP .
CHECK T_VBAK IS NOT INITIAL.
SELECT VBELN "sales document
POSNR "sales document item
MATNR "meterial no
MATKL "meterial group
ARKTX "shart text for sales order item
PSTYV "sales document item category
NETWR "net value of order item
WERKS "plant(own or external)
FROM
VBAP
INTO TABLE T_VBAP
FOR ALL ENTRIES IN T_VBAK
WHERE VBELN = T_VBAK-VBELN.
ENDFORM. " sub_get_vbap
*&---------------------------------------------------------------------*
*& Form sub_get_kna1
*&---------------------------------------------------------------------*
* this routine is used to get the customar data from database.
*----------------------------------------------------------------------*
FORM SUB_GET_KNA1 .
DATA:T_VBAK1 TYPE STANDARD TABLE OF TY_VBAK.
T_VBAK1 = T_VBAK.
SORT T_VBAK1 BY KUNNR.
DELETE ADJACENT DUPLICATES FROM T_VBAK1 COMPARING KUNNR.
SELECT KUNNR "customar no1
NAME1 "name1
ORT01 "city
PSTLZ "postal code
REGIO "region(state)
FROM
KNA1
INTO TABLE T_KNA1
FOR ALL ENTRIES IN T_VBAK1
WHERE KUNNR = T_VBAK1-KUNNR.
ENDFORM. " sub_get_kna1
*&---------------------------------------------------------------------*
*& Form sub_get_t001w
*&---------------------------------------------------------------------*
* this routine is used to get t001w data from database.
*----------------------------------------------------------------------*
FORM SUB_GET_T001W .
CHECK T_VBAP IS NOT INITIAL.
DATA:T_VBAP1 TYPE STANDARD TABLE OF TY_VBAP.
T_VBAP1 = T_VBAP.
SORT T_VBAP1 BY WERKS.
DELETE ADJACENT DUPLICATES FROM T_VBAP1 COMPARING WERKS.
SELECT WERKS "plant
NAME1 "name
ORT01 "city
FROM
T001W
INTO TABLE T_T001W
FOR ALL ENTRIES IN T_VBAP
WHERE WERKS = T_VBAP-WERKS.
ENDFORM. " sub_get_t001w
*&---------------------------------------------------------------------*
*& Form sub_populate_data_final_output
*&-----------------------------------------------------------------------------*
* this routine is used to populating the data into final output internal table
*------------------------------------------------------------------------------*
FORM SUB_POPULATE_DATA_FINAL_OUTPUT .
*looping sales order item internal table
LOOP AT T_VBAP INTO W_VBAP.
W_OUTPUT-POSNR = W_VBAP-POSNR.
W_OUTPUT-MATNR = W_VBAP-MATNR.
W_OUTPUT-MATKL = W_VBAP-MATKL.
W_OUTPUT-ARKTX = W_VBAP-ARKTX.
W_OUTPUT-PSTYV = W_VBAP-PSTYV.
W_OUTPUT-NETWR = W_VBAP-NETWR.
*reading sales order header table.
CLEAR:W_VBAK.
READ TABLE T_VBAK INTO W_VBAK WITH KEY VBELN = W_VBAP-VBELN.
IF SY-SUBRC = 0.
W_OUTPUT-VBELN = W_VBAK-VBELN.
W_OUTPUT-ERDAT = W_VBAK-ERDAT.
W_OUTPUT-AUDAT = W_VBAK-AUDAT.
W_OUTPUT-VKORG = W_VBAK-VKORG.
W_OUTPUT-VTWEG = W_VBAK-VTWEG.
W_OUTPUT-VKGRP = W_VBAK-VKGRP.
W_OUTPUT-KUNNR = W_VBAK-KUNNR.
ENDIF.
*reading customar data.
CLEAR:W_KNA1.
READ TABLE T_KNA1 INTO W_KNA1 WITH KEY KUNNR = W_VBAK-KUNNR.
IF SY-SUBRC = 0.
W_OUTPUT-KUNNR = W_KNA1-KUNNR.
W_OUTPUT-NAME1 = W_KNA1-NAME1.
W_OUTPUT-ORT01 = W_KNA1-ORT01.
W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.
W_OUTPUT-REGIO = W_KNA1-REGIO.
ENDIF.
*reading plants/branches data.
CLEAR:W_T001W.
READ TABLE T_T001W INTO W_T001W WITH KEY WERKS = W_VBAP-WERKS.
IF SY-SUBRC = 0.
W_OUTPUT-WERKS = W_T001W-WERKS.
W_OUTPUT-NAME1 = W_T001W-NAME1.
W_OUTPUT-ORT01 = W_T001W-ORT01.
ENDIF.
APPEND W_OUTPUT TO T_OUTPUT.
CLEAR:W_OUTPUT.
ENDLOOP.
SORT T_OUTPUT BY KUNNR WERKS.
ENDFORM. " sub_populate_data_final_output
*&---------------------------------------------------------------------*
*& Form sub_display_output
*&---------------------------------------------------------------------*
* this routine is used to display the final output.
*----------------------------------------------------------------------*
FORM SUB_DISPLAY_OUTPUT .
*looping the final output internal table
LOOP AT T_OUTPUT INTO W_OUTPUT1.
W_OUTPUT = W_OUTPUT1.
AT NEW KUNNR.
ULINE.
WRITE:/2 W_OUTPUT-KUNNR , 20 W_OUTPUT-NAME1, 30 W_OUTPUT-AUDAT, 40 W_OUTPUTVKORG
, 50 W_OUTPUT-VTWEG ,
60 W_OUTPUT-VKGRP , 70 W_OUTPUT-KUNNR , 80 W_OUTPUT-PSTLZ , 90
W_OUTPUT-REGIO , 100 W_OUTPUT-ORT01.
ULINE.
ENDAT.
WRITE:/2 W_OUTPUT-POSNR , 20 W_OUTPUT-MATNR , 30 W_OUTPUT-MATKL , 40 W_OUTPUTARKTX
, 50 W_OUTPUT-PSTYV ,
60 W_OUTPUT-ORT01 , 70 W_OUTPUT-NETWR.
*caluculating subtotal.
AT END OF KUNNR.
ULINE.
SUM.
WRITE:/60 'SUBTOTAL' :,70 W_OUTPUT1-NETWR.
ENDAT.
*caluculating grand total.
AT LAST.
ULINE.
SUM.
WRITE:/60 'GRAND TOTAL': , 70 W_OUTPUT1-NETWR.
ULINE.
WRITE:/80 'Prepared by RK'.
ENDAT.
ENDLOOP.
ENDFORM. " sub_display_output
*&---------------------------------------------------------------------*
*& Report ZSD_R_RDDL002_S_CUST_REP_RK28
*&
*&---------------------------------------------------------------------*
*& AUTHOR: KRANTHI.
*& REPORT NAME: SALES REPORT DISPLAYING CUSTOMAR WIZE.
*& PURPOSE: TO DISPLAY ALL CUSTOMARS AND PLANTS BASED ON SALES ORDER
*& REQUEST NO:SMPK 900987.
*& VERSION:V1.
*& SPEC : 01.
*&
*&---------------------------------------------------------------------*
*& MODIFICATION LOG:
*& MOD1:I ADDED TWO NEW FIELDS KUNNR AND POSNR.
*&---------------------------------------------------------------------*
REPORT ZSD_R_RDDL002_S_CUST_REP_RK28 NO STANDARD PAGE HEADING LINE-SIZE 100.
*&---------------------------------------------------------------------*
*& Structores declaration
*&---------------------------------------------------------------------*
*structor declaration for sales order header.
TYPES:BEGIN OF TY_VBAK ,
VBELN TYPE VBELN_VA, "sales document
ERDAT TYPE ERDAT , "date on which record was created
AUDAT TYPE AUDAT , "document date
VKORG TYPE VKORG , "sales organization
VTWEG TYPE VTWEG , "distribution chennel
VKGRP TYPE VKGRP , "distribution group
KUNNR TYPE KUNAG , "sold-to party
END OF TY_VBAK ,
*structor declaration for sales order item.
BEGIN OF TY_VBAP ,
VBELN TYPE VBELN_VA, "sales document
POSNR TYPE POSNR_VA, "sales document item
MATNR TYPE MATNR , "meterial no
MATKL TYPE MATKL , "meterial group
ARKTX TYPE ARKTX , "shart text for sales order item
PSTYV TYPE PSTYV , "sales document item category
NETWR TYPE NETWR , "net value of order item
WERKS TYPE WERKS_EXT, "plant(own or external)
END OF TY_VBAP ,
*structor declaration for customar.
BEGIN OF TY_KNA1 ,
KUNNR TYPE KUNNR , "customar no1
NAME1 TYPE NAME1_GP, "name1
ORT01 TYPE ORT01_GP, "city
PSTLZ TYPE PSTLZ , "postal code
REGIO TYPE REGIO , "region(state)
END OF TY_KNA1 ,
*structor declaration for plants/branches.
BEGIN OF TY_T001W ,
WERKS TYPE WERKS_D , "plant
NAME1 TYPE NAME1 , "name
ORT01 TYPE ORT01 , "city
END OF TY_T001W ,
*structor declaration for final output for sales order wize.
BEGIN OF TY_OUTPUT_S,
KUNNR_C TYPE KUNNR , "customar no1
NAME1 TYPE NAME1_GP, "name1
ORT01 TYPE ORT01_GP, "city
PSTLZ TYPE PSTLZ , "postal code
REGIO TYPE REGIO , "region(state)
VBELN TYPE VBELN_VA, "sales document
ERDAT TYPE ERDAT , "date on which record was created
AUDAT TYPE AUDAT , "document date
VKORG TYPE VKORG , "sales organization
VTWEG TYPE VTWEG , "distribution chennel
VKGRP TYPE VKGRP , "distribution group
KUNNR TYPE KUNAG , "sold-to party
* VBELN TYPE VBELN_VA, "sales document
POSNR TYPE POSNR_VA, "sales document item
MATNR TYPE MATNR , "meterial no
MATKL TYPE MATKL , "meterial group
ARKTX TYPE ARKTX , "shart text for sales order item
PSTYV TYPE PSTYV , "sales document item category
NETWR TYPE NETWR , "net value of order item
* WERKS_o TYPE WERKS_EXT, "plant(own or external)
WERKS TYPE WERKS_D , "plant
* NAME1 TYPE NAME1 , "name
* ORT01 TYPE ORT01 , "city
END OF TY_OUTPUT_S .
*&---------------------------------------------------------------------*
*& internal tables declaration
*&---------------------------------------------------------------------*
*itab declaration for sales order header.
DATA:T_VBAK TYPE STANDARD TABLE OF TY_VBAK,
*itab declaration for sales order item.
T_VBAP TYPE STANDARD TABLE OF TY_VBAP,
*itab declaration for customar.
T_KNA1 TYPE STANDARD TABLE OF TY_KNA1,
*itab declaration for plants/branches.
T_T001W TYPE STANDARD TABLE OF TY_T001W,
*itab declaration for final output.
T_OUTPUT TYPE STANDARD TABLE OF TY_OUTPUT_S,
*&---------------------------------------------------------------------*
*& workareas declaration
*&---------------------------------------------------------------------*
*workarea declaration for sales order header.
W_VBAK TYPE TY_VBAK,
*workarea declaration for sales order item.
W_VBAP TYPE TY_VBAP,
*workarea declaration for customar.
W_KNA1 TYPE TY_KNA1,
*workarea declaration for plants/branches.
W_T001W TYPE TY_T001W,
*workarea declaration for final output.
W_OUTPUT TYPE TY_OUTPUT_S,
W_OUTPUT1 TYPE TY_OUTPUT_S,
*&---------------------------------------------------------------------
*& global variable declaration.
*&---------------------------------------------------------------------*
G_kunnr TYPE VBAK-kunnr.
*&---------------------------------------------------------------------*
*& selection screen declaration.
*&---------------------------------------------------------------------*
SELECTION-SCREEN:BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:S_kunnr FOR G_kunnr.
SELECTION-SCREEN:END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& initilization event declaration
*&---------------------------------------------------------------------*
INITIALIZATION.
*clearing workareas
CLEAR:W_VBAK,
W_VBAP,
W_KNA1,
W_T001W,
W_OUTPUT.
*refreshing internal table
REFRESH:T_VBAK,
T_VBAP,
T_KNA1,
T_T001W,
T_OUTPUT.
*&---------------------------------------------------------------------*
*& at selection screen event declaration
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
*validating sales order number
DATA:L_kunnr TYPE kunnr.
SELECT SINGLE
kunnr
INTO
L_kunnr
FROM
kna1
WHERE kunnr IN S_kunnr.
IF SY-SUBRC <> 0 .
MESSAGE:E002(YNRK_MESS) WITH 'no data found from' S_KUNNR-LOW 'to' S_KUNNR-HIGH
.
ENDIF.
*&---------------------------------------------------------------------*
*& start of selection event declaration
*&---------------------------------------------------------------------*
START-OF-SELECTION.
*get vbak data.
PERFORM SUB_GET_VBAK.
*get vbap data.
PERFORM SUB_GET_VBAP.
*get kna1 data.
PERFORM SUB_GET_KNA1.
*get t001w data.
PERFORM SUB_GET_T001W.
*&---------------------------------------------------------------------*
*& top of page event declaration
*&---------------------------------------------------------------------*
TOP-OF-PAGE.
*displaying the report heading.
WRITE:/40 'SALESORDER REPORT'.
ULINE.
*displaying the header column headings
WRITE:/2 'customar no', 20 'name1' , 30 'document date' , 40 'sales organization',
50 'distribution chennel' ,
60 'distribution group' , 70'sold-to party' , 80 'postal code' , 90
'region',100 'city'.
ULINE.
*displaying the item column headings.
WRITE:/2 'sales item' , 20 'meterial no' , 30 'meterial group', 40 'shart text' ,
50 'item catagory' ,
60 'city' , 70 'net value'.
*&---------------------------------------------------------------------*
*& end of selection event declaration
*&---------------------------------------------------------------------*
END-OF-SELECTION.
*populating data into final output internal table.
PERFORM SUB_POPULATE_DATA_FINAL_OUTPUT.
*displaying the final output.
PERFORM SUB_DISPLAY_OUTPUT.
*&---------------------------------------------------------------------*
*& Form sub_get_vbak
*&---------------------------------------------------------------------*
* this routine is used to get the sales order header data from database.
*----------------------------------------------------------------------*
FORM SUB_GET_VBAK .
SELECT VBELN "sales document
ERDAT "date on which record was created
AUDAT "document date
VKORG "sales organization
VTWEG "distribution chennel
VKGRP "distribution group
KUNNR "sold-to party
FROM
VBAK
INTO TABLE T_VBAK
WHERE kunnr IN S_kunnr.
IF SY-SUBRC <> 0.
MESSAGE:I003(YNRK_MESS) WITH 'no data found in the given range'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " sub_get_vbak
*&---------------------------------------------------------------------*
*& Form sub_get_vbap
*&---------------------------------------------------------------------*
* this routine is used to get sales order item data.
*----------------------------------------------------------------------*
FORM SUB_GET_VBAP .
CHECK T_VBAK IS NOT INITIAL.
SELECT VBELN "sales document
POSNR "sales document item
MATNR "meterial no
MATKL "meterial group
ARKTX "shart text for sales order item
PSTYV "sales document item category
NETWR "net value of order item
WERKS "plant(own or external)
FROM
VBAP
INTO TABLE T_VBAP
FOR ALL ENTRIES IN T_VBAK
WHERE VBELN = T_VBAK-VBELN.
ENDFORM. " sub_get_vbap
*&---------------------------------------------------------------------*
*& Form sub_get_kna1
*&---------------------------------------------------------------------*
* this routine is used to get the customar data from database.
*----------------------------------------------------------------------*
FORM SUB_GET_KNA1 .
DATA:T_VBAK1 TYPE STANDARD TABLE OF TY_VBAK.
T_VBAK1 = T_VBAK.
SORT T_VBAK1 BY KUNNR.
DELETE ADJACENT DUPLICATES FROM T_VBAK1 COMPARING KUNNR.
SELECT KUNNR "customar no1
NAME1 "name1
ORT01 "city
PSTLZ "postal code
REGIO "region(state)
FROM
KNA1
INTO TABLE T_KNA1
FOR ALL ENTRIES IN T_VBAK1
WHERE KUNNR = T_VBAK1-KUNNR.
ENDFORM. " sub_get_kna1
*&---------------------------------------------------------------------*
*& Form sub_get_t001w
*&---------------------------------------------------------------------*
* this routine is used to get t001w data from database.
*----------------------------------------------------------------------*
FORM SUB_GET_T001W .
CHECK T_VBAP IS NOT INITIAL.
DATA:T_VBAP1 TYPE STANDARD TABLE OF TY_VBAP.
T_VBAP1 = T_VBAP.
SORT T_VBAP1 BY WERKS.
DELETE ADJACENT DUPLICATES FROM T_VBAP1 COMPARING WERKS.
SELECT WERKS "plant
NAME1 "name
ORT01 "city
FROM
T001W
INTO TABLE T_T001W
FOR ALL ENTRIES IN T_VBAP
WHERE WERKS = T_VBAP-WERKS.
ENDFORM. " sub_get_t001w
*&---------------------------------------------------------------------*
*& Form sub_populate_data_final_output
*&-----------------------------------------------------------------------------*
* this routine is used to populating the data into final output internal table
*------------------------------------------------------------------------------*
FORM SUB_POPULATE_DATA_FINAL_OUTPUT .
*looping sales order item internal table
LOOP AT T_VBAP INTO W_VBAP.
W_OUTPUT-POSNR = W_VBAP-POSNR.
W_OUTPUT-MATNR = W_VBAP-MATNR.
W_OUTPUT-MATKL = W_VBAP-MATKL.
W_OUTPUT-ARKTX = W_VBAP-ARKTX.
W_OUTPUT-PSTYV = W_VBAP-PSTYV.
W_OUTPUT-NETWR = W_VBAP-NETWR.
*reading sales order header table.
CLEAR:W_VBAK.
READ TABLE T_VBAK INTO W_VBAK WITH KEY VBELN = W_VBAP-VBELN.
IF SY-SUBRC = 0.
W_OUTPUT-VBELN = W_VBAK-VBELN.
W_OUTPUT-ERDAT = W_VBAK-ERDAT.
W_OUTPUT-AUDAT = W_VBAK-AUDAT.
W_OUTPUT-VKORG = W_VBAK-VKORG.
W_OUTPUT-VTWEG = W_VBAK-VTWEG.
W_OUTPUT-VKGRP = W_VBAK-VKGRP.
W_OUTPUT-KUNNR = W_VBAK-KUNNR.
ENDIF.
*reading customar data.
CLEAR:W_KNA1.
READ TABLE T_KNA1 INTO W_KNA1 WITH KEY KUNNR = W_VBAK-KUNNR.
IF SY-SUBRC = 0.
W_OUTPUT-KUNNR = W_KNA1-KUNNR.
W_OUTPUT-NAME1 = W_KNA1-NAME1.
W_OUTPUT-ORT01 = W_KNA1-ORT01.
W_OUTPUT-PSTLZ = W_KNA1-PSTLZ.
W_OUTPUT-REGIO = W_KNA1-REGIO.
ENDIF.
*reading plants/branches data.
CLEAR:W_T001W.
READ TABLE T_T001W INTO W_T001W WITH KEY WERKS = W_VBAP-WERKS.
IF SY-SUBRC = 0.
W_OUTPUT-WERKS = W_T001W-WERKS.
W_OUTPUT-NAME1 = W_T001W-NAME1.
W_OUTPUT-ORT01 = W_T001W-ORT01.
ENDIF.
APPEND W_OUTPUT TO T_OUTPUT.
CLEAR:W_OUTPUT.
ENDLOOP.
SORT T_OUTPUT BY KUNNR WERKS.
ENDFORM. " sub_populate_data_final_output
*&---------------------------------------------------------------------*
*& Form sub_display_output
*&---------------------------------------------------------------------*
* this routine is used to display the final output.
*----------------------------------------------------------------------*
FORM SUB_DISPLAY_OUTPUT .
*looping the final output internal table
LOOP AT T_OUTPUT INTO W_OUTPUT1.
W_OUTPUT = W_OUTPUT1.
AT NEW KUNNR.
ULINE.
WRITE:/2 W_OUTPUT-KUNNR , 20 W_OUTPUT-NAME1, 30 W_OUTPUT-AUDAT, 40 W_OUTPUTVKORG
, 50 W_OUTPUT-VTWEG ,
60 W_OUTPUT-VKGRP , 70 W_OUTPUT-KUNNR , 80 W_OUTPUT-PSTLZ , 90
W_OUTPUT-REGIO , 100 W_OUTPUT-ORT01.
ULINE.
ENDAT.
WRITE:/2 W_OUTPUT-POSNR , 20 W_OUTPUT-MATNR , 30 W_OUTPUT-MATKL , 40 W_OUTPUTARKTX
, 50 W_OUTPUT-PSTYV ,
60 W_OUTPUT-ORT01 , 70 W_OUTPUT-NETWR.
*caluculating subtotal.
AT END OF KUNNR.
ULINE.
SUM.
WRITE:/60 'SUBTOTAL' :,70 W_OUTPUT1-NETWR.
ENDAT.
*caluculating grand total.
AT LAST.
ULINE.
SUM.
WRITE:/60 'GRAND TOTAL': , 70 W_OUTPUT1-NETWR.
ULINE.
WRITE:/80 'Prepared by RK'.
ENDAT.
ENDLOOP.
ENDFORM. " sub_display_output