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: 

how to display table control from ALV report

bizo
Explorer
0 Kudos
1,250

i made a program to display as an output an ALV report with a check box column and a custom button with custom FCT code.

when the alv is displayed and multiple rows are checked ,i need to fetch data of the selected rows with the check box and display them on a new window with a table control.

please take into consideration that iam still new to abap ,so plz explain your answers.

tables : vbak,
tvakt,
dd07t,
kna1.

TYPE-POOLS: slis.
*&---------------------------------------------------------------------*


*Data declaration and types constructing
*-----------------------------------------------


types : begin of task_report,
check(1) type c,
vbeln type vbak-vbeln,
kunnr type vbak-kunnr,
audat type vbak-audat,
vbtyp type vbak-vbtyp,
netwr type vbak-netwr,
waerk type vbak-waerk,
auart type vbak-auart,
name1 type kna1-name1,
stras type kna1-stras,
bezei type tvakt-bezei,
ddtext type DD07T-ddtext,
color(4) type c,
end of task_report.


DATA : it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
is_layout type slis_layout_alv,
it_excluding TYPE slis_t_extab,
wa_excluding TYPE slis_extab.

DATA : it_task_report type table of task_report,
wa_task_report type task_report.


SELECTION-SCREEN begin of BLOCK B.

SELECT-OPTIONS or_num for WA_TASK_REPORT-vbeln.
SELECT-OPTIONS cust for WA_TASK_REPORT-kunnr.

SELECTION-SCREEN END OF BLOCK B.


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



select
a~vbeln,
a~kunnr,
a~audat,
a~vbtyp,
a~netwr,
a~waerk,
a~auart,
b~name1,
b~stras,
c~bezei,
d~ddtext
from vbak as a INNER JOIN kna1 as b on a~KUNNR = b~KUNNR
INNER JOIN TVAKT as c on a~AUART = c~AUART and c~SPRAS = 'E'
INNER JOIN dd07t as d on a~VBTYP = d~DOMVALUE_L and d~DDLANGUAGE = 'E' and d~DOMNAME = 'VBTYP'
where a~vbeln in @or_num and a~kunnr in @cust
into CORRESPONDING FIELDS OF table @IT_TASK_REPORT.

clear WA_TASK_REPORT.
LOOP AT IT_TASK_REPORT INTO WA_TASK_REPORT.
IF WA_TASK_REPORT-netwr GE 10000.
WA_TASK_REPORT-color = 'C500'.
ENDIF.
MODIFY IT_TASK_REPORT FROM WA_TASK_REPORT TRANSPORTING color.
CLEAR: WA_TASK_REPORT.
ENDLOOP.

*-------------------------------------------------------------------Building the field catalogue-----------------------------------------------------------------------------*

wa_fcat-fieldname ='CHECK'.

wa_fcat-seltext_m ='Check'.

wa_fcat-tabname ='it_task_report'.

wa_fcat-EDIT = 'X'.

WA_FCAT-CHECKBOX = 'X'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='VBELN'.

wa_fcat-seltext_m ='Sales order number'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.


wa_fcat-fieldname ='VBELN'.

wa_fcat-seltext_m ='Sales order number'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.


wa_fcat-fieldname ='KUNNR'.

wa_fcat-seltext_m ='Customer'.

wa_fcat-tabname ='it_task_report'.


APPEND wa_fcat TO it_fcat.

clear WA_FCAT.


wa_fcat-fieldname ='NAME1'.

wa_fcat-seltext_m ='Customer name'.

wa_fcat-tabname ='it_task_report'.


APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='STRAS'.

wa_fcat-seltext_m ='Address'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='AUDAT'.

wa_fcat-seltext_m ='Document date'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.


CLEAR wa_fcat.

wa_fcat-fieldname ='VBTYP'.

wa_fcat-seltext_m ='Document category'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='DDTEXT'.

wa_fcat-seltext_m ='Document category description'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='NETWR'.

wa_fcat-seltext_m ='Net value'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='WAERK'.

wa_fcat-seltext_m ='Currency'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='AUART'.

wa_fcat-seltext_m ='Sales order type'.

wa_fcat-tabname ='it_task_report'.

APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

wa_fcat-fieldname ='BEZEI'.

wa_fcat-seltext_m ='Order type description'.

wa_fcat-tabname ='it_task_report'.


APPEND wa_fcat TO it_fcat.

CLEAR wa_fcat.

*--------------------------------------------------------------------finished building field catalog-----------------------------------------------------------------------*

IS_LAYOUT-info_FIELDNAME = 'COLOR'.
IS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IT_FIELDCAT = it_fcat
IS_LAYOUT = is_layout
I_callback_user_command = 'USER_COMMAND'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
TABLES
t_outtab = IT_TASK_REPORT
EXCEPTIONS
program_error = 1
OTHERS = 2.


*----------------------------------------------------------*
* FORM USER_COMMAND *
*----------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*----------------------------------------------------------*

FORM USER_COMMAND using r_ucomm like sy-UCOMM
rs_selfield type slis_selfield.
IF r_ucomm = '&FAD'.

*what to write in here to fetch the selected rows with the check box and display them on a table control in a new *window "&FAD is the FCT code of the custom button"

ENDIF.

FORM SET_PF_STATUS using rx_extab type SLIS_t_EXTAB.
SET PF-STATUS 'TASK1_PF'.
ENDFORM.

* the pf status is for adding the custom button

1 ACCEPTED SOLUTION

DominikTylczyn
Active Contributor
1,090

Hello bizo

I think your solution should have the following logical steps triggered after &FAD command:

  1. Loop at ALV list and get all selected rows. Copy the rows to another internal table.
  2. Call a dialog screen that implements the table control displaying record in the internal table.

Before that, you need to define a dialog screen in your report. The easies way to do that is to open your report in SE80 and create the screen from there. The screen needs to implement a table control. You can either build the table control manually - Creating a Table Control or use the Table Control Wizard. I strongly recommend the latter as it is very easy to use and implements all bells and whistles like page up and page down automatically.

Make sure to implement exit function in your dialog screen so the user can go from the table control display back to the ALV list.

Best regards

Dominik Tylczynski

9 REPLIES 9

DominikTylczyn
Active Contributor
1,090

Please update your question and format the source code with the button

bizo
Explorer
0 Kudos
1,090

I made the custom button with the GUI status screen , just disregard it and put any event you would like and remove the I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS' part from the code

DominikTylczyn
Active Contributor
1,091

Hello bizo

I think your solution should have the following logical steps triggered after &FAD command:

  1. Loop at ALV list and get all selected rows. Copy the rows to another internal table.
  2. Call a dialog screen that implements the table control displaying record in the internal table.

Before that, you need to define a dialog screen in your report. The easies way to do that is to open your report in SE80 and create the screen from there. The screen needs to implement a table control. You can either build the table control manually - Creating a Table Control or use the Table Control Wizard. I strongly recommend the latter as it is very easy to use and implements all bells and whistles like page up and page down automatically.

Make sure to implement exit function in your dialog screen so the user can go from the table control display back to the ALV list.

Best regards

Dominik Tylczynski

0 Kudos
1,090

I am new to this so just bare with me, i opened se80 and choose my program -> right clicked on it -> create -> screen ->entered 2000 as screen number.

now it's asking about the screen type what should i choose : 1-normal, 2-subscreen, 3-modal dialog box ?

and if Iam gonna face any determinative questions after this step what should i choose

0 Kudos
1,090

bizo You should choose either normal or dialog box depending on if you want to display the table control full screen or in a pop up window.

You requirement is not hard to implement. Nevertheless, if you are new to ABAP dialog programming, you should read SAP Help pages:

and go through some ABAP dialog programming tutorials that you can Google up e.g. SAP ABAP Dialog Programming

Sandra_Rossi
Active Contributor
0 Kudos
1,090

Please edit your question, select your code and press the button [CODE], as shown by Dominik, which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!

Sandra_Rossi
Active Contributor
0 Kudos
1,090

If you have a custom function code, I recommend not prefixing it with "&", but prefixing it with "Z". ("ZFAD")

bizo
Explorer
0 Kudos
1,090

oh sorry i didn't get that at first ,that's my first question on the community, i will edit it

bizo
Explorer
0 Kudos
1,090

ok for some reason iam not able to edit it. it just keep shifting the code beneath the code area after updating any way , https://abapeditor.com/

here is a link for online editor to adjust the color and indentation.