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: 

Get cell value from alv grid

paulopinto99
Member
0 Kudos

Hello everyone. I'm developing a program in which I show the user the data of the productions orders and when he clicks on the details button (I added gui status), it should show the details of that specific production order. How do I get the data from this cell to use in the where clause?

(obs: Please skip the code repetition, I'll deal with that later.)


My code:

REPORT  ZPRODUCTION_ORDER.

TYPE-POOLS: slis.

TABLES: AUFK, AFPO, AFKO.

DATA : GR_TABLE TYPE REF TO CL_SALV_TABLE,
IT_ORDER TYPE TABLE OF ZSORDER,
lv_error_message TYPE string,
it_fieldcat type slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv,
lt_sort type slis_t_sortinfo_alv,
ls_sort type slis_sortinfo_alv,
program TYPE sy-repid VALUE sy-repid.

SELECTION-SCREEN BEGIN OF BLOCK part1 WITH FRAME TITLE text-001.

PARAMETERS: p_ccode TYPE AUFK-BUKRS.
select-options: p_plant for AUFK-WERKS,
p_slocat for AUFK-STORT,
p_porder for AFPO-AUFNR,
p_podate for AFPO-STRMP.

SELECTION-SCREEN END OF BLOCK part1.

START-OF-SELECTION.

"IF p_ccode <> '' AND p_plant <> ''.
SELECT AUFK~AUFNR AS PORDER AUFK~WERKS AS PLANT
AUFK~STORT AS SLOCAT AFPO~STRMP AS PODATE
AFPO~MATNR AS PMATERIAL AFKO~GAMNG AS QUANTITY AFPO~MEINS AS UNIT
INTO CORRESPONDING FIELDS OF TABLE IT_ORDER
FROM AUFK
LEFT JOIN AFPO ON AUFK~AUFNR = AFPO~AUFNR
LEFT JOIN AFKO ON AUFK~AUFNR = AFKO~AUFNR
WHERE AUFK~BUKRS = p_ccode. "AND AUFK~WERKS = p_plant.

wa_fieldcat-FIELDNAME = 'PORDER'.
wa_fieldcat-seltext_m = 'Production Order'.
APPEND wa_fieldcat to it_fieldcat.

wa_fieldcat-FIELDNAME = 'PLANT'.
wa_fieldcat-seltext_m = 'Plant'.
APPEND wa_fieldcat to it_fieldcat.

wa_fieldcat-FIELDNAME = 'SLOCAT'.
wa_fieldcat-seltext_m = 'Storage Location'.
APPEND wa_fieldcat to it_fieldcat.

wa_fieldcat-FIELDNAME = 'PODATE'.
wa_fieldcat-seltext_m = 'Production Order Date'.
APPEND wa_fieldcat to it_fieldcat.

wa_fieldcat-FIELDNAME = 'PMATERIAL'.
wa_fieldcat-seltext_m = 'Production Material'.
APPEND wa_fieldcat to it_fieldcat.

wa_fieldcat-FIELDNAME = 'QUANTITY'.
wa_fieldcat-seltext_m = 'Quantity'.
APPEND wa_fieldcat to it_fieldcat.

wa_fieldcat-FIELDNAME = 'UNIT'.
wa_fieldcat-seltext_m = 'Unit'.
APPEND wa_fieldcat to it_fieldcat.

ls_sort-fieldname = 'PORDER'.
ls_sort-down = 'X'.
APPEND ls_sort to lt_sort.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = program
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = it_fieldcat
IT_SORT = lt_sort
TABLES
T_OUTTAB = it_order
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
lv_error_message = 'Production Order not found.'.
MESSAGE lv_error_message TYPE 'E'.
ENDIF.

FORM pf_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'GUI_STATUS' EXCLUDING rt_extab.
ENDFORM.


FORM user_command USING ucomm TYPE sy-ucomm selfield TYPE slis_selfield.

DATA: lv_order_number TYPE AUFK-AUFNR,
it_fieldcat2 type slis_t_fieldcat_alv,
IT_DETAIL TYPE TABLE OF ZSORDER.

IF ucomm = 'DETAIL'.

SELECT AUFK~AUFNR AS PORDER AUFK~WERKS AS PLANT
AUFK~STORT AS SLOCAT AFPO~STRMP AS PODATE
AFPO~MATNR AS PMATERIAL AFKO~GAMNG AS QUANTITY AFPO~MEINS AS UNIT
INTO CORRESPONDING FIELDS OF TABLE IT_DETAIL
FROM AUFK
LEFT JOIN AFPO ON AUFK~AUFNR = AFPO~AUFNR
LEFT JOIN AFKO ON AUFK~AUFNR = AFKO~AUFNR.
"WHERE AUFK~AUFNR = ... Here -> WHERE Prod.Order = selected.



wa_fieldcat-FIELDNAME = 'PORDER'.
wa_fieldcat-seltext_m = 'Production Order'.
APPEND wa_fieldcat to it_fieldcat2.

wa_fieldcat-FIELDNAME = 'PLANT'.
wa_fieldcat-seltext_m = 'Plant'.
APPEND wa_fieldcat to it_fieldcat2.

wa_fieldcat-FIELDNAME = 'SLOCAT'.
wa_fieldcat-seltext_m = 'Storage Location'.
APPEND wa_fieldcat to it_fieldcat2.

wa_fieldcat-FIELDNAME = 'PODATE'.
wa_fieldcat-seltext_m = 'Production Order Date'.
APPEND wa_fieldcat to it_fieldcat2.

wa_fieldcat-FIELDNAME = 'PMATERIAL'.
wa_fieldcat-seltext_m = 'Production Material'.
APPEND wa_fieldcat to it_fieldcat2.

wa_fieldcat-FIELDNAME = 'QUANTITY'.
wa_fieldcat-seltext_m = 'Quantity'.
APPEND wa_fieldcat to it_fieldcat2.

wa_fieldcat-FIELDNAME = 'UNIT'.
wa_fieldcat-seltext_m = 'Unit'.
APPEND wa_fieldcat to it_fieldcat2.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = it_fieldcat2
TABLES
T_OUTTAB = it_detail
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
lv_error_message = 'Error opening details.'.
MESSAGE lv_error_message TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM.
END-OF-SELECTION.

5 REPLIES 5

hdeveloper
Participant
0 Kudos

Hi, I think you don't need a "detail" button in the gui status. You can do for example the column production order clickable. I have an ALV version for this but OO. I hope be helpful for you. Look below example with sales orders:

After clicking sales order, it will take to the corresponding document:

You have to do something similar but with production orders.

For this, you have to define an event handler:


CLASS lcl_event_receiver_0100 DEFINITION.
PUBLIC SECTION.
METHODS:
hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no,

on_f4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING
sender
e_fieldname
e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display.

ENDCLASS.

And then the implementation. In my case it was:

CLASS lcl_event_receiver_0100 IMPLEMENTATION.
METHOD hotspot_click.
DATA:
lt_data LIKE gs_dynpro_data-dynpro_0100-t_alv_data,
lt_data_copy LIKE gs_dynpro_data-dynpro_0100-t_alv_data,
lt_sort_criteria TYPE lvc_t_sort,
lv_es_row_no TYPE lvc_s_roid,
lv_es_row_info TYPE lvc_s_row,
lv_es_col_info TYPE lvc_s_col,
lv_is_row_id TYPE lvc_s_row,
lv_stable TYPE lvc_s_stbl VALUE 'XX'.

FIELD-SYMBOLS:
<data> LIKE LINE OF gs_dynpro_data-dynpro_0100-t_alv_data,
<vbeln> LIKE LINE OF s_vbeln.

READ TABLE gs_dynpro_data-dynpro_0100-t_alv_data[] ASSIGNING <data> INDEX es_row_no-row_id.
IF sy-subrc = 0.
IF e_column_id-fieldname = 'VBELN'.
SET PARAMETER ID 'AUN' FIELD <data>-vbeln.
ENDIF.
endif.

CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.

COMMIT WORK AND WAIT.

And in the field catalogue you will have to set the corresponding field as hotspot:

  READ TABLE gs_dynpro_data-dynpro_0100-t_fieldcat WITH KEY fieldname = 'VBELN' ASSIGNING <fcat>.
IF sy-subrc = 0.
<fcat>-hotspot = abap_true.
<fcat>-key = abap_true.
ENDIF.

And to finish, you will have to set the handler also:

SET HANDLER:
gs_dynpro_data-dynpro_0100-o_event_handler->hotspot_click FOR gs_dynpro_data-dynpro_0100-o_grid,

0 Kudos

Just a clarification. The last statement "SET HANDLER" goes after calling the ALV. It means, after the method:

CALL METHOD gs_dynpro_data-dynpro_0100-o_grid->set_table_for_first_display
EXPORTING
is_layout = ls_layout
it_toolbar_excluding = lt_uifun
i_structure_name = gc_alv-alv_structure_

hope this helps

For information, instead of a comment, I'd recommend using menu Actions > Edit to improve your answer (possibly indicate "EDIT" to mention what change you did).

Sandra_Rossi
Active Contributor

I'm not answering your question, just two remarks:

REUSE_ALV_GRID_DISPLAY is obsolete. Use CL_SALV_TABLE instead.

END-OF-SELECTION is useless/is obsolete.

0 Kudos

Hi Paulo,

there are several ways for the ALV to make this work. I would suggest to use an OO version of the ALV and make the column AUFNR either a hotspot (see fieldcat) or sensitive to double click. Then you can get the value of your cell in the event listener.

I usually add the navigation profile (if_navp) to our cl_gui_alv_grid. You just call the factory and hand over your internal table after instantiating your ALV. As a result the end users can define their own calls to other transactions .

data(go_navp) = cl_navp_factory=>factory(
io_alv = go_alv
is_profile_key = ls_disvariant
it_table = lt_table ).

Hope this helps.