Thursday, February 21, 2019

Update Z-Table through Editable AlV Grid in SAP ABAP

Update Z-Table through Editable AlV Grid in SAP ABAP.

Read More Customer Exit ..........


REPORT ZQAM_PP_01.

INCLUDE ZQAM_PP_01_TOP.
INCLUDE ZQAM_PP_01_SEL.
INCLUDE ZQAM_PP_01_SUB.

START-OF-SELECTION.

  PERFORM get_data.
  PERFORM alv_fieldcat.
  PERFORM get_events.
  PERFORM sub_comment_build USING t_list_top_of_page.
  PERFORM alv_display.
***************************************************************

TOP PAGE
********************************************
*&---------------------------------------------------------------------*
*&  Include           ZQAM_PP_01_TOP
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Type-Pool Declaration
*&---------------------------------------------------------------------*
TYPE-POOLS: slis.
*&---------------------------------------------------------------------*
*& ALV Data Declaration
*&---------------------------------------------------------------------*
DATA: it_fieldcat            TYPE slis_t_fieldcat_alv.
DATA: wa_fieldcat            LIKE LINE OF it_fieldcat.
DATA: t_list_top_of_page     TYPE slis_t_listheader.
DATA: it_events              TYPE slis_t_event WITH HEADER LINE.
DATA: g_save                 TYPE c VALUE 'A'.
DATA: gt_sort                TYPE slis_t_sortinfo_alv.
DATA: gx_save                TYPE c VALUE 'A'.
DATA: gx_variant             TYPE disvariant.
DATA: g_variant              TYPE disvariant.
DATA: gs_layout              TYPE slis_layout_alv.
DATA: t_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.
DATA: t_i_event              TYPE slis_alv_event.
*&---------------------------------------------------------------------*
*& External Table Declaration                                          *
*&---------------------------------------------------------------------*
TABLES: zqampp01,mara,makt.

*&---------------------------------------------------------------------*
*& Internal Table Declaration                                          *
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_zqampp01,
         matnr      TYPE matnr,
         maktx      TYPE maktx,
         user_def1  TYPE zuser_def1,
         user_def2  TYPE zuser_def2,
         user_def3  TYPE zuser_def3,
         user_def4  TYPE zuser_def4,
         user_def5  TYPE zuser_def5,
         user_def6  TYPE zuser_def6,
         user_def7  TYPE zuser_def7,
         user_def8  TYPE zuser_def8,
         user_def9  TYPE zuser_def9,
         user_def10 TYPE zuser_def10,
*         user_def11 TYPE zuser_def11,
       END OF ty_zqampp01.

TYPES:BEGIN OF ty_mara,
        matnr TYPE matnr,
        mtart TYPE mtart,
      END OF  ty_mara.

TYPES:BEGIN OF ty_makt,
        matnr TYPE matnr,
        maktx TYPE maktx,
      END OF  ty_makt.

TYPES:
  ty_document_list TYPE  sodocchgi1,
  ty_packing_list  TYPE  sopcklsti1,
  ty_attachment    TYPE  solisti1,
  ty_receiver      TYPE  somlreci1,
  ty_message       TYPE  solisti1.

*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Variables Declaration                                               *
*&---------------------------------------------------------------------*
DATA: it_stru  TYPE STANDARD TABLE OF ty_zqampp01,
      it_stru1  TYPE STANDARD TABLE OF ty_zqampp01,
      wa_stru1 TYPE ty_zqampp01,
      wa_stru  TYPE ty_zqampp01.

DATA: it_mara TYPE STANDARD TABLE OF ty_mara,
      wa_mara TYPE ty_mara.

DATA: it_makt TYPE STANDARD TABLE OF ty_makt,
      wa_makt TYPE ty_makt.

DATA: id_tabix TYPE sy-tabix.


DATA: it_packing_list  TYPE STANDARD TABLE OF ty_packing_list  WITH HEADER LINE,
      it_receiver      TYPE STANDARD TABLE OF ty_receiver      WITH HEADER LINE,
      it_body_msg      TYPE STANDARD TABLE OF ty_message       WITH HEADER LINE,
      it_attachment    TYPE STANDARD TABLE OF ty_attachment    WITH HEADER LINE,
      it_document_list TYPE STANDARD TABLE OF ty_document_list WITH HEADER LINE.

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE,
      it_attach  TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE.

DATA: mailtext TYPE STANDARD TABLE OF solisti1 WITH HEADER LINE,
      mailrec  TYPE STANDARD TABLE OF somlreci1 WITH HEADER LINE.

DATA: wa_packing_list  TYPE ty_packing_list,
      wa_receiver      TYPE ty_receiver,
      wa_body_msg      TYPE ty_message,
      wa_attachment    TYPE ty_attachment,
      wa_document_list TYPE ty_document_list.
*CONSTANTS: c_check(1) VALUE 'X'.

DATA: ls_ans TYPE string.

DATA: l_resize  TYPE i,
      tab_line  TYPE i,
      l_snt_all TYPE c LENGTH 1.
*DATA: mail_data TYPE sodocchgi1.

*******************************************************************************
SELECTION PAGE
*******************************************************************************
*&---------------------------------------------------------------------*
*&  Include           ZQAM_PP_01_SEL
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_matnr FOR wa_mara-matnr. "material no input
SELECTION-SCREEN END OF BLOCK b1.
******************************************************************************
SUB PAGE
******************************************************************************
*&---------------------------------------------------------------------*
*&  Include           ZQAM_PP_01_SUB
*&---------------------------------------------------------------------*
*START-OF-SELECTION.

FORM get_data.

  SELECT matnr
         maktx
         user_def1
         user_def2
         user_def3
         user_def4
         user_def5
         user_def6
         user_def7
         user_def8
         user_def9
         user_def10
*         user_def11
    FROM zqampp01
    INTO TABLE it_stru
    WHERE matnr IN s_matnr.
  IF it_stru[] IS INITIAL.
    SELECT matnr
           mtart
      FROM mara
      INTO TABLE it_mara
      WHERE matnr IN s_matnr
      AND  mtart = 'YFGR'.
    IF it_mara[] IS NOT INITIAL.
      SELECT matnr
             maktx
    FROM makt
    INTO TABLE it_makt
     FOR ALL ENTRIES IN it_mara
    WHERE matnr = it_mara-matnr.

      LOOP AT it_mara INTO wa_mara.
        wa_stru-matnr = wa_mara-matnr.
        READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr.
        IF sy-subrc = 0.
          wa_stru-maktx = wa_makt-maktx.
        ENDIF.
        APPEND wa_stru TO it_stru.
        CLEAR:wa_stru.
        CLEAR:wa_makt.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.



FORM alv_fieldcat .
  DATA: counter TYPE i.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'MATNR'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Em_Name'.
  wa_fieldcat-no_zero   = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'MAKTX'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Em_Name'.
  wa_fieldcat-no_zero   = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF1'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 1'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF2'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 2'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF3'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 3'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.


  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF4'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 34'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF5'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 5'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF6'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 6'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF7'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 3'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF8'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 8'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF9'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 9'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  counter = counter + 1.
  wa_fieldcat-col_pos    = counter.
  wa_fieldcat-fieldname  = 'USER_DEF10'.
  wa_fieldcat-tabname    = 'IT_STRU'.
  wa_fieldcat-seltext_l  = 'Col 10'.
  wa_fieldcat-no_zero    = 'X'.
  wa_fieldcat-edit        = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

*  counter = counter + 1.
*  wa_fieldcat-col_pos    = counter.
*  wa_fieldcat-fieldname  = 'USER_DEF11'.
*  wa_fieldcat-tabname    = 'IT_STRU'.
*  wa_fieldcat-seltext_l  = 'Col 11'.
*  wa_fieldcat-no_zero    = 'X'.
*  wa_fieldcat-edit        = 'X'.
*  APPEND wa_fieldcat TO it_fieldcat.
*  CLEAR wa_fieldcat.
ENDFORM.

FORM get_events .
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 0
    IMPORTING
      et_events       = it_events[]
    EXCEPTIONS
      list_type_wrong = 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.

  READ TABLE it_events WITH KEY name = slis_ev_top_of_page
                                INTO it_events.
  IF sy-subrc = 0.
    MOVE t_formname_top_of_page TO it_events-form.
    APPEND it_events.
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  SUB_COMMENT_BUILD
*&---------------------------------------------------------------------*
FORM sub_comment_build  USING  i_top_of_page TYPE slis_t_listheader.
  DATA: ls_line TYPE slis_listheader.
  DATA: wrk_name     TYPE string.

*  wrk_name = 'Squirrel Softech Pvt. Ltd.'.

  CLEAR ls_line.

  ls_line-typ  = 'H'.
*  ls_line-info = wrk_name.
  APPEND ls_line TO i_top_of_page.
  ls_line-typ  = 'H'.
  ls_line-info = 'Details Report'.
  APPEND ls_line TO i_top_of_page.
ENDFORM.                    " SUB_COMMENT_BUILD

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_list_top_of_page.
ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  ALV_DISPLAY
*&---------------------------------------------------------------------*
FORM alv_display .
  gs_layout-zebra                = 'X'.
  gs_layout-detail_popup         = 'X'.
  gs_layout-detail_initial_lines = 'X'.
  gs_layout-colwidth_optimize    = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat              = it_fieldcat
      it_events                = it_events[]
      i_callback_program       = sy-repid
      is_layout                = gs_layout
      it_sort                  = gt_sort[]
      i_save                   = g_save
      is_variant               = gx_variant
      i_callback_pf_status_set = 'ZSAVE'
      i_callback_user_command  = 'USER_COMMAND'
    TABLES
      t_outtab                 = it_stru[].
  .
ENDFORM.                    " ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM zsave USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZSAVE'.
*  SET PF-STATUS 'START'.
ENDFORM.                    "text


*&---------------------------------------------------------------------*
*&      form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->ucomm      text
*      -->selfield   text
*----------------------------------------------------------------------*
FORM user_command USING ucomm  TYPE sy-ucomm
                        selfield TYPE slis_selfield.

  DATA: gd_repid LIKE sy-repid,
        ref_grid TYPE REF TO cl_gui_alv_grid.

  IF ref_grid IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = ref_grid.
  ENDIF.
  IF NOT ref_grid IS INITIAL.
    CALL METHOD ref_grid->check_changed_data.
  ENDIF.
  CASE sy-ucomm.
    WHEN 'SAVE'.
      LOOP AT it_stru INTO wa_stru.
        SELECT matnr
               maktx
               user_def1
               user_def2
               user_def3
               user_def4
               user_def5
               user_def6
               user_def7
               user_def8
               user_def9
               user_def10
*               user_def11
          FROM zqampp01
          INTO TABLE it_stru
          WHERE matnr = wa_stru-matnr.
        IF sy-subrc = 0.
          UPDATE zqampp01
            SET matnr        = wa_stru-matnr
                maktx        = wa_stru-maktx
                user_def1    = wa_stru-user_def1
                user_def2    = wa_stru-user_def2
                user_def3    = wa_stru-user_def3
                user_def4    = wa_stru-user_def4
                user_def5    = wa_stru-user_def5
                user_def6    = wa_stru-user_def6
                user_def7    = wa_stru-user_def7
                user_def8    = wa_stru-user_def8
                user_def9    = wa_stru-user_def9
                user_def10   = wa_stru-user_def10
*                user_def11   = wa_stru-user_def11
                WHERE  matnr = wa_stru-matnr.
          IF sy-subrc = 0.
            COMMIT WORK AND WAIT.
          ENDIF.
        ELSE.
          zqampp01-matnr =   wa_stru-matnr.
          zqampp01-maktx =   wa_stru-maktx.
          zqampp01-user_def1 =  wa_stru-user_def1.
          zqampp01-user_def2 =  wa_stru-user_def2.
          zqampp01-user_def3 =  wa_stru-user_def3.
          zqampp01-user_def4 =  wa_stru-user_def4.
          zqampp01-user_def5 =  wa_stru-user_def5.
          zqampp01-user_def6 =  wa_stru-user_def6.
          zqampp01-user_def7 =  wa_stru-user_def7.
          zqampp01-user_def8 =  wa_stru-user_def8.
          zqampp01-user_def9 =  wa_stru-user_def9.
          zqampp01-user_def10 = wa_stru-user_def10.
*          zqampp01-user_def11 = wa_stru-user_def11.
          INSERT  zqampp01.
          IF sy-subrc = 0.
            COMMIT WORK AND WAIT.
          ENDIF.
        ENDIF.
      ENDLOOP.
  ENDCASE.
ENDFORM.

Read More Customer Exit ..........

1 comment:

  1. Sap Abap For Best Practice And Travel Related Guide: Update Z-Table Through Editable Alv Grid In Sap Abap >>>>> Download Now

    >>>>> Download Full

    Sap Abap For Best Practice And Travel Related Guide: Update Z-Table Through Editable Alv Grid In Sap Abap >>>>> Download LINK

    >>>>> Download Now

    Sap Abap For Best Practice And Travel Related Guide: Update Z-Table Through Editable Alv Grid In Sap Abap >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete