06-10-2021 7:34 AM
Hello.
I have a job to make Selection screen with two radio buttons for ALV and Excel output and there are two different conditions for every output with different columns. How to make two different outputs? Now it`s making all of two outputs in one viev.
Here`s my code:
*&---------------------------------------------------------------------*
*& Report ZTASK2_REPORT
*&---------------------------------------------------------------------*
REPORT ztask2_report.
TABLES: aufm, caufv.
TYPES: BEGIN OF my_tab,
mblnr TYPE aufm-mblnr,
matnr TYPE aufm-matnr,
shkzg TYPE aufm-shkzg,
menge TYPE aufm-menge,
dmbtr TYPE aufm-dmbtr,
ktext TYPE caufv-ktext,
erdat TYPE caufv-erdat,
auart TYPE caufv-auart,
END OF my_tab.
DATA: gt_aufmcaufv TYPE TABLE OF my_tab.
***Excel
DATA:
lo_table TYPE REF TO cl_salv_table,
lx_xml TYPE xstring.
***
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: a_bldat FOR aufm-bldat.
PARAMETERS: rg_op1 RADIOBUTTON GROUP opx DEFAULT 'X'. "ALV
PARAMETERS: rg_op2 RADIOBUTTON GROUP opx. "Excel
SELECTION-SCREEN END OF BLOCK bl1.
START-OF-SELECTION.
***
IF rg_op1 EQ 'X'. "ALV
SELECT
au~mblnr
au~matnr
au~shkzg
au~menge
au~dmbtr
au~bldat
au~aufnr
ca~ktext
ca~auart
ca~erdat
ca~aufnr
INTO CORRESPONDING FIELDS OF TABLE gt_aufmcaufv
FROM
aufm AS au
INNER JOIN
caufv AS ca
ON
au~bldat = ca~erdat
WHERE
au~aufnr = ca~aufnr
AND
ca~auart = 'PI01'.
ELSEIF rg_op2 EQ 'X'. "Excel
SELECT
au~matnr
au~menge
au~dmbtr
INTO CORRESPONDING FIELDS OF TABLE gt_aufmcaufv
FROM
aufm AS au
INNER JOIN
caufv AS ca
ON
au~bldat = ca~erdat
WHERE
au~shkzg = 'S'.
ENDIF.
***
IF rg_op1 EQ 'X'. "ALV
PERFORM display_alv.
ELSEIF rg_op2 EQ 'X'. "Excel
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_table
CHANGING
t_table = gt_aufmcaufv ). "my table
CATCH cx_salv_msg.
ENDTRY.
lx_xml = lo_table->to_xml( xml_type = '10' ). "XLSX
CALL FUNCTION 'XML_EXPORT_DIALOG'
EXPORTING
i_xml = lx_xml
i_default_extension = 'XLSX'
i_initial_directory = ''
i_default_file_name = 'export.XLSX'
i_mask = 'Excel (*.XLSX)|*.XLSX'
EXCEPTIONS
application_not_executable = 1
OTHERS = 2.
ENDIF.
END-OF-SELECTION.
*** Form display_alv
FORM display_alv.
DATA:
gc_alv_table TYPE REF TO cl_salv_table,
gc_functions TYPE REF TO cl_salv_functions,
gc_columns TYPE REF TO cl_salv_columns_table.
cl_salv_table=>factory(
IMPORTING r_salv_table = gc_alv_table
CHANGING t_table = gt_aufmcaufv[]
).
gc_alv_table->display( ).
ENDFORM. "display_alv
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}.L0S31 {
font-style: italic;
color: #808080;
}.L0S32 {
color: #3399FF;
}.L0S33 {
color: #4DA619;
}.L0S52 {
color: #0000FF;
}.L0S55 {
color: #800080;
}.L0S70 {
color: #808080;
}
06-10-2021 10:03 AM
Your code is a mess.
First of all, try to modularize (if you want not to go full OOP, at least keep the code as clean as possible).
Something like
start-of-selection.
case 'X'.
when opt_alv.
perform alv.
when opt_xls.
perform xls.
endcase.
This will help you (and everyone else) to understand your code. If you refactor your program this way, you will:
06-10-2021 7:34 AM
Welcome and Thank you for visiting SAP Community to get answers to your questions. Please add more details to your question, e.g. you can also add a screenshot. With that, you can reach a broader range of experts to get your question answered. I also recommend to do this tutorial https://developers.sap.com/tutorials/community-qa.html
The more details you provide, the more likely it is that members will be able to assist you.
Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.
Regards, Svea
SAP Community Global Moderator
06-10-2021 10:03 AM
Your code is a mess.
First of all, try to modularize (if you want not to go full OOP, at least keep the code as clean as possible).
Something like
start-of-selection.
case 'X'.
when opt_alv.
perform alv.
when opt_xls.
perform xls.
endcase.
This will help you (and everyone else) to understand your code. If you refactor your program this way, you will:
06-10-2021 10:07 AM
I deleted my previous answer because I thought it was not a true answer, but I'm not 100% sure, because I think with the CODE addition, the OP has removed the PERFORM alv thingie.
06-10-2021 11:01 PM
06-11-2021 7:10 AM
No problem. But remember, to be new in something is not an excuse to do it the wrong way. Try to read something about the benefits of OOP or, at least, modularization and those things that make your code clean.
06-10-2021 10:06 AM
Hiyas, Sandra... I'm not sure if the OP wants to hide columns (his post is as messy as his code). I understood the program does both outputs regardless the radiobutton selected.
06-10-2021 11:03 AM
Please clarify what result you expect for radio button 1 and for radio button 2.
06-10-2021 12:03 PM
By default the program will of course not distinguish the two sets of fields / columns in your ALV as you didn't write anything for that.
You could (inclusive options)
06-10-2021 11:02 PM