Skip to Content
0
Former Member
Jan 28, 2009 at 06:42 PM

Problem is When i click the record in alv report it has to go to Va02 tran

26 Views

Hi Everyone,

When i click on sales order number it has to go to transaction code Va02 for that i wrote code as like this....

&----


*& Report ZOPEN_SALES_ORDER

*&

&----


*&

*&

&----


Report ZOPEN_SALES_ORDER1.

TYPE-POOLs : slis.

tables:kna1,mara.

DATA : FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA : IMPORT_VARIANT LIKE DISVARIANT.

DATA : XREPID LIKE SY-REPID.

DATA : LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA : P_SORT TYPE STANDARD TABLE OF SLIS_SORTINFO_ALV.

DATA : I_EVENTS TYPE SLIS_T_EVENT,

I_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,

T_REPID LIKE SY-REPID.

TYPES: BEGIN OF ty_report.

INCLUDE STRUCTURE BAPIORDERS.

TYPES: KDMAT TYPE VBAP-KDMAT,

aedat TYPE sy-datum,

MENGE TYPE BAPIORDERS-DLV_QTY,

END OF ty_report.

DATA: it_report TYPE STANDARD TABLE OF ty_report with HEADER LINE,

wa_report TYPE ty_report.

data: cust type BAPI1007-CUSTOMER,

p_sales type BAPIORDERS-SALES_ORG,

vbeln type vbap-vbeln.

selection-screen begin of block bk1 with frame title text-001.

PARAMETERS :p_cust type BAPI1007-CUSTOMER .

*PARAMETERS p_sales type BAPIORDERS-SALES_ORG .

PARAMETERS: p_matnr type mara-matnr.

parameters: p_sd_doc type BAPIORDERS-SD_DOC.

PARAMETERS: p_date type BAPIORDERS-REQ_DATE.

PARAMETERS: p_plant type vbap-werks.

*PARAMETERS P_KDMAT TYPE VBAP-KDMAT.

*PARAMETERS P_WERKS TYPE VBAP-WERKS.

*PARAMETERS P_PO TYPE EKKO-ebeln.

selection-screen end of block bk1.

at SELECTION-SCREEN .

if P_cust is INITIAL and p_matnr is INITIAL and P_sd_doc is INITIAL

and P_date is INITIAL and p_plant is INITIAL. .

message e000(0) with 'Please Fill At Least One Field '.

endif.

If p_cust is not INITIAL .

select single VKORG from vbak into p_sales where kunnr eq p_cust.

  • message 'Execute The Repport' Type 'E'.

elseif p_matnr is not INITIAL .

clear p_cust.

clear p_sales.

select single VBELN from vbap into vbeln where matnr eq p_matnr.

if vbeln is not INITIAL.

SELECT single kunnr vkorg from vbak into (cust,p_sales) where vbeln eq vbeln.

p_cust = cust.

p_sales = p_sales.

endif.

elseif P_sd_doc is not INITIAL.

clear p_cust.

clear p_sales.

SELECT single kunnr vkorg from vbak into (cust,p_sales) where vbeln eq P_SD_DOC.

p_cust = cust.

p_sales = p_sales.

elseif p_date is not initial.

clear vbeln.

clear p_cust.

clear p_sales.

select single VBELN from vbep into vbeln where EDATU eq p_date and POSNR = '10' and etenr = '0001'.

if vbeln is not INITIAL.

SELECT single kunnr vkorg from vbak into (cust,p_sales) where vbeln eq vbeln.

p_cust = cust.

p_sales = p_sales.

endif.

elseif p_plant is not INITIAL.

clear vbeln.

clear p_cust.

clear p_sales.

select single VBELN from vbap into vbeln where werks eq p_plant.

if vbeln is not INITIAL.

SELECT single kunnr vkorg from vbak into (cust,p_sales) where vbeln eq vbeln.

p_cust = cust.

p_sales = p_sales.

endif.

endif.

INITIALIZATION.

T_REPID = SY-REPID.

CONSTANTS:C_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.

START-OF-SELECTION.

CALL FUNCTION 'BAPI_SALESORDER_GETLIST'

EXPORTING

CUSTOMER_NUMBER = p_cust

SALES_ORGANIZATION = p_sales

MATERIAL = p_matnr

DOCUMENT_DATE = p_date

  • DOCUMENT_DATE_TO =

  • PURCHASE_ORDER =

  • TRANSACTION_GROUP = 0

  • PURCHASE_ORDER_NUMBER =

  • MATERIAL_EVG =

  • IMPORTING

  • RETURN =

TABLES

SALES_ORDERS = it_report

.

LOOP AT it_report INTO wa_report.

SELECT SINGLE KDMAT INTO wa_report-KDMAT FROM VBAP

WHERE VBELN = wa_report-SD_DOC AND POSNR = wa_report-ITM_NUMBER.

SELECT SINGLE aedat FROM ekko Into wa_report-aedat

where ebeln = wa_report-PURCH_NO.

wa_report-menge = wa_report-REQ_QTY - wa_report-dlv_qty.

  • select single edatu from vbep into wa_

MODIFY it_report FROM wa_report INDEX SY-TABIX.

ENDLOOP.

PERFORM DISPLAY.

FORM DISPLAY .

PERFORM FIELDCAT_INIT USING FIELDCAT[].

PERFORM LAYOUT_BUILD USING LAYOUT.

PERFORM EVENTTAB_BUILD USING I_EVENTS.

PERFORM COMMENT_BUILD USING I_LIST_TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = T_REPID

  • I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IT_FIELDCAT = FIELDCAT

IS_LAYOUT = LAYOUT

IT_EVENTS = I_EVENTS[]

I_DEFAULT = 'X'

I_SAVE = 'A'

TABLES

T_OUTTAB = it_report

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " DISPLAY

FORM FIELDCAT_INIT USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA : CNTR TYPE I.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'SD_DOC'.

LS_FIELDCAT-SELTEXT_L = 'Sales Order'.

LS_FIELDCAT-HOTSPOT = 'X'. " HAND APPEARS.

LS_FIELDCAT-KEY = 'X'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'ITM_NUMBER'.

LS_FIELDCAT-SELTEXT_L = 'Item Number'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'SOLD_TO'.

LS_FIELDCAT-SELTEXT_L = 'Customer Number'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'NAME'.

LS_FIELDCAT-SELTEXT_L = 'Customer NAME'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'MATERIAL'.

LS_FIELDCAT-SELTEXT_L = 'Material'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'SHORT_TEXT'.

LS_FIELDCAT-SELTEXT_L = 'Material Short Text'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'KDMAT'.

LS_FIELDCAT-SELTEXT_L = 'Customer Material'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'PLANT'.

LS_FIELDCAT-SELTEXT_L = 'Plant'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'PURCH_NO'.

LS_FIELDCAT-SELTEXT_L = 'Purchase Order Nuber'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'AEDAT'.

LS_FIELDCAT-SELTEXT_L = 'PO Date'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'REQ_QTY'.

LS_FIELDCAT-SELTEXT_L = 'Sales Order Quantity'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'REQ_DATE'.

LS_FIELDCAT-SELTEXT_L = 'Required Date'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'DLV_QTY'.

LS_FIELDCAT-SELTEXT_L = 'Delivered Quantity'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'MENGE'.

LS_FIELDCAT-SELTEXT_L = 'Open Quantity'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'CREATION_DATE'.

LS_FIELDCAT-SELTEXT_L = 'Creation Date'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'DOC_STATUS'.

LS_FIELDCAT-SELTEXT_L = 'Sales Document Status'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'NET_PRICE'.

LS_FIELDCAT-SELTEXT_L = 'Net Price'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'COND_P_UNT'.

LS_FIELDCAT-SELTEXT_L = 'Condition Pricing Unit'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'COND_UNIT'.

LS_FIELDCAT-SELTEXT_L = 'Condition Unit'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

CLEAR LS_FIELDCAT.

CNTR = CNTR + 1.

LS_FIELDCAT-COL_POS = CNTR.

LS_FIELDCAT-FIELDNAME = 'NET_VALUE'.

LS_FIELDCAT-SELTEXT_L = 'Net Value in Document Currency'.

LS_FIELDCAT-OUTPUTLEN = 15.

APPEND LS_FIELDCAT TO FIELDCAT.

endform.

FORM LAYOUT_BUILD USING LAYOUT TYPE SLIS_LAYOUT_ALV.

LAYOUT-ZEBRA = 'X'.

LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  • LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

  • LAYOUT-BOX_TABNAME = 'ITAB'.

  • LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

ENDFORM. " layout_build

&----


*& Form eventtab_build

&----


  • Initialize events

----


  • -->L_EVENTS Table used to store the events

----


FORM EVENTTAB_BUILD USING L_EVENTS TYPE SLIS_T_EVENT.

DATA: LS_EVENT TYPE SLIS_ALV_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = L_EVENTS.

READ TABLE L_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE INTO LS_EVENT.

IF SY-SUBRC = 0.

MOVE C_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.

APPEND LS_EVENT TO L_EVENTS.

ENDIF.

ENDFORM. "eventtab_build

&----


*& Form comment_build

&----


----


  • -->L_LIST_TOP_OF_PAGE Table used to store the list header

----


FORM COMMENT_BUILD USING L_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

DATA: LS_LINE TYPE SLIS_LISTHEADER.

DATA: DATE1(200) TYPE C.

DATA: DATE2(4) TYPE C.

DATA: DATE3(12) TYPE C.

DATA: DATE4(12) TYPE C.

DATA: TIME1(200) TYPE C.

DATA: TIME2(4) TYPE C.

DATA: VALUE1(100).

DATA: VALUE2(50).

CONCATENATE SY-UZEIT+0(2) ':'

SY-UZEIT+2(2) ':'

SY-UZEIT+4(2) INTO TIME1.

DATE2 = SY-DATUM+6(2).

CONCATENATE DATE2 '/' INTO DATE1." separated by space.

DATE2 = SY-DATUM+4(2).

CONCATENATE DATE1 DATE2 '/' INTO DATE1.

DATE2 = SY-DATUM+0(4).

CONCATENATE DATE1 DATE2 INTO DATE1.

LS_LINE-TYP = 'H'.

LS_LINE-INFO = 'Open Sales Report'.

APPEND LS_LINE TO L_LIST_TOP_OF_PAGE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'User Name :'.

LS_LINE-INFO = SY-UNAME.

APPEND LS_LINE TO L_LIST_TOP_OF_PAGE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Execution Date :'.

LS_LINE-INFO = DATE1.

APPEND LS_LINE TO L_LIST_TOP_OF_PAGE.

LS_LINE-TYP = 'S'.

LS_LINE-KEY = 'Execution Time :'.

LS_LINE-INFO = TIME1.

APPEND LS_LINE TO L_LIST_TOP_OF_PAGE.

ENDFORM. "comment_build

&----


*& Form top_of_page

&----


  • SAP Logo on top of page

----


FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = I_LIST_TOP_OF_PAGE.

ENDFORM. "top_of_page

*FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM

*RS_SELFIELD TYPE SLIS_SELFIELD.

FORM USER_COMMAND USING r_ucomm like sy-ucomm

ls_selfield TYPE slis_selfield.

  • READ TABLE it_report ."into it_report INDEX RS_SELFIELD-TABINDEX.

  • IF SY-SUBRC = 0.

CASE r_UCOMM.

WHEN 'SD_DOC'.

SET PARAMETER ID 'AUN' FIELD IT_REPORT-SD_DOC.

CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.

clear IT_report-SD_DOC.

endcase.

  • ENDIF.

endform.

Pls correct me .....