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

How to create checkboxes in module pool dynamically in m.pool (without alv)

abaper_guy
Active Participant
0 Kudos
1,625

According to my requirements , i do not know how many checkboxes i will create , during compile time. So during PAI only i will like to create checkboxes on my screen. Some people suggested making alv with checbox but I would like to do this without using ALV

1 ACCEPTED SOLUTION
Read only

che_eky
Active Contributor
0 Kudos
1,121

You could create all check boxes to start with and make them invisible on first entry (using screen attributes). Then during PAI or PBO work out how many you actually need and make them visible to the user.

9 REPLIES 9
Read only

Kiran_Valluru
Active Contributor
0 Kudos
1,121

Hi,.

Use CL_DD_DOCUMENT Class and create check box fields dynamically..

hope this helps you.,

Thanks & Regards,

Kiran

Read only

che_eky
Active Contributor
0 Kudos
1,122

You could create all check boxes to start with and make them invisible on first entry (using screen attributes). Then during PAI or PBO work out how many you actually need and make them visible to the user.

Read only

abaper_guy
Active Participant
0 Kudos
1,121

@Che Eky: Thanks for your reply. My problem is that I do not know until runtime that how many checkboxes will have to be created.It actually depends upon user input. So i cant create any checkboxes manually(satically) from before.

THANKS

Read only

che_eky
Active Contributor
0 Kudos
1,121

I think you misunderstood what I said. Say you will only ever need a maximum of 10 check boxes. Create the 10 check boxes in the screen painter. On first entry to the screen make all the check boxes invisible (using logic in the PBO). Then when you know exactly how many check boxes are required you can make them visible / invisible as required in the PBO.

This is one way of achieving what you require in a dialog. I am not sure it can be done dynamically.

Read only

Former Member
0 Kudos
1,121

Hi amber,

If the checkboxes can be shown in a separate screen, you can also use the list processor...

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.

SET PF-STATUS space.

SUPPRESS DIALOG.

DO 5 TIMES.

WRITE: / '' AS CHECKBOX, sy-index.

ENDDO.

Otherwise I guess an ALV would be the best option...

Read only

abaper_guy
Active Participant
0 Kudos
1,121

Thanks for your replies.

@Manu D'Haeyer : Yes my requirements is for the same screen only. Can u guide me how to do it with ALV because in ALV that toolbar will come which i dont want to come above the checkboxes. Also is there a direct way of adding a checkbox in an ALV using some fieldcatalog ?? ,

THANKS

Read only

Former Member
0 Kudos
1,121

Hi

If you want to create a certain (variable) number of checkbox (without ALV) you can use the old STEPLOOP (It's simalar the table control)

Max

Read only

Former Member
0 Kudos
1,121
PARAMETERS: P_CK TYPE I.

DATA: BEGIN OF T_CK_BOX OCCURS 0,
        CK   TYPE FLAG,
        TEXT TYPE TEXT40,
      END   OF T_CK_BOX.

DATA: V_CURSOR TYPE I.

START-OF-SELECTION.

  DO P_CK TIMES.
    T_CK_BOX-TEXT = 'Check Box'.
    WRITE SY-INDEX TO T_CK_BOX-TEXT+10 LEFT-JUSTIFIED.
    APPEND T_CK_BOX.
  ENDDO.

  CALL SCREEN 100.

PROCESS BEFORE OUTPUT.
  LOOP AT T_CK_BOX CURSOR V_CURSOR.
  ENDLOOP.
*
PROCESS AFTER INPUT.
  LOOP AT T_CK_BOX.
  ENDLOOP.

but I don't know if the effect is what you want.

Max

Read only

Former Member
0 Kudos
1,121

Hi,

Hiding the standard toolbar is not a problem. Please check this:


TYPES: BEGIN OF ty_chk,
         chk1 TYPE flag,
         fld1 TYPE string,
        END OF ty_chk,
        tt_chk TYPE STANDARD TABLE OF ty_chk.
 
DATA: gt_checkboxes TYPE tt_chk,
      gs_chk TYPE ty_chk.
 
DATA: lr_cont    TYPE REF TO cl_gui_custom_container,
      gr_table   TYPE REF TO cl_salv_table,
      lr_funct   TYPE REF TO cl_salv_functions,
      lr_columns TYPE REF TO cl_salv_columns_table,
      lr_column  TYPE REF TO cl_salv_column_table.
 

FIELD-SYMBOLS: <fs> TYPE ty_chk.

 
PARAMETERS: p_nb TYPE int1.

 
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
 CLASS lcl_event_handler DEFINITION.
 
   PUBLIC SECTION.
     METHODS:
       on_link_click FOR EVENT link_click OF cl_salv_events_table
         IMPORTING row column.
 
 ENDCLASS. "lcl_event_handler DEFINITION
 

*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
 CLASS lcl_event_handler IMPLEMENTATION.
   METHOD on_link_click.
 *-- Get the value of the checkbox and set the value accordingly
     FIELD-SYMBOLS: <lfa_data> LIKE LINE OF gt_checkboxes.
     READ TABLE gt_checkboxes ASSIGNING <lfa_data> INDEX row.
     CHECK sy-subrc IS INITIAL.
     IF <lfa_data>-chk1 IS INITIAL.
       <lfa_data>-chk1 = 'X'.
     ELSE.
       CLEAR <lfa_data>-chk1.
     ENDIF.
     gr_table->refresh( ).
   ENDMETHOD. "on_link_click

 ENDCLASS. "lcl_event_handler IMPLEMENTATION
 

START-OF-SELECTION.

   DO p_nb TIMES.
     APPEND INITIAL LINE TO gt_checkboxes ASSIGNING <fs>.
     <fs>-fld1 = 'Test new line'.
   ENDDO.
 

  CALL SCREEN 100.

 
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
 MODULE status_0100 OUTPUT.
   SET PF-STATUS 'ST100'.
 
  IF lr_cont IS NOT BOUND.
     IF cl_salv_table=>is_offline( ) EQ if_salv_c_bool_sap=>false.
       CREATE OBJECT lr_cont
         EXPORTING
           container_name = 'CONT'.
     ENDIF.
 
    TRY.
         CALL METHOD cl_salv_table=>factory
           EXPORTING
             r_container    = lr_cont
             container_name = 'CONT'
           IMPORTING
             r_salv_table   = gr_table
           CHANGING
             t_table        = gt_checkboxes.
       CATCH cx_salv_msg.
         EXIT.
     ENDTRY.
 
*-- Activate functions
     lr_funct = gr_table->get_functions( ).
     lr_funct->set_all( abap_false ).                "Remove standard ALV toolbar
     lr_columns = gr_table->get_columns( ).
     lr_columns->set_optimize( 'X' ).
     lr_columns->set_headers_visible( abap_false ).  "Remove column header
 
    TRY.
         lr_column ?= lr_columns->get_column( 'CHK1' ).
         lr_column->set_cell_type( if_salv_c_cell_type=>checkbox_hotspot ).
         lr_column->set_long_text( 'CHECK' ).
       CATCH cx_salv_not_found.                          "#EC NO_HANDLER
     ENDTRY.
 
*-- Get the event object
     DATA: lo_events TYPE REF TO cl_salv_events_table.
     lo_events = gr_table->get_event( ).
 
*-- Instantiate the event handler object
     DATA: lo_event_handler TYPE REF TO lcl_event_handler.
     CREATE OBJECT lo_event_handler.

*-- Event handler
     SET HANDLER lo_event_handler->on_link_click FOR lo_events.
 
*-- Show checkboxes list
     gr_table->display( ).
   ENDIF.
 ENDMODULE.                 " STATUS_0100  OUTPUT

 
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
 MODULE user_command_0100 INPUT.
   CASE sy-ucomm.
     WHEN 'BACK'.
       LEAVE.
   ENDCASE.
 ENDMODULE.                 " USER_COMMAND_0100  INPUT 

Here, I also removed the column header...

Kr,

m.