Skip to Content
0
Sep 19, 2012 at 08:18 AM

report background variant problem

39 Views

Dear All ,

I have a problem to execute the report in background process , For that It has a parameter date(in range form) as input

so for that I have to create a Variant here the date is in reange form , that means high date is system date

and low date is month first date , I have created the variant , So when I report the run to scheduled it then

it showing cancel status ,

For your reference the Code is here , The date which to be varied in variant is S_audat ,

How can I create Variant for that Please suggest.

*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Report ZCRPT_SD_089

*&---------------------------------------------------------------------*

REPORT zcrpt_sd_089.

INCLUDE zalvlist_2.

*&---------------------------------------------------------------------*

*& TABLES

*&---------------------------------------------------------------------*

TABLES: vbak ,

vbap ,

vbrk,

lips ,

vbrp ,

dd07l ,

dd07t ,

ekko ,

lfa1 ,

vbep .

TYPE-POOLS : slis .

TYPE-POOLS: vrm.

DATA: name TYPE vrm_id,

list TYPE vrm_values,

value LIKE LINE OF list.

*&---------------------------------------------------------------------*

*& Selection Screen

*&---------------------------------------------------------------------*

SELECTION-SCREEN : BEGIN OF BLOCK bk1 WITH FRAME TITLE text-002 .

SELECT-OPTIONS : s_matnr FOR vbap-matnr ,

s_vkorg FOR vbak-vkorg ,

s_vtweg FOR vbak-vtweg ,

s_vkbur FOR vbak-vkbur,

s_spart FOR vbak-spart ,

s_kunnr FOR vbak-kunnr ,

s_werks FOR vbap-werks ,

s_vbeln FOR vbak-vbeln ,

s_ebeln FOR ekko-ebeln ,

s_audat FOR vbak-audat ,

s_edatu FOR vbep-edatu NO-DISPLAY.

SELECTION-SCREEN : END OF BLOCK bk1 .

SELECTION-SCREEN : BEGIN OF BLOCK bk2 WITH FRAME TITLE text-003 .

PARAMETERS: p_chk_so AS CHECKBOX DEFAULT 'X',

p_chk_po AS CHECKBOX DEFAULT 'X',

p_chk_dm AS CHECKBOX DEFAULT 'X'.

PARAMETERS: ps_parm(8) AS LISTBOX VISIBLE LENGTH 12.

.

SELECTION-SCREEN : END OF BLOCK bk2 .

DATA : BEGIN OF date,

low(10) TYPE c,

high(10) TYPE c,

END OF date.

*&---------------------------------------------------------------------*

*& Internal Tables

*&---------------------------------------------------------------------*

DATA : BEGIN OF disp OCCURS 0 ,

document(5),

iconid LIKE icon-id ,

werks LIKE vbap-werks , " Plant

wenam LIKE t001w-name1, " Plant Name

vkorg LIKE vbak-vkorg , " Sales Org.

vtext LIKE tvkot-vtext, " Sales Org.Text

vtweg LIKE vbak-vtweg , " Dist.Channel

vttxt LIKE tvtwt-vtext, " Dist.Chan.Text

vkbur LIKE vbak-vkbur, " Sales Office

vkbtx LIKE tvkbt-bezei, " Sales Off.Text

spart LIKE vbak-spart , " Division

sptxt LIKE tspat-vtext, " Div.Text

kvgr1 LIKE vbak-kvgr1 , " District

k1txt LIKE tvv1t-bezei, " Dist.Text

kvgr2 LIKE vbak-kvgr2 , " Taluka

k2txt LIKE tvv2t-bezei, " Taluka Text

kvgr3 LIKE vbak-kvgr3 , " Village

k3txt LIKE tvv3t-bezei, " Vill.Text

zzlzone LIKE vbap-zzlzone , " Transport.Zone(SP)

lztxt LIKE tzont-vtext, " Trans.Zone Desc(SP)

regio LIKE kna1-regio , " Region

regtx LIKE t005u-bezei, " Reg.Text

land1 LIKE kna1-land1 , " Country Code

landx LIKE t005t-landx, " Count.Desc

matnr LIKE vbap-matnr , " Material

kunnr LIKE vbak-kunnr , " Sold To Party

spnam LIKE kna1-name1 , " SP Name

* added by kanak dt. 20.09.2011

lifnr TYPE lfa1-lifnr , " Forwarding agent code

faname TYPE lfa1-name1 , " Forwading agent name

* end

spcity LIKE kna1-ort01 , " SP City

kunag LIKE vbak-kunnr , " SP

shnam LIKE kna1-name1 , " SH Name

shnam2 LIKE adrc-name2 , " Ship to Party Name2

shnam3 LIKE adrc-name3 , " Ship to Party Name3

shnam4 LIKE adrc-name4 , " Ship to Party Name4

shcity LIKE kna1-ort01 , " SH City

sh_zone LIKE vbap-zzlzone , " Transport.Zone(SH)

sh_lztxt LIKE tzont-vtext, " Trans.Zone Desc(SH)

sh_regio LIKE kna1-regio , " Region(SH)

sh_land1 LIKE kna1-land1 , " Country(SH)

audat LIKE vbak-audat , " Sales Doc Date

vbeln LIKE vbap-vbeln , " Sales Doc No

auart LIKE vbak-auart , " Sales Doc type

posnr LIKE vbap-posnr , " Item No

etenr LIKE vbep-etenr , " Sch.Line Item

edatu LIKE vbep-edatu , " Sch.Line date

ebeln LIKE ekko-ebeln , " PO No

ebelp LIKE ekpo-ebelp , " PO Item No

kwmeng LIKE vbap-kwmeng , " Sales Qty

wmeng LIKE vbep-wmeng, " Sch.Order Qty

lfimg LIKE lips-lfimg , " Del.Qty

fkimg LIKE vbrp-fkimg , " Invoice Qty

balqty LIKE vbrp-fkimg , " Balance Qty

cmgst LIKE vbuk-cmgst , " Status of Credit Checks

crtxt LIKE dd07t-ddtext , " Status Desc

imm_td_kwmeng LIKE vbap-kwmeng, " Imm.Trade Qty

imm_nt_kwmeng LIKE vbap-kwmeng, " Imm.Non-Trade Qty

sch_td_kwmeng LIKE vbap-kwmeng, " Sch.Trade Qty

sch_nt_kwmeng LIKE vbap-kwmeng, " Sch.Non-Trade Qty

st_kwmeng LIKE vbap-kwmeng, " Stock Transfer Qty

tot_kwmeng LIKE vbap-kwmeng, " Total(Trade + Non-Trade)

route LIKE vbap-route, " Route

rt_bezei LIKE tvrot-bezei, " Route Description

gbsta LIKE vbup-gbsta, " Completion Status

erdat LIKE vbak-erdat, "Entry Date

erzet LIKE vbak-erzet, " Entry time

diff_date TYPE p, " Date Differance

compl_flag(1),

agent TYPE vbak-vkbur,

name1 TYPE kna1-name1,

duration TYPE tvro-fahztd, "Order Pending Duration

KBETR LIKE KONV-KBETR,

KNUMV LIKE VBAK-KNUMV.

* vkbur type vbak-vkbur . " CCC Code

INCLUDE STRUCTURE zsd_matgroups. " Inc.For Mat.Groups

DATA : END OF disp.

*&---------------------------------------------------------------------*

*& Initialization

*&---------------------------------------------------------------------*

INITIALIZATION.

repname = sy-repid.

PERFORM fill_init_audat.

PERFORM build_eventtab USING events[].

PERFORM build_layout .

PERFORM initialize_variant.

*&---------------------------------------------------------------------*

*& At Selection Screen

*&---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.

PERFORM f4_for_variant.

AT SELECTION-SCREEN.

IF p_chk_so NE 'X' AND p_chk_po NE 'X' AND p_chk_dm NE 'X'.

MESSAGE e002(sy) WITH 'Please Select Atleast one option'.

ENDIF.

IF ps_parm EQ space.

MESSAGE e000(zcvs) WITH 'Please Select With Schedule'

'Or Without Schedule'.

ENDIF.

PERFORM pai_of_selection_screen.

AT SELECTION-SCREEN OUTPUT.

name = 'PS_PARM'.

value-key = '1'.

value-text = 'Workable'.

APPEND value TO list.

value-key = '2'.

value-text = 'Schedule'.

APPEND value TO list.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = name

values = list.

ps_parm = '1'.

*&---------------------------------------------------------------------*

*& Start of selection

*&---------------------------------------------------------------------*

START-OF-SELECTION .

PERFORM initialise_fieldtab.

PERFORM check_plant_data.

IF p_chk_so EQ 'X'.

PERFORM get_so .

ENDIF.

IF p_chk_po EQ 'X'.

PERFORM get_po .

ENDIF.

IF p_chk_dm EQ 'X'.

PERFORM get_dms .

ENDIF.

PERFORM convert_date_to_external.

PERFORM segregate_dist_chann_qty.

PERFORM get_sd_matgroups.

PERFORM delete_dup_order_qty.

PERFORM get_order_delay_duration.

PERFORM display_data USING disp[].

*&---------------------------------------------------------------------*

*& Form get_so

*&---------------------------------------------------------------------*

FORM get_so .

PERFORM fill_schedule_date.

DATA : tabix LIKE sy-tabix.

DATA : it_vapma LIKE vapma OCCURS 0 WITH HEADER LINE.

DATA : it_vbap LIKE vbap OCCURS 0 WITH HEADER LINE.

DATA : it_vbep LIKE vbep OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_vbfa OCCURS 0,

flag(1).

INCLUDE STRUCTURE vbfa.

DATA : END OF it_vbfa.

DATA : it_vbfa_tmp LIKE it_vbfa OCCURS 0 WITH HEADER LINE.

DATA : it_vbfa_tmp1 LIKE it_vbfa OCCURS 0 WITH HEADER LINE.

DATA : p_xcpdk TYPE vbpa-xcpdk,

p_adrnr TYPE vbpa-adrnr.

DATA : p_wmeng_inv LIKE vbep-wmeng.

DATA : p_propagate_inv LIKE vbrp-fkimg.

DATA : p_act_so_qty LIKE vbrp-fkimg.

DATA : p_wmeng_dlv LIKE vbep-wmeng.

DATA : p_propagate_dlv LIKE lips-lfimg.

* Retrieve the Sales Order Materials as per the Parameters

*----------------------------------------------------------

SELECT * FROM vapma CLIENT SPECIFIED

INTO CORRESPONDING FIELDS OF TABLE it_vapma

WHERE mandt = sy-mandt

AND matnr IN s_matnr

AND vkorg IN s_vkorg

AND trvog EQ 0

AND audat IN s_audat " HCG2006

AND vtweg IN s_vtweg

AND spart IN s_spart

AND auart NOT IN

('ZFRE','ZDRE','ZDIS','ZDVR')

AND kunnr IN s_kunnr

AND vkbur IN s_vkbur

AND vbeln IN s_vbeln

AND werks IN s_werks.

.

CHECK NOT it_vapma[] IS INITIAL.

SORT it_vapma BY vbeln posnr.

* Retrieve the Sales Order Details

*----------------------------------------------------------

CHECK it_vapma[] IS NOT INITIAL.

SELECT * FROM vbap CLIENT SPECIFIED

INTO CORRESPONDING FIELDS OF TABLE it_vbap

FOR ALL ENTRIES IN it_vapma

WHERE mandt EQ sy-mandt

AND vbeln EQ it_vapma-vbeln

AND posnr EQ it_vapma-posnr .

*--------------NEW BLOCK ADDED BY AJAY FOR SPEED UP REPORT

SELECT vbelv vbtyp_n rfmng rfmng FROM vbfa

CLIENT SPECIFIED

INTO CORRESPONDING FIELDS OF TABLE it_vbfa_tmp

FOR ALL ENTRIES IN it_vbap

WHERE mandt EQ sy-mandt

AND vbelv EQ it_vbap-vbeln

AND vbtyp_n IN ('N','M')

AND rfmng NE 0

AND vbelv EQ it_vbap-vbeln.

SORT it_vbfa_tmp BY vbelv.

LOOP AT it_vbfa_tmp.

IF it_vbfa_tmp-vbtyp_n EQ 'N'.

it_vbfa_tmp-rfmng = it_vbfa_tmp-rfmng * -1.

ENDIF.

MODIFY it_vbfa_tmp.

MOVE-CORRESPONDING it_vbfa_tmp TO it_vbfa_tmp1.

COLLECT it_vbfa_tmp1.

ENDLOOP.

LOOP AT it_vbap.

tabix = sy-tabix.

READ TABLE it_vbfa_tmp1 WITH KEY vbelv = it_vbap-vbeln.

IF sy-subrc EQ 0.

IF it_vbap-kwmeng EQ it_vbfa_tmp1-rfmng.

DELETE it_vapma WHERE vbeln = it_vbap-vbeln.

DELETE it_vbap INDEX tabix.

ENDIF.

ENDIF.

ENDLOOP.

*--------------NEW BLOCK ENDED BY AJAY FOR SPEED UP REPORT

* Retrieve the Sales Order Schedule Line Details

*----------------------------------------------------------

SELECT * FROM vbep CLIENT SPECIFIED

INTO CORRESPONDING FIELDS OF TABLE it_vbep

FOR ALL ENTRIES IN it_vapma

WHERE mandt EQ sy-mandt

AND vbeln EQ it_vapma-vbeln

AND posnr EQ it_vapma-posnr

AND bmeng GT 0

AND edatu LE s_edatu-high.

CLEAR it_vbfa[].

* Get the Document Flow of the Order For Delivery And Invoice

*------------------------------------------------------------------

SELECT * FROM vbfa

INTO CORRESPONDING FIELDS OF TABLE it_vbfa

FOR ALL ENTRIES IN it_vbap

WHERE vbelv EQ it_vbap-vbeln

AND posnv EQ it_vbap-posnr

AND rfmng NE 0

* AND mandt EQ sy-mandt

AND vbtyp_n IN ('J','M').

* DELETE IT_VBEP WHERE WMENG IS INITIAL.

SORT it_vbep BY vbeln posnr .

LOOP AT it_vbep .

CLEAR: p_xcpdk, p_adrnr .

READ TABLE it_vapma WITH KEY vbeln = it_vbep-vbeln

posnr = it_vbep-posnr .

CHECK sy-subrc EQ 0 .

READ TABLE it_vbap WITH KEY vbeln = it_vbep-vbeln

posnr = it_vbep-posnr .

CHECK sy-subrc EQ 0 .

IF it_vbap-abgru NE space AND it_vbap-abgru NE '18'.

DELETE it_vbep.

CONTINUE.

ENDIF.

it_vbep-wmeng = it_vbep-bmeng.

MOVE-CORRESPONDING it_vapma TO disp .

MOVE-CORRESPONDING it_vbep TO disp .

MOVE-CORRESPONDING it_vbap TO disp .

disp-diff_date = sy-datum - disp-edatu.

* Check to see whether the Order lies in the Order Date

* Range.If Not Delete the Record else

* get the District,Taluka,Village Data

*-------------------------------------------------------------

SELECT SINGLE audat kvgr1 kvgr2 kvgr3 FROM vbak

INTO (disp-audat, disp-kvgr1,

disp-kvgr2,disp-kvgr3)

WHERE vbeln EQ it_vbap-vbeln

AND audat IN s_audat AND lifsk EQ ''.

IF sy-subrc NE 0.

DELETE it_vbep.

CONTINUE.

ENDIF.

* Get the Ship To Party Information

*----------------------------------------

SELECT SINGLE kunnr xcpdk adrnr FROM vbpa

INTO (disp-kunag,p_xcpdk,p_adrnr)

WHERE vbeln EQ it_vbap-vbeln

AND posnr EQ '000000'

AND parvw EQ 'WE' .

* Added by kanak on dt 29.09.2011

* Get the Forwarding Agent Information

*----------------------------------------

BREAK : KANAK.

SELECT SINGLE lifnr FROM vbpa

INTO disp-lifnr

WHERE vbeln EQ it_vbap-vbeln

AND parvw EQ 'SP' .

IF sy-subrc EQ 0 .

SELECT SINGLE name1 FROM LFA1

INTO disp-faname

WHERE lifnr = disp-lifnr.

ENDIF.

* end

* Get the Name,City of Ship To Party

*------------------------------------------------------

IF p_xcpdk NE 'X'.

SELECT SINGLE name1 name2 name3 name4 ort01 regio land1 lzone FROM kna1

INTO (disp-shnam,disp-shnam2,disp-shnam3,disp-shnam4,

disp-shcity,disp-sh_regio,disp-sh_land1,disp-sh_zone)

WHERE kunnr EQ disp-kunag .

ELSE.

SELECT SINGLE name1 name2 name3 name4 city1

region country transpzone FROM adrc

INTO (disp-shnam,disp-shnam2,disp-shnam3,disp-shnam4,

disp-shcity,disp-sh_regio,disp-sh_land1,disp-sh_zone)

WHERE addrnumber EQ p_adrnr .

* SELECT SINGLE TRANSPZONE FROM ZCTA_TZONE

* INTO DISP-SH_ZONE

* WHERE LAND1 EQ DISP-SH_LAND1

* AND REGIO EQ DISP-SH_REGIO.

ENDIF.

* Get the Name,City,Regio, Country of Sold To Party

*------------------------------------------------------

SELECT SINGLE name1 ort01 regio land1 lzone FROM kna1

INTO (disp-spnam,disp-spcity,disp-regio,

disp-land1,disp-zzlzone)

WHERE kunnr EQ disp-kunnr .

* Set as Document SO-Sales Order

*-----------------------------------

disp-document = 'SO' .

* Get Invoice & Delivery Data From Document Flow

*------------------------------------------------------

IF it_vbep-wmeng IS NOT INITIAL.

CLEAR : p_wmeng_inv,

p_wmeng_dlv,

p_act_so_qty.

p_act_so_qty = it_vbep-wmeng.

p_wmeng_inv = it_vbep-wmeng.

p_wmeng_dlv = it_vbep-wmeng.

LOOP AT it_vbfa WHERE vbelv EQ it_vbap-vbeln

AND posnv EQ it_vbap-posnr

AND flag NE 'X'.

IF it_vbfa-vbtyp_n EQ 'M'

OR it_vbfa-vbtyp_n EQ 'N'.

CHECK p_wmeng_inv IS NOT INITIAL.

ELSE.

CHECK p_wmeng_dlv IS NOT INITIAL.

ENDIF.

CASE it_vbfa-vbtyp_n.

* Delivery

*------------------

WHEN 'J' .

SELECT SINGLE * FROM lips

WHERE vbeln EQ it_vbfa-vbeln

AND posnr EQ it_vbfa-posnn .

IF sy-subrc EQ 0 .

disp-lfimg = disp-lfimg + lips-lfimg.

ENDIF .

* Invoice

*------------------

WHEN 'M' .

SELECT SINGLE * FROM vbrp

WHERE vbeln EQ it_vbfa-vbeln

AND posnr EQ it_vbfa-posnn .

IF sy-subrc EQ 0 .

CLEAR vbrk.

SELECT SINGLE * FROM vbrk WHERE vbeln EQ it_vbfa-vbeln

AND rfbsk NE 'E'

AND sfakn EQ space

AND fksto EQ space.

IF sy-subrc EQ 0 .

IF vbrk-fkart NE 'ZDIS'.

disp-fkimg = disp-fkimg + vbrp-fkimg .

ENDIF.

ENDIF .

ENDIF.

* Invoice Cancellation

*------------------------------

* WHEN 'N' .

* SELECT SINGLE * FROM VBRP

* WHERE VBELN EQ IT_VBFA-VBELN

* AND POSNR EQ IT_VBFA-POSNN .

* IF SY-SUBRC EQ 0 .

* CLEAR VBRK.

* SELECT SINGLE * FROM VBRK WHERE VBELN EQ IT_VBFA-VBELN.

* IF SY-SUBRC EQ 0 .

* IF VBRK-FKART NE 'ZDIS'.

* DISP-FKIMG = DISP-FKIMG - VBRP-FKIMG .

* ENDIF .

* ENDIF.

* ENDIF.

ENDCASE .

IF it_vbfa-vbtyp_n EQ 'M'

OR it_vbfa-vbtyp_n EQ 'N'.

disp-fkimg = disp-fkimg - p_propagate_inv.

IF disp-fkimg GT disp-wmeng.

disp-fkimg = disp-wmeng.

p_propagate_inv = p_wmeng_inv.

ELSE.

CLEAR p_propagate_inv.

ENDIF.

IF it_vbfa-vbtyp_n EQ 'M' .

p_wmeng_inv = p_act_so_qty - disp-fkimg.

ELSEIF it_vbfa-vbtyp_n EQ 'N'.

p_wmeng_inv = vbrp-fkimg + disp-fkimg.

ENDIF.

IF p_propagate_inv IS INITIAL.

it_vbfa-flag = 'X'.

ENDIF.

MODIFY it_vbfa TRANSPORTING flag.

ELSE.

disp-lfimg = disp-lfimg - p_propagate_dlv.

IF disp-lfimg GT disp-wmeng.

disp-lfimg = disp-wmeng.

p_propagate_dlv = p_wmeng_dlv.

ELSE.

CLEAR p_propagate_dlv.

ENDIF.

p_wmeng_dlv = p_act_so_qty - disp-lfimg.

IF p_propagate_dlv IS INITIAL.

it_vbfa-flag = 'X'.

ENDIF.

MODIFY it_vbfa TRANSPORTING flag.

ENDIF.

ENDLOOP .

ENDIF.

disp-balqty = disp-wmeng - disp-fkimg .

************************************************************************

tables :ZPAND_ORD.

data : it_ZPAND_ORD type standard table of

ZPAND_ORD with header line.

data : wa_ZPAND_ORD like ZPAND_ORD.

SELECT * FROM ZPAND_ORD

INTO CORRESPONDING FIELDS OF TABLE it_ZPAND_ORD

*FOR ALL ENTRIES IN disp

WHERE vbeln = it_vbap-vbeln.

*break-point.

*

*LOOP AT DISP.

READ TABLE IT_ZPAND_ORD INTO

wa_ZPAND_ORD WITH KEY vbeln = it_vbap-vbeln.

IF sy-subrc NE 0.

ZPAND_ORD-kunnr = disp-kunnr.

ZPAND_ORD-VBELN = it_vbap-VBELN.

ZPAND_ORD-BALQTY = disp-BALQTY.

ZPAND_ORD-AUDAT = s_audat-LOW.

ZPAND_ORD-AUDAT_H = s_audat-HIGH.

ZPAND_ORD-MATNR = disp-MATNR.

INSERT ZPAND_ORD .

ELSE.

UPDATE ZPAND_ORD SET

VBELN = it_vbap-VBELN

AUDAT = s_AUDAT-LOW

AUDAT_H = s_AUDAT-HIGH

BALQTY = disp-BALQTY

MATNR = disp-MATNR

wHERE kunnr = DISP-kunnr.

DELETE FROM ZPAND_ORD WHERE KUNNR EQ ' '.

*"FOR DELETING THE PAST DATE ENTRIES.

*

*IF wa_ZPAND_ORD-x LT SY-DATUM.

*DELETE zcust_outstnad.

*ENDIF.

*

ENDIF.

*ENDLOOP.

****************************************************************

SELECT SINGLE gbsta INTO disp-gbsta

FROM vbup

WHERE vbeln EQ disp-vbeln

AND posnr EQ disp-posnr.

SELECT SINGLE cmgst INTO disp-cmgst

FROM vbuk

WHERE vbeln EQ disp-vbeln .

IF disp-cmgst EQ 'B' OR disp-cmgst EQ 'C' .

disp-iconid = '@0A@' .

ELSEIF disp-cmgst EQ 'D' .

disp-iconid = '@09@' .

ELSE.

disp-iconid = '@08@' .

ENDIF .

PERFORM get_description .

APPEND disp .

CLEAR disp .

ENDLOOP .

*added commision agent on request of Mr Bhavesh Patel

*changed by Devendra Rane 14.07.2008

LOOP AT disp.

SELECT SINGLE kunnr FROM vbpa

INTO disp-agent

WHERE vbeln EQ disp-vbeln

AND parvw EQ 'ZA'.

SELECT SINGLE name1 FROM kna1 INTO disp-name1

WHERE kunnr = disp-agent.

"FOR RATE PER BAG FIELD BY MEGHNA

SELECT SINGLE KNUMV INTO DISP-KNUMV

FROM VBAK

WHERE VBELN = DISP-VBELN.

SELECT SINGLE KBETR INTO DISP-KBETR

FROM KONV

WHERE KNUMV = DISP-KNUMV

AND KSCHL IN ('ZB01','ZB00').

MODIFY disp INDEX sy-tabix TRANSPORTING agent name1 KBETR.

CLEAR disp.

ENDLOOP.

*end addition

ENDFORM. " get_so

*&---------------------------------------------------------------------*

*& Form get_po

*&---------------------------------------------------------------------*

FORM get_po .

DATA : it_ekbe LIKE ekbe OCCURS 0 WITH HEADER LINE .

DATA : it_vbfa LIKE vbfa OCCURS 0 WITH HEADER LINE .

DATA : BEGIN OF it_ekko OCCURS 0 ,

ebeln LIKE ekko-ebeln ,

ebelp LIKE ekpo-ebelp ,

kunnr LIKE kna1-kunnr ,

kunag LIKE kna1-kunnr ,

vkorg LIKE vbak-vkorg ,

vtweg LIKE vbak-vtweg ,

spart LIKE vbak-spart ,

vstel LIKE ekpv-vstel ,

route LIKE ekpv-route ,

END OF it_ekko .

DATA : it_ekpo LIKE ekpo OCCURS 0 WITH HEADER LINE .

DATA : it_ekkn LIKE ekkn OCCURS 0 WITH HEADER LINE .

DATA : it_ekpv LIKE ekpv OCCURS 0 WITH HEADER LINE .

* Get the Purchase Header Data

*-------------------------------

SELECT a~ebeln b~vstel b~kunnr b~kunag

b~vkorg b~vtweg b~spart b~ebelp

b~route

INTO CORRESPONDING FIELDS OF TABLE it_ekko

FROM ekko AS a

INNER JOIN

ekpv AS b

ON a~mandt EQ b~mandt

AND a~ebeln EQ b~ebeln

WHERE

a~ebeln IN s_ebeln

AND

(

( a~bsart IN ('ZSTF','ZSTD','ZSTC','ZCJP')

* AND a~frgke EQ 'R'

)

OR

a~bsart IN ('ZSTE')

)

AND a~reswk IN s_werks

AND a~bedat IN s_audat " HCG2006

AND b~kunnr IN s_kunnr

AND b~vkorg IN s_vkorg

AND b~vtweg IN s_vtweg

AND b~spart IN s_spart .

CHECK NOT it_ekko[] IS INITIAL.

* Get the Purchase Details Data

*-------------------------------

SELECT * FROM ekpo CLIENT SPECIFIED

INTO CORRESPONDING FIELDS OF TABLE it_ekpo

FOR ALL ENTRIES IN it_ekko

WHERE mandt EQ sy-mandt

AND ebeln EQ it_ekko-ebeln

AND ebelp EQ it_ekko-ebelp

AND elikz EQ space.

SELECT * FROM ekkn CLIENT SPECIFIED

INTO TABLE it_ekkn

FOR ALL ENTRIES IN it_ekko

WHERE mandt EQ sy-mandt

AND ebeln EQ it_ekko-ebeln

AND ebelp EQ it_ekko-ebelp .

SELECT * FROM ekpv CLIENT SPECIFIED

INTO TABLE it_ekpv

FOR ALL ENTRIES IN it_ekko

WHERE mandt EQ sy-mandt

AND ebeln EQ it_ekko-ebeln

AND ebelp EQ it_ekko-ebelp .

LOOP AT it_ekko .

READ TABLE it_ekpo WITH KEY ebeln = it_ekko-ebeln

ebelp = it_ekko-ebelp .

CHECK sy-subrc EQ 0 .

MOVE : it_ekko-ebeln TO disp-ebeln ,

it_ekko-ebelp TO disp-ebelp ,

it_ekko-kunnr TO disp-kunnr ,

it_ekko-kunnr TO disp-kunag ,

it_ekko-vkorg TO disp-vkorg ,

it_ekko-vtweg TO disp-vtweg ,

it_ekko-spart TO disp-spart ,

it_ekko-vstel TO disp-werks ,

it_ekpo-matnr TO disp-matnr ,

it_ekpo-menge TO disp-kwmeng ,

it_ekpo-menge TO disp-wmeng ,

it_ekko-route TO disp-route .

READ TABLE it_ekkn WITH KEY ebeln = it_ekko-ebeln

ebelp = it_ekko-ebelp .

IF sy-subrc EQ 0 .

SELECT SINGLE kunnr INTO disp-kunnr

FROM vbak

WHERE vbeln EQ it_ekkn-vbeln .

ELSE .

READ TABLE it_ekpv WITH KEY ebeln = it_ekko-ebeln

ebelp = it_ekko-ebelp .

IF sy-subrc EQ 0 .

disp-kunnr = it_ekpv-kunnr .

ENDIF.

ENDIF .

* Get the District,Taluka,Village Data

*-------------------------------------------------------------

SELECT SINGLE kvgr1 kvgr2 kvgr3 FROM knvv

INTO (disp-kvgr1,disp-kvgr2,disp-kvgr3)

WHERE kunnr EQ disp-kunag

AND vkorg EQ disp-vkorg

AND vtweg EQ disp-vtweg

AND spart EQ disp-spart .

* Get the name,City,Region,Country of Sold to Party

*-------------------------------------------------------------

SELECT SINGLE name1 ort01 regio land1 lzone FROM kna1

INTO (disp-spnam,disp-spcity,disp-regio,

disp-land1,disp-zzlzone)

WHERE kunnr EQ disp-kunnr .

* Get the name,City of Ship to Party

*-------------------------------------------------------------

SELECT SINGLE name1 ort01 FROM kna1

INTO (disp-shnam,disp-shcity)

WHERE kunnr EQ disp-kunag .

* Set as Document SO-Sales Order

*-----------------------------------

disp-document = 'PO' .

SELECT * FROM ekbe

INTO CORRESPONDING FIELDS OF TABLE it_ekbe

WHERE ebeln EQ disp-ebeln

AND ebelp EQ disp-ebelp

AND bewtp EQ 'L'

AND menge NE 0 .

* Get Invoice & Delivery Data From Document Flow

*------------------------------------------------------

LOOP AT it_ekbe .

disp-lfimg = disp-lfimg + it_ekbe-menge.

SELECT * FROM vbfa CLIENT SPECIFIED

INTO CORRESPONDING FIELDS OF TABLE it_vbfa

WHERE mandt EQ sy-mandt

AND vbelv EQ it_ekbe-belnr

AND posnv EQ it_ekbe-buzei

AND rfmng NE 0

AND vbtyp_n EQ 'U' .

LOOP AT it_vbfa .

SELECT SINGLE * FROM vbrk

WHERE vbeln EQ it_vbfa-vbeln

AND rfbsk NE 'E'.

CHECK sy-subrc EQ 0.

SELECT SINGLE * FROM vbrp

WHERE vbeln EQ it_vbfa-vbeln

AND posnr EQ it_vbfa-posnn .

IF sy-subrc EQ 0 .

disp-fkimg = disp-fkimg + vbrp-fkimg .

ENDIF .

ENDLOOP .

ENDLOOP .

disp-balqty = disp-kwmeng - disp-fkimg .

* Get the Sales Order Number as per the PO Number

*---------------------------------------------------

SELECT SINGLE vbelv posnv FROM vbfa

INTO (disp-vbeln, disp-posnr)

WHERE vbeln EQ disp-ebeln

AND posnn EQ disp-ebelp

AND vbtyp_v EQ 'C'

AND vbtyp_n EQ 'V'.

IF sy-subrc EQ 0.

SELECT SINGLE vtweg auart audat erzet FROM vbak

INTO (disp-vtweg, disp-auart, disp-audat, disp-erzet)

WHERE vbeln EQ disp-vbeln.

ENDIF.

PERFORM get_description .

APPEND disp .

CLEAR disp .

ENDLOOP .

ENDFORM. " get_po

*&---------------------------------------------------------------------*

*& Form get_dms

*&---------------------------------------------------------------------*

FORM get_dms .

DATA : it_order LIKE zcta_order OCCURS 0 WITH HEADER LINE .

* Get the Orders From DMS that are still pending for SAP Order

*----------------------------------------------------------------

SELECT * FROM zcta_order

INTO CORRESPONDING FIELDS OF TABLE it_order

WHERE oddi_no EQ space

AND tflag EQ '0' .

LOOP AT it_order .

MOVE : it_order-dealer_code TO disp-kunnr ,

it_order-cons_code TO disp-kunag ,

it_order-mat_code TO disp-matnr ,

it_order-order_qty TO disp-kwmeng ,

it_order-order_qty TO disp-wmeng ,

'DMS' TO disp-document .

SELECT SINGLE vkorg FROM tvkbz INTO disp-vkorg

WHERE vtweg EQ '10'

AND vkbur EQ it_order-ccc_code .

disp-vtweg = '10' .

disp-spart = '10' .

* Get the District,Taluka,Village Data

*-------------------------------------------------------------

SELECT SINGLE kvgr1 kvgr2 kvgr3 FROM knvv

INTO (disp-kvgr1,disp-kvgr2,disp-kvgr3)

WHERE kunnr EQ disp-kunnr

AND vkorg EQ disp-vkorg

AND vtweg EQ disp-vtweg

AND spart EQ disp-spart .

* Get the name,City,Region,Country of Sold to Party

*-------------------------------------------------------------

SELECT SINGLE name1 ort01 regio land1 lzone FROM kna1

INTO (disp-spnam,disp-spcity,disp-regio,

disp-land1,disp-zzlzone)

WHERE kunnr EQ disp-kunnr .

* Get the name,City of Ship to Party

*-------------------------------------------------------------

SELECT SINGLE name1 ort01 FROM kna1

INTO (disp-shnam,disp-shcity)

WHERE kunnr EQ disp-kunag .

PERFORM get_description .

APPEND disp .

CLEAR disp .

ENDLOOP .

ENDFORM. " get_dms

*&---------------------------------------------------------------------*

*& Form get_description

*&---------------------------------------------------------------------*

FORM get_description .

* Plant Description

*-------------------

SELECT SINGLE name1 INTO disp-wenam

FROM t001w CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND werks EQ disp-werks .

* Sales Organisation Description

*----------------------------------

SELECT SINGLE vtext INTO disp-vtext

FROM tvkot CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND vkorg EQ disp-vkorg .

* Distribution Channel Description

*-----------------------------------

SELECT SINGLE vtext INTO disp-vttxt

FROM tvtwt CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND vtweg EQ disp-vtweg .

* Division Description

*-------------------

SELECT SINGLE vtext INTO disp-sptxt

FROM tspat CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND spart EQ disp-spart .

* District Description

*-------------------

SELECT SINGLE bezei INTO disp-k1txt

FROM tvv1t CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND kvgr1 EQ disp-kvgr1 .

* Taluka Description

*-------------------

SELECT SINGLE bezei INTO disp-k2txt

FROM tvv2t CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND kvgr2 EQ disp-kvgr2 .

* Village Description

*-------------------

SELECT SINGLE bezei INTO disp-k3txt

FROM tvv3t CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND kvgr3 EQ disp-kvgr3 .

** Transportation Zone Description

**----------------------------------

* SELECT SINGLE vtext INTO disp-lztxt

* FROM tzont CLIENT SPECIFIED

* WHERE mandt EQ sy-mandt

* AND spras EQ sy-langu

* AND land1 EQ disp-land1

* AND zone1 EQ disp-zzlzone .

* Transporter Zone Description(SP)

*---------------------------------

SELECT SINGLE vtext INTO disp-lztxt

FROM zcta_tzone

WHERE land1 EQ disp-land1

AND regio EQ disp-regio

AND transpzone EQ disp-zzlzone.

* Transporter Zone Description(SH)

*---------------------------------

SELECT SINGLE vtext INTO disp-sh_lztxt

FROM zcta_tzone

WHERE land1 EQ disp-sh_land1

AND regio EQ disp-sh_regio

AND transpzone EQ disp-sh_zone.

* Region Description

*----------------------------

SELECT SINGLE bezei INTO disp-regtx

FROM t005u CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND land1 EQ disp-land1

AND bland EQ disp-regio .

* Country Description

*----------------------------

SELECT SINGLE landx INTO disp-landx

FROM t005t CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND land1 EQ disp-land1 .

* Sales Office Description

*----------------------------

SELECT SINGLE bezei INTO disp-vkbtx

FROM tvkbt CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND vkbur EQ disp-vkbur .

* Route Description

*----------------------------

SELECT SINGLE bezei INTO disp-rt_bezei

FROM tvrot CLIENT SPECIFIED

WHERE mandt EQ sy-mandt

AND spras EQ sy-langu

AND route EQ disp-route .

* Credit Status Desc.

*-----------------------

SELECT SINGLE * FROM dd07l

WHERE domname EQ 'CMGST'

AND domvalue_l EQ disp-cmgst .

IF sy-subrc EQ 0 .

SELECT SINGLE ddtext INTO disp-crtxt

FROM dd07t

WHERE domname EQ 'CMGST'

AND ddlanguage EQ sy-langu

AND valpos EQ dd07l-valpos .

ENDIF .

ENDFORM. " get_description

*&---------------------------------------------------------------------*

*& Form initialise_fieldtab

*&---------------------------------------------------------------------*

FORM initialise_fieldtab .

tabname = 'DISP'.

PERFORM:

append_fieldcat USING 1 'WERKS' 'Plant' 10,

append_fieldcat USING 1 'ICONID' 'Status' 10,

append_fieldcat USING 2 'WENAM' 'Plant Desc.' 15,

append_fieldcat USING 3 'VKORG' 'Sales Org' 10,

append_fieldcat USING 4 'VTEXT' 'Sales Org.Desc ' 15,

append_fieldcat USING 5 'VTWEG' 'Dist.channel' 10,

append_fieldcat USING 6 'VTTXT' 'Dist.Channel ' 15,

append_fieldcat USING 7 'VKBUR' 'Sales office' 10,

append_fieldcat USING 8 'VKBTX' 'Sales Office' 15,

append_fieldcat USING 9 'SPART' 'Division' 10,

append_fieldcat USING 10 'SPTXT' 'Division' 15,

append_fieldcat USING 11 'KVGR1' 'District' 10,

append_fieldcat USING 12 'K1TXT' 'District' 15,

append_fieldcat USING 13 'KVGR2' 'Taluka' 10,

append_fieldcat USING 14 'K2TXT' 'Taluka' 15,

append_fieldcat USING 15 'KVGR3' 'Village' 10,

append_fieldcat USING 16 'K3TXT' 'Village' 15,

append_fieldcat USING 17 'ZZLZONE' 'Trans.Zone(SP)' 10,

append_fieldcat USING 18 'LZTXT' 'Zone Desc.(SP)' 15,

append_fieldcat USING 19 'REGIO' 'Region Code' 15,

append_fieldcat USING 20 'REGTX' 'Region ' 15,

append_fieldcat USING 21 'LAND1' 'Country Code' 15,

append_fieldcat USING 22 'LANDX' 'Country' 15,

append_fieldcat USING 23 'MATNR' 'Material' 15,

append_fieldcat USING 24 'KUNNR' 'Sold-Party Code' 15,

append_fieldcat USING 25 'SPNAM' 'Sold To party ' 15,

append_fieldcat USING 26 'SPCITY' 'Sold-Party City' 15,

append_fieldcat USING 27 'KUNAG' 'Ship-Party Code' 15,

append_fieldcat USING 28 'SHNAM' 'Ship To Party ' 15,

append_fieldcat USING 29 'SHCITY' 'Ship-Party City' 15,

append_fieldcat USING 30 'VBELN' 'Sales Doc No' 15,

append_fieldcat USING 31 'POSNR' 'Item No' 15,

append_fieldcat USING 32 'ETENR' 'Sch.Line Item' 15,

append_fieldcat USING 33 'EDATU' 'Sch.Line Date' 15,

append_fieldcat USING 34 'EBELN' 'PO No' 15,

append_fieldcat USING 35 'EBELP' 'PO Item No' 15,

append_fieldcat USING 36 'KWMENG' 'Order Qty' 15,

append_fieldcat USING 37 'WMENG' 'Sch.Order Qty' 15,

append_fieldcat USING 38 'LFIMG' 'Delivery Qty' 15,

append_fieldcat USING 39 'FKIMG' 'Invoice Qty' 15,

append_fieldcat USING 40 'BALQTY' 'Balance Qty' 15,

append_fieldcat USING 41 'CMGST' 'Ov.all.Cr.status' 15,

append_fieldcat USING 42 'CRTXT' 'Cr.Limit Desc.' 15,

append_fieldcat USING 43 'SH_ZONE' 'Trans.Zone(SH)' 10,

append_fieldcat USING 44 'SH_LZTXT' 'Zone Desc.(SH)' 15,

append_fieldcat USING 45 'AUDAT' 'SO.Date' 15,

append_fieldcat USING 46 'DOCUMENT' 'Document' 15,

append_fieldcat USING 47 'IMM_TD_KWMENG' 'Imm.Trade Qty' 15,

append_fieldcat USING 48 'SCH_TD_KWMENG' 'Sch.Trade Qty.' 15,

append_fieldcat USING 49 'IMM_NT_KWMENG' 'Imm.Non-Trade Qty' 10,

append_fieldcat USING 50 'SCH_NT_KWMENG' 'Sch.Non-Trade Qty' 15,

append_fieldcat USING 51 'TOT_KWMENG' 'Total(Trd+Non.Trd)' 15,

append_fieldcat USING 52 'ST_KWMENG' 'Stk Trsf.Qty' 15,

append_fieldcat USING 53 'MVGR1' 'Type Code' 15,

append_fieldcat USING 54 'MVGR1_TEXT' 'Type' 15,

append_fieldcat USING 55 'MVGR2' 'Grade Code' 15,

append_fieldcat USING 56 'MVGR2_TEXT' 'Grade' 15,

append_fieldcat USING 57 'MVGR3' 'Packing Code' 15,

append_fieldcat USING 58 'MVGR3_TEXT' 'Packing' 15,

append_fieldcat USING 59 'MVGR4' 'Packing Color Code' 15,

append_fieldcat USING 60 'MVGR4_TEXT' 'Packing Color' 15,

append_fieldcat USING 61 'MVGR5' 'Packing Size Code' 15,

append_fieldcat USING 62 'MVGR5_TEXT' 'Packing Size' 15,

append_fieldcat USING 63 'AUART' 'Sales Doc Type' 15,

append_fieldcat USING 62 'ROUTE' 'Route Code' 15,

append_fieldcat USING 63 'RT_BEZEI' 'Route' 15,

append_fieldcat USING 64 'GBSTA' 'Order Completed' 15,

append_fieldcat USING 65 'COMPL_FLAG' 'Completed Flag' 15,

append_fieldcat USING 66 'SHNAM2' 'Address2' 15,

append_fieldcat USING 67 'SHNAM3' 'Address3' 15,

append_fieldcat USING 68 'SHNAM4' 'Address4' 15,

append_fieldcat USING 69 'ERZET' 'Entry Time' 15,

append_fieldcat USING 70 'DIFF_DATE' 'Day Delay' 15,

append_fieldcat USING 70 'DURATION' 'Order Duration' 15,

append_fieldcat USING 71 'NAME1' 'Com Agent' 15,

APPEND_FIELDCAT USING 72 'KBETR' 'Rate Per Bag' 15 ,

* ADDED BY KANAK DT 20.09.2011

append_fieldcat USING 73 'LIFNR' 'Forwarding Agent Code' 15,

append_fieldcat USING 74 'FANAME' 'Forwarding Agent Name ' 15.

* END

ENDFORM. " initialise_fieldtab

*&---------------------------------------------------------------------*

*& Form fill_init_audat

*&---------------------------------------------------------------------*

FORM fill_init_audat .

s_audat-high = sy-datum.

s_audat-low = s_audat-high.

s_audat-low+6(2) = '01'.

s_audat-sign = 'I'.

s_audat-option = 'BT'.

APPEND s_audat.

ENDFORM. " fill_init_audat

*&---------------------------------------------------------------------*

*& Form segregate_dist_chann_qty

*&---------------------------------------------------------------------*

FORM segregate_dist_chann_qty .

LOOP AT disp.

SHIFT DISP-KUNNR LEFT DELETING LEADING '0'. " "to remove prceding zereos from party code by meghna

CASE disp-vtweg .

WHEN '10'.

IF disp-audat EQ disp-edatu.

disp-imm_td_kwmeng = disp-kwmeng.

ELSE.

disp-sch_td_kwmeng = disp-kwmeng.

ENDIF.

WHEN '20'.

IF disp-audat EQ disp-edatu.

disp-imm_nt_kwmeng = disp-kwmeng.

ELSE.

disp-sch_nt_kwmeng = disp-kwmeng.

ENDIF.

WHEN '30'.

disp-st_kwmeng = disp-kwmeng.

ENDCASE.

disp-tot_kwmeng = disp-imm_td_kwmeng + disp-sch_td_kwmeng

+ disp-imm_nt_kwmeng + disp-sch_nt_kwmeng.

MODIFY disp.

CLEAR disp.

ENDLOOP.

ENDFORM. " segregate_dist_chann_qty

*&---------------------------------------------------------------------*

*& Form get_sd_matgroups

*&---------------------------------------------------------------------*

FORM get_sd_matgroups .

LOOP AT disp.

CALL FUNCTION 'ZCFM_SD_MATGROUPS'

EXPORTING

matnr = disp-matnr

vkorg = disp-vkorg

vtweg = disp-vtweg

IMPORTING

mvgr1 = disp-mvgr1

mvgr1_text = disp-mvgr1_text

mvgr2 = disp-mvgr2

mvgr2_text = disp-mvgr2_text

mvgr3 = disp-mvgr3

mvgr3_text = disp-mvgr3_text

mvgr4 = disp-mvgr4

mvgr4_text = disp-mvgr4_text

mvgr5 = disp-mvgr5

mvgr5_text = disp-mvgr5_text.

MODIFY disp.

CLEAR disp.

ENDLOOP.

ENDFORM. " get_sd_matgroups

*&---------------------------------------------------------------------*

*& Form DELETE_DUP_ORDER_QTY

*&---------------------------------------------------------------------*

FORM delete_dup_order_qty .

DATA : p_prv_vbeln LIKE vbak-vbeln,

p_prv_posnr LIKE vbap-posnr.

DATA : p_start_flag(1).

DATA : p_tot_kwmeng LIKE vbap-kwmeng,

p_tot_fkimg LIKE vbrp-fkimg.

DATA : p_wa_disp LIKE LINE OF disp.

SORT disp BY vbeln posnr.

LOOP AT disp.

CLEAR p_start_flag.

IF disp-vbeln NE p_prv_vbeln

OR disp-posnr NE p_prv_posnr.

p_start_flag = 'X'.

IF p_prv_vbeln IS NOT INITIAL

AND p_prv_posnr IS NOT INITIAL.

CLEAR p_wa_disp.

IF p_tot_kwmeng EQ p_tot_fkimg.

p_wa_disp-compl_flag = 'X'.

MODIFY disp FROM p_wa_disp TRANSPORTING compl_flag

WHERE vbeln EQ p_prv_vbeln

AND posnr EQ p_prv_posnr.

ENDIF.

CLEAR: p_tot_kwmeng, p_tot_fkimg.

ENDIF.

ENDIF.

p_tot_kwmeng = p_tot_kwmeng + disp-kwmeng.

p_tot_fkimg = p_tot_fkimg + disp-fkimg.

IF p_start_flag NE 'X'.

CLEAR disp-kwmeng.

ENDIF.

p_prv_vbeln = disp-vbeln.

p_prv_posnr = disp-posnr .

MODIFY disp.

ENDLOOP.

ENDFORM. " DELETE_DUP_ORDER_QTY

**************************************************************

* FORM FILL SCHEDULE DATE

**************************************************************

FORM fill_schedule_date.

CLEAR s_edatu.

IF ps_parm = '1'.

s_edatu-high = s_audat-high.

s_edatu-low = s_audat-low.

s_edatu-sign = 'I'.

s_edatu-option = 'BT'.

APPEND s_edatu.

ELSE.

s_edatu-high = '99991231'.

s_edatu-low = s_audat-low.

s_edatu-sign = 'I'.

s_edatu-option = 'BT'.

APPEND s_edatu.

ENDIF.

ENDFORM. "FILL_SCHEDULE_DATE

*********************************************************************

* CHECK_PLANT_DATA FOR AUTHORITY CHECK OF PLANT

*********************************************************************

FORM check_plant_data.

DATA: usergroups TYPE TABLE OF usgroups WITH HEADER LINE.

DATA: BEGIN OF auth_tab OCCURS 0.

INCLUDE STRUCTURE usvalues.

DATA: END OF auth_tab.

DATA: BEGIN OF auth_tab_tmp OCCURS 0.

INCLUDE STRUCTURE usvalues.

DATA: END OF auth_tab_tmp.

DATA plant_text(200).

DATA : BEGIN OF it_plant OCCURS 0,

werks LIKE vbrp-werks,

END OF it_plant.

DATA tabix LIKE sy-tabix.

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string.

CALL FUNCTION 'SUSR_USER_GROUP_GROUPS_GET'

EXPORTING

bname = sy-uname

TABLES

usergroups = usergroups.

IF usergroups-usergroup EQ 'ZDEP'.

CALL FUNCTION 'SUSR_USER_AUTH_FOR_OBJ_GET'

EXPORTING

user_name = sy-uname

sel_object = 'V_LIKP_VST'

TABLES

values = auth_tab

EXCEPTIONS

user_name_not_exist = 1

not_authorized = 2

internal_error = 3

OTHERS = 4.

GET PARAMETER ID 'ZPLANT' FIELD plant_text .

SPLIT plant_text AT ',' INTO: str1 str2 str3,

TABLE it_plant.

IF it_plant[] IS INITIAL.

ELSE.

IF s_werks[] IS INITIAL.

LOOP AT it_plant.

s_werks-sign = 'I'.

s_werks-option = 'EQ'.

s_werks-low = it_plant-werks.

APPEND s_werks.

ENDLOOP.

ELSE.

LOOP AT s_werks.

IF s_werks-option = 'CP' OR

s_werks-option = 'BT'.

DELETE s_werks.

CLEAR s_werks.

ELSE.

IF s_werks-option = 'EQ'.

IF plant_text CS s_werks-low.

ELSE.

DELETE s_werks.

CLEAR s_werks.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

IF s_werks[] IS INITIAL.

LOOP AT it_plant.

s_werks-sign = 'I'.

s_werks-option = 'EQ'.

s_werks-low = it_plant-werks.

APPEND s_werks.

ENDLOOP.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. "CHECK_PLANT_DATA

*&---------------------------------------------------------------------*

*& Form convert_date_to_external

*&---------------------------------------------------------------------*

FORM convert_date_to_external .

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

date_internal = s_audat-low

IMPORTING

date_external = date-low.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

date_internal = s_audat-high

IMPORTING

date_external = date-high.

ENDFORM. " convert_date_to_external

*&--------------------------------------------------------------------*

*& Form set_alv_user_command_form

*&--------------------------------------------------------------------*

FORM set_alv_user_command_form .

user_command = 'USER_COMMAND'.

ENDFORM. "set_alv_user_command_form

*---------------------------------------------------------------------*

* FORM user_command *

*---------------------------------------------------------------------*

FORM user_command USING rs_comm LIKE sy-ucomm

ls_selfield TYPE slis_selfield.

CHECK ls_selfield-value IS NOT INITIAL.

CHECK rs_comm EQ '&IC1'.

CASE ls_selfield-fieldname.

WHEN 'VBELN'.

SET PARAMETER ID 'VF' FIELD ls_selfield-value.

CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.

ENDCASE.

ENDFORM. "user_command

*&--------------------------------------------------------------------*

*& Form form_get_date_range

*&--------------------------------------------------------------------*

FORM form_get_date_range CHANGING p_text .

DATA: p_fr_date(10),

p_to_date(10).

* CHECK P_FKDAT-LOW IS NOT INITIAL.

* CONCATENATE P_FKDAT-LOW+6(2) P_FKDAT-LOW+4(2) P_FKDAT-LOW(4)

* INTO P_FR_DATE SEPARATED BY '.'.

CONCATENATE 'Order Date : ' date-low ' To ' date-high INTO p_text SEPARATED BY space.

* CHECK P_FKDAT-HIGH IS NOT INITIAL.

* CONCATENATE P_FKDAT-HIGH+6(2) P_FKDAT-HIGH+4(2) P_FKDAT-HIGH(4)

* INTO P_TO_DATE SEPARATED BY '.'.

* CONCATENATE P_TEXT ' To ' P_TO_DATE INTO P_TEXT SEPARATED BY SPACE.

ENDFORM. "form_get_date_range

*&---------------------------------------------------------------------*

*& Form get_time_difference

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_ITAB_DTDIS text

* -->P_ITAB_UZDIS1 text

* -->P_ITAB_DAREG text

* -->P_ITAB_UAREG text

* -->P_ITAB_DEL_TR_TIME text

*----------------------------------------------------------------------*

FORM get_time_difference USING p_itab_dtdis

p_itab_uzdis1

p_itab_dareg

p_itab_uareg

p_itab_del_tr_time.

CALL FUNCTION 'SD_CALC_DURATION_FROM_DATETIME'

EXPORTING

i_date1 = p_itab_dtdis

i_time1 = p_itab_uzdis1

i_date2 = p_itab_dareg

i_time2 = p_itab_uareg

IMPORTING

e_tdiff = p_itab_del_tr_time.

ENDFORM. " get_time_difference

*&---------------------------------------------------------------------*

*& Form get_order_delay_duration

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM get_order_delay_duration .

LOOP AT disp.

IF ( disp-erdat IS NOT INITIAL ) AND ( disp-erzet IS NOT INITIAL ).

PERFORM get_time_difference

USING

disp-erdat

disp-erzet

sy-datum

sy-uzeit

disp-duration.

MODIFY disp.

ENDIF.

CLEAR disp.

ENDLOOP.

ENDFORM. " get_order_delay_duration

Regards,

Rihan

SAP-abaper