Friday, 8 October 2021

Create SAP Z Table ( Tcode - SE11 )

let's discuss with Details.

First call Tcode SE11 see blow :


SE11



Select Database Table ex.  ZDEMO.



SE11-01



Fill  short Description ex.  Table For Demo.
Delivery Class choose : A. (Application Table)
Data Browser / Table View  Maint - Display /Maintenance Allowed  with restrictions

SE11-03


Chosee Sheet Field

SE11-04



Fill the Column Field with field you want to create dan Data element

SE11-05



After Complete, You can Activate 

SE11-06



When Active Error Message came Appear, " Maintan and save Technical Setting  For ZDEMO

SE11-07



Klik Button  Technical  Settings , See Below

SE11-08




Fill The Data Class : APP0

SE11-09



Fill Size Category  with 4  

SE11-10



Like this Below 

SE11-11



Then Save  and Activate

SE11-12



Then error like this :  It's Mean we Must Maintan  Table Category

SE11-13



In Extras - Enhancement Category . Klik

SE11-14



Choose  Can Be Enhacement (Character  type or Numeric)  klik Copy

SE11-15



Then Activate

SE11-16



Check With SE16 - ZDEMO

SE11-17



Create Z table has Succes.





SE11-18






Tuesday, 18 February 2020

Send Popup Message BAPI- RS_SET_SELSCREEN_STATUS

 



REPORT  Z_MSG_CLIENT.

INCLUDE ZMSGTOP.
INCLUDE ZMSGPRO

  AT SELECTION-SCREEN OUTPUT.
  APPEND :
    'PRIN' TO it_ucomm,  "for print
    'SPOS' TO it_ucomm,
    'E' TO it_ucomm.    "for back


  CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
    EXPORTING
      p_status  sy-pfkey
    TABLES
      p_exclude it_ucomm.


INITIALIZATION.
PERFORM BINT.

START-OF-SELECTION.
PERFORM COL_DATA.
*PERFORM DISPLAY.


Include------------
*&---------------------------------------------------------------------*
*&  Include           ZUSERTOP
*&---------------------------------------------------------------------*

TABLES USR02,USR06,USER_ADDR,ZTBUSRLCS.

CONTROLS ZCTRUSER TYPE TABLEVIEW USING SCREEN '100'.

RANGESR_BEFORE FOR BSIS-BUDAT,
        R_CURRENT FOR BSIS-BUDAT.
TYPE-POOLS slisicon,vimty.


*Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 WITH FRAME.
SELECT-OPTIONSS_BNAME FOR USR02-BNAME.
PARAMETERSr_mess(128DEFAULT ' '."." like T100-TEXT.

*MESSAGE(128) default ' Error ! Please" logoff now ! '.
*            r_det RADIOBUTTON GROUP rad1 DEFAULT 'X',
*            r_sum RADIOBUTTON GROUP rad1.

SELECTION-SCREEN END OF BLOCK BLOCK1.
* interne Tabelle mit Auftragskopfdaten *

TYPES :
   BEGIN OF ty_mod,
      row TYPE i,
   END OF ty_mod.

DATA :
i_mod              TYPE STANDARD TABLE OF ty_mod,
i_del              TYPE STANDARD TABLE OF ty_mod.

DATAit_ucomm TYPE TABLE OF sy-ucomm.

TYPES:  BEGIN OF i_usr_s,
          BNAME type  USER_ADDR-BNAME,
          CLASS type  USR02-CLASS,
          UFLAG type  USR02-UFLAG,
          TRDAT type  USR02-TRDAT,
          LTIME type  USR02-LTIME,
          GLTGV type  USR02-GLTGV,
          GLTGB type  USR02-GLTGB,
          ERDAT type USR02-ERDAT,
          VONDAT  type  USR06-VONDAT,
          BISDAT  type  USR06-BISDAT,
          LIC_TYPE  type  USR06-LIC_TYPE,
          NAME_FIRST  type  USER_ADDR-NAME_FIRST,
          NAME_LAST type  USER_ADDR-NAME_LAST,
          NAME_TEXTC  type  USER_ADDR-NAME_TEXTC,
          DEPARTMENT  type  USER_ADDR-DEPARTMENT,
          ctr_stat(15type C,
          no(1type P,
          exp(1type C,
          lockby(30TYPE C,
        END OF i_usr_s.

TYPES:  BEGIN OF i_sum,
        ctr_stat(15type C,
        bname type usr02-bname,
        NO type  P" DECIMALS 0,
        gltgb TYPE usr02-gltgb,
        exp(1)  TYPE C,
        NOP(3type C,
        END OF i_sum.

CLASS lcl_event_receiver DEFINITION DEFERRED.
DATAo_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.


DATAi_usr_usr2 LIKE TABLE OF usr02,
      i_usr_dat type standard Table OF i_usr_s WITH HEADER LINE,
      i_usr_su type standard Table OF i_sum WITH HEADER LINE,
      i_usr_susu type standard Table OF i_sum WITH HEADER LINE,
      i_usr_sum type standard Table OF i_sum WITH HEADER LINE,
      i_usr_summ LIKE TABLE OF ZTBUSRLCS with header line.

DATAtable_n TYPE i,
      table_nn TYPE i,
      sy_repid_save LIKE sy-repid,
      sumrec type i.

DATA datval type sy-datum,
       gstring TYPE c.

DATA ls_exclude TYPE ui_func,
       pt_exclude TYPE ui_functions,
       NO TYPE STRING.

DATAt_fldcat     TYPE slis_t_fieldcat_alv,
      s_fldcat     TYPE slis_fieldcat_alv,
      t_sort       TYPE slis_t_sortinfo_alv," WITH HEADER LINE,
      wa_sortinfo TYPE slis_sortinfo_alv,
      t_events     TYPE slis_t_event WITH HEADER LINE,
      t_event_exit TYPE slis_t_event_exit WITH HEADER LINE,
      x_layout     TYPE slis_layout_alv,
       gd_layout    TYPE lvc_s_layo,
      x_print      TYPE slis_print_alv,
      x_variant    TYPE disvariant,
      d_repid      TYPE sy-repid,
      ct_type(2,
      f_fldcat2 type slis_t_fieldcat_alv with header line,
      g_layout type slis_layout_alv,
      gs_fieldcatalog TYPE lvc_s_fcat OCCURS 0,
      gv_fcat LIKE LINE OF gs_fieldcatalog,
      gus_fieldcatalog TYPE lvc_s_fcat OCCURS 0.

DATABEGIN OF gt_outtab occurs ."with header line.
        include structure ZTBUSRLCS.
DATAcelltab type LVC_T_STYL.
DATAEND OF gt_outtab.
DATAit_table LIKE standard table of gt_outtab WITH HEADER LINE,
      t_table LIKE standard table of gt_outtab WITH HEADER LINE.


DATAOK_CODE LIKE sy-ucomm,
      save_ok like sy-ucomm,
      g_container TYPE scrfname VALUE 'ZCTRUSER',
      grid1  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gs_layout TYPE lvc_s_layo,
      g_max type value 100.

DATA user_name LIKE usr02-bname,
      user_mess LIKE t100-text.


AT SELECTION-SCREEN.
*--------------------------------------------------------------------
* C L A S S E S
*--------------------------------------------------------------------
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:   handle_data_changed
               FOR EVENT data_changed OF cl_gui_alv_grid
               IMPORTING er_data_changed.

ENDCLASS.                    "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD  handle_data_changed.

*event is ttriggered when data is changed in the output

*    PERFORM check_data USING er_data_changed
*                             i_usr_summ.

  ENDMETHOD.                    "handle_data_changed
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION


*&---------------------------------------------------------------------*
*&  Include           ZUSERPRO
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  BINT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BINT .

  DEFINE f_fldcat.
    clear s_fldcat.
    s_fldcat-fieldname &1.
*    s_fldcat-key       = &2.
    s_fldcat-decimals_out  &2.
    s_fldcat-seltext_l &3.
    s_fldcat-outputlen  &4.
    s_fldcat-just      &5.
    s_fldcat-no_out    &6.
    s_fldcat-datatype  &7.
    s_fldcat-qfieldname &8.
    s_fldcat-no_zero  &9.
*    s_fldcat-outputlen  = &10.

    append s_fldcat to t_fldcat.
  END-OF-DEFINITION.

ENDFORM.                    " BINT
*&---------------------------------------------------------------------*
*&      Form  SUMMARY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SUMMARY .
  IF NOT i_usr_dat IS INITIAL.
    LOOP AT i_usr_dat .
      MOVE-CORRESPONDING i_usr_dat to i_usr_su.
      Append i_usr_su.
    ENDLOOP.
  ELSE.
    STOP.
  ENDIF.

  SORT i_usr_su by ctr_stat.
  LOOP AT i_usr_su.
    AT END OF ctr_stat.
      Read table i_usr_su INDEX sy-tabix.
      SUM.
      i_usr_sum-ctr_stat i_usr_su-ctr_stat.
      i_usr_sum-no i_usr_su-no.
      APPEND i_usr_sum.
    ENDAT.
  ENDLOOP.

  LOOP AT i_usr_sum.
    i_usr_sum-nop i_usr_sum-no.
    modify i_usr_sum.
  ENDLOOP.

  i_usr_sum-ctr_stat 'TOTAL USER '.
  i_usr_sum-nop sumrec.
  APPEND i_usr_sum.

*  Update to Summary table
  IF SY-SUBRC EQ 0.
    LOOP AT i_usr_sum .
      i_usr_summ-CLIENT sy-mandt.
      i_usr_summ-USERSAP i_usr_sum-ctr_stat.
      i_usr_summ-SUMOF i_usr_sum-nop.
*      i_usr_summ-SAVEDATE = SY-DATUM.   " unmark this after test
      append  i_usr_summ.
    ENDLOOP.
  ENDIF.


*   Update itab From Table
  CLEAR i_usr_summ.
  LOOP AT i_usr_summ.
    SELECT SINGLE CURRLCS SAVEDATE from ZTBUSRLCS
   INTO (i_usr_summ-CURRLCS,i_usr_summ-SAVEDATE)
 WHERE USERSAP EQ i_usr_summ-USERSAP.
    MODIFY i_usr_summ.
  ENDLOOP.

ENDFORM.                    " SUMMARY
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  COL_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM COL_DATA .

  CLEAR USR02,USR06,USER_ADDR .
  SELECT usr02~bname usr02~class usr02~uflag usr02~trdat usr02~ltime
         usr02~gltgv usr02~gltgb usr02~erdat
         user_addr~name_first user_addr~name_last user_addr~name_textc
         user_addr~department
  INTO CORRESPONDING FIELDS OF TABLE i_usr_dat
  FROM  usr02
  INNER JOIN user_addr AS user_addr ON user_addr~bname usr02~bname
  WHERE usr02~bname IN s_bname.

  table_n 0.
  DESCRIBE TABLE i_usr_dat LINES table_n.
  IF table_n EQ 0.
    CALL FUNCTION 'C14A_POPUP_NO_HITS'.
    STOP.
  ENDIF.


  LOOP AT i_usr_dat.
    user_name i_usr_dat-bname.
    user_mess r_mess.

    CALL FUNCTION 'TH_POPUP'
      EXPORTING
        CLIENT               sy-mandt
        USER                 user_name
        MESSAGE              r_mess
*   MESSAGE_LEN          = 0
*   CUT_BLANKS           = ' '
 EXCEPTIONS
   USER_NOT_FOUND       1
   OTHERS               2
              .
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " COL_DATA

*&---------------------------------------------------------------------*
*&      Form  SWITCH_EDIT_MODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SWITCH_EDIT_MODE .

*  PERFORM MODIFY_SCR.


  IF grid1->is_ready_for_inputeq 0.
* set edit enabled cells ready for input
    CALL METHOD grid1->set_ready_for_input
      EXPORTING
        i_ready_for_input 1.

    CALL METHOD GRID1->CHECK_CHANGED_DATA.
*    UPDATE ZTBUSRLCS FROM TABLE i_usr_summ.

  ELSE.
* lock edit enabled cells against input
    CALL METHOD grid1->set_ready_for_input
      EXPORTING
        i_ready_for_input 0.

  ENDIF.

ENDFORM.                    " SWITCH_EDIT_MODE
*&---------------------------------------------------------------------*
*&      Form  SAVEMONEY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SAVEMONEY .

  IF grid1->is_ready_for_inputEQ 0.
    MESSAGE ' Cannot Save Data in Display Mode' TYPE 'S'.
  ELSE.

    CALL METHOD grid1->set_table_for_first_display
      EXPORTING
        i_structure_name 'ZTBUSRLCS'
        is_layout        gs_layout
      CHANGING
        it_outtab        gt_outtab[].


    CALL METHOD grid1->register_edit_event
      EXPORTING
        i_event_id cl_gui_alv_grid=>mc_evt_modified.

    CALL METHOD grid1->register_edit_event
      EXPORTING
        i_event_id cl_gui_alv_grid=>mc_evt_enter.

    CALL METHOD Grid1->REGISTER_EDIT_EVENT
      EXPORTING
        I_EVENT_ID CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
      EXCEPTIONS
        ERROR      1
        OTHERS     2.


    CREATE OBJECT o_event_receiver.
    SET HANDLER o_event_receiver->handle_data_changed FOR grid1.

    CALL METHOD cl_gui_control=>set_focus
      EXPORTING
        control grid1.


    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
        titlebar       'SAVING DATA'
        text_question  'Do you want save the data?'
        icon_button_1  'icon_booking_ok'
      IMPORTING
        answer         gstring
      EXCEPTIONS
        text_not_found 1
        OTHERS         2.

    IF gstring '1' ).
      MESSAGE ' Data Saved' TYPE 'S'.
      READ TABLE i_usr_summ INDEX sy-tabix"l_selfield-tabindex.

* Update or Save Data to Table
      Delete from ZTBUSRLCS.

*      IF SY-SUBRC EQ 0.
      IF i_usr_summ IS NOT INITIAL.
        LOOP AT gt_outtab.

          gt_outtab-SAVEDATE SY-DATUM.
          ZTBUSRLCS-CLIENT   SY-MANDT.
          ZTBUSRLCS-USERSAP  gt_outtab-USERSAP.
          ZTBUSRLCS-SUMOF    gt_outtab-SUMOF.
          ZTBUSRLCS-CURRLCS  gt_outtab-CURRLCS.
          ZTBUSRLCS-SAVEDATE gt_outtab-SAVEDATE.
          MODIFY gt_outtab.

          INSERT ZTBUSRLCS.
        ENDLOOP.
      ENDIF.
    ENDIF.


    CALL METHOD grid1->set_ready_for_input
      EXPORTING
        i_ready_for_input 0.


    CALL METHOD grid1->set_table_for_first_display
    EXPORTING
*        is_variant           = l2_layout
      i_structure_name 'ZTBUSRLCS'
        i_save               'A'
      it_toolbar_excluding pt_exclude
      is_layout        gs_layout
    CHANGING
      it_fieldcatalog  gus_fieldcatalog
      it_outtab        gt_outtab[].


  ENDIF.


ENDFORM.                    " SAVEMONEY
*&---------------------------------------------------------------------*
*&      Form  MODIFY_SCR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM MODIFY_SCR .


  SET PF-STATUS 'PF_PUSER'.
  refresh it_ucomm.

  APPEND :
    'PRIN' TO it_ucomm,  "for print
    'E' TO it_ucomm.    "for back

  CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
    EXPORTING
      p_status  sy-pfkey
    TABLES
      p_exclude it_ucomm.

 

ENDFORM.                    " MODIFY_SCR





Visitor

Code Syntax Try...Endtry

  Code : Report Try. Parameters  NUMBER  type  I . data  RESULT  type  P  decimals  2 . data  OREF  type  ref  to  CX_ROOT . data  TEXT  typ...