Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Report: Plant wise open sales order

Former Member
0 Kudos

Hi,

Can anyone help me out in gettting plant wise open sales order,

Regards

Shrinath

6 REPLIES 6

Former Member
0 Kudos

&----


*& Report ZOPEN_SALESORDER

*&

&----


*&

*&

&----


report zopen_salesorder message-id arc no standard page heading.

tables :kna1,vbak.

select-options : so_vkorg for vbak-vkorg ,

so_vtweg for vbak-vtweg ,

so_spart for vbak-spart,

so_kunnr for kna1-kunnr.

data : keybalance like bapi3007_3 occurs 0 with header line.

data : begin of sales_open occurs 0 ,

vbeln like vbak-vbeln,

auart like vbak-auart,

kunnr like kna1-kunnr,

bstnk like vbak-bstnk,

lfstk like vbuk-lfstk,

fkstk like vbuk-fkstk,

gbstk like vbuk-gbstk,

end of sales_open.

data : begin of itm_sales occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

lfsta like vbup-lfsta,

lfgsa like vbup-lfgsa,

fksta like vbup-fksta,

fksaa like vbup-fksaa,

gbsta like vbup-gbsta,

end of itm_sales.

***

data : l_kunnr like kna1-kunnr,

l_vkorg like vbak-vkorg,

l_vtweg like vbak-vtweg,

l_spart like vbak-spart.

data: v_statusl(20) type c,

v_statusb(20) type c,

v_statusf(20) type c,

v_statusg(20) type c,

v_status(20) type c,

v_field(1) type c.

**Selection Screen Validations.

at selection-screen.

perform validations.

&----


*& Form Validations

&----


text

-


--> p1 text

<-- p2 text

-


form validations.

**Customer

if not so_kunnr[] is initial.

select single kunnr into l_kunnr

from kna1

where kunnr in so_kunnr.

if sy-subrc ne 0.

message e002 with text-005.

endif.

endif.

**Sales Organization

if not so_vkorg[] is initial.

select single vkorg into l_vkorg

from tvko

where vkorg in so_vkorg.

if sy-subrc ne 0.

message e003 with text-006.

endif.

endif.

**Distribution Channel

if not so_vtweg[] is initial.

select single vtweg into l_vtweg

from tvkov

where vkorg in so_vkorg

and vtweg in so_vtweg.

if sy-subrc ne 0.

message e004 with text-007.

endif.

endif.

**Division

if not so_spart[] is initial.

select single spart into l_spart

from tvta

where vkorg in so_vkorg

and vtweg in so_vtweg

and spart in so_spart.

if sy-subrc ne 0.

message e005 with text-008.

endif.

endif.

endform. " Validations

top-of-page.

perform sales_top_of_page.

start-of-selection.

perform sales_sel.

&----


*& Form sales_sel

&----


text

-


--> p1 text

<-- p2 text

-


form sales_sel.

data: date type sy-datum.

date = sy-datum - 3000.

select vbeln auart kunnr bstnk

lfstk fkstk gbstk

into table sales_open

from vbakuk

where vkorg in so_vkorg

and vtweg in so_vtweg

and spart in so_spart

and kunnr in so_kunnr

"and gbstk ne 'C'.

and gbstk in ('A','B')

and erdat >= date.

loop at sales_open.

call function 'BAPI_AR_ACC_GETKEYDATEBALANCE'

exporting

companycode = '1919'

customer = sales_open-kunnr

keydate = sy-datum

tables

keybalance = keybalance.

read table keybalance index sy-tabix.

write:/4 sy-vline,

5 sales_open-vbeln color 2 intensified on,

16 sy-vline,

17 sales_open-auart color 2 intensified on,

27 sy-vline,

28 sales_open-kunnr color 2 intensified on,

40 sy-vline,

41 sales_open-bstnk color 2 intensified on,

55 sy-vline,

56 sales_open-lfstk,

76 sy-vline,

77 sales_open-fkstk,

96 sy-vline,

97 sales_open-gbstk ,

117 sy-vline,

118 keybalance-lc_bal,

142 sy-vline.

"hide sales_open-vbeln .

endloop.

write :/4 sy-uline(160).

endform. " sales_sel

&----


*& Form sales_top_of_page

&----


text

-


--> p1 text

<-- p2 text

-


form sales_top_of_page.

write:/4 sy-uline(160),

50 'OPEN SALES ORDERS' color 7 intensified on .

write: /4 sy-vline,

5 'SalesOrder' color 1 ,

16 sy-vline,

17 'OrderType' color 1,

27 sy-vline,

28 'Customer' color 1,

40 sy-vline,

41 'PoNumber' color 1,

55 sy-vline,

56 'Delivery Status' color 1,

76 sy-vline,

77 'Billing Status' color 1,

96 sy-vline,

97 'Processing Status' color 1,

117 sy-vline,

130 'Balance' color 1,

142 sy-vline.

write:/4 sy-uline(160).

endform. " sales_top_of_page

"at line-selection.

"select a~vbeln

"a~posnr

"a~matnr

"* a~kwmeng

"b~lfsta

"b~lfgsa

"b~fksta

"b~fksaa

"b~gbsta

"into table itm_sales

"from vbap as a join vbup as b

"on avbeln eq bvbeln

"and aposnr eq bposnr

"and b~gbsta ne 'C'

"where a~vbeln eq sales_open-vbeln.

"if not sales_open is initial.

"loop at itm_sales.

"write:/5 itm_sales-vbeln,

"itm_sales-posnr,

"itm_sales-matnr,

"itm_sales-lfsta,

"itm_sales-lfgsa,

"itm_sales-fksta,

"itm_sales-fksaa,

"itm_sales-gbsta.

"endloop.

"endif.

Reward points if useful.

0 Kudos

your report does not work - i copied it to a sandbox and crosschecked its results using MD04 and MD06. there were loads of open sales orders in a plant which your report didn't show.

i suggest you use the same algorithms that MD04-06 use.

Former Member
0 Kudos

Hi sangshetty,

Follow these steps :

1. Select Plant Sales Order, Line Item with Join on VBAP and VBUP (if you want plant on selection-screen mention it in where condition)

Note : VBUP contain all status for Sales orders

2. Depending upon status of various document filter the data. Here you are referring as Open Sales Order (Not sure if it means sales order is incomplete or billing is not created, delivery is not created etc.. You can find all the status in VBUP).

Regards,

Mohaiyuddin

RoySayak
Active Participant
0 Kudos

Hi,

You can get the Sales order status from VBUK,VBUP. prepare the report using it. use vbak from plants.

Thanks & Regards,

Sayak

Former Member
0 Kudos

Hi,

You can take the selection criteria based on plant from VBAP-werks and retrive the date based on you requirment.

Regards

Rams

Former Member
0 Kudos

hi

good

This is the logic (include LV05TFOF):

code IF LVBUK-LFGSK = ' '.

CHECK VBCOM-VBOFF = ' ' OR

LVBUK-GBSTK = 'A' OR LVBUK-GBSTK = 'B'.

LVBMTV-STATUS = LVBUK-GBSTK.

FELDNAME = 'GBSTK'.

ELSE.

IF LVBUK-LFGSK = 'C'.

CHECK VBCOM-VBOFF = ' ' OR

LVBUK-GBSTK = 'A' OR LVBUK-GBSTK = 'B'.

LVBMTV-STATUS = LVBUK-GBSTK.

FELDNAME = 'GBSTK'.

ELSE.

CHECK VBCOM-VBOFF = ' ' OR

LVBUK-LFGSK = 'A' OR LVBUK-LFGSK = 'B'.

LVBMTV-STATUS = LVBUK-LFGSK.

FELDNAME = 'LFGSK'.

ENDIF.

ENDIF.[/code]

thanks

mrutyun^