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: 

Add check box before each line

Former Member
0 Kudos

Hi All,

I am using alv grid to print the out put. It is comming correct. I want to add check box before each line of out put. How can I do it?

And in the selection screen I want delivery block p_lifsk as '01' fixed, so that user cannot change the value.

Please help me.

Thanks

Veni.


PERFORM get_data.
  PERFORM PROCESS_data.
  perform sub_alv_routines.
  perform comment_build  using t_list_top_of_page[].
  g_repid = sy-repid.
  perform alv_build_fieldcat using 'IT_OUTPUT' g_repid.
  perform sub_call_alv_grid tables it_output.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

By pressing the Control button you can select more than rows...

Also it will be easy for you to handle if you are going to have additional buttons on the application toolbar..

For the selected rows..You can just use the following statements..

LOOP AT IT_OUTPUT WHERE CHECK = 'X'.

ENDLOOP.

If you are having a check box in the screen..And if you have additional buttons..It is not properly capturing the rows that are selected...I checked it..

Let me know if you have any questions..

Thanks,

Naren

24 REPLIES 24

Former Member
0 Kudos

add a field for the check box in the internal table and in the field catalog add a check box.

eg:

fcat_wa-col_pos = col_pos.

fcat_wa-fieldname = field.

fcat_wa-datatype = rtable.

fcat_wa-inttype = rinttype.

fcat_wa-outputlen = routputlength.

fcat_wa-decimals_out = rdecimal.

fcat_wa-seltext_l = rseltext.

fcat_wa-ref_tabname = rtable.

fcat_wa-key = key.

fcat_wa-checkbox = checkbox.

if you are updating the check box after the grid is created then dont forget to refresh the selected line

rs-refresh = 'X'

0 Kudos

Hi KE,

My field cat looks like this. where do you want me to add check box.

and also how should I declare it in the internal table.

Thanks

Veni

form alv_build_fieldcat using lt_output l_repid.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = l_repid

i_internal_tabname = lt_output

i_inclname = l_repid

changing

ct_fieldcat = it_alv_field_cat[]

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0. "something went wrong...

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

exit.

endif.

endform. " ALV_BUILD_FIELDCAT

Former Member
0 Kudos

what does your it_alv_field_cat[] have? it should be the catalog where you can include the check box. and in the above internal table it_output include a field with 1 char

Former Member
0 Kudos

Are you using ABAP OO or FM to display the ALV..

Thanks,

Naren

0 Kudos

Hi,

Data: it_alv_field_cat type slis_fieldcat_alv occurs 0 with header line,

I declared

CBOX AS CHECKBOX in it_output.

I am getting this error.

"Unable to interpret "AS". Possible causes of error: Incorrect spelling or comma error."

I am using FM only.

Thanks

Veni.

Former Member
0 Kudos

Hi,

In the internal table it_output have a field for the check box..

CHECK TYPE CHAR1,

After calling the FIELDCATALOG_MERGE function module..Modify the fieldcatalog internal table..

DATA: S_FIELDCATALOG type SLIS_T_FIELDCAT_ALV.

s_fieldcatalog-checkbox = 'X'.

MODIFY it_alv_field_cat from s_fieldcatalog

transporting checkbox

where fieldname = 'CHECK'.

Thanks,

Naren

0 Kudos

Hi Naren,

I declared CBOX in it_output.

I made the following changes, please look at it.

Thanks

Veni.

<u>This is my previous code.</u>

Data: it_alv_field_cat type slis_fieldcat_alv occurs 0 with header line,

form alv_build_fieldcat using lt_output l_repid.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = l_repid

i_internal_tabname = lt_output

i_inclname = l_repid

changing

ct_fieldcat = it_alv_field_cat[]

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0. "something went wrong...

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

exit.

endif.

endform. " ALV_BUILD_FIELDCAT

<u>I changed it to,</u>

DATA: S_FIELDCATALOG type SLIS_T_FIELDCAT_ALV.

form alv_build_fieldcat using lt_output l_repid.

s_fieldcatalog-checkbox = 'X'.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = l_repid

i_internal_tabname = lt_output

i_inclname = l_repid

changing

ct_fieldcat = s_fieldcatalog[]

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0. "something went wrong...

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

exit.

endif.

endform. " ALV_BUILD_FIELDCAT

Former Member
0 Kudos

Hi,

The changes are marked in bold..

form alv_build_fieldcat using lt_output l_repid.

<b>DATA: S_FIELDCATALOG type SLIS_T_FIELDCAT_ALV.</b>

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = l_repid

i_internal_tabname = lt_output

i_inclname = l_repid

changing

ct_fieldcat = s_fieldcatalog[]

exceptions

inconsistent_interface = 1

program_error = 2

others = 3.

if sy-subrc <> 0. "something went wrong...

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

exit.

endif.

<b>s_fieldcatalog-checkbox = 'X'.

MODIFY it_alv_field_cat from s_fieldcatalog

transporting checkbox

where fieldname = 'CBOX'.</b>

endform. " ALV_BUILD_FIELDCAT

0 Kudos

Thank you Naren,

I tried it with the changes. It is now giving me the error saying '"S_FIELDCATALOG" is a table without a header line and therefore has no component called "BOX_FIELDNAME". '

it is comming at

s_fieldcatalog-checkbox = 'X'.

Thank you

Veni.

Former Member
0 Kudos

Hi,

Declare the s_fieldcatalog..

DATA: S_FIELDCATALOG type slis_fieldcat_alv..

Thanks,

Naren

0 Kudos

Hi Naren,

I declared the data stmt but did not add 'with header line'. Now I added no syntax errors, but in the out put I donot see any check box.

Please help me.

Thanks

Veni.

Former Member
0 Kudos

Hi,

Did you do the modify statement as I mentioned above..

MODIFY it_alv_field_cat from s_fieldcatalog

transporting checkbox

where fieldname = 'CBOX'.

THanks,

Naren

Former Member
0 Kudos

Hi,

Check this sample program..

TYPE-POOLS: slis.

DATA: BEGIN OF itab1 OCCURS 0,

check TYPE c,

vbeln LIKE vbep-vbeln,

posnr LIKE vbep-posnr,

END OF itab1.

DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv.

DATA: v_repid TYPE syrepid.

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = v_repid

i_internal_tabname = 'ITAB1'

i_inclname = v_repid

CHANGING

ct_fieldcat = t_fieldcatalog.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

s_fieldcatalog-checkbox = 'X'.

s_fieldcatalog-edit = 'X'.

MODIFY t_fieldcatalog FROM s_fieldcatalog

TRANSPORTING checkbox edit

WHERE fieldname = 'CHECK'.

DATA: s_layout TYPE slis_layout_alv.

SELECT vbeln posnr UP TO 10 ROWS

FROM vbep

INTO CORRESPONDING FIELDS OF TABLE itab1.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

it_fieldcat = t_fieldcatalog

is_layout = s_layout

TABLES

t_outtab = itab1

EXCEPTIONS

program_error = 1

OTHERS = 2.

Thanks,

Naren

0 Kudos

Hi Naren,

Yes, I modified the statement as you mentioned. I will try from the sample program now.

Thanks

Veni.

0 Kudos

Hi Naren,

I checked the sample program. I did not see much difference. I just added s_fieldcatalog-edit = 'X'.

Then I ran the program, no luck, no check box in out put.

I am sending my program and include, can you please check it.

Thanks

Veni.


REPORT ZSDR_DELIBLOCK
       no standard page heading line-size 255.

*TYPE-POOLS: slis.
TABLES: LIKP, TVLS.

include zfri_alv_grid_db.

data: g_repid like sy-repid.

DATA: Begin of IT_LIKP occurs 0,
      VBELN like LIKP-VBELN,
      LFDAT like LIKP-LFDAT,
      KUNNR like LIKP-KUNNR,
      KNKLI LIKE LIKP-KNKLI,
      NETWR like LIKP-NETWR,
      End of IT_LIKP.

DATA: Begin of IT_OUTPUT occurs 0,
      CHECK TYPE CHAR1,
      VBELN like LIKP-VBELN,
      LFDAT like LIKP-LFDAT,
      KUNNR like LIKP-KUNNR,
      KNKLI LIKE LIKP-KNKLI,
      NETWR like LIKP-NETWR,
      End of IT_OUTPUT.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: S_LFDAT FOR LIKP-LFDAT,
                S_LIFSK FOR LIKP-LIFSK,
                S_KUNNR FOR LIKP-KUNNR.
PARAMETERS: P_LIFSK TYPE LIKP-LIFSK DEFAULT '01'.

SELECTION-SCREEN END OF BLOCK b1.

at selection-screen output.

  loop at screen.
    if screen-name = 'P_LIFSK'.
      screen-input = 0.
      modify screen.
    endif.
  endloop.

start-of-selection.
  PERFORM get_data.
  PERFORM PROCESS_data.
  perform sub_alv_routines.
  perform comment_build  using t_list_top_of_page[].
  g_repid = sy-repid.
  perform alv_build_fieldcat using 'IT_OUTPUT' g_repid.
  perform sub_call_alv_grid tables it_output.

FORM get_data.
  SELECT VBELN LFDAT KUNNR KNKLI NETWR
                FROM LIKP
                INTO TABLE IT_LIKP
                WHERE LFDAT IN S_LFDAT
                  AND LIFSK IN S_LIFSK
                  AND KUNNR IN S_KUNNR
                  AND LIFSK = P_LIFSK.
ENDFORM.                    " get_data

FORM process_data.

  loop at it_LIKP.
    if sy-subrc = 0.
      move-corresponding it_LIKP to it_output.
      append it_output.
      clear it_output.
    endif.
  endloop.

ENDFORM.                    " process_data


form top_of_page .
  call function 'REUSE_ALV_COMMENTARY_WRITE'
           exporting
             i_logo             = 'HTMLCNTL_TESTHTM2_SAPLOGO'
*              i_logo             = 'ENJOYSAP_LOGO'
                it_list_commentary = t_list_top_of_page.

endform.                    "top_of_page

form comment_build using lt_top_of_page type slis_t_listheader.
  data:
      ls_line type slis_listheader.
*  Company code
  clear ls_line.
  ls_line-typ  = 'S'.
  ls_line-key  = 'customer'.
  ls_line-info = s_kunnr.
  append ls_line to lt_top_of_page.
endform.                    " comment_build

-




data:
  g_variant              like  disvariant.          "variants

type-pools:  slis.                                "Global types

data: s_alv_layout_cat          type slis_layout_alv.
data: s_alv_print_cat           type slis_print_alv.

data: it_alv_field_cat type slis_fieldcat_alv occurs 0 with header line,
      S_FIELDCATALOG type slis_fieldcat_alv occurs 0 with header line,
      i_fieldcat type slis_fieldcat_alv occurs 0 with header line,
      w_fieldcat like line of i_fieldcat.        "ALV FieldCat WorkArea
* ALV sort catalog
data: it_alv_sort_cat type slis_sortinfo_alv occurs 0 with header line.
* ALV event catalog
data: it_alv_event_cat type slis_alv_event occurs 0 with header line.
data: t_list_top_of_page type slis_t_listheader.

form sub_alv_routines.
* Populate the layout catalog for alv
  perform alv_layout.
* Populate the event catalog for alv
  perform alv_events.
* Populate the print catalog for alv
  perform alv_print.
endform.                 "sub_alv_routines

form sub_call_alv_grid tables lt_output.

* Call ALV display
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = sy-cprog
            is_layout               = s_alv_layout_cat
            i_callback_user_command = 'USER_COMMAND'
            it_fieldcat             = it_alv_field_cat[]
*           it_sort                 = it_alv_sort_cat[]
            i_save                  = 'A'
            is_variant              = g_variant
            it_events               = it_alv_event_cat[]
            is_print                = s_alv_print_cat
            i_grid_title            = text-t01
       tables
            t_outtab                = lt_output
       exceptions
            program_error           = 1
            others                  = 2.


*  if sy-subrc <> 0.
*    message e048. "Error executing func. module REUSE_ALV_LIST_DISPLAY
*  endif.


endform.                    " sub_call_alv_grid

form alv_layout.

* Enable striped output display if user wants
  s_alv_layout_cat-zebra                = 'X'.
* Optimize column width if user wants
  s_alv_layout_cat-colwidth_optimize    = 'X'.
  s_alv_layout_cat-box_fieldname        = space.
  s_alv_layout_cat-no_input             = 'X'.
*  if p_lines = 'X'.
*    s_alv_layout_cat-no_vline           = ' '.
*  else.
*    s_alv_layout_cat-no_vline           = 'X'.
*  endif.
  s_alv_layout_cat-no_colhead           = ' '.
  s_alv_layout_cat-lights_condense      = 'X'.
  s_alv_layout_cat-info_fieldname       = 'ALV_COLOR'.
  s_alv_layout_cat-confirmation_prompt  = 'X'.
  s_alv_layout_cat-detail_popup         = 'X'.
  s_alv_layout_cat-detail_initial_lines = 'X'.

endform.                    " alv_layout

form alv_events.
* Declare event catalog for page headers
  clear it_alv_event_cat.
  it_alv_event_cat-name = 'TOP_OF_PAGE'.
  it_alv_event_cat-form = 'TOP_OF_PAGE'.
  append it_alv_event_cat.

* Declare event catalog for report footers
  clear it_alv_event_cat.
  it_alv_event_cat-name = 'END_OF_LIST'.
  it_alv_event_cat-form = 'END_OF_LIST'.
*  append it_alv_event_cat.


endform.                    " alv_events

form alv_print.
* Declare print catalog for statistics page
  s_alv_print_cat-no_print_listinfos = 'X'.

endform.                    " alv_print


form alv_build_fieldcat  using lt_output  l_repid.
* This function module will build the bulk of the field catalog,
* but apparently there is still need for some changes...
* cannot use sy-repid for i_program_name
* i_inclname must be hardcoded for this to work
* i_internal_tabname must be in capital letters

*DATA: S_FIELDCATALOG type SLIS_T_FIELDCAT_ALV occurs 0.

  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       exporting
          i_program_name         = l_repid
          i_internal_tabname     = lt_output
*         I_CLIENT_NEVER_DISPLAY = 'X'
          i_inclname             = l_repid
       changing
          ct_fieldcat            = it_alv_field_cat[]
      exceptions
           inconsistent_interface = 1
           program_error          = 2
           others                 = 3.

  if sy-subrc <> 0.                    "something went wrong...
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    exit.
  endif.

  s_fieldcatalog-checkbox = 'X'.
  s_fieldcatalog-edit = 'X'.

  MODIFY it_alv_field_cat from s_fieldcatalog
  transporting checkbox
  where fieldname = 'CHECK'.

endform.                    " ALV_BUILD_FIELDCAT

Former Member
0 Kudos

Hi,

In the internal table it_output use type c instead of type char1 for the field check..

DATA: Begin of IT_OUTPUT occurs 0,

<b> CHECK TYPE C,</b>

VBELN like LIKP-VBELN,

LFDAT like LIKP-LFDAT,

KUNNR like LIKP-KUNNR,

KNKLI LIKE LIKP-KNKLI,

NETWR like LIKP-NETWR,

End of IT_OUTPUT.

THanks,

Naren

0 Kudos

Thank you very much Naren.

I dont know how I ignored that. Now I have the check boxes in column1. But these are disabled. How can I make these enable, so that I can check the required deliveries for processing.

Thanks

Veni.

Former Member
0 Kudos

Hi,

In modify statement you are not passing the EDIT field..Eventhough you modified the structure S_FIELDCATALOG..

MODIFY it_alv_field_cat from s_fieldcatalog

transporting checkbox <b>EDIT</b>

where fieldname = 'CHECK'.

Thanks,

Naren

0 Kudos

Hi Naren,

Before the EDIT, The output has column 1 with chech boxes.

After the EDIT,The out put has push buttons before each row and column 1 with chech boxes which can be selected.

How to get rid of these buttons.

Thanks

Veni.

Former Member
0 Kudos

Hi,

I believe you cannot ignore those buttons...If you want the buttons instead of the check boxes..Comment the MODIFY statement..

*MODIFY t_fieldcatalog FROM s_fieldcatalog

*TRANSPORTING checkbox edit

*WHERE fieldname = 'CHECK'

Then in the layout structure in the box_fieldname field remove space and give the value 'CHECK'..

s_alv_layout_cat-box_fieldname = 'CHECK'.

Thanks,

Naren

0 Kudos

Hi Naren,

Sorry I am taking lot of your time. I did as you mentioned above, Report looks great but with these buttons I cannot select more that one.

Can we get rid of these buttons and have check boxes only.

Thanks

Veni.

Former Member
0 Kudos

Hi,

By pressing the Control button you can select more than rows...

Also it will be easy for you to handle if you are going to have additional buttons on the application toolbar..

For the selected rows..You can just use the following statements..

LOOP AT IT_OUTPUT WHERE CHECK = 'X'.

ENDLOOP.

If you are having a check box in the screen..And if you have additional buttons..It is not properly capturing the rows that are selected...I checked it..

Let me know if you have any questions..

Thanks,

Naren

0 Kudos

Thank you Very Much Naren.

I really Appritiate your help.

Regards,

Veni.

Former Member
0 Kudos

You are welcome )

Thanks,

Naren