Application Development and Automation 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: 
Read only

help needed on ALV grid program

Former Member
0 Likes
419

hi experts,

i am new to sap learning reports.

my requirement is to:

display a alv report with four fields vbeln(sales order),erdat,matnr,posnr using tables vbak and vbap using reuse_alv_grid display.when the output is displayed in grid format,and if we double click any sales order number it should take me to VA03(sales order display)transaction code with the sales order number i clicked and give the information abt that sales order number.

i know we should use 'at-user command' statement here to achieve this.

i need the exact code for at-user command.please can anyone help me with this?

the code what i wrote is....


TABLES: vbak,vbap.

TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_final,
vbeln LIKE vbak-vbeln,
erdat LIKE vbak-erdat,
matnr LIKE vbap-matnr,
posnr LIKE vbap-posnr,
END OF t_final.

DATA: i_final TYPE STANDARD TABLE OF t_final INITIAL SIZE 0,
wa_final TYPE t_final.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
*Start-of-selection.
START-OF-SELECTION.

PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
&---------------------------------------------------------------------
*& Form BUILD_FIELDCATALOG
&---------------------------------------------------------------------
• Build Fieldcatalog for ALV Report
--------------------------------------------------------------------------------
 FORM build_fieldcatalog.

fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'sales order'.
fieldcatalog-col_pos = 0.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.

fieldcatalog-fieldname = 'ERDAT'.
fieldcatalog-seltext_m = 'date'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'material no.'.
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.

fieldcatalog-fieldname = 'POSNR'.
fieldcatalog-seltext_m = 'line item no.'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
&---------------------------------------------------------------------
*& Form BUILD_LAYOUT
&---------------------------------------------------------------------
• Build layout for ALV grid report
--------------------------------------------------------------------------------
 FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
• gd_layout-totals_only = 'X'. 
• gd_layout-f2code = 'DISP'. "Sets fcode for when double 
• "click(press f2) 
• gd_layout-zebra = 'X'. 
• gd_layout-group_change_edit = 'X'. 
• gd_layout-header_text = 'helllllo'. 
ENDFORM. " BUILD_LAYOUT
&---------------------------------------------------------------------
*& Form DISPLAY_ALV_REPORT
&---------------------------------------------------------------------
• Display report using ALV grid
--------------------------------------------------------------------------------
 FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
• i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM 
i_callback_user_command = 'USER_COMMAND'
• i_grid_title = outtext 
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
• it_special_groups = gd_tabgroup 
• IT_EVENTS = GT_XEVENTS 
i_save = 'X'
• is_variant = z_template 

TABLES
t_outtab = i_final
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_ALV_REPORT
&---------------------------------------------------------------------
*& Form DATA_RETRIEVAL
&---------------------------------------------------------------------
• Retrieve data form EKPO table and populate itab it_ekko
--------------------------------------------------------------------------------
 FORM data_retrieval.

SELECT a~vbeln a~erdat b~matnr b~posnr FROM vbak AS a
INNER JOIN vbap AS b ON a~vbeln = b~vbeln
INTO TABLE i_final WHERE a~vbeln = b~vbeln.
ENDFORM. " DATA_RETRIEVAL

<REMOVED BY MODERATOR>

thanks in advance.

Edited by: Alvaro Tejada Galindo on Feb 11, 2008 2:33 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
394

Hello ,

Do like this.


&---------------------------------------------------------------------
*& Form F_USER_COMMAND_ALV
&---------------------------------------------------------------------


text 
----------------------------------------------------------------------

--> p1 text 
<-- p2 text 
----------------------------------------------------------------------
FORM F_ALV_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.

CASE R_UCOMM.
WHEN '&IC1'.




Hotspot selektion 
CASE RS_SELFIELD-FIELDNAME.

WHEN 'VBELN'.


SET PARAMETER ID 'VBK' FIELD ITAB-VBELN. @ Check the correct parameter ID
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

Cheers,

Vasanth

2 REPLIES 2
Read only

Former Member
0 Likes
395

Hello ,

Do like this.


&---------------------------------------------------------------------
*& Form F_USER_COMMAND_ALV
&---------------------------------------------------------------------


text 
----------------------------------------------------------------------

--> p1 text 
<-- p2 text 
----------------------------------------------------------------------
FORM F_ALV_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.

CASE R_UCOMM.
WHEN '&IC1'.




Hotspot selektion 
CASE RS_SELFIELD-FIELDNAME.

WHEN 'VBELN'.


SET PARAMETER ID 'VBK' FIELD ITAB-VBELN. @ Check the correct parameter ID
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

Cheers,

Vasanth

Read only

0 Likes
394

hi vasanth,

thank u so much for ur response.

i got the output.