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

ALV

Former Member
0 Likes
474

Hi Experts,

I have make a report with Plant as select option.Depending upon the plant i have a display data from VBAK and VBAP table in form of grid.

Now the problem is i need 2 Radio buttons and Plant on the result page . And i have to call events when either of two buttons are clicked.

Please guide me that can i use ALV for this. In my Alv display i need one Field as editable and if user changes that field . Other field value must change ..

Please help me on this

Thanks and Regards

Neha Kapoor

Hi Experts,

I have make a report with Plant as select option.Depending upon the plant i have a display data from VBAK and VBAP table in form of grid.

Now the problem is i need 2 Radio buttons and Plant on the result page . And i have to call events when either of two buttons are clicked.

Please guide me that can i use ALV for this. In my Alv display i need one Field as editable and if user changes that field . Other field value must change ..

Please help me on this

Thanks and Regards

Neha Kapoor

2 REPLIES 2
Read only

Former Member
0 Likes
444

Hello,

Here is a sample program that simulates radio buttons by using icons with hotspots.

PROGRAM ZUS_SDN_BCALV_GRID_DEMO_2.
 
* Based on: BCALV_GRID_DEMO.
 
TYPE-POOLS: icon.
 
 
TYPES: BEGIN OF ty_s_sflight.
INCLUDE TYPE sflight.
TYPES: button1    TYPE lvc_emphsz.
TYPES: button2    TYPE lvc_emphsz.
TYPES: button3    TYPE lvc_emphsz.
TYPES: button4    TYPE lvc_emphsz.
TYPES: END OF ty_s_sflight.
 
 
DATA:
  gt_sflight    TYPE STANDARD TABLE OF ty_s_sflight,
  gt_fcat       TYPE lvc_t_fcat.
 
 
DATA: ok_code LIKE sy-ucomm,
*      gt_sflight TYPE TABLE OF sflight,
      g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
      grid1  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container.
 
 
 
 
*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
 
  PUBLIC SECTION.
 
    CLASS-DATA:
      md_cnt    TYPE i.
 
    CLASS-METHODS:
      handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no
          sender.
 
ENDCLASS.                    "lcl_eventhandler DEFINITION
 
 
*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
 
  METHOD handle_hotspot_click.
* define local data
    FIELD-SYMBOLS:
      <ls_entry>    TYPE ty_s_sflight,
      <ld_fld>      TYPE ANY.
 
    READ TABLE gt_sflight ASSIGNING <ls_entry> INDEX es_row_no-row_id.
    CHECK ( <ls_entry> IS ASSIGNED ).
 
*   Set all radio buttons "unselected"
    <ls_entry>-button1 =  icon_wd_radio_button_empty.
    <ls_entry>-button2 =  icon_wd_radio_button_empty.
    <ls_entry>-button3 =  icon_wd_radio_button_empty.
    <ls_entry>-button4 =  icon_wd_radio_button_empty.
 
    ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE <ls_entry>
                                              TO <ld_fld>.
    IF ( <ld_fld> IS ASSIGNED ).
*     Set selected radio button "selected".
      <ld_fld> = icon_wd_radio_button.
    ENDIF.
 
*   Force PAI followed by refresh of table display in PBO
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'DUMMY'
*      IMPORTING
*        RC       =
        .
 
 
 
  ENDMETHOD.                    "handle_hotspot_click
 
ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
 
 
START-OF-SELECTION.
 
*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
 
  PERFORM select_data.
 
 
  CALL SCREEN 100.
 
 
*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
           EXPORTING container_name = g_container.
    CREATE OBJECT grid1
           EXPORTING i_parent = g_custom_container.
 
    PERFORM build_fieldcatalog.
 
    CALL METHOD grid1->set_table_for_first_display
*      EXPORTING
*        i_structure_name = 'SFLIGHT'
      CHANGING
        it_fieldcatalog  = gt_fcat
        it_outtab        = gt_sflight.
 
*   Set event handler for event TOOLBAR
    SET HANDLER:
      lcl_eventhandler=>handle_hotspot_click FOR grid1.
 
  else.
    CALL METHOD grid1->refresh_table_display
*      EXPORTING
*        IS_STABLE      =
*        I_SOFT_REFRESH =
      EXCEPTIONS
        FINISHED       = 1
        others         = 2.
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
 
  ENDIF.
 
 
 
ENDMODULE.                    "PBO OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
*   to react on oi_custom_events:
  CALL METHOD cl_gui_cfw=>dispatch.
  CASE ok_code.
    WHEN 'EXIT'.
      PERFORM exit_program.
    WHEN OTHERS.
*     do nothing
  ENDCASE.
  CLEAR ok_code.
ENDMODULE.                    "PAI INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
*  CALL METHOD G_CUSTOM_CONTAINER->FREE.
*  CALL METHOD CL_GUI_CFW=>FLUSH.
  LEAVE PROGRAM.
ENDFORM.                    "EXIT_PROGRAM
 
 
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat,
    ls_hype        TYPE lvc_s_hype.
 
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'LVC_S_FCAT'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 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.
  DELETE gt_fcat WHERE ( fieldname <> 'EMPHASIZE' ).
 
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'SFLIGHT'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 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.
 
 
  READ TABLE gt_fcat INTO ls_fcat
       WITH KEY fieldname = 'EMPHASIZE'.
  IF ( syst-subrc = 0 ).
    DELETE gt_fcat INDEX syst-tabix.
  ENDIF.
 
  ls_fcat-fieldname = 'BUTTON4'.
  ls_fcat-icon    = 'X'.
  ls_fcat-hotspot = 'X'.
  INSERT ls_fcat INTO gt_fcat INDEX 4.
*
  ls_fcat-fieldname = 'BUTTON3'.
  INSERT ls_fcat INTO gt_fcat INDEX 4.
*
  ls_fcat-fieldname = 'BUTTON2'.
  INSERT ls_fcat INTO gt_fcat INDEX 4.
*
  ls_fcat-fieldname = 'BUTTON1'.
  INSERT ls_fcat INTO gt_fcat INDEX 4.
 
 
  LOOP AT gt_fcat INTO ls_fcat.
    ls_fcat-col_pos = syst-tabix.
    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDLOOP.
 
 
 
 
 
 
ENDFORM.                    " BUILD_FIELDCATALOG
 
 
*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM select_data .
* define local data
  DATA:
    ls_sflight    TYPE ty_s_sflight.
 
 
  SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
 
  ls_sflight-button1 = icon_wd_radio_button.
  ls_sflight-button2 = icon_wd_radio_button_empty.
  ls_sflight-button3 = icon_wd_radio_button_empty.
  ls_sflight-button4 = icon_wd_radio_button_empty.
*
  MODIFY gt_sflight FROM ls_sflight
      TRANSPORTING button1 button2 button3 button4
    WHERE ( carrid IS NOT INITIAL ).
 
ENDFORM.                    " SELECT_DATA

Regards

Deepu.K

Check this link :

Read only

Former Member
0 Likes
444

hi..

this may helps u

u need to copy stadard screen elemetn to MARATAB1(at PF -STATUS)

You should copy the 'STANDARD' GUI status from program SAPLSLVC_FULLSCREEN

type this one in SE41 program name is:SAPLSLVC_FULLSCREEN

status : STANDARD_FULLSCREEN

and copy it ...

----


  • Type-pool

----


type-pools slis.

----


  • Tables

----


tables: mara,sscrfields.

----


  • Selection screen

----


select-options: s_matnr for mara-matnr.

PARAMETERS: p_email TYPE somlreci1-receiver.

TYPES: BEGIN OF t_charmara,

matnr(18) TYPE c, " Material Number

ernam(12) TYPE c, " Person Credited

aenam(12) TYPE c, " Person Changed Object

pstat(15) TYPE c, " Maintenance Status

END OF t_charmara.

----


  • Data Declarations

----


data: rt_extab type slis_t_extab, " Table of inactive function

  • codes

wa_charmara TYPE t_charmara, " work area of mara Table

fs_fieldcat type slis_t_fieldcat_alv,

" Field catalog with field

  • descriptions

t_fieldcat like line of fs_fieldcat,

" Table of Field catalog

r_ucomm like sy-ucomm, " User Command

rs_selfield TYPE slis_selfield. " cursor position ALV

data: filedlayout type slis_layout_alv,

heading type slis_t_listheader with header line,

t_event type slis_t_event.

data: fs_event like line of t_event.

data: fs_sort type slis_sortinfo_alv,

t_sort type slis_t_sortinfo_alv.

data: w_char(200) type c,

w_matnr type mara-matnr.

  • fs_sort-fieldname = 'MATNR'.

  • fs_sort-up = 'X'.

  • fs_sort-group = '*'.

  • append fs_sort to t_sort.

  • clear fS_sort.

DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

w_cnt TYPE i,

w_sent_all(1) TYPE c,

w_doc_data LIKE sodocchgi1,

gd_error TYPE sy-subrc,

gd_reciever TYPE sy-subrc.

----


  • Internal Tables

----


data: begin of it_mara occurs 0,

matnr like mara-matnr, " Material Number

ernam like mara-ernam, " Person Credited

aenam like mara-aenam, " Person Changed Object

pstat like mara-pstat, " Maintenance Status

end of it_mara.

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

*at selection-screen on field event

AT SELECTION-SCREEN on s_matnr.

PERFORM f0100_VALIDATE_MATERIAL_NUMBER.

start-of-selection.

  • retrive Data from the data base table Mara

perform retrive_data_from_mara.

end-of-selection.

*Field catalog with field descriptions

perform fieldcat.

*perform top_of_page.

PERFORM EVENT_LIST.

*ALV Grid Display

perform alv_display.

  • Creating one Push button ENTER

perform maratab1 USING RT_EXTAB.

&----


*& Form f0100_VALIDATE_MATERIAL_NUMBER

&----


  • text

----


  • There are no interface parameters to be passed to this subroutine

----


FORM F0100_VALIDATE_MATERIAL_NUMBER .

select matnr " Material Number

from mara

up to 1 rows

into mara-matnr

where matnr in s_matnr.

endselect.

IF sy-subrc NE 0.

clear sscrfields-ucomm.

MESSAGE e000 WITH 'Enter valid Material number'(003).

ENDIF. " IF sy-subrc NE 0

ENDFORM. " f0100_VALIDATE_MATERIAL_NUMBER

&----


*& Form retrive_data_from_mara

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM retrive_data_from_mara .

select matnr " Material Number

ernam " Person Credited

aenam " Person Changed Object

pstat " Maintenance Status

from mara

into table It_mara

where matnr in s_matnr.

IF sy-subrc NE 0.

MESSAGE i001 WITH 'Records are not found'.

exit.

stop.

ENDIF. " IF sy-subrc NE 0

ENDFORM. " retrive_data_from_mara

&----


*& Form fieldcat

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM fieldcat .

*field catalog for MATNR

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'MATNR'.

t_fieldcat-col_pos = 1.

<b>t_fieldcat-edit = 'x'.</b>

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for ERNAM

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'ERNAM'.

t_fieldcat-col_pos = 2.

<b>t_fieldcat-edit = 'x'.</b>

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for AENAM

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'AENAM'.

t_fieldcat-col_pos = 3.

<b>t_fieldcat-edit = 'x'.</b>

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

*field catalog for PSTAT

t_FIELDCAT-REF_TABNAME = 'MARA'.

t_fieldcat-fieldname = 'PSTAT'.

t_fieldcat-col_pos = 4.

<b>t_fieldcat-edit = 'x'.</b>

append t_fieldcat to fs_fieldcat.

clear t_fieldcat.

ENDFORM. " fieldcat

&----


*& Form EVENT_LIST

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM EVENT_LIST .

fs_event-name ='TOP_OF_PAGE'.

fs_event-form = 'TOP_PAGE'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

fs_event-name ='END_OF_PAGE'.

fs_event-form = 'END_PAGE'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

fs_event-name ='END_OF_LIST'.

fs_event-form = 'LIST_END'.

append fs_event TO t_EVENT.

CLEAR FS_EVENT.

ENDFORM. " EVENT_LIST

&----


*& Form alv_display

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM alv_display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_PF_STATUS_SET = 'MARATAB1'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

IT_FIELDCAT = FS_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = T_SORT

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

IT_EVENTS = T_EVENT

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IR_SALV_LIST_ADAPTER =

  • IT_EXCEPT_QINFO =

  • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = IT_MARA[]

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " alv_display

form TOP_PAGE.

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = 'Created by : Vijay Pawar'.

append wa_listheader to tbl_listheader.

wa_listheader-typ = 'S'.

concatenate ' Date ' sy-datum into

wa_listheader-info separated by space.

append wa_listheader to tbl_listheader.

wa_listheader-typ = 'S'.

concatenate ' From ' s_matnr-low ' To ' s_matnr-high into

wa_listheader-info separated by space.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " form TOP_PAGE.

form END_PAGE.

STATICS W_PAGE TYPE I .

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = W_PAGE.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

add 1 to w_page.

endform. " form END_PAGE.

form list_end.

data:tbl_listheader type slis_t_listheader,

wa_listheader type slis_listheader .

wa_listheader-typ = 'S'.

wa_listheader-info = '......................................Last Page'

.

append wa_listheader to tbl_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = tbl_listheader

  • I_LOGO =

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

endform. " form list_end.

&----


*& Form maratab1

&----


  • text

----


  • -->P_RT_EXTAB text

----


FORM maratab1 USING P_RT_EXTAB.

SET PF-STATUS 'MARATAB1' EXCLUDING rt_extab.

ENDFORM. " maratab1

FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

case r_ucomm.

when 'ENTER'.

perform bulid_xls_data_table.

PERFORM send_file_as_email_attachment

tables it_message

it_attach

using p_email "'[email protected]'

'Example .xls documnet attachment'

'XLS'

'filename'

' '

' '

' '

changing gd_error

gd_reciever.

perform populate_email_message_body.

PERFORM initiate_mail_execute_program.

endcase. " case r_ucomm.

endform. " FORM user_command

  • perform populate_email_message_body.

*

  • PERFORM initiate_mail_execute_program.

  • CALL FUNCTION 'RH_START_EXCEL_WITH_DATA'

  • EXPORTING

  • DATA_FILENAME = 'MARA.XLS'

  • DATA_PATH_FLAG = 'W'

    • DATA_ENVIRONMENT =

  • DATA_TABLE = ITAB[]

    • MACRO_FILENAME =

    • MACRO_PATH_FLAG = 'E'

    • MACRO_ENVIRONMENT =

  • WAIT = 'X'

    • DELETE_FILE = 'X'

  • EXCEPTIONS

  • NO_BATCH = 1

  • EXCEL_NOT_INSTALLED = 2

  • INTERNAL_ERROR = 3

  • CANCELLED = 4

  • DOWNLOAD_ERROR = 5

  • NO_AUTHORITY = 6

  • FILE_NOT_DELETED = 7

  • OTHERS = 8

  • .

  • IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  • ENDIF.

  • leave to list-processing.

  • endcase.

&----


*& Form bulid_xls_data_table

&----


  • text

----


*There are no interface parameters to be passed to this subroutine

----


FORM bulid_xls_data_table .

  • CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode

  • con_tab TYPE x VALUE '09'. "OK for non Unicode

*If you have Unicode check active in program attributes thnen you will

*need to declare constants as follows

*class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

con_cret type c value cl_abap_char_utilities=>CR_LF.

CONCATENATE 'matnr' 'ernam' 'aenam' 'pstat'

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

LOOP AT It_mara INTO wa_charmara.

CONCATENATE wa_charmara-matnr wa_charmara-ernam

wa_charmara-aenam wa_charmara-pstat

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

ENDLOOP. " LOOP AT it_mara INTO...

ENDFORM. " bulid_xls_data_table

&----


*& Form send_file_as_email_attachment

&----


  • Send email

----


  • -->P_IT_MESSAGE text

  • -->P_IT_ATTACH text

  • -->P_P_EMAIL text

  • -->P_0387 text

  • -->P_0388 text

  • -->P_0389 text

  • -->P_0390 text

  • -->P_0391 text

  • -->P_0392 text

  • <--P_GD_ERROR text

  • <--P_GD_RECIEVER text

----


FORM send_file_as_email_attachment tables pit_message

pit_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

DATA: ld_error TYPE sy-subrc,

ld_reciever TYPE sy-subrc,

ld_mtitle LIKE sodocchgi1-obj_descr,

ld_email LIKE somlreci1-receiver,

ld_format TYPE so_obj_tp ,

ld_attdescription TYPE so_obj_nam ,

ld_attfilename TYPE so_obj_des ,

ld_sender_address LIKE soextreci1-receiver,

ld_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

READ TABLE it_attach INDEX w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = pit_attach[].

  • Describe the body of the message

CLEAR t_packing_list.

REFRESH t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

APPEND t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

APPEND t_packing_list.

  • Add the recipients email address

CLEAR t_receivers.

REFRESH t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

APPEND t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

IMPORTING

sent_to_all = w_sent_all

TABLES

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

receivers = t_receivers

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

LOOP AT t_receivers.

ld_receiver = t_receivers-retrn_code.

ENDLOOP.

ENDFORM. " send_file_as_email_attachment

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


FORM initiate_mail_execute_program.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

&----


*& Form POPULATE_EMAIL_MESSAGE_BODY

&----


  • Populate message body text

----


form populate_email_message_body.

REFRESH it_message.

it_message = 'Please find attached a list test mara records'.

APPEND it_message.

endform. "form populate_email_message_bod

<b>

Reward points if useful</b>

Regads

Ashu