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: 

working with two custom containers on same screen

former_member185116
Active Participant
0 Kudos
986

hello all,

we have developed a Z-Report like this,

when i click the hotspot field on first container the corresponding data is displayed on second container,

however if no data exists for that particular record,

i tried to display message (MESSAGE 'No data Exists' type 'I')...

but the problem is when i select another record(which has data) it is throwing error,

********this is my code*************************


FORM ALV_DISPLAY_ON_SAME_SCREEN .

if custom2 IS INITIAL .


     CREATE OBJECT CUSTOM2
       EXPORTING
*        PARENT                      =
         CONTAINER_NAME              = 'CONTAINER2'
*        STYLE                       =
*        LIFETIME                    = lifetime_default
*        REPID                       =
*        DYNNR                       =
*        NO_AUTODEF_PROGID_DYNNR     =
*      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 GRID2
       EXPORTING
*        I_SHELLSTYLE      = 0
*        I_LIFETIME        =
         I_PARENT          = custom2
*        I_APPL_EVENTS     = space
*        I_PARENTDBG       =
*        I_APPLOGPARENT    =
*        I_GRAPHICSPARENT  =
*        I_NAME            =
*        I_FCAT_COMPLETE   = SPACE
*      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.






*fieldcat for second custom container *************************


   REFRESH it_fcat2.
   clear  wa_fcat2.


    clear wa_fcat2.
    wa_fcat2-col_pos = 1.
    wa_fcat2-fieldname = 'PSPNR'.
    wa_fcat2-tabname = 'IT_SEC_PROJ'.
    wa_fcat2-outputlen = 20.
    wa_fcat2-coltext = 'Proj Def'.
    wa_fcat2-style = ALV_STYLE_FONT_BOLD.
*   wa_fcat2-just = 'C'.
*   wa_fcat2-emphasize = 'C501'.
    APPEND wa_fcat2 to it_fcat2.
    clear wa_fcat2.


    clear wa_fcat2.
    wa_fcat2-col_pos = 2.
    wa_fcat2-fieldname = 'POST1'.
    wa_fcat2-tabname = 'IT_SEC_PROJ'.
    wa_fcat2-outputlen = 30.
    wa_fcat2-coltext = 'Description'.
    wa_fcat2-style = ALV_STYLE_FONT_BOLD.
*   wa_fcat2-just = 'C'.
*   wa_fcat2-emphasize = 'C501'.
    APPEND wa_fcat2 to it_fcat2.
    clear wa_fcat2.


    clear wa_fcat2.
    wa_fcat2-col_pos = 3.
    wa_fcat2-fieldname = 'WTJHR'.
    wa_fcat2-tabname = 'IT_SEC_PROJ'.
    wa_fcat2-outputlen = 20.
    wa_fcat2-coltext = 'Budget Division Level'.
    wa_fcat2-style = ALV_STYLE_FONT_BOLD.
    wa_fcat2-do_sum = 'X'.
*   wa_fcat2-just = 'C'.
*   wa_fcat2-emphasize = 'C501'.
    APPEND wa_fcat2 to it_fcat2.
    clear wa_fcat2.


    clear wa_fcat2.
    wa_fcat2-col_pos = 4.
    wa_fcat2-fieldname = 'WTJHR1'.
    wa_fcat2-tabname = 'IT_SEC_PROJ'.
    wa_fcat2-outputlen = 20.
    wa_fcat2-coltext = 'Budget Issued to WOs'.
    wa_fcat2-style = ALV_STYLE_FONT_BOLD.
*   wa_fcat2-just = 'C'.
    wa_fcat2-emphasize = 'C501'.
    wa_fcat2-do_sum = 'X'.
    wa_fcat2-hotspot = 'X'.
    APPEND wa_fcat2 to it_fcat2.
    clear wa_fcat2.


    clear wa_fcat2.
    wa_fcat2-col_pos = 5.
    wa_fcat2-fieldname = 'BAL'.
    wa_fcat2-tabname = 'IT_SEC_PROJ'.
    wa_fcat2-outputlen = 20.
    wa_fcat2-coltext = 'Balance'.
    wa_fcat2-style = ALV_STYLE_FONT_BOLD.
    wa_fcat2-do_sum = 'X'.
*   wa_fcat2-just = 'C'.
*   wa_fcat2-emphasize = 'C601'.
*   wa_fcat2-hotspot = 'X'.
    APPEND wa_fcat2 to it_fcat2.
    clear wa_fcat2.



*********string******************************

string1 = 'Wise Budget Details'.

CONCATENATE lv_ptext string1 into string2 SEPARATED BY space.

*layout details *****************************
  wa_layout2-cwidth_opt = 'X'.
  wa_layout2-zebra = 'X'.
  wa_layout2-GRID_TITLE = string2.
*variant details ******************************
  wa_variant2-report = sy-repid.
  wa_variant2-username = sy-uname.



*if it_sec_proj[] is NOT INITIAL.

  CALL METHOD GRID2->SET_TABLE_FOR_FIRST_DISPLAY
     EXPORTING
*     I_BUFFER_ACTIVE               =
*     I_BYPASSING_BUFFER            =
*     I_CONSISTENCY_CHECK           =
*     I_STRUCTURE_NAME              =
       IS_VARIANT                    = wa_variant2
       I_SAVE                        = 'A'
*      I_DEFAULT                     = 'X'
       IS_LAYOUT                     = wa_layout2
*     IS_PRINT                      =
*     IT_SPECIAL_GROUPS             =
*     IT_TOOLBAR_EXCLUDING          =
*     IT_HYPERLINK                  =
*     IT_ALV_GRAPHICS               =
*     IT_EXCEPT_QINFO               =
*     IR_SALV_ADAPTER               =
    CHANGING
      IT_OUTTAB                     = it_sec_proj
      IT_FIELDCATALOG               = it_fcat2
*     IT_SORT                       =
*     IT_FILTER                     =
    EXCEPTIONS
      INVALID_PARAMETER_COMBINATION = 1
      PROGRAM_ERROR                 = 2
      TOO_MANY_LINES                = 3
      others                        = 4
          .
  IF SY-SUBRC <> 0.
*  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.






  else.


   call METHOD grid2->refresh_table_display.



  endif.            "endif of custom2 is initial



CREATE OBJECT obj_event_class2.
set HANDLER obj_event_class2->handle_hotspot_click FOR grid2.




ENDFORM.                    " ALV_DISPLAY_ON_SAME_SCREEN

***************************************************

how do i avoid this...

thanks in advance.....

11 REPLIES 11

former_member182550
Active Contributor
0 Kudos
543

The first time that you show the ALV grid in the second container,  use (as you do) Set_Table_For_First_Display.   Thereafter,  if grid2 has already been instantiated,  replace the data in Grid2's source table and then call method refresh_table_display.

Or....

Go the long way round and completely dispose of Grid2 and recreate it but that's overkill.

Regards

Rich

0 Kudos
543

hi richard,

thanks for your quick reply,

that is fine,but i want to display a message (when no data exist)...

0 Kudos
543

Easy,

clear the source data table,  refresh the second grid and then use the MESSAGE statement with a type I message.

However,  I was answering your question:

"but the problem is when i select another record(which has data) it is throwing error,"

Also take note of Raymonds reply.

Regards

Rich

0 Kudos
543

hi richard,

solved half part,

but when i display 'No data Exist' message ,at the same time  i need to disable the data on the right side,

the data on the right side(which is previous records data) should disappear...

0 Kudos
543

The data will  (or should) dissappear once your user selects the green tick on the message box,  however,  you could try:

Call Method cl_Gui_Cfw=>Flush( ).

Place this after you refresh the grid and before you display the message.

As an aside,  replace the hotspot_click event with a selection changed event,  something like this:

*
*               Add additional handlers to handle the changed row events etc
*
                Call Method Me->Register_Delayed_Event
                     Exporting
                       i_Event_Id = Me->Mc_Evt_Delayed_Change_Select
                     Exceptions
                       Others = 1.
*
*               Change the delay reaction time to make the grid more reactive -
*               hence the lcl wrapper class.
*
                Me->Set_Delay_Time( ).
                Set Handler: Me->Handle_Del_Chgd_Sel_CBack For Me.

Then,  when your user moves up or down the grid,  the data on the left will change (if you put your code for populating grid2 in the correct handler),  and if there is no data it will just appear blank.

Rich

0 Kudos
543

richrad,

Call Method cl_Gui_Cfw=>Flush( ). is not working....


is there any other method which makes to disappear data on right side when green tick is selected on message window...


or else is it an efficient programming skill to again call


CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY



with an empty table data...

0 Kudos
543

Are you calling refresh_table_display after updating the table used by the grid ?  When I say updating I mean either updating with the records you wish to display,  or clearing the table if there are no records ?

There is no reason to call set_table_for_first_display after your first call - Refresh_table_display is there to do eaxctly what it says.

I have no problem in doing exactly the same as you do:


  method REDISPLAY.

*

*        Column width optimisation does not work.

*

*        From OSS note 1009650

*

*             [12] Within the ALV Grid, the system calculates the optimal column width only during the

*             first call due to performance reasons.

*

*             If the method CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY is called for the grid instance, the system

*             does not optimize the grid again.

*

*             To force the grid to be optimized again, the methods CL_GUI_ALV_GRID->GET_FRONTEND_LAYOUT and

*             CL_GUI_ALV_GRID->SET_FRONTEND_LAYOUT must be called before the method

*             CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY is called. The transfer of the parameter CWIDTH_OPT = 'X'

*             ensures that the column widths are calculated again.

*

*             In the object model of the ALV (package SALV_OM), you must reset the column optimization by calling

*             the method cl_salv_columns->set_optimize before you call the method cl_salv_table->refresh.*

*

         Data: ls_Stable Type ALV_Stable_Flags.

*

         ls_Stable-Row = Abap_True.

         ls_Stable-Col = Abap_True.

         Me->Set_FrontEnd_Layout( Me->Get_Wrapper_Layout( ) ).

         Me->Refresh_Table_Display( Exporting is_Stable = ls_Stable ).

         Free: ls_Stable.

  endmethod.

Rich

raymond_giuseppi
Active Contributor
0 Kudos
543

Which error did you got?

Hint: Use the variant "handle" field to distinguish both ALV catalogs/variants and prevent some errors.

Regards,

Raymond

Chintu6august
Contributor
0 Kudos
543

hi,

call method grid2->set_table_for_first_display outside the IF condition of custom container 2.

as your custom container object is not initial after the first selection that's why you are getting this prompt.

thanks!!

0 Kudos
543

Hi,

     where you are throwing the error,I mean your validation part for checking the data exists for the particular record or not?

If my guess is right you are throwing the Information massage for error , So even after the error the  below code is being executed this should be the problem

    

try using

     MESSAGE <your message> TYPE 'E' DISPLAY LIKE 'I'.

Hope this helps.

0 Kudos
543

hi,

it should be like this

     MESSAGE <your message> TYPE 'I' DISPLAY LIKE 'E'.

after the error the  below code will execute.

thanks!!