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: 

Dynamic column output based on selection.

former_member184119
Active Contributor
0 Kudos
256

Hi all,

I have certain qualification select-options upon the selection-screen.

I have 5001 to 5012 range of qualificaitons.

If user select only 5001 to 5003....

I want only 3 columns ...or else if user wants to select 5008 to 5012 output should be have columns 5008 , 09,10,11...

I am displaying output in

mail format only

concanate 'COL1' COL2' 'COL2' TO STRING SEPERATED BY C=>LB.

loop at itab.

CONCATE ITAB-1 itab-2 itab-3 to Xstring.

endloop.

Thanks and regards

sas

Edited by: saslove sap on Jul 7, 2010 5:36 AM

15 REPLIES 15

Former Member
0 Kudos
132

check then standard report DEMO_SELECT_DYNAMIC_COLUMNS

or use the following FM

CALL FUNCTION 'FREE_SELECTIONS_INIT'

CALL FUNCTION 'FREE_SELECTIONS_DIALOG'

Edited by: kk.adhvaryu on Jul 7, 2010 12:15 PM

0 Kudos
132

Nope this is not the answer can any one help me

Regards

sas

Edited by: saslove sap on Jul 7, 2010 4:57 PM

0 Kudos
132

Hi saslove,

generally, the easiest way for handling dynamic columns is to create the maximum number of and then just do not use all of them.

But honestly, the snippet you posted won't work on a static number of columns. The term "displaying output in mail format only" needs some clarification.

A clear question may get a clear answer - and vice versa.

Regards,

Clemens

0 Kudos
132

Your requirement, if I understand correctly, is similar to dynamic selections provided in reports based on logical database. The ldB programs use dynamic where clause in their select. May be you could look at some of them.

0 Kudos
132

i think you just want to retrieve data and the columns based upon your record selection

if you use parameters you can conditionally surpress the column and column headings based upon that and the data retrieved should pull what is selected

0 Kudos
132

Well Ok I am clearing my requirement

My report output will generate only mail attachment (Attachment is of excel format ) !!

This mail attachment ouput is already having certain columns....The last column is qualifation columns...

In the selection-screen user inputs the desired qualifications he want....

select-options: s_orgeh for p0024-orgeh no-display.

So for example user selected certain range from 5008 to 5012 ( 4 qualificaitons) the output should be 4 columns additional

empno empname ssnno . 5008text 5009 text 5010text 5011text

1 sas 123 yes no yes no.

If no qualitifaction is selected no qualification should be added to the output.

empno empname ssnno

1 sas 123

I believe this makes clear , in addition I am adding the how the mail attachment code I have written ..Please see below ...

0 Kudos
132

> FORM PREPARE_ATTACHMENT .

>

> DATA: L_TEXT TYPE CHAR255. " Text content for mail attachment

>

> DATA: BEGIN OF S_OUTPUT OCCURS 1,

> X TYPE STRING,

> END OF S_OUTPUT.

>

> DATA X_OUTPUT TYPE XSTRING.

>

>

>

>

> CONCATENATE

> 'Personnel Number'

> 'Employee GUID'

> 'Last Name'

> 'First Name'

> 'Position Number'

> 'Position Title'

> 'Department Number'

> 'Department Name'

> 'Employee Subgroup text'

> 'Employee Group text'

> 'SBU Head Personnel Number'

> 'SBU Head GUID'

> 'SBU Head Name'

> 'Supervisor Personnel Number'

> 'Supervisor GUID'

> 'Supervisor Name'

> 'Personnel Subarea text'

> 'CF1-Director function'

> 'CF2-Nonexecutive director function'

> 'CF3-Chief Executive function'

> 'CF8-Apportionment & oversight function'

> 'CF10-Compliance oversight function'

>

> 'CF11-Money laundering reporting function'

> 'CF28-Systems & controls function'

> 'CF29-Significant management function'

> 'CF30-Customer function, Investment Advice'

> 'CF30-Customer function, Investment Mgmt'

> 'CF30-Customer function, Trading'

> 'Admin - FSA T&C qualifying role'

>

> INTO S_OUTPUT-X SEPARATED BY C_TAB.

>

> APPEND S_OUTPUT.

>

> LOOP AT GIT_ITAB ASSIGNING <GFS_ITAB>.

> CLEAR S_OUTPUT.

> CONCATENATE

> <GFS_ITAB>-PERNR <GFS_ITAB>-EMPGUID <GFS_ITAB>-LNAME <GFS_ITAB>-FNAME <GFS_ITAB>-POSITION <GFS_ITAB>-POSTITLE <GFS_ITAB>-DEPTNO <GFS_ITAB>-DEPTNAME <GFS_ITAB>-EMPSUBTEXT <GFS_ITAB>-EMPGRPTEXT

> <GFS_ITAB>-SBUNO <GFS_ITAB>-SBUGUID <GFS_ITAB>-SBUNAME <GFS_ITAB>-SUPVNO <GFS_ITAB>-SUPVGUID <GFS_ITAB>-SUPVNAME <GFS_ITAB>-PSUBAREATEXT <GFS_ITAB>-CF1 <GFS_ITAB>-CF2 <GFS_ITAB>-CF3 <GFS_ITAB>-CF4 <GFS_ITAB>-CF5 <GFS_ITAB>-CF6

> <GFS_ITAB>-CF7 <GFS_ITAB>-CF8 <GFS_ITAB>-CF9 <GFS_ITAB>-CF10 <GFS_ITAB>-CF11 <GFS_ITAB>-CF12

>

> INTO S_OUTPUT-X SEPARATED BY C_TAB.

> *concatenate s_output-x c_cr into s_output-x.

> APPEND S_OUTPUT.

>

> ENDLOOP.

>

> DATA:S_OUTPUT1 TYPE STRING.

> CLEAR S_OUTPUT1.

>

> LOOP AT S_OUTPUT .

> CONCATENATE S_OUTPUT1 S_OUTPUT-X CL_ABAP_CHAR_UTILITIES=>CR_LF INTO S_OUTPUT1.

> ENDLOOP.

>

> *CONVERTING STRING INOT XSTRING

>

> CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

> EXPORTING

> TEXT = S_OUTPUT1

> IMPORTING

> BUFFER = X_OUTPUT.

>

> *CONVERTING XSTRING TO BINARY STRING

> CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

> EXPORTING

> BUFFER = X_OUTPUT

> TABLES

> BINARY_TAB = I_ATTACH.

> ENDFORM. " PREPARE_ATTACHMENT

In the above code from CF1 TO CF30 column headers should be dynamic and should be populated based on selection of qualifcation

Edited by: saslove sap on Jul 7, 2010 9:35 PM..

Edited by: saslove sap on Jul 8, 2010 3:25 PM

SuhaSaha
Advisor
Advisor
0 Kudos
132

Basically if i understand your question, you need to generate a dynamic based on the selection-screen input. Correct ?

Check my response in this thread:

Edited by: Suhas Saha on Jul 7, 2010 8:43 PM

Former Member
0 Kudos
132

I would do it this way

TYPES:

begin of ty_line,

col5001 type..,

col5002 type ..,

..

col5012 type ..,

end of ty_line,

ty_tab TYPE TABLE OF ty_line.

DATA: lt_itab TYPE ty_tab (I assumed the col names are col5001,2...12)

ls_itab LIKE LINE lt_itab,

lv_fieldname TYPE fieldname,

lv_index TYPE numc3.

FIELD-SYMBOLS: <fs_field> TYPE ANY.

lv_index = qualfier-low+1(3). " (e.g. 001)

LOOP AT lt_itab INTO ls_itab.

CLEAR xstring.

DO.

CONCATENATE 'col' '5' lv_index INTO lv_fieldname..

ASSIGN COMPONENT lv_fieldname OF STRUCTURE ls_itab TO <fs_field>.

CONCATENATE XSTRING <fs_field> TO XSTRING.

lv_index = lv_index + 1.

IF lv_index > qualfier-high+1(3).

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

This is the way I would do this code more or less (sorry for errors but I was abaping here

Bests Bogusia

0 Kudos
132

Can you explain what is Qualifier high , low here?

I assume those as select-options.

But what if user inputs multiple ranges or Subsequent ranges Ex:

single values: 5001 , 50008 , 5011??

Regards

sas

0 Kudos
132

Well I have harcoded the value as below.I have no choice find . Instead of using mutiple 'IF' conditions ANY other options are left:

CONCATENATE

'Personnel Number' 'Employee GUID' 'Last Name' 'First Name' 'Position Number' 'Position Title' 'Department Number'

'Department Name' 'Employee Subgroup text' 'Employee Group text' 'SBU Head Personnel Number' 'SBU Head GUID'

'SBU Head Name' 'Supervisor Personnel Number' 'Supervisor GUID' 'Supervisor Name'

'Personnel Subarea text'

  • 'CF1-Director function'

  • 'CF2-Nonexecutive director function'

  • 'CF3-Chief Executive function'

  • 'CF8-Apportionment & oversight function'

  • 'CF10-Compliance oversight function'

*

  • 'CF11-Money laundering reporting function'

  • 'CF28-Systems & controls function'

  • 'CF29-Significant management function'

  • 'CF30-Customer function, Investment Advice'

  • 'CF30-Customer function, Investment Mgmt'

  • 'CF30-Customer function, Trading'

  • 'Admin - FSA T&C qualifying role'

INTO S_OUTPUT-X SEPARATED BY C_TAB.

IF C = 'X'.

IF '50000001' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF1-Director function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000002' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF2-Nonexecutive director function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000003' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF3-Chief Executive function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000004' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF8-Apportionment & oversight function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000005' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF10-Compliance oversight function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000006' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF11-Money laundering reporting function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000007' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF28-Systems & controls function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000008' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF29-Significant management function' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000009' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF30-Customer function, Investment Advice' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000010' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF30-Customer function, Investment Mgmt' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000011' IN s_quali[].

CONCATENATE S_OUTPUT-X 'CF30-Customer function, Trading' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000012' IN s_quali[].

CONCATENATE S_OUTPUT-X 'Admin - FSA T&C qualifying role' INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

endif.

APPEND S_OUTPUT.

LOOP AT GIT_ITAB ASSIGNING <GFS_ITAB>.

CLEAR S_OUTPUT.

CONCATENATE

<GFS_ITAB>-PERNR <GFS_ITAB>-EMPGUID <GFS_ITAB>-LNAME <GFS_ITAB>-FNAME <GFS_ITAB>-POSITION <GFS_ITAB>-POSTITLE <GFS_ITAB>-DEPTNO <GFS_ITAB>-DEPTNAME <GFS_ITAB>-EMPSUBTEXT <GFS_ITAB>-EMPGRPTEXT

<GFS_ITAB>-SBUNO <GFS_ITAB>-SBUGUID <GFS_ITAB>-SBUNAME <GFS_ITAB>-SUPVNO <GFS_ITAB>-SUPVGUID <GFS_ITAB>-SUPVNAME <GFS_ITAB>-PSUBAREATEXT

INTO S_OUTPUT-X SEPARATED BY C_TAB.

IF C = 'X'.

IF '50000001' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF1 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000002' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF2 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000003' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF3 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000004' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF4 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000005' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF5 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000006' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF6 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000007' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF7 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000008' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF8 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000009' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF9 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000010' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF10 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000011' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF11 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

IF '50000012' IN s_quali[].

CONCATENATE S_OUTPUT-X <GFS_ITAB>-CF12 INTO S_OUTPUT-X SEPARATED BY C_TAB.

endIF.

endif.

  • <GFS_ITAB>-CF2 <GFS_ITAB>-CF3 <GFS_ITAB>-CF4 <GFS_ITAB>-CF5 <GFS_ITAB>-CF6

  • <GFS_ITAB>-CF7 <GFS_ITAB>-CF8 <GFS_ITAB>-CF9 <GFS_ITAB>-CF10 <GFS_ITAB>-CF11 <GFS_ITAB>-CF12

*concatenate s_output-x c_cr into s_output-x.

APPEND S_OUTPUT.

ENDLOOP.

0 Kudos
132

Can you explain what is Qualifier high , low here?

I assume those as select-options.

But what if user inputs multiple ranges or Subsequent ranges Ex:

single values: 5001 , 50008 , 5011??

Regards

sas

Hello in fact I have not predicted such situation in my c ode but it should not be diffucult just loop at the

range entries and assign field symbols properly

I will try to rewrite code later

bests Bogusia

former_member184119
Active Contributor
0 Kudos
132

I hardcoded to get the answer

0 Kudos
132

Actually u got answer but not dynamic so i past sample code base on dynamic so any user can take help form this sample code


REPORT  ZDEMO_TEST.
TYPE-POOLS: slis.
DATA: ls_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fieldcat TYPE slis_fieldcat_alv,
      layout TYPE slis_layout_alv.
DATA: BEGIN OF itab OCCURS 0,
rast1 TYPE p DECIMALS 2,                  "Rasterfeld 1
        rast2 TYPE p DECIMALS 2,                  "Rasterfeld 2
        rast3 TYPE p DECIMALS 2,                  "Rasterfeld 3
        rast4 TYPE p DECIMALS 2,                  "Rasterfeld 4
        rast5 TYPE p DECIMALS 2,                  "Rasterfeld 5
        rast6 TYPE p DECIMALS 2,                  "Rasterfeld 6
 END OF itab.
DATA : r1(20) TYPE c ,
       r2(12) TYPE c ,
       r3(12) TYPE c ,
       r4(12) TYPE c ,
       r5(12) TYPE c ,
       r6(12) TYPE c .
       DATA: count TYPE p.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 01(30) text-026.
SELECTION-SCREEN POSITION POS_LOW.
PARAMETERS: rastbis1 LIKE rfpdo1-allgrogr DEFAULT '000'.
PARAMETERS: rastbis2 LIKE rfpdo1-allgrogr DEFAULT '020'.
PARAMETERS: rastbis3 LIKE rfpdo1-allgrogr DEFAULT '040'.
PARAMETERS: rastbis4 LIKE rfpdo1-allgrogr DEFAULT '080'.
PARAMETERS: rastbis5 LIKE rfpdo1-allgrogr DEFAULT '100'.
SELECTION-SCREEN END OF LINE.
AT SELECTION-SCREEN.
  IF rastbis1 GT '998'
  OR rastbis2 GT '998'
  OR rastbis3 GT '998'
  OR rastbis4 GT '998'
  OR rastbis5 GT '998'.

  ENDIF.

  IF NOT rastbis5 IS INITIAL.
    IF  rastbis5 GT rastbis4
    AND rastbis4 GT rastbis3
    AND rastbis3 GT rastbis2
    AND rastbis2 GT rastbis1.
    ELSE.
*      MESSAGE 
    ENDIF.
  ELSE.
    IF NOT rastbis4 IS INITIAL.
      IF  rastbis4 GT rastbis3
      AND rastbis3 GT rastbis2
      AND rastbis2 GT rastbis1.
      ELSE.
*        MESSAGE e379.
      ENDIF.
    ELSE.
      IF NOT rastbis3 IS INITIAL.
        IF  rastbis3 GT rastbis2
        AND rastbis2 GT rastbis1.
        ELSE.
*          MESSAGE e379.
        ENDIF.
      ELSE.
        IF NOT rastbis2 IS INITIAL.
          IF  rastbis2 GT rastbis1.
          ELSE.
*            MESSAGE e379.
          ENDIF.
        ELSE.
*         nichts zu tun
        ENDIF.
      ENDIF.
    ENDIF.
    endif.
      itab-rast1 = '100'.
      itab-rast2 = '100'.
      itab-rast3 = '100'.
      itab-rast4 = '100'.
      itab-rast5 = '100'.
      itab-rast6 = '100'.
      append itab.


Edited by: kk.adhvaryu on Oct 1, 2010 8:42 AM

0 Kudos
132

count = 1.

IF rastbis1 NE '000'.
 CONCATENATE ' UPTO ' rastbis1 INTO r1.

  wa_fieldcat-tabname = 'RTAB1'.
  wa_fieldcat-col_pos = count.
  wa_fieldcat-fieldname = 'RAST1'.
  wa_fieldcat-seltext_l = r1.
  APPEND wa_fieldcat TO ls_fieldcat.
  count = count + 1.
endif.
  rastbis1 = rastbis1 + 1 .
  CONCATENATE rastbis1 ' TO ' rastbis2 INTO r2.

  wa_fieldcat-tabname = 'RTAB1'.
  wa_fieldcat-col_pos = count.
  wa_fieldcat-fieldname = 'RAST2'.
  wa_fieldcat-seltext_l = r2 .
  APPEND wa_fieldcat TO ls_fieldcat.
  count = count + 1.

  rastbis2 = rastbis2 + 1 .
  CONCATENATE rastbis2 ' TO ' rastbis3 INTO r3.

  wa_fieldcat-tabname = 'RTAB1'.
  wa_fieldcat-col_pos = count.
  wa_fieldcat-fieldname = 'RAST3'.
  wa_fieldcat-seltext_l = r3.
  APPEND wa_fieldcat TO ls_fieldcat.
  count = count + 1.

  rastbis3 = rastbis3 + 1 .
  CONCATENATE rastbis3 ' TO ' rastbis4 INTO r4.

  wa_fieldcat-tabname = 'RTAB1'.
  wa_fieldcat-col_pos = count.
  wa_fieldcat-fieldname = 'RAST4'.
  wa_fieldcat-seltext_l = r4.
  APPEND wa_fieldcat TO ls_fieldcat.
  count = count + 1.

  rastbis4 = rastbis4 + 1 .
  CONCATENATE rastbis4 ' TO ' rastbis5 INTO r5.

  wa_fieldcat-tabname = 'RTAB1'.
  wa_fieldcat-col_pos = count.
  wa_fieldcat-fieldname = 'RAST5'.
  wa_fieldcat-seltext_l = r5.
  APPEND wa_fieldcat TO ls_fieldcat.
  count = count + 1.

  rastbis5 = rastbis5 + 1 .
  CONCATENATE 'From ' rastbis5  INTO r6.

  wa_fieldcat-tabname = 'RTAB1'.
  wa_fieldcat-col_pos = count.
  wa_fieldcat-fieldname = 'RAST6'.
  wa_fieldcat-seltext_l = r6.
  APPEND wa_fieldcat TO ls_fieldcat.
  count = count + 1.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = 'ZDEMO_TEST'
*      i_callback_user_command  = 'USER_COMM'
      i_callback_user_command  = ''
*      is_layout                = u_er_layout
      is_layout                = layout
      it_fieldcat              = ls_fieldcat
      i_default                = 'X'
      i_save                   = 'A'
*      i_callback_pf_status_set = 'SET_PF_STATUS'
    TABLES
      t_outtab                 = itab.
*    ENDIF.
*  ENDIF.