You are on page 1of 41

4/13/23, 12:35 PM SAPTech: 2017

SAPTech search

Classic Home

31st May 2017 ALV Split Using class


REPORT zdemo_split_container.
TYPES : BEGIN OF type_ekko,
        ebeln TYPE ekko-ebeln,
        bukrs TYPE ekko-bukrs,
      END OF type_ekko,
      BEGIN OF type_ekpo,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        matnr TYPE ekpo-matnr,
      END OF type_ekpo.

DATA: t_ekko TYPE STANDARD TABLE OF type_ekko,
      t_ekpo TYPE STANDARD TABLE OF type_ekpo,
      w_ekko TYPE type_ekko,
      w_ekpo TYPE type_ekpo.

DATA: o_cont TYPE REF TO cl_gui_custom_container,
      o_grid TYPE REF TO cl_gui_alv_grid,        "header grid
      o_grid1 TYPE REF TO cl_gui_alv_grid.       "footer grid

DATA:  dg_header       TYPE REF TO cl_gui_container,        "header container
       dg_footer       TYPE REF TO cl_gui_container,        "footer container
       dg_splitter     TYPE REF TO cl_gui_splitter_container. "split

DATA: t_fcat TYPE lvc_t_fcat,
      t_fcat1 TYPE lvc_t_fcat,
      w_fcat TYPE lvc_s_fcat.

DATA: v_ebeln TYPE ekko-ebeln.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  SELECT-OPTIONS s_ebeln FOR v_ebeln.
SELECTION-SCREEN END OF BLOCK b1.
CLASS lcl_event DEFINITION.
  PUBLIC SECTION.
    METHODS: m_event_handler FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id es_ro
w_no.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_event
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event IMPLEMENTATION.
METHOD m_event_handler.
  CASE e_column_id-fieldname.
    WHEN 'EBELN' .
      CLEAR w_ekko.
*      Read header table on hotspot click and fetch data from item table
      READ TABLE t_ekko INTO w_ekko INDEX e_row_id-index.
      IF sy-subrc EQ 0.
        REFRESH t_ekpo.
        SELECT ebeln
               ebelp
               matnr
        FROM ekpo
        INTO TABLE t_ekpo
        WHERE ebeln = w_ekko-ebeln.
      ENDIF.
      IF t_ekpo IS NOT INITIAL.
           CALL METHOD o_grid1->set_table_for_first_display
             EXPORTING
Rs. 8,754 Rs. 6,991 Dynamic Rs. 2,699
Views Rs. 13,499
theme. Powered by Blogger. Rs. 4,999 Rs. 8,291

https://mysapnuts.blogspot.com/2017/ 1/41
4/13/23, 12:35 PM SAPTech: 2017
               i_structure_name              = 'TYPE_EKPO'
SAPTech              CHANGING
               it_outtab                     = t_ekpo
               it_fieldcatalog               = t_fcat1
Classic Home
             EXCEPTIONS
               invalid_parameter_combination = 1
               program_error                 = 2
               too_many_lines                = 3
               OTHERS                        = 4.
           IF sy-subrc <> 0.
*            Implement suitable error handling here
           ENDIF.
      ENDIF.
    WHEN OTHERS.
  ENDCASE.
ENDMETHOD.
ENDCLASS.               "lcl_event

START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'MENU'.
  SET TITLEBAR 'TITLE'.
  IF o_cont IS INITIAL.

*    Create object for container
    CREATE OBJECT o_cont
      EXPORTING
        container_name              = 'CONT'.
  ENDIF.

*  Initiate splitter
  CREATE OBJECT dg_splitter
    EXPORTING
      parent            = o_cont
      rows              = 2
      columns           = 1.

*  set the container for each part of container
*  headr container
CALL METHOD dg_splitter->get_container
  EXPORTING
    row       = 1
    column    = 1
  RECEIVING
    container = dg_header .

* Footer container
 CALL METHOD dg_splitter->get_container
  EXPORTING
    row       = 2
    column    = 1
  RECEIVING
    container = dg_footer.

* Set height for the container
 CALL METHOD dg_splitter->set_row_height
   EXPORTING
     id                = 1
     height            = 50 .

* initiate grid for haeader
CREATE OBJECT o_grid
  EXPORTING
    i_parent          = dg_header.

* Initiate grid for footer
CREATE OBJECT o_grid1
  EXPORTING
    i_parent          = dg_footer.

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 2/41
4/13/23, 12:35 PM SAPTech: 2017
* Fetch data for header table

SAPTechPERFORM  f_fetch_ekko.
IF t_ekko IS NOT INITIAL.
   PERFORM f_fcat.                  "Build fcat for header table
Classic Home
   PERFORM f_set_handle.            "set andler for events
   PERFORM f_display_table.         "Dislay the table
ENDIF.
PERFORM f_fcat_ekpo.                 "Build fcat for ekpo item table
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
  WHEN 'EXIT'.
    LEAVE PROGRAM.
  WHEN 'BACK'.
    LEAVE PROGRAM.
  WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Form  F_FETCH_EKKO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_fetch_ekko .
   SELECT  ebeln
           bukrs
   FROM ekko
   INTO TABLE t_ekko
   WHERE ebeln IN s_ebeln.
     IF sy-subrc EQ 0.
        SORT t_ekko BY ebeln.
     ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_fcat .
   w_fcat-fieldname = 'EBELN'.
   w_fcat-coltext   = ' PO Number '.
   w_fcat-hotspot   = 'X'.
   w_fcat-key       = 'X'.
   APPEND w_fcat TO t_fcat.
   CLEAR w_fcat.

   w_fcat-fieldname = 'BUKRS'.
   w_fcat-coltext   = ' Company Code '.
   APPEND w_fcat TO t_fcat.
   CLEAR w_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_SET_HANDLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_set_handle .
DATA: o_ref TYPE REF TO lcl_event.
CREATE OBJECT o_ref.
SET HANDLER o_ref->m_event_handler FOR o_grid.
ENDFORM.
*&---------------------------------------------------------------------*
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 3/41
4/13/23, 12:35 PM SAPTech: 2017
*&      Form  F_DISPLAY_TABLE

SAPTech*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
Classic Home
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_table .
CALL METHOD o_grid->set_table_for_first_display
  EXPORTING
    i_structure_name              = 'TYPE_EKKO'
  CHANGING
    it_outtab                     = t_ekko
    it_fieldcatalog               = t_fcat
  EXCEPTIONS
    invalid_parameter_combination = 1
    program_error                 = 2
    too_many_lines                = 3
    OTHERS                        = 4
        .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_FCAT_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_fcat_ekpo .
w_fcat-fieldname = 'EBELN'.
w_fcat-coltext   = 'PO Number'.
APPEND w_fcat TO t_fcat1.
CLEAR w_fcat.

w_fcat-fieldname = 'EBELP'.
w_fcat-coltext   = 'Item Number'.
APPEND w_fcat TO t_fcat1.
CLEAR w_fcat.

w_fcat-fieldname = 'MATNR'.
w_fcat-coltext   = 'Material Number'.
APPEND w_fcat TO t_fcat1.
CLEAR w_fcat.
ENDFORM.

Posted 31st May 2017 by Blogger

0 Add a comment

25th May 2017 TOP OF PAGE in OOPS ALV


REPORT zdemo_repo_oops.
PARAMETERS: p_matnr TYPE mara-matnr.
TYPES: BEGIN OF type_mara,
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 4/41
4/13/23, 12:35 PM SAPTech: 2017
        matnr TYPE mara-matnr,
SAPTech        ersda  TYPE mara-ersda,
        ernam TYPE mara-ernam,
      END OF type_mara.
Classic Home
DATA: t_mara TYPE STANDARD TABLE OF type_mara,
      w_mara TYPE type_mara.

DATA: o_contain TYPE REF TO cl_gui_custom_container,
      o_grid    TYPE REF TO cl_gui_alv_grid.
DATA: t_fcat    TYPE lvc_t_fcat,
      w_fcat    TYPE lvc_s_fcat.
 DATA:  dg_parent_grid     TYPE REF TO cl_gui_container,
       dg_html_cntrl        TYPE REF TO cl_gui_html_viewer,
       dg_parent_html     TYPE REF TO cl_gui_container,
       dg_splitter          TYPE REF TO cl_gui_splitter_container,
       dg_dyndoc_id TYPE REF TO cl_dd_document.
CLASS lcl_event DEFINITION.
  PUBLIC SECTION.
  METHODS: event_handle FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no
,
           top_of_page1 FOR EVENT top_of_page   OF cl_gui_alv_grid IMPORTING e_dyndoc_id.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_event
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event IMPLEMENTATION.
METHOD event_handle.
 CASE e_column_id-fieldname.
   WHEN 'MATNR'.
    READ TABLE t_mara INTO w_mara INDEX e_row_id-index ."TRANSPORTING matnr.
     IF sy-subrc EQ 0.
      SET PARAMETER ID 'MAT' FIELD w_mara-matnr.
      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
    ENDIF.
   WHEN OTHERS.
  ENDCASE.
ENDMETHOD.

METHOD top_of_page1 .
  DATA : dl_text(255) TYPE c. "Text
  DATA: lv_date TYPE char10.

CALL METHOD dg_dyndoc_id->add_text
  EXPORTING
    text          = 'This is Demo of Top of Page'
    sap_style     = cl_dd_area=>heading.
  CALL METHOD dg_dyndoc_id->new_line.

  CONCATENATE sy-datum+6(2) sy-datum+4(2) sy-datum+0(4) INTO lv_date SEPARATED BY '.'.
  CONCATENATE 'Date : ' lv_date INTO dl_text SEPARATED BY space.
  CALL METHOD dg_dyndoc_id->add_text
  EXPORTING
    text          = dl_text
    sap_style     = cl_dd_area=>heading.

  PERFORM f_set_header_html USING dg_dyndoc_id.
ENDMETHOD.
ENDCLASS.               "lcl_event

START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  IF o_contain IS INITIAL.
    SET PF-STATUS 'STATUS'.
    SET TITLEBAR 'TITLE'.
    CREATE OBJECT o_contain
      EXPORTING
        container_name              = 'CONT'.
  ENDIF. Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 5/41
4/13/23, 12:35 PM SAPTech: 2017
  CREATE OBJECT dg_dyndoc_id
SAPTech  CREATE 
EXPORTING    style  = 'ALV_GRID'.
OBJECT dg_splitter
  EXPORTING
Classic Home
    parent            = o_contain
    rows              = 2
    columns           = 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.
CALL METHOD dg_splitter->get_container
  EXPORTING
    row       = 1
    column    = 1
  RECEIVING
    container = dg_parent_html.
CALL METHOD dg_splitter->get_container
  EXPORTING
    row       = 2
    column    = 1
  RECEIVING
    container = dg_parent_grid
    .
CALL METHOD dg_splitter->set_row_height
  EXPORTING
    id                = 1
    height            = 20.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

 CREATE OBJECT o_grid
         EXPORTING i_parent = dg_parent_grid.
*  CALL METHOD o_grid->register_edit_event
*    EXPORTING
*      i_event_id = cl_gui_alv_grid=>mc_evt_enter.
PERFORM f_fetch.
  IF t_mara IS  NOT INITIAL.
    PERFORM f_build_fcat.
    PERFORM f_register_handler.
    PERFORM f_display_table.
  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE sy-ucomm.
    WHEN 'EXIT' .
      LEAVE PROGRAM.
*    WHEN .
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Form  F_FETCH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_fetch .
 SELECT
   matnr
   ersda
   ernam
 FROM mara INTO TABLE t_mara WHERE matnr = p_matnr.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_BUILD_FCAT
*&---------------------------------------------------------------------*
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 6/41
4/13/23, 12:35 PM SAPTech: 2017
*       text

SAPTech*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
Classic Home
*----------------------------------------------------------------------*
FORM f_build_fcat .
w_fcat-fieldname = 'MATNR'.
w_fcat-key = 'X'.
w_fcat-coltext = 'Material Number '.
w_fcat-hotspot = 'X'.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'ERSDA'.
w_fcat-coltext = 'Created Date '.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'ERNAM'.
w_fcat-coltext = 'Name '.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_REGISTER_HANDLER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_register_handler .
DATA: o_handle TYPE REF TO lcl_event.
CREATE OBJECT o_handle.
SET HANDLER o_handle->event_handle FOR o_grid.
SET HANDLER o_handle->top_of_page1 FOR o_grid.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_table .
 CALL METHOD o_grid->set_table_for_first_display
   EXPORTING
     i_buffer_active               = space
     i_bypassing_buffer            = 'X'
     i_structure_name              = 'TYPE_MARA'
     i_save                        = 'A'
   CHANGING
     it_outtab                     = t_mara
     it_fieldcatalog               = t_fcat
*     it_sort                       =
*     it_filter                     =
   EXCEPTIONS
     invalid_parameter_combination = 1
     program_error                 = 2
     too_many_lines                = 3
     OTHERS                        = 4
         .
 IF sy-subrc <> 0.
*  Implement suitable error handling here
 ENDIF.
  "do these..{
* Initializing document
  CALL METHOD dg_dyndoc_id->initialize_document.

* Processing events
  CALL METHOD o_grid->list_processing_events
    EXPORTING
      i_event_name = 'TOP_OF_PAGE'
      i_dyndoc_id  = dg_dyndoc_id. Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 7/41
4/13/23, 12:35 PM SAPTech: 2017
ENDFORM.

SAPTech*&---------------------------------------------------------------------*
*&      Form  F_SET_HEADER_HTML
*&---------------------------------------------------------------------*
Classic Home
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_set_header_html USING dg_dyndoc_id TYPE REF TO cl_dd_document.
 DATA : dl_length  TYPE i,                           " Length
        dl_background_id TYPE sdydo_key VALUE space. " Background_id
* Creating html control
  IF dg_html_cntrl IS INITIAL.
    CREATE OBJECT dg_html_cntrl
         EXPORTING
              parent    = dg_parent_html.
  ENDIF.
* Reuse_alv_grid_commentary_set
  CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
    EXPORTING
      document = dg_dyndoc_id
      bottom   = space
    IMPORTING
      length   = dl_length.
* Get TOP->HTML_TABLE ready
  CALL METHOD dg_dyndoc_id->merge_document.
* Set wallpaper
  CALL METHOD dg_dyndoc_id->set_document_background
    EXPORTING
      picture_id = dl_background_id.
* Connect TOP document to HTML-Control
  dg_dyndoc_id->html_control = dg_html_cntrl.
* Display TOP document
  CALL METHOD dg_dyndoc_id->display_document
    EXPORTING
      reuse_control      = 'X'
      parent             = dg_parent_html
    EXCEPTIONS
      html_display_error = 1.
  IF sy-subrc NE 0.
    MESSAGE 'Error in displaying top-of-page' TYPE 'E'.
  ENDIF.
ENDFORM.

Posted 25th May 2017 by Blogger

0 Add a comment

24th May 2017 cONTAINER eVENT OOPS alv


REPORT zdemo_repo_oops.
PARAMETERS: p_matnr TYPE mara-matnr.
TYPES: BEGIN OF type_mara,
        matnr TYPE mara-matnr,
        ersda TYPE mara-ersda,
        ernam TYPE mara-ernam,
      END OF type_mara.
DATA: t_mara TYPE STANDARD TABLE OF type_mara,
      w_mara TYPE type_mara.

DATA: o_contain TYPE REF TO cl_gui_custom_container,
      o_grid    TYPE REF TO cl_gui_alv_grid.
DATA: t_fcat    TYPE lvc_t_fcat,
      w_fcat    TYPE lvc_s_fcat.
CLASS lcl_event DEFINITION.
  PUBLIC SECTION.
  METHODS: event_handle FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no
 .
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_event
*&---------------------------------------------------------------------*
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 8/41
4/13/23, 12:35 PM SAPTech: 2017
*        Text

SAPTech*----------------------------------------------------------------------*
CLASS lcl_event IMPLEMENTATION.
METHOD event_handle.
Classic Home
 CASE e_column_id-fieldname.
   WHEN 'MATNR'.
    READ TABLE t_mara INTO w_mara INDEX e_row_id-index ."TRANSPORTING matnr.
     IF sy-subrc EQ 0.
      SET PARAMETER ID 'MAT' FIELD w_mara-matnr.
      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
    ENDIF.
   WHEN OTHERS.
  ENDCASE.
ENDMETHOD.
ENDCLASS.               "lcl_event

START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  IF o_contain IS INITIAL.
    SET PF-STATUS 'STATUS'.
    SET TITLEBAR 'TITLE'.
    CREATE OBJECT o_contain
      EXPORTING
        container_name              = 'CONT'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6
        .
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CREATE OBJECT o_grid
      EXPORTING
        i_parent          = o_contain
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5
        .
    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.
PERFORM f_fetch.
  IF t_mara IS  NOT INITIAL.
    PERFORM f_build_fcat.
    PERFORM f_register_handler.
    PERFORM f_display_table.
  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE sy-ucomm.
    WHEN 'EXIT' .
      LEAVE PROGRAM.
*    WHEN . Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 9/41
4/13/23, 12:35 PM SAPTech: 2017
    WHEN OTHERS.
SAPTech  ENDMODULE.
ENDCASE.

*&---------------------------------------------------------------------*
Classic Home
*&      Form  F_FETCH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_fetch .
 SELECT
   matnr
   ersda
   ernam
 FROM mara INTO TABLE t_mara WHERE matnr = p_matnr.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_BUILD_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_build_fcat .
w_fcat-fieldname = 'MATNR'.
w_fcat-key = 'X'.
w_fcat-coltext = 'Material Number '.
w_fcat-hotspot = 'X'.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'ERSDA'.
w_fcat-coltext = 'Created Date '.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'ERNAM'.
w_fcat-coltext = 'Name '.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_REGISTER_HANDLER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_register_handler .
DATA: o_handle TYPE REF TO lcl_event.
CREATE OBJECT o_handle.
SET HANDLER o_handle->event_handle FOR o_grid.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_table .
 CALL METHOD o_grid->set_table_for_first_display
   EXPORTING
     i_buffer_active               = space
     i_bypassing_buffer            = 'X'
*     i_consistency_check           =
     i_structure_name              = 'TYPE_MARA'
*     is_variant                    =
*     i_save                        =
*     i_default                     = 'X'
*     is_layout                     = Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 10/41
4/13/23, 12:35 PM SAPTech: 2017
*     is_print                      =

SAPTech*     it_special_groups             =
*     it_toolbar_excluding          =
*     it_hyperlink                  =
Classic Home
*     it_alv_graphics               =
*     it_except_qinfo               =
*     ir_salv_adapter               =
   CHANGING
     it_outtab                     = t_mara
     it_fieldcatalog               = t_fcat
*     it_sort                       =
*     it_filter                     =
   EXCEPTIONS
     invalid_parameter_combination = 1
     program_error                 = 2
     too_many_lines                = 3
     OTHERS                        = 4
         .
 IF sy-subrc <> 0.
*  Implement suitable error handling here
 ENDIF.

ENDFORM.

Posted 24th May 2017 by Blogger

0 Add a comment

24th May 2017 Interactive ALV OOPS


REPORT ZDEMO_REPO_OOPS.
PARAMETERS: p_matnr TYPE mara-matnr.
TYPES: BEGIN OF type_mara,
        matnr TYPE mara-matnr,
        ersda TYPE mara-ersda,
        ernam TYPE mara-ernam,
      END OF type_mara.
DATA: t_mara TYPE STANDARD TABLE OF type_mara,
      w_mara TYPE type_mara.
data: o_salv TYPE REF TO CL_SALV_TABLE.
DATA: lr_cols TYPE REF TO CL_SALV_COLUMNs_TABLE,
      lr_col  TYPE REF TO CL_SALV_COLUMN_TABLE.

class lcl_event DEFINITION DEFERRED.
DATA: GR_EVENTS TYPE REF TO lcl_event.
START-OF-SELECTION.
select matnr
       ersda
       ernam
FROM mara
INTO TABLE t_mara
WHERE matnr = p_matnr.
  IF sy-subrc eq 0.
    sort t_mara by matnr.
    PERFORM f_display_table. Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 11/41
4/13/23, 12:35 PM SAPTech: 2017
  ENDIF.

SAPTech      class  lcl_event DEFINITION.
PUBLIC SECTION.
    methods: event_handle for EVENT double_click of CL_SALV_EVENTS_TABLE
Classic Home
                          IMPORTING row column."col.
  ENDCLASS.
*&---------------------------------------------------------------------*
*&      Form  F_DISPLAY_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_display_table .
 CALL METHOD cl_salv_table=>factory
   IMPORTING
     r_salv_table   = o_salv
   CHANGING
     t_table        = t_mara
     .
* Set Hotspot
 PERFORM f_set_hotspot.
* *Register events
 PERFORM f_regis_event.

o_salv->display( ).
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_SET_HOTSPOT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_set_hotspot .
CALL METHOD o_salv->get_columns
  RECEIVING
    value  = lr_cols
    .
 LR_COL ?= LR_COLS->GET_COLUMN( 'MATNR' ).
 CALL METHOD lr_col->set_cell_type
   EXPORTING
     value  = IF_SALV_C_CELL_TYPE=>hotspot
     .

ENDFORM.

*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_event
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event IMPLEMENTATION.
METHOD event_handle.
  READ TABLE t_mara INTO w_mara INDEX row.
  IF sy-subrc eq 0.
     set PARAMETER ID 'MAT' FIELD w_mara-matnr.
     CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
  ENDIF.
ENDMETHOD.
ENDCLASS.               "lcl_event
*&---------------------------------------------------------------------*
*&      Form  F_REGIS_EVENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_regis_event .
DATA: LR_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.
LR_EVENTS = o_sALV->GET_EVENT( ). "get event
CREATE OBJECT GR_EVENTS.
*SET HANDLER GR_EVENTS->double_click FOR LR_EVENTS. "register event handler method
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 12/41
4/13/23, 12:35 PM SAPTech: 2017
SET HANDLER GR_EVENTS->event_handle FOR LR_EVENTS. "register event handler method

SAPTech
*set standard ALV functions visible
Classic Home
*This method will give all pf staus on application bar which will be not visible
* on screen after using Factory method
*TRY.
CALL METHOD o_salv->set_screen_status
  EXPORTING
    report        =  'SALV_TEST_FUNCTIONS'
    pfstatus      =  'SALV_STANDARD'
    set_functions = o_salv->c_functions_all
    .
*ENDTRY.

ENDFORM.

Posted 24th May 2017 by Blogger

0 Add a comment

24th May 2017 Interactive ALV Grid


REPORT zdemo_repo.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: r1 RADIOBUTTON GROUP g1 DEFAULT 'X'USER-COMMAND ac,
            r2 RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK b1.
TABLES : mara,vbrk.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
  SELECT-OPTIONS : s_matnr FOR mara-matnr MODIF ID m1,
                   s_date FOR mara-ersda MODIF ID m1.
  SELECT-OPTIONS : s_vbeln FOR vbrk-vbeln MODIF ID m2,
                   s_fkart FOR vbrk-fkart MODIF ID m2.
SELECTION-SCREEN END OF BLOCK b2.
TYPES: BEGIN OF type_mara,
        matnr TYPE mara-matnr,
        ersda TYPE mara-ersda,
        ernam TYPE mara-ernam,
        laeda TYPE mara-laeda,
        aenam TYPE mara-aenam,
      END OF type_mara.

 TYPES : BEGIN OF type_vbrk,
         vbeln TYPE vbrk-vbeln,
         fkart TYPE vbrk-fkart,
         fktyp TYPE vbrk-fktyp,
         vbtyp TYPE vbrk-vbtyp,
       END OF type_vbrk.

DATA: t_mara TYPE STANDARD TABLE OF type_mara,
      w_mara TYPE type_mara,
      t_vbrk TYPE STANDARD TABLE OF type_mara,
      w_vbrk TYPE type_mara.
DATA: t_fcat TYPE slis_t_fieldcat_alv ,
      w_fcat TYPE slis_fieldcat_alv .
AT SELECTION-SCREEN OUTPUT.
  IF r1 EQ 'X'.
    LOOP AT SCREEN.
      IF screen-group1 = 'M2'.
         screen-input = '0'.
         MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.
  IF r2 EQ 'X'.
    LOOP AT SCREEN.
      IF screen-group1 = 'M1'.
         screen-input = 0.
      MODIFY SCREEN.
      ENDIF.
    ENDLOOP.
  ENDIF.
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 13/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTech    START-OF-SELECTION.
IF r1 EQ 'X'.
     PERFORM fetch_mara.
Classic Home
  ENDIF.
  IF r2 eq 'X'.
     MESSAGE 'Under construction ' TYPE 'I' DISPLAY LIKE 'E'.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  FETCH_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fetch_mara .
  SELECT matnr
         ersda
         ernam
         laeda
         aenam
   FROM mara INTO TABLE t_mara
   WHERE matnr IN s_matnr
    AND  ersda IN s_date ."UP TO 5 rows.
    IF sy-subrc EQ 0.
       SORT t_mara BY matnr.
       PERFORM display_mara.
    ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_mara .

PERFORM f_make_field_cat.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
         i_callback_program                = sy-repid
         i_callback_user_command           = 'USER_COMMAND_MARA'
         i_callback_top_of_page            = 'TOP_OF_PAGE_MARA'
         i_structure_name                  = 'TYPE_MARA'
         it_fieldcat                       = t_fcat
        TABLES
          t_outtab                         = t_mara
       EXCEPTIONS
         program_error                     = 1
         OTHERS                            = 2
                .
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.
REFRESH t_fcat.
CLEAR w_fcat.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  F_MAKE_FIELD_CAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f_make_field_cat .

w_fcat-fieldname = 'MATNR'.
w_fcat-seltext_l = 'Material Number'.
w_fcat-seltext_m = 'Material'.
w_fcat-seltext_s = 'Mat'.
w_fcat-hotspot   = 'X'.
APPEND w_fcat TO t_fcat. Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 14/41
4/13/23, 12:35 PM SAPTech: 2017
CLEAR w_fcat.

SAPTechw_fcat-fieldname = 'ERSDA'.
w_fcat-seltext_l = 'Created Date'.
Classic Home
w_fcat-seltext_m = 'Date'.
w_fcat-seltext_s = 'Date'.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'ERNAM'.
w_fcat-seltext_l = 'Emp Name'.
w_fcat-seltext_m = 'Name'.
w_fcat-seltext_s = 'Name'.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'LAEDA'.
w_fcat-seltext_l = 'laeda'.
w_fcat-seltext_m = 'laeda'.
w_fcat-seltext_s = 'laeda'.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.

w_fcat-fieldname = 'AENAM'.
w_fcat-seltext_l = 'aenam'.
w_fcat-seltext_m = 'aenam'.
w_fcat-seltext_s = 'aenam'.
APPEND w_fcat TO t_fcat.
CLEAR w_fcat.
ENDFORM.

FORM user_command_mara USING r_comm   LIKE sy-ucomm
                             rs_field TYPE slis_selfield.
  CASE r_comm.
    WHEN '&IC1'.
      IF rs_field-fieldname = 'MATNR'.
        READ TABLE t_mara INTO w_mara INDEX rs_field-tabindex.
       IF sy-subrc EQ 0.
         SET PARAMETER ID 'MAT' FIELD w_mara-matnr.
         CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
       ENDIF.
      ENDIF.
    WHEN OTHERS.
  ENDCASE.
  ENDFORM.

FORM top_of_page_mara.
  DATA: t_listheader TYPE slis_t_listheader,
        w_listheader TYPE slis_listheader .
DATA: lv_date TYPE char10.
CONCATENATE sy-datum+6(2) sy-datum+4(2) sy-datum+0(4) INTO lv_date SEPARATED BY '.'.
  w_listheader-typ = 'S'.
  w_listheader-key = 'Date'.
  w_listheader-info = lv_date.
  APPEND w_listheader to t_listheader.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary       = t_listheader
*     I_LOGO                   =
*     I_END_OF_LIST_GRID       =
*     I_ALV_FORM               =
            .

ENDFORM.

Posted 24th May 2017 by Blogger

0 Add a comment

23rd May 2017 Casting in OOPs


REPORT zdemo_oo_down_up_cast.
CLASS lcl_shape DEFINITION.
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 15/41
4/13/23, 12:35 PM SAPTech: 2017
  PUBLIC SECTION.

SAPTech   METHODs display.
ENDCLASS.
CLASS lcl_circle DEFINITION INHERITING FROM lcl_shape.
Classic Home
  PUBLIC SECTION.
    METHODS: display REDEFINITION,
             calcul.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_shape
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_shape IMPLEMENTATION.
METHOD display.
  WRITE: / 'I am Shape'.
ENDMETHOD.
ENDCLASS.               "lcl_shape
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_circle
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_circle IMPLEMENTATION.
METHOD display.
  write: / 'I am cirecle'.
ENDMETHOD.
METHOD cAlcul.
  write : / 'Perimeter is 2pir'.
ENDMETHOD.
ENDCLASS.               "lcl_circle
DATA : o_shape TYPE REF TO lcl_shape,
       o_circle TYPE REF TO lcl_circle .
START-OF-SELECTION.
CREATE OBJECT : o_shape, o_circle.
CALL METHOD o_shape->display( ). "i am shape
CALL METHOD o_circle->display( ). " i am circle
* Narrowing cast or Upcast
o_shape = o_circle.
CALL METHOD o_shape->display( ). " i am circle
*CALL METHOD o_shape->cAlcul( ). " Syntax error
* Widening cast or down cast
o_circle ?= o_shape.
CALL METHOD o_circle->display( ). " i am circle
CALL METHOD o_circle->cAlcul( ). " i am circle
CALL METHOD o_shape->display( ). " i am circle

Posted 23rd May 2017 by Blogger

0 Add a comment

18th April 2017 Dynamic Internal Table


*&---------------------------------------------------------------------*
*& Report  ZDEMO_INTERACTIVE_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zdemo_interactive_alv.
TYPE-POOLS : abap, slis.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE,
<fs_wa>,
<fs_field>.
DATA: lobj_stdesc TYPE REF TO cl_abap_structdescr,
      lt_fields   TYPE cl_abap_structdescr=>included_view,
      lw_fields   TYPE LINE OF cl_abap_structdescr=>included_view,
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 16/41
4/13/23, 12:35 PM SAPTech: 2017
      lw_desc     TYPE x030l,
SAPTech      lw_fldcat    TYPE LINE OF lvc_t_fcat,
*      lv_stname   TYPE dd02l-tabname,
      it_fcat     TYPE  lvc_t_fcat.
Classic Home
DATA : o_cust TYPE REF TO cl_gui_custom_container,
       o_alv TYPE REF TO cl_gui_alv_grid.

DATA: dyn_table    TYPE REF TO data,
      dyn_line     TYPE REF TO data,
      wa_fieldcat TYPE lvc_s_fcat,
      it_fieldcat TYPE lvc_t_fcat.

*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_tab_group TYPE slis_t_sp_group_alv,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid.
DATA : it_tabdescr TYPE abap_compdescr_tab,
       wa_tabdescr TYPE abap_compdescr.
DATA : ref_table_descr TYPE REF TO cl_abap_structdescr.

SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
PARAMETERS: p_table(30) TYPE c DEFAULT 'SFLIGHT',
            p_rows(30)  TYPE c ,
            p_col(30)   TYPE c.

SELECTION-SCREEN END OF BLOCK block1.

***********************************************************************
*start-of-selection.
START-OF-SELECTION.

  PERFORM get_table_structure.
  PERFORM create_itab_dynamically.
  PERFORM get_data.

  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Form  get_table_structure
*&---------------------------------------------------------------------*
*       Get structure of an SAP table
*----------------------------------------------------------------------*
FORM get_table_structure.

* Return structure of the table.
  ref_table_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
  it_tabdescr[] = ref_table_descr->components[].

  LOOP AT it_tabdescr INTO wa_tabdescr.
    CLEAR wa_fieldcat.
    IF wa_tabdescr-name NE 'MANDT'.
      wa_fieldcat-fieldname = wa_tabdescr-name .
      wa_fieldcat-edit      = 'X'.
      wa_fieldcat-datatype  = wa_tabdescr-type_kind.
      wa_fieldcat-inttype   = wa_tabdescr-type_kind.
      wa_fieldcat-intlen    = wa_tabdescr-length.
      wa_fieldcat-decimals  = wa_tabdescr-decimals.
      APPEND wa_fieldcat TO it_fieldcat.
    ENDIF.

    IF sy-tabix EQ p_col.
      EXIT.
    ENDIF.
  ENDLOOP.

ENDFORM.                    "get_table_structure

*&---------------------------------------------------------------------*
*&      Form  create_itab_dynamically
*&---------------------------------------------------------------------*
*       Create internal table dynamically
*----------------------------------------------------------------------*
FORM create_itab_dynamically.
* Create dynamic internal table and assign to Field-Symbol
  CALL METHOD cl_alv_table_create=>create_dynamic_table
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 17/41
4/13/23, 12:35 PM SAPTech: 2017
    EXPORTING
SAPTech      it_fieldcatalog 
    IMPORTING
= it_fieldcat

      ep_table        = dyn_table.
Classic Home
  ASSIGN dyn_table->* TO <fs_table>.
* Create dynamic work area and assign to Field Symbol
  CREATE DATA dyn_line LIKE LINE OF <fs_table>.
  ASSIGN dyn_line->* TO <fs_wa>.

ENDFORM.                    "create_itab_dynamically

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       Populate dynamic itab
*----------------------------------------------------------------------*
FORM get_data.
* Select Data from table using field symbol which points to dynamic itab
  SELECT * INTO CORRESPONDING FIELDS OF TABLE  <fs_table>
  FROM (p_table) UP TO p_rows ROWS .
ENDFORM.                    "get_data

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS'.
  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  set_handler  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_handler OUTPUT.

  CREATE OBJECT o_cust

  EXPORTING
    container_name              = 'CUSTOM'.

  CREATE OBJECT o_alv
  EXPORTING
    i_parent          = o_cust.
*  CALL METHOD o_alv->s

  CALL METHOD o_alv->set_table_for_first_display
  EXPORTING
    i_save = 'A'
*    i_structure_name              = 'SFLIGHT'
  CHANGING
    it_outtab                     = <fs_table>
    it_fieldcatalog               = it_fieldcat.

ENDMODULE.                 " set_handler  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'SAVE'.
      PERFORM save_details.
*WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  save_details
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 18/41
4/13/23, 12:35 PM SAPTech: 2017
*&---------------------------------------------------------------------*

SAPTech*       text
*----------------------------------------------------------------------*
*  -->  p1        text
Classic Home
*  <--  p2        text
*----------------------------------------------------------------------*
form save_details .
DATA : lv_refresh TYPE c VALUE 'X'.
  CALL METHOD o_alv->check_changed_data
*    IMPORTING
*      E_VALID   =
    CHANGING
      C_REFRESH = lv_refresh.
  PERFORM display_save_data.
endform.                    " save_details
*&---------------------------------------------------------------------*
*&      Form  display_save_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_save_data .
*CALL SCREEN 110.
DATA : o_cust1 TYPE REF TO cl_gui_custom_container,
       o_alv1 TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT o_cust1
  EXPORTING
    container_name              = 'SAVE_CUSTOM'
  EXCEPTIONS
    CNTL_ERROR                  = 1
    CNTL_SYSTEM_ERROR           = 2
    CREATE_ERROR                = 3
    LIFETIME_ERROR              = 4
    LIFETIME_DYNPRO_DYNPRO_LINK = 5
    others                      = 6
    .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT o_alv1
  EXPORTING
    i_parent          = o_cust1
  EXCEPTIONS
    ERROR_CNTL_CREATE = 1
    ERROR_CNTL_INIT   = 2
    ERROR_CNTL_LINK   = 3
    ERROR_DP_CREATE   = 4
    others            = 5
    .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Return structure of the table.
  ref_table_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
  it_tabdescr[] = ref_table_descr->components[].
CLEAR: wa_tabdescr,wa_fieldcat.
REFRESH it_fieldcat.
  LOOP AT it_tabdescr INTO wa_tabdescr.
    CLEAR wa_fieldcat.
    IF wa_tabdescr-name NE 'MANDT'.
      wa_fieldcat-fieldname = wa_tabdescr-name .
*      wa_fieldcat-EDIT      = 'X'.
      wa_fieldcat-datatype  = wa_tabdescr-type_kind.
      wa_fieldcat-inttype   = wa_tabdescr-type_kind.
      wa_fieldcat-intlen    = wa_tabdescr-length.
      wa_fieldcat-DECIMALS  = wa_tabdescr-DECIMALS.
      APPEND wa_fieldcat TO it_fieldcat.
    ENDIF.

    IF sy-tabix EQ p_col.
      EXIT.
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 19/41
4/13/23, 12:35 PM SAPTech: 2017
    ENDIF.

SAPTech  CALL METHOD 
ENDLOOP.
o_alv1->set_table_for_first_display
  CHANGING
Classic Home
    it_outtab                     = <fs_table>
    IT_FIELDCATALOG               = it_fieldcat
  EXCEPTIONS
    INVALID_PARAMETER_COMBINATION = 1
    PROGRAM_ERROR                 = 2
    TOO_MANY_LINES                = 3
    others                        = 4
        .
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.                    " display_save_data

[https://2.bp.blogspot.com/-7ohvIjnIg78/WPcDxojigXI/AAAAAAAAOWY/z-5Zmqs389ERV1sMD-ad-
B5DHGujZe1hgCLcB/s1600/screen.png]

Screen snap

Thank you :)
Facebook page [https://www.facebook.com/mySAPTech]

Posted 18th April 2017 by Blogger

0 Add a comment

2nd April 2017 Persistence Class In ABAP


Persistence Service:
By default the lifetime and scope of the object is within the program where it is declared i.e. once the control comes out
of the program the memory allocated for the object will be destroyed. To store the state of the object permanently we
use PERSISTENCE SERVICE.

 PERSISTENCE SERVICE can be implemented in 2 ways.


      (1) Business Key Identity.
      (2) Global Unique Identifier  (GUID).

Persistence service is implemented by using Persistence classes.

The term persistent object comes from 'persistence' which indeed means the 'permanent storage'. 
Persistent Objects are the ones who give an indication that the state of an object would be permanently stored even after
the execution of the program.

This data is known as transient. Data that can be preserved beyond the run time of the program is known as persistent.
When working with persistent data, system loads data in transient state and stores it back to persistent state after use.

ABAP Program stays in the local ABAP memory for the session only till the run time of that program. This data lives only
as long as its context – that is, as long as its associated procedure (for local procedure data); its object (for attributes of
classes); or its program (for global program data). This means that the data and state is preserved only till the context of
the program is active.

The Persistence Service is a software layer that manages persistent objects. This software layer consists of a general
part and a class-specific part. It is made up of global classes and interfaces from the Class Library. The class-specific
part is specially generated for each persistent class

CL_persistent
You create the class CL_persistent as a persistent class using the Class Builder.
The objects of this class are managed by the Persistence Service. These objects are known as managed objects . (Note
that a managed object does not necessarily have to be a persistent object).
Instances of each persistent class CL_persistent can be either protected (CREATE PROTECTED) or abstract.
The Class Builder generates the SET and GET methods for the attributes of this class. The name of these classes
always begins with CL_; there are no conventions governing the rest of the class name. You can adapt the generated
class to your own requirements.

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 20/41
4/13/23, 12:35 PM SAPTech: 2017
For each persistent Class, default two more class will generate.
       a. Base class  ( CB_class_name)
SAPTech        b. Agent or Actor Class (CA_class_name)

CA_persistent and CB_persistent Classes


Classic Home
For each persistent class (CL_persistent) the Class Builder generates two further classes, CA_persistent and
CB_persistent. These classes form the class-specific part of the Persistence Service. CB_persistent is a subclass of a
general abstract superclass of all class actors, CL_OS_CA_COMMON.

CA_persistent is known as the class actor (or class agent), which is used to manage the managed object of the class
CL_persistent, and where database accesses actually take place. The class actor inherits its methods from the abstract
superclass CB_persistent. The programmer can extend the class actor and redefine its methods (in particular, those for
accessing the database). You cannot change the superclass CB_persistent. Each class actor is a friend of the managed
class. The class actor is a singleton: It has the attribute CREATE PRIVATE. Exactly one instance of a class actor is
created when it is first accessed.

Interfaces for the Class Actor


The class actor implements the interfaces IF_OS_FACTORY, IF_OS_CA_PERSISTENCY, and IF_OS_CA_INSTANCE.
You can use both the interface methods and the class methods. Interfaces also offer generic access by means of
interface reference variables. In the ABAP program, interface reference variables of the same type can be used to
access different class agents for different persistent classes. The interfaces represent the general part of the Persistence
Service.

Management Interface for the Persistent Class


The persistent class implements the management interface IF_OS_STATE, which lets you access the managed objects
of different persistent classes in the same way.

Other Interfaces and Classes


The persistent class and the class actor are related to other interfaces and classes in the Persistence Service, but these
are mainly used internally. To find the names of these object types, refer to the definition of the persistent class and class
actor in the Class Builder.

AGENT Attribute of the Class Actor


The AGENT static attribute is a reference variable with the type of the class CA_persistent. When you first access this
attribute in an ABAP program, the static constructor of the class CA_persistent generates exactly one instance of this
class, to which the AGENT attribute then points. This object is part of the Persistence Service; its methods are then used
to manage the object of the persistent class. There is only one object of the class CA_persistent for each program since
you cannot create objects externally using CREATE OBJECT.
Since we know Base class will be Abstract Class 
Methods Inherited from CB_persistent

CREATE_PERSISTENT
Creates a new persistent object. The interface is generated according to the mapping of the persistent class to the ABAP
Dictionary. If the persistent object is managed using business keys, the interface will contain the relevant importing
parameters. If the persistent object is managed using GUIDs, a new instance GUID is generated when the object is
created. Independently of which keys manage the object, there are optional importing parameters for all persistent
attributes. The return value RESULT has the type of the persistent class and contains a reference to the persistent object
generated. Each program can contain only one object for each key. The object is saved to the database using the
COMMIT WORK statement. When the Persistence Service creates the object, it doesnot check whether it already exists
in the database. An error occurs only when you try to save an existing object. If you are unsure, we recommend that you
check whether the object already exists using the GET_PERSISTENT method.

GET_PERSISTENT
Loads a persistent object from the database and generates a suitable runtime object in the ABAP program. The interface
is generated according to the mapping of the persistent class to the ABAP Dictionary. The method is only available if the
persistent object is managed using business keys, and has the relevant importing parameters. The return value RESULT
has the type of the persistent class and contains a reference to the persistent object loaded. If an object with the same
key already exists in the program, it is not loaded again; instead, the system returns the reference to the object already
loaded. Changes to the object's attributes are saved to the database using the COMMIT WORK statement.

DELETE_PERSISTENT
Deletes a persistent object. To delete the persistent object in the database as well, you have to execute the COMMIT
WORK statement. The interface is generated according to the mapping of the persistent class to the ABAP Dictionary.
The method is only available if the persistent object is managed using business keys, and has the relevant importing
parameters.

CREATE_TRANSIENT
Generates a transient object of the persistent class. The method interface is the same as the interface for the
CREATE_PERSISTENT method. Objects created using CREATE_TRANSIENT are managed by the Persistence Service
but have no connection to the database. With CREATE_TRANSIENT, you cannot generate more than one object with the
same key in the program.

GET_TRANSIENT
Gets the reference to a transient object of the persistent class. The method interface is the same as the interface for the
GET_PERSISTENT method. The object must have been created with the CREATE_TRANSIENT method. The system
does not look for a corresponding persistent object in the database.

Now will see How to create and access the Persistence class and objects .

1. GoTo SE24
 Give  Persistence Class Name : ZCL_DEMO_PER1
 Click  On Create .

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 21/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTech
Classic Home

[https://4.bp.blogspot.com/-
E6oSNRrDmvs/WOC43nsBD7I/AAAAAAAAOTA/76HPRcTJHh0v-7ttc194xc7RdTcs4tfaACLcB/s1600/Create.png]

Here I have highlighted 2 Parts .


  a. I have selected Public
  b. Persistence class
Click on save and activate .

2.  Goto Properties tab of the class.

[https://4.bp.blogspot.com/-
pzsoVDdWpj0/WOC5gVjlw1I/AAAAAAAAOTI/7_50ksoNr0AjU_79aYhFmZyokpoURLM5gCLcB/s1600/proper.png]

We  can see here , though we have selected Public Installation , After creating it will be
 Protected and in read format means you can't change it.
So, Persistence class always will be Protected .

After creating Persistence Class by default 2 more class will create .


    1.  Base class
    2. Agent / Actor Class
Now goto friends tab of persistence class and check . There you will get your base class
name ZCB_DEMO_PER1
This class will be Abstract class.

3. Now goto the Agent / Actor class. ZCA_DEMO_PER1


 In properties tab , you can see that base class ZCB_DEMO_PER1 is the super class of the
agent class ZCA_DEMO_PER1.
It means we can inherit base class method to actor class method.
Also in properties tab you can see that Actor class is the Private class. It means only
static method / Attribute we can access.

Now goto constructor of the Agent / Actor class , There you will see that we are creating object of the class. Since it is Private class
, we can't create object outside of the class. So we are creating the object in class itself.

Agent / Actor Class has static constructor and we have earlier discuss about constructor . 
You can refer Constructor [https://mysapnuts.blogspot.in/2017/03/constructor-and-class-constructor.html]   .
Since Agent class has Static Constructor so it will access using Static method/ Attribute / Event etc.
In Agent class  we have a static attribute Agent  using this we are instantiating Static constructor of Agent Class and  this will
create object of Agent class. You can go inside the constructor and double click on that method and see the codes , you will come
to know.

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 22/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTech
Classic Home

[https://4.bp.blogspot.com/-P_dO-
EPQKzs/WODA0ppOezI/AAAAAAAAOTY/UgXPsDIJ_gEygHsIb_YaVmSb2XyTTY-ygCLcB/s1600/obj.png]

We have discussed a lot about basics things .


Now will come back to persistence class.
4. Since upto step 2 we have create persistence class .

[https://3.bp.blogspot.com/-
veLhOg1KUyU/WODBXppylBI/AAAAAAAAOTg/HBnjOTJ94MU2aIuqsnrxQHPmHQSAPa19ACLcB/s1600/pers.png]

5. Click on persistence and it will ask you for Table / Structure. Give the Table name and press Enter.

[https://2.bp.blogspot.com/-
kgyXqqz3b5I/WODCFmMtbzI/AAAAAAAAOTo/Adr_SUkTrrsAeAJvtF2QWYGj9NwguF8hQCLcB/s1600/pers_t.png]

6. After this we need to do Mapping.

[https://3.bp.blogspot.com/-
_OSEgmPVCWI/WODCa1fV9BI/AAAAAAAAOTs/azuE0jwh5L8JRNVlgX-wZkjMjae2uALpACLcB/s1600/tab.png]

Double click on each and every field and click on set attribute Values which is near to field arrow mark.
Map each and every field . If any field  is pending it will throw error . So this thing we need to consider .
Again one more thing we need to consider is, If you are creating any Custom Table ,don't take any pre-defind attribute . Please
prefer Data element and Domain.

Otherwise it will throw error.


7. After mapping . Click on Generate setting and click on Generate method for Query.

[https://2.bp.blogspot.com/-4M2hC2KgClo/WODD5LnXAxI/AAAAAAAAOT4/-FF4ugZEC7kO-IKwEi6iUtzqpttF5v2nwCLcB/s1600/sett.png]

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 23/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTech
Classic Home

[https://1.bp.blogspot.com/-
tL9Eyx3z4Nk/WODEJDSILII/AAAAAAAAOT8/tWlvINk5QLwfCyp3FCAM0AnPQTCLroX4gCLcB/s1600/ste.png]

After this save -> Back


8. Activate the Class . While activating a pop-up will come to Activate the Actor class.

[https://3.bp.blogspot.com/-7xh7y9Cy7JY/WODFDCMilZI/AAAAAAAAOUI/QEg8us2iHkI8d2Ybpla9bzKgpyMH8paMgCLcB/s1600/actor.png]

Press Yes and activate the Actor class.


After Activating so many GET_ and SET_ method will generate .

[https://2.bp.blogspot.com/-
z4TfGVzgqJA/WODFjl2K9FI/AAAAAAAAOUQ/-RdbzS_qIqsQkq_gmGvVihH2EubTwlq7QCLcB/s1600/meth.png]

So here we have done with persistence class.


Now we can use this class to CREATE / READ/ DELETE / UPDATE . We can do it in report using SE38.

9. Goto SE38 and create a report and write your code and call Create_persistence / Get_persistent / Delete_persistent .

*&---------------------------------------------------------------------*
*& Report  ZCL_DEMO_PER1_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zcl_demo_per1_report.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_sno TYPE z_sno,
            p_sname TYPE zempname,
            p_zmarks TYPE zmarks.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: r_create RADIOBUTTON GROUP g1,
            r_delete RADIOBUTTON GROUP g1,
            r_pers   RADIOBUTTON GROUP g1,
            r_update RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK b2.
*----------------------------------------------------------------------*
*       CLASS lcl_pers DEFINITION
*----------------------------------------------------------------------*
*
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 24/41
4/13/23, 12:35 PM SAPTech: 2017
*----------------------------------------------------------------------*
SAPTechCLASS lcl_pers DEFINITION.
  PUBLIC SECTION.
Classic Home
    DATA: obj_agent TYPE REF TO zca_demo_per1,
          obj_per   TYPE REF TO zcl_demo_per1.
    DATA: gv_name   TYPE ZEMPNAME,
          gv_marks  TYPE ZMARKS.
    METHODS: lm_create_persistent IMPORTING i_sno TYPE z_sno
                                         i_zsname TYPE zempname
                                         i_zmarks TYPE zmarks,
            lm_get_persistent     IMPORTING i_sno TYPE z_sno
                                         i_zsname TYPE zempname
                                         i_zmarks TYPE zmarks,
            lm_delete_persistent  IMPORTING i_sno TYPE z_sno
                                         i_zsname TYPE zempname
                                         i_zmarks TYPE zmarks,
            lm_update_persistent  IMPORTING i_sno TYPE z_sno
                                         i_zsname TYPE zempname
                                         i_zmarks TYPE zmarks.

ENDCLASS.                    "lcl_pers DEFINITION
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_pers
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_pers IMPLEMENTATION.

  METHOD lm_create_persistent .
    obj_agent = zca_demo_per1=>agent.
    TRY.
        CALL METHOD obj_agent->create_persistent(
          EXPORTING
            i_zsno = p_sno
          RECEIVING
            result = obj_per ).
        TRY.
            CALL METHOD obj_per->set_zsname
              EXPORTING
                i_zsname = p_sname.
          CATCH cx_os_object_not_found .
        ENDTRY.
        TRY.
            CALL METHOD obj_per->set_zmarks
              EXPORTING
                i_zmarks = p_zmarks.
          CATCH cx_os_object_not_found .
        ENDTRY.

WRITE : / 'Record Created for ', p_sno, p_sname, p_zmarks.
        COMMIT WORK.
      CATCH cx_os_object_existing .
        MESSAGE 'Records Alredy exists!!' TYPE 'I' DISPLAY LIKE 'E'.
    ENDTRY.

  ENDMETHOD.                    "create_persistent

  METHOD lm_get_persistent.
    obj_agent = zca_demo_per1=>agent.

    TRY.
    CALL METHOD obj_agent->get_persistent
      EXPORTING
        i_zsno = p_sno
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 25/41
4/13/23, 12:35 PM SAPTech: 2017
      receiving
SAPTech        result = obj_per
        .
Classic      CATCH cx_os_object_not_found .
Home
    ENDTRY.
IF obj_per is INITIAL.
   MESSAGE 'Record does not exists !!' TYPE 'E'.
   exit.
ENDIF.
   TRY.
   CALL METHOD obj_per->get_zsname
     RECEIVING
       result =  gv_name
       .
    CATCH cx_os_object_not_found .
   ENDTRY.

   TRY.
   CALL METHOD obj_per->get_zmarks
     RECEIVING
       result = gv_marks
       .
    CATCH cx_os_object_not_found .
   ENDTRY.

WRITE : / 'Name '  ,' Marks'.
write : / gv_name,
          gv_marks.

  ENDMETHOD.                    "get_persistent
  METHOD lm_delete_persistent.
    obj_agent = zca_demo_per1=>agent.
    TRY.
CALL METHOD obj_agent->delete_persistent
  EXPORTING
    i_zsno = p_sno
    .
COMMIT WORK.
WRITE : / 'Record deleted for the id :' , p_sno.
 CATCH cx_os_object_not_existing .
MESSAGE 'Record doesnt exists' TYPE 'E'. 
ENDTRY.
  ENDMETHOD.                    "delete_persistent

  METHOD lm_update_persistent .
   obj_agent = zca_demo_per1=>agent.

    TRY.
    CALL METHOD obj_agent->get_persistent
      EXPORTING
        i_zsno = p_sno
      receiving
        result = obj_per
        .
     CATCH cx_os_object_not_found .
    ENDTRY.
IF obj_per is INITIAL.
   MESSAGE 'Record does not exists !!' TYPE 'E'.
   exit.
ENDIF.
TRY.
CALL METHOD obj_per->set_zsname
  EXPORTING
    i_zsname = p_sname
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 26/41
4/13/23, 12:35 PM SAPTech: 2017
    .

SAPTech CATCH cx_os_object_not_found .
ENDTRY.
Classic Home
TRY.
CALL METHOD obj_per->set_zmarks
  EXPORTING
    i_zmarks = p_zmarks
    .
 CATCH cx_os_object_not_found .
ENDTRY.
COMMIT work. 
WRITE: / '_______________________________'.
write : / ' SL No', 'Name ', 'Marks '.
WRITE : / p_sno, p_sname, p_zmarks.

  ENDMETHOD.
ENDCLASS.               "lcl_pers

START-OF-SELECTION.
  DATA: obj_ref TYPE REF TO lcl_pers.
  CREATE OBJECT obj_ref.
  IF r_create EQ 'X'.
    CALL METHOD obj_ref->lm_create_persistent
      EXPORTING
        i_sno    = p_sno
        i_zsname = p_sname
        i_zmarks = p_zmarks.
  ENDIF.
  IF r_pers eq 'X'.
   CALL METHOD obj_ref->lm_get_persistent
      EXPORTING
        i_sno    = p_sno
        i_zsname = p_sname
        i_zmarks = p_zmarks.
  ENDIF.
  IF r_delete eq 'X'.
   CALL METHOD obj_ref->lm_delete_persistent
      EXPORTING
        i_sno    = p_sno
        i_zsname = p_sname
        i_zmarks = p_zmarks.

  ENDIF.
    IF r_update eq 'X'.
   CALL METHOD obj_ref->lm_update_persistent
      EXPORTING
        i_sno    = p_sno
        i_zsname = p_sname
        i_zmarks = p_zmarks.

  ENDIF.

Save -> Activate -> Execute

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 27/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTech
Classic Home

[https://4.bp.blogspot.com/-9sriFXYUn6E/WODGrzf0zEI/AAAAAAAAOUc/Vjr-xqgp-rUo_DoC5FdabFJERKzzxNSbQCLcB/s1600/Create_e.png]

Press Execute .

[https://4.bp.blogspot.com/-
meulAuyLNK0/WODG9uHvqGI/AAAAAAAAOUg/50EIFoTSWTAShuc5MXft-SGYmoI4r6WlACLcB/s1600/cret_s.png]

You can check your Table , Entry has got created .

[https://2.bp.blogspot.com/-
TQzGSAF5mmo/WODHj33C2GI/AAAAAAAAOUo/KfCKub9Pfns6SmPBMUx5VWuf6vcCVqV4wCLcB/s1600/table_e.png]

10. Read:

[https://4.bp.blogspot.com/-
AXtTlRBPnHI/WODH6xVTBeI/AAAAAAAAOUs/YXvZNN5qcPsn3VdQnAIstQ4xv4af8T2EACLcB/s1600/read.png]

Press Execute -> Output 

[https://1.bp.blogspot.com/-
YxqCgHUxBjQ/WODIUIhKiqI/AAAAAAAAOUw/svGeif_RN3oH2QFYkgWOCoeXHSmp3ZvtQCLcB/s1600/read_o.png]

11. Update : 

[https://4.bp.blogspot.com/-
FO8bnZMXVCk/WODT2YIc9LI/AAAAAAAAOVc/v71avsRcs-syb8JkrJUEjzDPenG_4QkAACLcB/s1600/update.png]

Press Execute -> check you table 

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 28/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTech
Classic Home

[https://2.bp.blogspot.com/-
aajsnRnHyvU/WODUD_954MI/AAAAAAAAOVg/zU-NovL-qfMLv4gO6be9757xvsj_OZ1AwCLcB/s1600/update_o.png]

12. Delete:

[https://1.bp.blogspot.com/-
FlGXtEitj8M/WODUc1BmrHI/AAAAAAAAOVk/CtPcJXfR3PEC-Mg7MQrKFyRg7tCPJyV1QCLcB/s1600/dele.png]

Execute -> Check your table 

[https://1.bp.blogspot.com/-8lG8HZ6GgLM/WODKtKVR3YI/AAAAAAAAOVM/RtJyV6KI4mYyeXCnRe22YVVea0oEcyyeQCLcB/s1600/dele_o.png
]

In Next blog will see how to create more entries at a time.


Thanks :)
FaceBook Page [https://www.facebook.com/mySAPTech]  
Please subscribe my YouTube  [https://www.youtube.com/channel/UCqavHO6DeJ3zjjSS1jcs9FA] Channel
[https://www.youtube.com/channel/UCqavHO6DeJ3zjjSS1jcs9FA]

New Blog Link [https://leetcode-sap-abap.blogspot.com/]

  

Posted 2nd April 2017 by Blogger

7 View comments

29th March 2017 SINGLETON CLASSES


Often, there is a requirement that you would want to create only one instance of the class. To put it in other words, you do not want any one
to create instance of the class if already created. This is a common requirement in many application designs. 
So how do we achieve this ? Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 29/41
4/13/23, 12:35 PM SAPTech: 2017

SAPTechExample - Logger Classes


The Singleton pattern is used in the design of logger classes. This classes are usually implemented as a singletons, and provides a global
Classic logging access point in all the application components without being necessary to create an object each time a logging operations is
Home
performed.

 How to create Singleton Class in Local Class?

*&---------------------------------------------------------------------*
*& Report  ZDEMO_SINGLETON_CLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_SINGLETON_CLASS.
PARAMETERS: p_matnr TYPE mara-matnr.
*DATA: BEGIN OF type_mara
TYPES: BEGIN OF type_mara,
        matnr TYPE mara-matnr,
        ersda TYPE mara-ersda,
        ernam TYPE mara-ernam,
      END OF type_mara.
DATA: t_mara TYPE STANDARD TABLE OF type_mara,
      w_mara TYPE type_mara.
CLASS lcl_sing DEFINITION CREATE PRIVATE.
  PUBLIC SECTION.
     class-DATA : o_self_ref TYPE REF TO lcl_sing.
     METHODS: fetch.
     CLASS-METHODS: object_create.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_sing
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_sing IMPLEMENTATION.
  METHOD fetch.
    select matnr
           ersda
           ernam
    FROM mara
    INto TABLE t_mara
    WHERE matnr = p_matnr.
      IF sy-subrc eq 0.
        LOOP AT t_mara INTO w_mara.
          WRITE:  / w_mara-matnr,
                  / w_mara-ersda ,
                 / w_mara-ernam  .
        ENDLOOP.
      ENDIF.
  ENDMETHOD.
  METHOD object_create.
    DATA: obj_ret_ref TYPE REF TO lcl_sing.
    IF o_self_ref is NOT bound .
      CREATE OBJECT obj_ret_ref.
      o_self_ref = obj_ret_ref.
    else.
      obj_ret_ref = o_self_ref.
    ENDIF.

    call METHOD obj_ret_ref->fetch.
  ENDMETHOD.
ENDCLASS.               "lcl_sing
START-OF-SELECTION.
*CALL METHOD lcl_sing=>object_create.
DATA: obj_out_ref TYPE REF TO lcl_sing.
CALL METHOD lcl_sing=>object_create( ).

"START-OF-SELECTION.
"CALL METHOD lcl_sing=>object_create. 

In This Code will not through Error and will get correct output .

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 30/41
4/13/23, 12:35 PM SAPTech: 2017
Thanks

SAPTechFacebook Page [https://www.facebook.com/mySAPTech]


Posted 29th March 2017 by Blogger
Classic Home
0 Add a comment

21st March 2017 Subclass cannot access the private component of superclass
As I told in earlier blog Private attributes and Methods we can't access outside of class/ subclass of that class.

Below Example you can see here.

*&---------------------------------------------------------------------*
*& Report  ZINSTA_CONST_OOPS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZINSTA_CONST_OOPS.
class lcl_inst DEFINITION.
  PUBLIC SECTION.
    DATA: comm_data(30) TYPE c VALUE 'Public Data'.
    METHODs: display.
  PROTECTED SECTION.
    DATA: prot_data(30) TYPE c VALUE 'Protected Data'.
  PRIVATE SECTION.
    DATA: priva_data(30) TYPE c VALUE 'Private Data'.
ENDCLASS.

CLASS lcl_inst_child DEFINITION INHERITING FROM lcl_inst.
  PUBLIC SECTION.
    METHODs: show.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst IMPLEMENTATION.
METHOD display.
  WRITE: 'Parent Class'.
  WRITE: sy-uline.
  WRITE: / comm_data,
           prot_data,
           priva_data.
ENDMETHOD.
ENDCLASS.               "lcl_inst

*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst_child
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst_child IMPLEMENTATION.
METHOD show.
  WRITE: / 'Data from parent in child'.
  WRITE: / Sy-uline.
  comm_data = 'Public in child changed'.
  prot_data = 'Protected in child changed'.
  WRITE: / sy-uline.
  WRITE: / comm_data,
         / prot_data,
         / priva_data.
ENDMETHOD.
ENDCLASS.               "lcl_inst_child
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 31/41
4/13/23, 12:35 PM SAPTech: 2017
START-OF-SELECTION.

SAPTechDATA:  obj1 TYPE REF TO lcl_inst.
DATA: obj1_c TYPE REF TO lcl_inst_child.
CREATE OBJECT obj1 .
Classic Home
CREATE OBJECT obj1_c .

call METHOD obj1->display.
CALL METHOD obj1_c->show.

skip 2.

obj1->comm_data = 'User Can Modify Public data'.
WRITE: / obj1->comm_data COLOR 5.

[https://3.bp.blogspot.com/-

dU0QyTf9Qws/WNFBG0JGqFI/AAAAAAAAOSk/6K0kCPiPsYszrgkoKhSBfdkMKkJ-a6XWACLcB/s1600/private.png]

If will try to access the private data will get error like this .
So, Private data can access by that class and friends of that class(This i will discuss Later )

Thanks :)
FaceBook Page [https://www.facebook.com/mySAPTech]

Posted 21st March 2017 by Blogger

0 Add a comment

21st March 2017 Class: Accessibility of different sections of a class


As we know that class has three Visibility access
       1. Public
       2. Protected
       3. Private

Here will use all visibility class and will see , how to use these in Class.
i have given a model example which will show you how user/subclass/class will interact with Public/protected data.

*&---------------------------------------------------------------------*
*& Report  ZINSTA_CONST_OOPS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZINSTA_CONST_OOPS.
class lcl_inst DEFINITION.
  PUBLIC SECTION.
    DATA: comm_data(30) TYPE c VALUE 'Public Data'.
    METHODs: display.
  PROTECTED SECTION.
    DATA: prot_data(30) TYPE c VALUE 'Protected Data'.
  PRIVATE SECTION.
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 32/41
4/13/23, 12:35 PM SAPTech: 2017
    DATA: priva_data(30) TYPE c VALUE 'Private Data'.

SAPTechENDCLASS.
CLASS lcl_inst_child DEFINITION INHERITING FROM lcl_inst.
Classic Home
  PUBLIC SECTION.
    METHODs: show.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst IMPLEMENTATION.
METHOD display.
  WRITE: 'Parent Class'.
  WRITE: sy-uline.
  WRITE: / comm_data,
           prot_data,
           priva_data.
ENDMETHOD.
ENDCLASS.               "lcl_inst

*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst_child
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst_child IMPLEMENTATION.
METHOD show.
  WRITE: / 'Data from parent in child'.
  WRITE: / Sy-uline.
  comm_data = 'Public in child changed'.
  prot_data = 'Protected in child changed'.
  WRITE: / sy-uline.
  WRITE: / comm_data,
         / prot_data.
ENDMETHOD.
ENDCLASS.               "lcl_inst_child
START-OF-SELECTION.
DATA: obj1 TYPE REF TO lcl_inst.
DATA: obj1_c TYPE REF TO lcl_inst_child.
CREATE OBJECT obj1 .
CREATE OBJECT obj1_c .

call METHOD obj1->display.
CALL METHOD obj1_c->show.

skip 2.

obj1->comm_data = 'User Can Modify Public data'.
WRITE: / obj1->comm_data COLOR 5.

Output:

[https://4.bp.blogspot.com/-9dLTiPvd7Lg/WNE96KIVePI/AAAAAAAAOSY/-
tUGsCS4cbQRX3TEMonJq6UFrRghpeSfwCLcB/s1600/pub_pro.png]

Will discuss about Private in next Blog 


Thank You :)
Facebook Page [https://www.facebook.com/mySAPTech]

  

Posted 21st March 2017 by Blogger

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 33/41
4/13/23, 12:36 PM SAPTech: 2017
0 Add a comment
SAPTech
Classic Home

21st March 2017 Static Constructor


There are two programs over here which will show you simple example on a static constructor. You will learn how to
declare a static constructor.
In earlier blog i have shown that ,when static constructor will trigger Click Here
[https://mysapnuts.blogspot.in/2017/03/constructor-and-class-constructor.html]

[https://2.bp.blogspot.com/-
D9bc76_TQhI/WNCZnZgRzoI/AAAAAAAAOSI/tg2S6WnYJXUAsw79WJDLVA4Glt9mqYLjQCLcB/s1600/Trigg.png]

Thank you  :)

Facebook Page [https://www.facebook.com/mySAPTech]

Posted 21st March 2017 by Blogger

0 Add a comment

19th March 2017 Instance Constructors can raise exceptions

 REPORT ZINSTA_CONST_OOPS.
class lcl_inst DEFINITION.
  PUBLIC SECTION.
  METHODS constructor IMPORTING num TYPE i
                      EXCEPTIONS e1.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst IMPLEMENTATION.
METHOD constructor.
  IF num lt 7.
    RAISE e1.
  ENDIF.
ENDMETHOD.
ENDCLASS.               "lcl_inst

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 34/41
4/13/23, 12:36 PM SAPTech: 2017
START-OF-SELECTION.

SAPTechDATA:  obj1 TYPE REF TO lcl_inst.
CREATE OBJECT obj1 EXPORTING num = 4
                   EXCEPTIONS e1 = 2.
Classic Home
IF sy-subrc eq 2.
  WRITE : / 'Exceptions raised  '.
ENDIF.

Output : Exceptions raised


In Next Topic will discuss about Static Constructor .
Facebook Page [https://www.facebook.com/mySAPTech/]

Posted 19th March 2017 by Blogger

0 Add a comment

19th March 2017 Constructors cannot have any export parameters

[https://2.bp.blogspot.com/-
xeciOXVzX0o/WM5EmKD4jUI/AAAAAAAAORw/dQ5H_089eXknYA0qg_IbedUlPIh5o1xswCLcB/s1600/export_not.png]

Facebook Page [https://www.facebook.com/mySAPTech/]  :)

Posted 19th March 2017 by Blogger

0 Add a comment

19th March 2017 Instance constructors can have import parameters.

 Values to them are passed at the time of CREATE OBJECT statement to create object from
the class containing the constructor.

REPORT ZINSTA_CONST_OOPS.
class lcl_inst DEFINITION.
  PUBLIC SECTION.
  METHODS constructor IMPORTING today TYPE d.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst IMPLEMENTATION.
METHOD constructor.
  write : / 'Today Is: ', today DD/MM/YYYY.
ENDMETHOD.
ENDCLASS.               "lcl_inst

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 35/41
4/13/23, 12:36 PM SAPTech: 2017
START-OF-SELECTION.

SAPTechDATA:  obj1 TYPE REF TO lcl_inst.
CREATE OBJECT obj1 EXPORTING today = sy-datum.

Classic Home
Output : Today Is:  19.03.2017
Facebook Page [https://www.facebook.com/mySAPTech/]

Posted 19th March 2017 by Blogger

0 Add a comment

19th March 2017 Instance Constructors get fired at the time of class instantiation

This simple program will show you that instance constructor methods of a class get triggered when an object is created from
the class.

REPORT ZINSTA_CONST_OOPS.
class lcl_inst DEFINITION.
  PUBLIC SECTION.
  METHODS constructor.
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_inst
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_inst IMPLEMENTATION.
METHOD constructor.
  write : / 'I am Instance Constructor'.
ENDMETHOD.
ENDCLASS.               "lcl_inst

START-OF-SELECTION.
DATA: obj1 TYPE REF TO lcl_inst.
CREATE OBJECT obj1.

Output : I am Instance Constructor


Facebook Page [https://www.facebook.com/mySAPTech/]

Posted 19th March 2017 by Blogger

0 Add a comment

Constructor and class-Constructor / Instance Constructor and


19th March 2017
Static Constructor

 Instance Constructor
The constructor is a special instance method in a class and is always named CONSTRUCTOR.
The constructor is automatically called at runtime with CREATE OBJECT statement.
Some Important points about constructor:
Each class can have only one constructor.
The constructor must be defined in PUBLIC SECTION.
The constructor's signature can have only importing parameters and exceptions.
The constructor's signature can not have exporting parameters. 
When exceptions are raised in the constructor, instances are not created so no main memory is
occupied.

Static Constructor
This is a special static method in a class and is always names CLASS_CONSTRUCTOR. It is
executed once per program. This constructor is called automatically before the class is
first accessed, but before any of the following actions are executed for the first time:
Creating instance of this class(CREATE OBJECT)
Accessing a static attribute of this class.
Calling a static method of this class.
Registering an event handler method for an event in this class.
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 36/41
4/13/23, 12:36 PM SAPTech: 2017
Some important points:
SAPTech Each class has only one static constructor
This constructor must be defined in PUBLIC SECTION.
Classic Home
The constructor's signature cannot have importing parameters or exceptions.

The static constructor cannot be called explicitly

Facebook Page [https://www.facebook.com/mySAPTech]

Posted 19th March 2017 by Blogger

0 Add a comment

18th March 2017 More about Classes / ABAP OOPS

Classes are templates for objects. Conversely, you can say that the type of an object is the same as its class. A class is an abstract

description of an object. You could say that it is a set of instructions for building an object. The attributes of objects are defined by

the components of the class, which describe the state and behavior of objects.

There is two types of class in ABAP

1. Global Classes

2. Local Classes

Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder

(Transaction SE24) in the ABAP Workbench. They are stored centrally in Class pools in the class library in the Repository. All

ABAP programs have access to these global  classes.

 Local classes are defined within an ABAP program. Local classes and  interfaces can only be used in the program in which they are

defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not

find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and

using a local class.

There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that

is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. 

Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the

interface of a global class, since the system must be able to guarantee that any program using an object of a global class can

recognize the data type of each interface parameter.

Structure of a Class

The following statements define the structure of a class:

·        A class contains components

·        Each component is assigned to a visibility section

·        Classes implement methods

Class Components

The components of a class make up its contents. All components are declared in the declaration part of the class. The components

define the attributes of the objects in a class. When you define the class, each component is assigned to one of the three visibility

sections, which define the external interface of the class.

 All of the components of a class are visible within the class. All components are in the same namespace. This means that all

components of the class must have names that are unique within the class.

There are two kinds of components in a class - those that exist separately for each object in the class(Static Class), and those that

exist only once for the whole class(Instance Class), regardless of the number of instances. Instance-specific components are known

as instance components. Components that are not instance-specific are called static components.

     a. Attributes

     b. Methods Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 37/41
4/13/23, 12:36 PM SAPTech: 2017

     c. Events
SAPTech
     d. Interfaces

Classic Attributes
Home

Attributes are internal data fields within a class that can have any ABAP data type. The state of an object is determined by the

contents of its attributes. One kind of attribute is the reference variable. Reference variables allow you to create and address

objects. Reference variables can be defined in classes, allowing you to access objects from within a class.

Instance Attributes

The contents of instance attributes define the instance-specific state of an object. You declare them using the DATA statement.

Static Attributes

The contents of static attributes define the state of the class that is valid for all instances of the class. Static attributes exist once for

each class. You declare them using the 

CLASS-DATA statement. They are accessible for the entire run time of the class.

All of the objects in a class can access its static attributes. If you change a static attribute in an object, the change is visible in all

other objects in the class.

The technical properties of instance attributes belong to the static properties of a class. It is therefore possible to refer in a LIKE

addition to the visible attributes of a class – through the class component selector or through reference variables, without prior

creation of an object.

Methods

Methods are internal procedures in a class that define the behavior of an object. They can access all of the attributes of a class. This

allows them to change the data content of an object. They also have a parameter interface, with which users can supply them with

values when calling them, and receive values back from them The private attributes of a class can only be changed by methods in

the same class.

The definition and parameter interface of a method is similar to that of function modules. You define a method meth in the definition

part of a class and implement it in the implementation part using the following processing block:

METHOD meth.

...

ENDMETHOD.

You can declare local data types and objects in methods in the same way as in other ABAP procedures (subroutines and function

modules). You call methods using the CALL METHOD statement.

Instance Methods

You declare instance methods using the METHODS statement. They can access all of the attributes of a class, and can trigger all of

the events of the class.

Static Methods

You declare static methods using the CLASS-METHODS statement. They can only access static attributes and trigger static events.

Special Methods

As well as normal methods, which you call using CALL METHOD, there are two special methods

called constructor and class_constructor that are automatically called when you create an object or when you first access the

components of a class.

Events

Objects or classes can use events to trigger event handler methods in other objects or classes. In a normal method call, one method

can be called by any number of users. When an event is triggered, any number of event handler methods can be called. The link

between the trigger and the handler is not established until run time. In a normal method call, the calling program determines the

methods that it wants to call. These methods must exist. With events, the handler determines the events to which it wants to react.

There does not have to be a handler method registered for every event.

The events of a class can be triggered in the methods of the same class using the RAISE EVENT statement. You can declare a method

of the same or a different class as an event handler method for the event evt of class class using the addition FOR EVENT evt OF

class.

Events have a similar parameter interface to methods, but only have output parameters. These parameters are passed by the trigger

(RAISE EVENT statement) to the event handler method, which receives them as input parameters.

The link between trigger and handler is established dynamically in a program using the SET HANDLER statement. The trigger and

handlers can be objects or classes, depending on whether you have instance or static events and event handler methods. When an

event is triggered, the corresponding event handler methods are executed in all registered handling classes.
Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 38/41
4/13/23, 12:36 PM SAPTech: 2017

Instance Events
SAPTech
You declare instance events using the EVENTS statement. An instance event can only be triggered in an instance method.

Classic Static Events


Home
You declare static events using the CLASS-EVENTS statement. All methods (instance and static methods) can trigger static events.

Static events are the only type of event that can be triggered in a static method.

Types

You can define your own ABAP data types within a class using the TYPES statement. Types are not instance-specific, and exist once

only for all of the objects in a class.

Constants

Constants are special static attributes. You set their values when you declare them, and they can then no longer be changed. You

declare constants using the CONSTANTS statement. Constants are not instance-specific, and exist once only for all of the objects in

a class.

Visibility Sections

You can divide the declaration part of a class into up to three visibility areas:

CLASS cl_def DEFINITION.

  PUBLIC SECTION.

...

  PROTECTED SECTION.

...

  PRIVATE SECTION.

...

ENDCLASS.

These areas define the external visibility of the class components, that is, the interface between the class and its users. Each

component of a class must be assigned to one of the visibility sections.

Public Section

All of the components declared in the public section are accessible to all users of the class, and to the methods of the class and any

classes that inherit from it. The public components of the class form the interface between the class and its users.

Protected Section

All of the components declared in the protected section are accessible to all methods of the class and of classes that inherit from it.

Protected components form a special interface between a class and its subclasses. Since inheritance is not active in Release 4.5B, the

protected section currently has the same effect as the private section.

Private Section

Components that you declare in the private section are only visible in the methods of the same class. The private components are not

part of the external interface of the class.

For Accessing the private method and attributes ,there is one method will discuss in next blog.

Facebook Page [https://www.facebook.com/mySAPTech/]

Posted 18th March 2017 by Blogger

0 Add a comment

11th February 2017 Local Class Using Event

Report zdemo_locl.

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 39/41
4/13/23, 12:36 PM SAPTech: 2017
CLASS lcl_exp DEFINITION.

SAPTech    PUBLIC SECTION.
METHODS: constructor IMPORTING num TYPE i
                       EXCEPTIONS e1.
Classic Home
ENDCLASS.
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_exp
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_exp IMPLEMENTATION.
  METHOD constructor .
    IF num gt 3.
      RAISE e1.
    ENDIF.
  ENDMETHOD.

ENDCLASS.               "lcl_exp

START-OF-SELECTION.
DATA: o1 TYPE REF TO lcl_exp.
DATA i1 TYPE i.
create OBJECT o1 EXPORTING num = 2
                            EXCEPTIONS e1 = 2..

IF sy-subrc eq 2.
  MESSAGE 'Sorry !' TYPE 'I'.
else .
  write : /23 'hello'.
ENDIF.

2.Factorial Of A Number

PARAMETERS: p_i TYPE i.
DATA: j TYPE i ,
      fact type i VALUE 1,
      i type i.
j = p_i.
i = 1.
DO j TIMES.

  fact = fact * i.
  i = i + 1.
ENDDO.

write :/23 'Factorial ',  fact.

3. Compare Two String

PARAMETERS: p_str1 TYPE string LOWER CASE, "Lower case will keep string whatever *you gave as


input like upper will be upper case and lower will be lower case.
            p_str2 TYPE string LOWER CASE.
DATA lv_len TYPE i.

lv_len = strlen( p_str1 ).

if p_str1 co p_str2.
  IF sy-fdpos eq lv_len.
   write 'Strings are equal '.
ENDIF.
else.
  sy-fdpos = sy-fdpos + 1.
  write:/23 'String Not Matched at position' , sy-fdpos .
ENDIF.

Posted 11th February 2017 by Blogger


Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 40/41
4/13/23, 12:36 PM SAPTech: 2017
2 View comments
SAPTech
Classic Home

Dynamic Views theme. Powered by Blogger.

https://mysapnuts.blogspot.com/2017/ 41/41

You might also like