‎2011 Aug 15 3:40 AM
HI All,
I am looking for experts advise here. My requirement is like this. I have 8 checkboxes in the selection screen. Based on the selected chekbox it has to pick the corresponding field table values. The selection of values I have completed but displaying them in a excel sheet is a challange here.
I have to display the record in the excel download(This I can Do through WS_DOWNLOAD). But the question is If I choose Check box A only thos fields needs to be displayed and if checkbox B only those fields needs to be displayed in excel. If both the checkboxes checked then all the fields needs to be displayed in the excel.
Could any one advise me how to achieve this functionality. Actually I picked the values corresponding to the checkbox and it is available in the different internal tables.
Chckbox 1 - itab1, chckbox 2 -itab2,chckbox3-tab3......
Regards
Ram.
‎2011 Aug 15 10:44 AM
DATA: ls_fcat TYPE lvc_s_fcat.
DATA: lt_fcat TYPE lvc_t_fcat.
FIELD-SYMBOLS:
<fs_dyn_table> TYPE STANDARD TABLE,
<fs_dyn_wa> TYPE ANY,
<fs_final> TYPE ANY,
<fs_val> TYPE ANY.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = iv_struc_name " THIS IS YOUR STRUCTURE FOR 8 CHECK BOX
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = lt_struc_fld
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
.
IF sy-subrc <> 0.
ev_failed = abap_true.
EXIT.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Count the columns, create fcat
LOOP AT lt_struc_fld INTO ls_struc_fld.
" DEFINE THE PROPERTIES OF THE FIELDCAT
" ONLY APPEND, IF THE USER HAS SELECTED THE CHECK BOX
ls_fcat-dd_outlen = ls_struc_fld-intlen.
ls_fcat-decimals = ls_struc_fld-decimals.
ls_fcat-datatype = ls_struc_fld-datatype.
ls_fcat-fieldname = ls_struc_fld-fieldname.
APPEND ls_fcat TO lt_fcat.
ENDLOOP.
ENDIF.
* Create a dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fcat
IMPORTING
ep_table = lt_dy_table.
* Create dynamic work area and assign to FS
ASSIGN lt_dy_table->* TO <fs_dyn_table>.
CREATE DATA lt_dy_line LIKE LINE OF <fs_dyn_table>.
ASSIGN lt_dy_line->* TO <fs_dyn_wa>.
"NOW GET THE DATA FROM THE TABLE TO YOUR INTERNAL TABLE
*SELECT * UP TO 4 ROWS
* FROM mara
* INTO TABLE <fs_tab>.
‎2011 Aug 15 6:42 AM
Hi Ram,
I think what you need is a dynamic internal table:
cl_alv_table_create=>create_dynamic_table
Best regards,
Oliver
‎2011 Aug 15 10:27 AM
Please go through the wiki below which tells you how to achieve this ....
[http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]
Thanks,
Anjaneya.
‎2011 Aug 17 2:42 AM
Hi All,
Thanks for your reply. I actually used the same code what you people have given in the thread. but when it creates the dynamic internal table it converted the field lengths into double.
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = dyn_table.
I used the above statement only. I actuallu created 3 or 4 structures and i want to merge themas a internal table depends upon the condition. Please let me know why the field lengths are being converted into double. For ex: I defined char 4 in the type but after it created the internal table the length was char 8.
Regards
Karthik
‎2011 Aug 17 3:00 AM
‎2011 Aug 15 10:29 AM
Hi Ram,
Another approach is by declaring your dynamic internal table using GENERATE SUBROUTINE POOL, (use SAP help to see example). And then move your complete itab data to this new declared itab.
Regards,
Oki
‎2011 Aug 15 10:44 AM
DATA: ls_fcat TYPE lvc_s_fcat.
DATA: lt_fcat TYPE lvc_t_fcat.
FIELD-SYMBOLS:
<fs_dyn_table> TYPE STANDARD TABLE,
<fs_dyn_wa> TYPE ANY,
<fs_final> TYPE ANY,
<fs_val> TYPE ANY.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = iv_struc_name " THIS IS YOUR STRUCTURE FOR 8 CHECK BOX
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = lt_struc_fld
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3
.
IF sy-subrc <> 0.
ev_failed = abap_true.
EXIT.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Count the columns, create fcat
LOOP AT lt_struc_fld INTO ls_struc_fld.
" DEFINE THE PROPERTIES OF THE FIELDCAT
" ONLY APPEND, IF THE USER HAS SELECTED THE CHECK BOX
ls_fcat-dd_outlen = ls_struc_fld-intlen.
ls_fcat-decimals = ls_struc_fld-decimals.
ls_fcat-datatype = ls_struc_fld-datatype.
ls_fcat-fieldname = ls_struc_fld-fieldname.
APPEND ls_fcat TO lt_fcat.
ENDLOOP.
ENDIF.
* Create a dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fcat
IMPORTING
ep_table = lt_dy_table.
* Create dynamic work area and assign to FS
ASSIGN lt_dy_table->* TO <fs_dyn_table>.
CREATE DATA lt_dy_line LIKE LINE OF <fs_dyn_table>.
ASSIGN lt_dy_line->* TO <fs_dyn_wa>.
"NOW GET THE DATA FROM THE TABLE TO YOUR INTERNAL TABLE
*SELECT * UP TO 4 ROWS
* FROM mara
* INTO TABLE <fs_tab>.