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

My code. Need improvement and help.

Former Member
0 Likes
632

Moderator message: please use a more descriptive subject line next time.

Hi,

I created report to compare MM invoices with generated SO ans SD invoices.

Have my own button to display detailes for selected rows.

But I have two problems.

1) Need to improve coding, because now I have two places with same queries.

Here I select from system tables to my tables details lines for selected rows:


CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_user_command FOR EVENT added_function OF cl_salv_events
        IMPORTING e_salv_function.
ENDCLASS.           "lcl_handle_events DEFINITION


CLASS lcl_handle_events IMPLEMENTATION.

  METHOD on_user_command.

* Get selected rows
    CLEAR gs_result.
    CLEAR lt_rows.
    lt_rows = go_selections->get_selected_rows( ).
    CHECK lt_rows[] IS NOT INITIAL.
    DESCRIBE TABLE lt_rows.

    CASE e_salv_function.
* check if functionbutton was pressed
      WHEN 'MYFUNCTION'.
        LOOP AT lt_rows INTO ls_rows.
          READ TABLE gt_result INTO gs_result INDEX ls_rows.

* perform select details data
          PERFORM select_detail_data.

-


FORM SELECT_DETAIL_DATA .
* Get invoice details for MM invoices
  SELECT belnr gjahr cobl_nr wrbtr prctr sgtxt menge mwskz bukrs shkzg zuonr meins
    FROM rbco
    INTO CORRESPONDING FIELDS OF TABLE gt_rbco
  WHERE belnr = gs_result-rbkp_belnr
    AND gjahr = gs_result-rbkp_gjahr
    AND buzei = '000000'.

* Get sales orders details
  SELECT vbeln posnr matnr matkl arktx pstyv netwr waerk kwmeng vrkme werks mwsbp
    FROM vbap
    INTO CORRESPONDING FIELDS OF TABLE gt_vbap
  WHERE vbeln = gs_result-vbak_vbeln.


* Get invoice details for SD invoices
  SELECT vbeln posnr uepos fkimg vrkme netwr pstyv mwsbp
    FROM vbrp
    INTO CORRESPONDING FIELDS OF TABLE gt_vbrp
   WHERE vbeln = gs_result-vbrk_vbeln.

ENDFORM.                    " SELECT_DETAIL_DATA

But then when I build result table I need to make this queries again:

* Build detail table
          CLEAR gs_rbco.
          CLEAR gs_vbap.
          CLEAR gs_vbfa.

          LOOP AT gt_rbco INTO gs_rbco WHERE belnr = gs_result-rbkp_belnr
                                         AND gjahr = gs_result-rbkp_gjahr
                                         AND buzei = '000000'.
* move rbco to details
            PERFORM move_rbco.

            READ TABLE gt_vbap INTO gs_vbap WITH TABLE KEY vbeln = gs_result-vbak_vbeln
                                                           posnr = gs_rbco-cobl_nr.
* move vbap to details
            PERFORM move_vbap.

            READ TABLE gt_vbfa INTO gs_vbfa WITH KEY vbelv = gs_vbap-vbeln
                                                     posnv = gs_vbap-posnr.

            READ TABLE gt_vbrp INTO gs_vbrp WITH TABLE KEY vbeln = gs_vbfa-vbeln
                                                           posnr = gs_vbfa-posnn.
* move vbrp to details
            PERFORM move_vbrp.

            APPEND gs_details TO gt_details.

          ENDLOOP.
        ENDLOOP.
        PERFORM display_details_alv.
    ENDCASE.
  ENDMETHOD.                    "on_user_command
ENDCLASS.                    "lcl_handle_events IMPLEMENTATION

Any idea how to not do this two times?

2)

FORM DISPLAY_DETAILS_ALV .
* create alv table
  try.
      cl_salv_table=>factory(
        importing
          r_salv_table = go_salv_table
        changing
          t_table      = gt_details ).
    catch cx_salv_msg.                                  "#EC NO_HANDLER
  endtry.

* set functions
  go_functions = go_salv_table->get_functions( ).
  go_functions->set_all( if_salv_c_bool_sap=>true ).

* set size and position
  go_salv_table->set_screen_popup(
      start_column = 15
      end_column   = 100
      start_line   = 5
      end_line     = 20 ).

* set selection mode
  go_selections = go_salv_table->get_selections( ).
  go_selections->set_selection_mode( if_salv_c_selection_mode=>ROW_COLUMN ).

* display table
  go_salv_table->display( ).

ENDFORM.                    " DETAILS_ALV_DISPLAY

is responsible for display detail lines in popup window. It works.

But I have problem that, when I close this popup, report does not see that I choosed another row and would like to display details (no rows is selected). I guess that program do not know that I close the popup and get back to result report screen.

Do I need to use another method exampe on_popup_close? Or how to manage with this that it will be possible to selecte and display details for other rows?

Moderator message: please use a more descriptive subject line next time.

Edited by: Thomas Zloch on Jul 9, 2010 11:24 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
558

Good Day,

I think the select queries that you have written is fine, when you need to read the data

there is no ther alternative but you have to use read or loop statements for the internal table

i see no unnecessary statements according to your code.

If you have data in internal table and want to avoid reading number of times may be try

with putting in subroutiens.

Regards and Best wishes.

3 REPLIES 3
Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
558

1) Not sure why you're saying there are two queries... I see SELECT statements only in the first place, but the second part of code is simply reading tables that are already in memory (of course, I wouldn't know what's inside those PERFORMs). I would only recommend not to use INTO CORRESPONDING FIELDS but instead just define the table accordingly.

You're also using the primary key in all SELECT statements, which is good. It seems that gs_rbco-cobl_nr should match with vbap-posnr, but I think if you tried to do JOIN or FOR ALL ENTRIES it won't be possible due to different field types. I think your program looks quite OK.

2) What do you mean by "report does not see that I choosed another row"? The pop-up gets called only once? The control doesn't seem to get passed back to main ALV? Quite honestly, I've never used OO ALV, but maybe there is some object you need to 'kill' or something?

Have you searched for some code examples on SCN?

Read only

Former Member
0 Likes
559

Good Day,

I think the select queries that you have written is fine, when you need to read the data

there is no ther alternative but you have to use read or loop statements for the internal table

i see no unnecessary statements according to your code.

If you have data in internal table and want to avoid reading number of times may be try

with putting in subroutiens.

Regards and Best wishes.

Read only

Former Member
0 Likes
558

Thank you for code review. It was very helpful.

And your right, now I see it.

First I search any records (using SELECT, and header document number), and then need to read thid data also based on position number.

I also solved problem with popup. In this window I also set row"column selection, and in that case number in lt_rows was replaced by selected/non-selected values from popup, and it was not possible to use function button. But when I added statement to clear detail table, and lt_rows it works just fine Ofcourse I also needed to change selection option in popup, but there is no need to mark any rows