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

Displaying internal table fields data based on user selection

Former Member
0 Likes
1,426

Hi all,

I am having a checkbox for each field in the internal table.

and i only have to display the fields of the internal table which the user has selected based on the check boxes provided.

Could you plz help me out, how can i display the data of only those fields which the user has selected initially.....

Thanks,

anil.

13 REPLIES 13
Read only

Former Member
0 Likes
1,388

hi anil reddy

Consider Your Internal table is ITAB and checkbox field is chk

Loop at itab where chk = 'X'.

Write "data"

Endloop.

Regards

Deva

Read only

Former Member
0 Likes
1,388

Hi,

when you build your fieldcat, test the checkboxes and include only the fields your user has selected.

Regards

Read only

Former Member
0 Likes
1,388

Try this way...

In ALV one can hide the fields based on condition.

while populating the field catalog check the condition which fields have been selected and in field catalog assignment check for condition...If condition fails hide the field...

Read only

Former Member
0 Likes
1,388

Hi Dude,

We can do it using ALV. Please follow the below steps.

1.while creating Field catelog For the Fields,Use the Condition,

If Field1 = 'X'.

i_fcat-col_pos = 5.

i_fcat-fieldname = 'SPART'.

i_fcat-tabname = 'IT_VBAK'.

i_fcat-seltext_l = 'DIVISION'.

append i_fcat.

clear i_fcat.

Endif.

Hope This Helps U.

Read only

Former Member
0 Likes
1,388

Hi Anil,

I didn't get your question. Checkboxes are on the output list or ALV?

Read only

0 Likes
1,388

Hi abijeet,

Actually i have to display the data of the internal table in the list not in ALV. and i have to display the data of only those

fields which the user has selected. For this i will provide a number of checkboxes based on the number of fields.

Lets assume in my internal table iam displaying KUNNR, LAND1, NAME1.

I will fetch data into these fields based on some select query.

and i will provide three check boxes for each of these fields.

If the user selects KUNNR check box i will display only that field data.

If the user selects KUNNR, and NAME1 checkboxes, i have to display these two fields data from the internal table.

And one more thing i should not use ALV here.

all the output should be in list itself.

Thanks,

Anil.

Read only

0 Likes
1,388

hi

Try this code

DO w_lines TIMES.
    w_cu_line = sy-index + 4.
    CLEAR: fs_spfli,
           fs_sflight,
           w_check.

    READ LINE w_cu_line FIELD VALUE
    w_check  INTO w_check
    fs_spfli-w_carrid INTO fs_spfli-w_carrid
    fs_spfli-w_connid INTO fs_spfli-w_connid.

    IF sy-subrc EQ 0.
      IF w_check EQ 'X'.
        Display the text here.

Regerds

Sumit Agarwal

Read only

0 Likes
1,388

Hi Anil,

Try this logic


REPORT z_sdn.

PARAMETERS:
  p_kunnr AS CHECKBOX DEFAULT 'X',
  p_land1 AS CHECKBOX,
  p_name1 AS CHECKBOX.


DATA:
  BEGIN OF fs_tab,
    kunnr     TYPE kunnr,
    land(10) TYPE c,
    name(10) TYPE c,
  END OF fs_tab.


DATA:
  t_tab LIKE
  TABLE OF
        fs_tab.

START-OF-SELECTION.

  CLEAR fs_tab.
  fs_tab-kunnr = '001'.
  fs_tab-land  = 'Land1'.
  fs_tab-name  = 'Name1'.
  APPEND fs_tab TO t_tab.

  CLEAR fs_tab.
  fs_tab-kunnr = '002'.
  fs_tab-land  = 'Land2'.
  fs_tab-name  = 'Name2'.
  APPEND fs_tab TO t_tab.


  IF p_kunnr = 'X'.
    WRITE: / 'KUNNR:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-kunnr.
    ENDLOOP.
  ENDIF.

  IF p_land1 = 'X'.
    WRITE: / 'LAND:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-land.
    ENDLOOP.
  ENDIF.

  IF p_name1 = 'X'.
    WRITE: / 'NAME:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-name.
    ENDLOOP.
  ENDIF.

Regards

Abhijeet

Read only

0 Likes
1,388

Hi Abhijeet,

Thanx for your reply.

This solution is diplaying data one after another.

But the data should be displayed as normal like

KUNNR LAND1 NAME1

10 IN x

20 CH Y

like it should display, but here it is displaying like

KUNNR

10

20

LAND1

IN

CH

like so....

Thanks,

Anil.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,388

if its alv..

build the field catalouge for which the check box is selected.

if normal report..

just write it through "IF" Condition

Ex: if chk1 = 'X'.

alvfld-fieldname = 'MATNR'.

endif

Read only

Former Member
0 Likes
1,388

Hi,

This is not the best solution but this can be one solution.

Check this code


REPORT z_sdn.

PARAMETERS:
  p_kunnr AS CHECKBOX DEFAULT 'X',
  p_land1 AS CHECKBOX,
  p_name1 AS CHECKBOX.


DATA:
  BEGIN OF fs_tab,
    kunnr     TYPE kunnr,
    land(10) TYPE c,
    name(10) TYPE c,
  END OF fs_tab.


DATA:
  t_tab LIKE
  TABLE OF
        fs_tab.

START-OF-SELECTION.

  CLEAR fs_tab.
  fs_tab-kunnr = '001'.
  fs_tab-land  = 'Land1'.
  fs_tab-name  = 'Name1'.
  APPEND fs_tab TO t_tab.

  CLEAR fs_tab.
  fs_tab-kunnr = '002'.
  fs_tab-land  = 'Land2'.
  fs_tab-name  = 'Name2'.
  APPEND fs_tab TO t_tab.


  IF p_kunnr = 'X' AND p_land1 IS INITIAL AND p_name1 IS INITIAL.
    WRITE: / 'KUNNR:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-kunnr.
    ENDLOOP.
  ENDIF.

  IF p_land1 = 'X' AND p_kunnr IS INITIAL AND p_name1 IS INITIAL.
    WRITE: / 'LAND:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-land.
    ENDLOOP.
  ENDIF.

  IF p_name1 = 'X' AND p_kunnr IS INITIAL AND p_land1 IS INITIAL.
    WRITE: / 'NAME:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-name.
    ENDLOOP.
  ENDIF.

  IF p_kunnr = 'X' AND p_land1 = 'X' AND p_name1 IS INITIAL.
    WRITE: / 'KUNNR:',
             'LAND'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-kunnr,
               fs_tab-land.
    ENDLOOP.
  ENDIF.

  IF p_kunnr = 'X' AND p_name1 = 'X' AND p_land1 IS INITIAL.
    WRITE: / 'KUNNR:',
             'NAME'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-kunnr,
               fs_tab-name.
    ENDLOOP.
  ENDIF.

  IF p_name1 = 'X' AND p_land1 = 'X' AND p_kunnr IS INITIAL.
    WRITE: / 'LAND:',
             'NAME:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-land,
               fs_tab-name.
    ENDLOOP.
  ENDIF.

  IF p_name1 = 'X' AND p_land1 = 'X' AND p_kunnr = 'X'.
    WRITE: / 'KUNNR',
             'LAND:',
             'NAME:'.
    LOOP AT t_tab INTO fs_tab.
      WRITE: / fs_tab-kunnr,
               fs_tab-land,
               fs_tab-name.
    ENDLOOP.
  ENDIF.

Regards

Abhijeet

Read only

0 Likes
1,388

Hi Abjijeet,

Thankyou for your replies.

It will work if there are limited fields to display.

but here i am having 9 fields to display. so , it will a bit tedious

to write IF conditions for all these fields.

thanks,

Anil.

Read only

Former Member
0 Likes
1,388

Hello


PARAMETERS:
  p_kunnr AS CHECKBOX,
  p_land1 AS CHECKBOX,
  p_name1 AS CHECKBOX.
 
DATA:
  BEGIN OF itab,
    kunnr like kna1-kunnr,
    land1 like kna1-land1,
    name1 like kna1-name1,
  END OF itab.
 
loop at itab.
  if p_kunnr = 'X'.
    write: itab-kunnr.
  endif.
  if p_land1 = 'X'.
    write: itab-land1.
  endif.
  if p_name1 = 'X'.
    write: itab-name1.
  endif.
new-line.
endloop.