‎2011 Nov 16 9:16 PM
Hi-
I have a SUBMIT statement in my code that, when executed, results in data in an ALV grid.
I want to modify the layout. How do I obtain this ALV grid object (the result of the SUBMIT statement) using the ALV OO model?
The problem is that I can't use a layout in the SUBMIT statement to modify the columns in the results because the layout could potentially be modified by end users. If it's possible to create a layout that cannot be modified, that would also solve the problem.
The program is the standard SAP program RFFMEPGAX.
Thanks,
Kevin
‎2011 Nov 17 3:54 AM
hi ,
TYPES : BEGIN OF w_tab .
include STRUCTURE rkpos . " You need to add structure as per your reqirment .
types: END OF w_tab .
DATA: text TYPE c LENGTH 10,
lt_selscreen TYPE TABLE OF rsparams WITH HEADER LINE .
DATA it_tab TYPE STANDARD TABLE OF w_tab WITH HEADER LINE.
FIELD-SYMBOLS : <lt_pay_data> TYPE ANY TABLE .
FIELD-SYMBOLS : <LT_TEST> TYPE ANY . "LIKE LINE OF it_tab .
DATA lr_pay_data TYPE REF TO data.
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_false
data = abap_true ).
SUBMIT RFFMEPGAX WITH SELECTION-TABLE lt_selscreen
WITH s_bukrs-low = 'BFL'
*WITH kstgr = '1001'
*WITH p_disvar = '//COST'
*WITH p_tcode = 'KSB1'
AND RETURN.
TRY.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_pay_data ).
ASSIGN lr_pay_data->* TO <lt_pay_data>.
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
cl_salv_bs_runtime_info=>clear_all( ).
LOOP AT <lt_pay_data> ASSIGNING <LT_TEST>.
MOVE-CORRESPONDING <LT_TEST> TO it_tab .
APPEND IT_TAB .
ENDLOOP.regards
Deepak.
‎2011 Nov 17 1:22 AM
You may check this blog
[Gain Programmatic Access to Data of SAPGUI ALV Reports|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/24944] [original link is broken] [original link is broken];
It seems like you can set the meta data before hand by calling the method CL_SALV_BS_RUNTIME_INFO=>SET_METADATA( ), however, you have to borrow the meta data building logic from the submitted program.
-Rajesh.
‎2011 Nov 17 3:54 AM
hi ,
TYPES : BEGIN OF w_tab .
include STRUCTURE rkpos . " You need to add structure as per your reqirment .
types: END OF w_tab .
DATA: text TYPE c LENGTH 10,
lt_selscreen TYPE TABLE OF rsparams WITH HEADER LINE .
DATA it_tab TYPE STANDARD TABLE OF w_tab WITH HEADER LINE.
FIELD-SYMBOLS : <lt_pay_data> TYPE ANY TABLE .
FIELD-SYMBOLS : <LT_TEST> TYPE ANY . "LIKE LINE OF it_tab .
DATA lr_pay_data TYPE REF TO data.
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_false
data = abap_true ).
SUBMIT RFFMEPGAX WITH SELECTION-TABLE lt_selscreen
WITH s_bukrs-low = 'BFL'
*WITH kstgr = '1001'
*WITH p_disvar = '//COST'
*WITH p_tcode = 'KSB1'
AND RETURN.
TRY.
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_pay_data ).
ASSIGN lr_pay_data->* TO <lt_pay_data>.
CATCH cx_salv_bs_sc_runtime_info.
MESSAGE `Unable to retrieve ALV data` TYPE 'E'.
ENDTRY.
cl_salv_bs_runtime_info=>clear_all( ).
LOOP AT <lt_pay_data> ASSIGNING <LT_TEST>.
MOVE-CORRESPONDING <LT_TEST> TO it_tab .
APPEND IT_TAB .
ENDLOOP.regards
Deepak.
‎2011 Nov 17 1:58 PM
‎2011 Nov 17 4:59 PM
I can't believe this actually worked.
>
> You rock!
Word of caution : If you employ the code posted above, you may run the risk of loosing all the interactive options provided as part of the original ALV in the submitted program through the 'USER_COMMAND' event and I also see considerable logic in building the meta data in the END-OF-SELECTION event of the program you may miss that part too.
If I were you, I would attempt to replicate the meta buidling logic(field catalog, layout, sort, events) from the submitted program
modify the meta to suit my own requirements in the Z* program, set the meta data before displaying the ALV by exploring the set_meta_data() method and SUBMIT the standard program without RETURN.
-Rajesh.
‎2021 Jul 12 4:12 PM
deepak.dhamat Thank you so much for this snippet. You saved our project!!!
‎2022 Mar 07 9:28 AM
‎2011 Nov 18 12:00 AM
clay995,
If all you really want to do is limit the fields that are in the alv and perhaps change the order of the fields, you could create a global display variant, making it the default. Then every time the the alv is created, the default layout would be used.
Bruce