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

Retrieving ALV grid from Submit statement

Former Member
0 Likes
24,503

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

1 ACCEPTED SOLUTION
Read only

deepak_dhamat
Active Contributor
8,410

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.

7 REPLIES 7
Read only

rajesh_paruchuru
Active Participant
0 Likes
8,410

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.

Read only

deepak_dhamat
Active Contributor
8,411

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.

Read only

0 Likes
8,410

I can't believe this actually worked.

You rock!

Read only

0 Likes
8,410

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.

Read only

0 Likes
8,410

deepak.dhamat Thank you so much for this snippet. You saved our project!!!

Read only

0 Likes
8,410

This piece of code is awesome!!!

Read only

Former Member
0 Likes
8,410

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