Powered By

Free XML Skins for Blogger

Powered by Blogger

Friday, August 8, 2008

SD Output/Email Program for Sales Order by Customer, Date, Sales

Sales Order by Organisation, Customer - To create the Sales Order by More no of Date's

User's can easily take the Report from this by selecting Different kinds like Customer Specific [And/Or] Sales Organisation Specific [And/Or] duration of date but Here Date is Mandatory Fields user must have to give date as a selection criteria

In Second level this report will interact with user where they can select date to see the full Details of Sales Order
Selection
- Sales Organisation
- Date
- Customer this will be usefull when Selecting the Checkbox
Standard Variants
- Output
- Sales Order

Example
Date SalesOrderNo Material Amount Currency
10.01.2007 8530 732 1000 INR

*&---------------------------------------------------------------------*
*& Report ZCHE_SALES_ORDER
*&--------Done by V.Chellavelu on 11.01.2007
--------------------------*

REPORT zche_sales_order .

****************************Declarations********************************
TABLES: vbkd,vepvg.",vbak,vbap,vbpa,vakpa, vapma.

DATA: BEGIN OF sal OCCURS 0,
ch TYPE checkbox,
vbeln LIKE vbak-vbeln, " sales document
netwr LIKE vbak-netwr, "Net Value of the SalesOrder
matnr LIKE vbap-matnr, "material no.
waerk LIKE vbak-waerk, "curr.
dat LIKE vbak-erdat, "date.
END OF sal.
DATA: newsal LIKE sal OCCURS 0 WITH HEADER LINE.

DATA: amount LIKE vbak-netwr, date2(15),date3(8),date4(1),
date5(2),date6(2).

DATA: lin LIKE sy-curow VALUE 1,"Screens, vertical cursor position at
"PAI available in SYST struc.
checkbox TYPE c ,
dat LIKE vbak-erdat.

*******************Selection**Screen**Design****************************
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: vkorg LIKE vepvg-vkorg,
vtweg LIKE vepvg-vtweg,
spart LIKE vepvg-spart.
SELECT-OPTIONS date FOR vbkd-bstdk DEFAULT sy-datum TO sy-datum
OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.

SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 10.
PARAMETERS: chk1 AS CHECKBOX.
SELECTION-SCREEN POSITION 20.
PARAMETERS: kunnr1 LIKE vbpa-kunnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK blk2.

********************First**Level**Operation*****************************
IF chk1 <> 'X'.
IF vkorg <> ''.
PERFORM organisation.
ELSE.
PERFORM organisation_else.
ENDIF.

ELSE.
IF vkorg <> ''.
PERFORM cus_orga.
ELSE.
PERFORM cus_orga_else.
ENDIF.
ENDIF.


* Displaying the contents which is selected from table by
* -selection conditions
SORT sal BY dat.

LOOP AT sal.
ON CHANGE OF sal-dat.
* FORMAT HOTSPOT ON.
IF sy-tabix = 1.
WRITE: sy-vline, sal-ch AS CHECKBOX,sal-dat .
CLEAR amount.
ELSE.
WRITE:sy-vline, amount,/ sy-vline, sal-ch AS CHECKBOX,sal-dat.
CLEAR amount.
ENDIF.
ENDON.
amount = amount + sal-netwr.
AT LAST.
WRITE:sy-vline, amount.
ULINE.
SUM.
* FORMAT HOTSPOT OFF.
FORMAT COLOR = 3.
WRITE:/ ' Total Amount:', sal-netwr UNDER amount.
ENDAT.
ENDLOOP.

**********************Interaction with report**************************

SET PF-STATUS 'BANU'. " To create Application ToolBar for Display
Button
* To verify Double click on BANU

AT USER-COMMAND. " This will execute after pressing Display Button
CASE sy-ucomm.
WHEN 'DISP'.
free newsal.
DO.
READ LINE lin FIELD VALUE sal-ch INTO checkbox.
IF sy-subrc NE 0. EXIT. ENDIF.
IF checkbox = 'X'.
PERFORM datecon.
PERFORM process.
ENDIF.
lin = lin + 1.
ENDDO.
PERFORM selection.
ENDCASE.

************************ SUB ROUTINE Area
******************************
*This Process SubRoutine will assign the values from current
* -InternalTable (sal) into other IT(newsal), by date which is
* - selected by CheckBox
FORM process.
LOOP AT sal WHERE dat = dat.
newsal-ch = 'X'.
newsal-vbeln = sal-vbeln.
newsal-netwr = sal-netwr.
newsal-matnr = sal-matnr.
newsal-waerk = sal-waerk.
newsal-dat = sal-dat.
APPEND newsal.
ENDLOOP.
ENDFORM. "process

*&---------This will display the values for selected dates from new --*
*---------------------internal Table (newsal)-------------------------*
*& Form SELECTION
*&--------------------------------------------------------------------*
*---------------------------------------------------------------------*
FORM selection.
ULINE.
FORMAT COLOR = 1.
WRITE:sy-vline,'Date',AT 14 sy-vline, 'Order NO', AT 27 sy-vline,
'Order Material', AT 48 sy-vline,'Order Value(AMT) Currency '.
FORMAT COLOR OFF.
ULINE.
LOOP AT newsal.
ON CHANGE OF newsal-dat.
IF sy-tabix <> 1.
WRITE:/ sy-vline, AT 14 sy-vline,AT 27 sy-vline,AT 48 sy-vline.
WRITE:/ sy-vline,newsal-dat,sy-vline,AT 27 sy-vline,AT 48 sy-vline.
ELSE.
WRITE: sy-vline,newsal-dat,sy-vline,AT 27 sy-vline,AT 48 sy-vline.
ENDIF.
ENDON.
WRITE:/ sy-vline, AT 14 sy-vline,newsal-vbeln,sy-vline,
newsal-matnr, sy-vline, newsal-netwr, newsal-waerk.

AT LAST.
SUM.
ULINE. FORMAT COLOR = 3.
WRITE:/ sy-vline, AT 15 'Total Amount for selected month:',
newsal-netwr UNDER newsal-netwr.
FORMAT COLOR OFF.
ULINE.
ENDAT.
ENDLOOP.
lin = 1.
FREE newsal.
ENDFORM. "SELECTION

* This Date convertion is must for pick the particular Date from the
* -displayed line, and here we are reversing the Date like
YYYY/MM/DD
* -because to Check or assign the date we need to give in reverse
order

*&--------------------------------------------------------------------*
*& Form DATECON
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM datecon.
date2 = sy-lisel(17).
SHIFT date2 LEFT BY 4 PLACES.
WHILE date2 <> ''.
SHIFT date2 RIGHT.
date4 = date2+11.
IF date4 <> '.'.
CONCATENATE date4 date3 INTO date3.
ENDIF.
ENDWHILE.
date5 = date3(2).
date6 = date3+2.
date3 = date3+4.
CONCATENATE date3 date6 date5 INTO date3.
dat = date3.
* SORT dat BY dat.
* DELETE ADJACENT DUPLICATES FROM dat COMPARING dat.
ENDFORM. "DATECON


* Here we are doing different kinds of selections by the EndUser's
needs

*&---------When user selectiong an Sales Organisation-----------------*
*& Form ORGANISATION
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM organisation.
SELECT f~vbeln p~matnr c~netwr c~waerk p~audat INTO (sal-vbeln,
sal-matnr, sal-netwr,sal-waerk, sal-dat) FROM ( vakpa AS f INNER JOIN
vbak AS c ON f~vbeln = c~vbeln ) INNER JOIN vapma AS p ON
f~vbeln = p~vbeln WHERE p~audat IN date AND p~vkorg = vkorg.
APPEND sal.
ENDSELECT.
ENDFORM. "ORGANISATION


*&---------Without Sales Organisation i.e All Organisation------------*
*& Form ORGANISATION_ELSE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM organisation_else.
SELECT f~vbeln p~matnr c~netwr c~waerk p~audat INTO (sal-vbeln,
sal-matnr, sal-netwr,sal-waerk, sal-dat) FROM ( vakpa AS f INNER JOIN
vbak AS c ON f~vbeln = c~vbeln ) INNER JOIN vapma AS p ON
f~vbeln = p~vbeln WHERE p~audat IN date.

APPEND sal.
ENDSELECT.
ENDFORM. "ORGANISATION_ELSE

*&------------When Selecting Customer by choosing CheckBox------------*
*& Form CUS_ORGA
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM cus_orga.
SELECT f~vbeln p~matnr c~netwr c~waerk p~audat INTO (sal-vbeln,
sal-matnr, sal-netwr,sal-waerk, sal-dat) FROM ( vakpa AS f INNER JOIN
vbak AS c ON f~vbeln = c~vbeln ) INNER JOIN vapma AS p ON
f~vbeln = p~vbeln WHERE p~audat IN date AND p~vkorg = vkorg AND
p~kunnr = kunnr1.

APPEND sal.
ENDSELECT.
ENDFORM. "CUS_ORGA

*&------------Without Customer by without choosing CheckBox-----------*
*& Form CUS_ORGA_ELSE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM cus_orga_else.
SELECT f~vbeln p~matnr c~netwr c~waerk p~audat INTO (sal-vbeln,
sal-matnr, sal-netwr,sal-waerk, sal-dat) FROM ( vakpa AS f INNER JOIN
vbak AS c ON f~vbeln = c~vbeln ) INNER JOIN vapma AS p ON
f~vbeln = p~vbeln WHERE p~audat IN date AND p~kunnr = kunnr1.

APPEND sal.
ENDSELECT.

No comments: