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

Runtime error while trying to execute custom F4 help in OOP ALV grid.

former_member308418
Participant
0 Likes
2,902

Dear All,

I am trying to add custom search help for one of my column in ALV grid. I'm using OOP ALV, when i click for search help for that column, the system shows runtime error like below.

I am new to OOP concept and tried to follow program BCALV_EDIT_03. But not getting this error occur. Please help me.

With regards.

1 ACCEPTED SOLUTION
Read only

former_member196651
Contributor
0 Likes
2,576

Hi,

In order to be able to provide a search help for a field in an ALV you must do the following things.

1) The field where F4 help need to be attached needs to be made editable.

2) Create an event handler class to handle the ONF4 event. You can refer the following code:

    CLASS lcl_alv1_handler DEFINITION.

    PUBLIC SECTION.

       "Tohandle F4 helps

       METHODS handle_f4 FOR EVENT onf4 OF cl_gui_alv_grid

               IMPORTING e_fieldname e_fieldvalue es_row_no er_event_data

                         et_bad_cells e_display.

    ENDCLASS.

   

   

   CLASS lcl_alv1_handler IMPLEMENTATION.

      METHOD handle_f4.

         

CASE e_fieldname.

     WHEN 'LIFNR'.               "Set F4 for courier vendor

         SELECT lifnr name1 FROM lfa1 INTO TABLE lt_lifnr.

       IF lt_lifnr IS NOT INITIAL.

         CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

           EXPORTING

             retfield           = 'LIFNR'

             window_title   = 'Vendors'

             value_org       = 'S'

           TABLES

             value_tab       = lt_lifnr

             return_tab      = lt_return

           EXCEPTIONS

             parameter_error = 1

             no_values_found = 2

             OTHERS          = 3.

         IF sy-subrc = 0.

           READ TABLE gt_final INTO wa_final_t INDEX es_row_no-row_id.

           IF sy-subrc = 0.

             READ TABLE lt_return INTO wa_return INDEX 1.

             IF sy-subrc = 0.

               CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                 EXPORTING

                   input  = wa_return-fieldval

                 IMPORTING

                   output = lv_lifnr.

               wa_final_t-lifnr  = lv_lifnr.

               MODIFY gt_final FROM wa_final_t INDEX es_row_no-row_id.

             ENDIF.

           ENDIF.

         ENDIF.

       ENDIF.

      ENDCASE.

         CALL METHOD o_alv->refresh_table_display.

      ENDMETHOD.

   ENDCLASS.

  

    In the above method, GT_FINAL-LIFNR is being overwritten by the LIFNR you had selected       from F4 help. So we will call the refresh_table_display after it to see the result in the ALV.

3) After creating the ALV object, add the fields to which the F4 has to be added. For this you

    need to declare an internal table based on  lvc_t_f4. Use the following code. Here O_ALV is    my ALV object.:

   

   CREATE OBJECT o_container

       EXPORTING

         container_name              = 'CUSTCON'

       EXCEPTIONS

         cntl_error                  = 1

         cntl_system_error           = 2

         create_error                = 3

         lifetime_error              = 4

         lifetime_dynpro_dynpro_link = 5

         OTHERS                      = 6.

     IF sy-subrc <> 0.

*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.

     CREATE OBJECT o_alv

       EXPORTING

         i_parent          = o_container

       EXCEPTIONS

         error_cntl_create = 1

         error_cntl_init   = 2

         error_cntl_link   = 3

         error_dp_create   = 4

         OTHERS            = 5.

     IF sy-subrc <> 0.

*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.


   CLEAR : gt_f4, wa_f4.

   wa_f4-fieldname   = 'LIFNR'.

   wa_f4-register    = 'X'.

   wa_f4-getbefore   = space.

   wa_f4-chngeafter  = space.

   APPEND wa_f4 TO gt_f4.

   Here I am assigning F4 to LIFNR field in the final internal table that is displayed using ALV.

   After this register this field for F4.

   

    CALL METHOD o_alv->register_f4_for_fields

       EXPORTING

          it_f4 = gt_f4.

    

   CREATE OBJECT o_alv_handler.

   SET HANDLER : o_alv_handler->handle_f4 FOR o_alv1.

   The object o_alv_handler is created based on the event handler class.

I hope that this will solve your issue. Revert if this is solved.

Rgards,

Abijith

17 REPLIES 17
Read only

former_member187748
Active Contributor
0 Likes
2,576

Hi,

please check your program, error is clearly saying that "you haven't assigned field symbols".

Please assign your field symbol something like

FIELD-SYMBOLS: <gt_table>      TYPE STANDARD TABLE,

                          <l_matnr>       TYPE ANY.

Read only

0 Likes
2,576

Thanks Sanjeev.

But i have not used field symbol in my program. The error is showing in internal code of sap not in my code. Also i think i am missing some thing but not understands where.

Read only

0 Likes
2,576

Hi,

can you please provide the code, you have written.

Read only

former_member223133
Active Participant
0 Likes
2,576

Hi,

It looks like field catalogue issue. Check the field names assigned in the field catalog as these must be in capitals.

Regards

Gangadhar

Read only

former_member196651
Contributor
0 Likes
2,577

Hi,

In order to be able to provide a search help for a field in an ALV you must do the following things.

1) The field where F4 help need to be attached needs to be made editable.

2) Create an event handler class to handle the ONF4 event. You can refer the following code:

    CLASS lcl_alv1_handler DEFINITION.

    PUBLIC SECTION.

       "Tohandle F4 helps

       METHODS handle_f4 FOR EVENT onf4 OF cl_gui_alv_grid

               IMPORTING e_fieldname e_fieldvalue es_row_no er_event_data

                         et_bad_cells e_display.

    ENDCLASS.

   

   

   CLASS lcl_alv1_handler IMPLEMENTATION.

      METHOD handle_f4.

         

CASE e_fieldname.

     WHEN 'LIFNR'.               "Set F4 for courier vendor

         SELECT lifnr name1 FROM lfa1 INTO TABLE lt_lifnr.

       IF lt_lifnr IS NOT INITIAL.

         CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'

           EXPORTING

             retfield           = 'LIFNR'

             window_title   = 'Vendors'

             value_org       = 'S'

           TABLES

             value_tab       = lt_lifnr

             return_tab      = lt_return

           EXCEPTIONS

             parameter_error = 1

             no_values_found = 2

             OTHERS          = 3.

         IF sy-subrc = 0.

           READ TABLE gt_final INTO wa_final_t INDEX es_row_no-row_id.

           IF sy-subrc = 0.

             READ TABLE lt_return INTO wa_return INDEX 1.

             IF sy-subrc = 0.

               CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

                 EXPORTING

                   input  = wa_return-fieldval

                 IMPORTING

                   output = lv_lifnr.

               wa_final_t-lifnr  = lv_lifnr.

               MODIFY gt_final FROM wa_final_t INDEX es_row_no-row_id.

             ENDIF.

           ENDIF.

         ENDIF.

       ENDIF.

      ENDCASE.

         CALL METHOD o_alv->refresh_table_display.

      ENDMETHOD.

   ENDCLASS.

  

    In the above method, GT_FINAL-LIFNR is being overwritten by the LIFNR you had selected       from F4 help. So we will call the refresh_table_display after it to see the result in the ALV.

3) After creating the ALV object, add the fields to which the F4 has to be added. For this you

    need to declare an internal table based on  lvc_t_f4. Use the following code. Here O_ALV is    my ALV object.:

   

   CREATE OBJECT o_container

       EXPORTING

         container_name              = 'CUSTCON'

       EXCEPTIONS

         cntl_error                  = 1

         cntl_system_error           = 2

         create_error                = 3

         lifetime_error              = 4

         lifetime_dynpro_dynpro_link = 5

         OTHERS                      = 6.

     IF sy-subrc <> 0.

*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.

     CREATE OBJECT o_alv

       EXPORTING

         i_parent          = o_container

       EXCEPTIONS

         error_cntl_create = 1

         error_cntl_init   = 2

         error_cntl_link   = 3

         error_dp_create   = 4

         OTHERS            = 5.

     IF sy-subrc <> 0.

*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.


   CLEAR : gt_f4, wa_f4.

   wa_f4-fieldname   = 'LIFNR'.

   wa_f4-register    = 'X'.

   wa_f4-getbefore   = space.

   wa_f4-chngeafter  = space.

   APPEND wa_f4 TO gt_f4.

   Here I am assigning F4 to LIFNR field in the final internal table that is displayed using ALV.

   After this register this field for F4.

   

    CALL METHOD o_alv->register_f4_for_fields

       EXPORTING

          it_f4 = gt_f4.

    

   CREATE OBJECT o_alv_handler.

   SET HANDLER : o_alv_handler->handle_f4 FOR o_alv1.

   The object o_alv_handler is created based on the event handler class.

I hope that this will solve your issue. Revert if this is solved.

Rgards,

Abijith

Read only

0 Likes
2,576

Thanks Abijith. This reply will help me a lot. I am trying this and let you know.

Read only

0 Likes
2,576

Dear Abijith,

Can you please clarify the line,

READ TABLE gt_final INTO wa_final_t INDEX es_row_no-row_id.


Is gt_final is the table u r passing to alv ?


READ TABLE lt_return INTO wa_return INDEX 1.

data declaration for lt_retun ? As because i am unaware of this, please tell me.


Thanks.



Read only

Former Member
0 Likes
2,576

Hi,

In your program, you are trying to access the field symbol which has not been assigned any value.

Please make sure you have something in FS before you perform any function with it.

Thanks,

Sachin

Read only

former_member196651
Contributor
0 Likes
2,576

Hi,

Yup. That is the table that is finally displayed using ALV.

Regards,

Abijith

Read only

former_member196651
Contributor
0 Likes
2,576

Hi,

I had used the statement READ TABLE lt_return INTO wa_return INDEX 1. to get the value that is being selected from the F4 help. I had used INDEX 1 in that statement, bcoz we will be able to select only one value from the F4 help.

Hope this clarifies.

Regards,

Abijith

Read only

0 Likes
2,576

Dear Abijith,

Now the seach help is showing "No input help is available" . I am sending my piece of code.

CLASS lcl_event_handler IMPLEMENTATION.

   METHOD handle_on_f4.
     CASE e_fieldname.

       WHEN 'OBJID'.               "Set F4 for courier vendor

         SELECT objid stext FROM hrp1000 INTO TABLE itab
                WHERE plvar = '01'
                AND   otype = 'Z6'.

         IF itab IS NOT INITIAL.

           CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
             EXPORTING
               retfield        = 'OBJID'
               window_title    = 'Object ID'
               value_org       = 'S'
             TABLES
               value_tab       = itab
               return_tab      = lt_return
             EXCEPTIONS
               parameter_error = 1
               no_values_found = 2
               OTHERS          = 3.

           IF sy-subrc = 0.

             READ TABLE it_emp_grp INTO wa_emp_grp INDEX es_row_no-row_id.

             IF sy-subrc = 0.

               READ TABLE lt_return INTO wa_return INDEX 1.

               IF sy-subrc = 0.

                 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                   EXPORTING
                     input  = wa_return-fieldval
                   IMPORTING
                     output = lv_objid.

                 wa_emp_grp-objid_z5  = lv_objid.

                 MODIFY it_emp_grp FROM wa_emp_grp INDEX es_row_no-row_id.
               ENDIF.
             ENDIF.
           ENDIF.
         ENDIF.
     ENDCASE.
  CALL METHOD alvgrid->refresh_table_display.

   ENDMETHOD.
  ENDCLASS.


FORM prepare_f4.

   wa_f4-fieldname = 'OBJID'.
   wa_f4-register = 'X'.
   wa_f4-getbefore = space.
   wa_f4-chngeafter = space.
   APPEND wa_f4 TO lt_f4 .

   DATA o_alv_handler TYPE REF TO lcl_event_handler.
   CALL METHOD alvgrid->register_f4_for_fields
     EXPORTING
       it_f4 = lt_f4.

ENDFORM.


Please take a look.



Thanks.

Read only

0 Likes
2,576

Hi Friend,

You forgot to register the event ONF4. Add this statement

SET HANDLER : o_alv_handler->handle_f4 FOR alvgrid.


This will solve your problem.


Regards,

Abijith


Read only

0 Likes
2,576

Dear Abijith,

The problem still shows the same message.

FORM prepare_f4.

   wa_f4-fieldname = 'OBJID'.
   wa_f4-register = 'X'.
   wa_f4-getbefore = space.
   wa_f4-chngeafter = space.
   APPEND wa_f4 TO lt_f4 .

   DATA o_alv_handler TYPE REF TO lcl_event_handler.
   CALL METHOD alvgrid->register_f4_for_fields
     EXPORTING
       it_f4 = lt_f4.

  DATA : event_handler TYPE REF TO lcl_event_handler.
     CREATE OBJECT event_handler.
     SET HANDLER event_handler->handle_on_f4 FOR alvgrid.

ENDFORM.



Also i got lt_return returns no value while debugging mode. Any idea why this happening?

Read only

0 Likes
2,576

Dear Abijith,

Can you please send me a whole code to check if i am doing anything wrong? It would help me a lot.

Thanks.

Read only

Former Member
0 Likes
2,576

This message was moderated.

Read only

Former Member
0 Likes
2,576

Hi,

Please set the wa_f4-getbefore = 'X' and check it again?

Regards,

Sudeesh Soni

Read only

0 Likes
2,576

Dear Sudeesh,

Setting this condition not helps to solve my issue.

Thanks.