Skip to Content
0
Jun 02, 2020 at 07:13 PM

Calling a smartform from the output of an ALV report when I press push button .

433 Views

Dear All,

guys I want to create ALV report to display data of T001 table of field BUKRS,WAERS and BUTXT.

now I want to display Alv report when I press the push button and push button must be created using PF status.

After displaying ALV report by clicking push button,when I select single row in Alv report that single report must be display in smartform.

please check my code below.

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; }

REPORT Z_ALV_USING_SMARTFORM_REPORT.

TABLES : T001 , sscrfields.
TYPE-POOLS : slis .

TYPES : BEGIN OF ty_T001 ,
BUKRS TYPE T001-BUKRS,
WAERS TYPE T001-WAERS,
BUTXT TYPE T001-BUTXT,
END OF ty_T001 .

DATA : it_T001 TYPE TABLE OF T001,
wa_T001 TYPE T001.

//I dont want this.
selection-screen begin of line.
SELECTION-SCREEN PUSHBUTTON 2(10) text-001 USER-COMMAND press.
selection-screen end of line.

initialization.


at selection-screen.
if SY-ucomm = 'PRESS'.

submit Z_ALV_USING_SMARTFORM_REPORT and return.

endif.

START-OF-SELECTION .

SELECT BUKRS WAERS BUTXT FROM T001 INTO CORRESPONDING FIELDS OF TABLE it_T001 .

DATA : it_fcat TYPE slis_t_fieldcat_alv ,
wa_fcat TYPE slis_fieldcat_alv .

DATA : wa_layout TYPE slis_layout_alv .

DATA : wa_grid TYPE lvc_s_glay .
DATA : variant TYPE disvariant .

data : FM_NAME type TDSFNAME.



PERFORM fieldcat .

wa_layout-colwidth_optimize = 'X' .
wa_layout-zebra = 'X' . " Zebra
wa_layout-coltab_fieldname = 'CELL'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
i_callback_user_command = 'USRCMD'
i_callback_top_of_page = 'TOPOFPAGE'
i_background_id = 'SKY'
i_grid_title = 'T001 Table'
i_grid_settings = wa_grid
is_layout = wa_layout
it_fieldcat = it_fcat
i_save = 'X'
is_variant = variant
TABLES
t_outtab = it_T001.

FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'Z_ALV_PF_STATUS'. "<----whatever your status
*is...
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
FORM fieldcat .
CLEAR it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'BUKRS'.
wa_fcat-tabname = 'IT_T001'.
wa_fcat-seltext_m = 'Company Codes'.
wa_fcat-no_zero = 'X'.
wa_fcat-key = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'WAERS'.
wa_fcat-tabname = 'IT_T001'.
wa_fcat-seltext_l = 'Currency Key'.
wa_fcat-key = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = 'BUTXT'.
wa_fcat-tabname = 'IT_T001'.
wa_fcat-seltext_m = 'COMPANY NAME'.
wa_fcat-key = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM .

*&---------------------------------------------------------------------*
*& Form USRCMD
*&---------------------------------------------------------------------*
FORM usrcmd USING ucomm TYPE sy-ucomm
selfield TYPE slis_selfield .
DATA : it_T001_1 LIKE it_T001 .
DATA : it_T001_2 TYPE TABLE OF T001 ,
wa_T001_2 TYPE T001 .

CASE ucomm .
WHEN '&IC1' .
READ TABLE it_T001 INTO wa_T001 INDEX selfield-tabindex .
APPEND wa_T001 TO it_T001_1 .

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'Z_DEMO_TEST4'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
FM_NAME = FM_NAME
* EXCEPTIONS
* NO_FORM = 1
* NO_FUNCTION_MODULE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


CALL FUNCTION FM_NAME
TABLES
it_T001 = it_T001_1.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDCASE.
ENDFORM . "USRCMD

*&---------------------------------------------------------------------*
*& Form TOPOFPAGE
*&---------------------------------------------------------------------*
FORM topofpage .
DATA: it_header TYPE TABLE OF slis_listheader ,
wa_header TYPE slis_listheader .

wa_header-typ = 'H'.
wa_header-info = 'ALV Report'.
APPEND wa_header TO it_header .
CLEAR wa_header. "



wa_header-typ = 'S'.
wa_header-key = 'DATE: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info.
APPEND wa_header TO it_header.
CLEAR wa_header.
ENDFORM.