Thursday, 9 June 2016

ALV Report using EDIT and SAVE option

Steps

  • Go to transaction code SE38.
  • Enter the program name Z or Y<program name>.
  • Enter the program Title name and  Select attribute type as Executable program.
  • Click on Save.

Source Code




TYPES BEGIN OF TY_SO,
        VBELN TYPE VBAK-VBELN,
        POSNR TYPE VBAP-POSNR,
        VKORG TYPE VBAK-VKORG,
        MATNR TYPE VBAP-MATNR,
        ARKTX TYPE VBAP-ARKTX,
        END OF TY_SO.

DATA WA_SO TYPE TY_SO,
       IT_SO TYPE TABLE OF TY_SO,
       IT_CPY TYPE TABLE OF TY_SO,
       WA_CPY TYPE TY_SO.


DATA IT_FIELDCAT TYPE  SLIS_T_FIELDCAT_ALV,
       WA_FIELDCAT TYPE slis_fieldcat_alv.

DATA WA_VBAP TYPE VBAP.

SELECT-OPTIONS S_VBELN FOR WA_SO-VBELN.

START-OF-SELECTION.

PERFORM FETCH_DATA USING S_VBELN[] CHANGING IT_SO.

IT_CPY IT_SO.     " Copying the content of IT_SO internal table into another internal table before                                         display

PERFORM FIELD_CATALOG CHANGING IT_FIELDCAT.

PERFORM DISPLAY USING IT_FIELDCAT IT_SO.




*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_S_VBELN[]  text
*      <--P_IT_SO  text
*----------------------------------------------------------------------*
form FETCH_DATA  using    p_s_vbeln LIKE S_VBELN[]
                 changing p_it_so LIKE IT_SO.

  SELECT A~VBELN POSNR VKORG MATNR ARKTX INTO TABLE p_it_so  FROM VBAK
    AS A INNER JOIN VBAP AS ON B~VBELN A~VBELN
    WHERE A~VBELN IN  p_s_vbeln.

endform.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_IT_FIELDCAT  text
*----------------------------------------------------------------------*
form FIELD_CATALOG  changing p_it_fieldcat  LIKE it_fieldcat .

WA_FIELDCAT-COL_POS 1.
WA_FIELDCAT-FIELDNAME 'VBELN'.
WA_FIELDCAT-OUTPUTLEN 10.
WA_FIELDCAT-SELTEXT_M 'BILLING DOC'.
WA_FIELDCAT-KEY 'X'.

APPEND WA_FIELDCAT TO P_IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-COL_POS 2.
WA_FIELDCAT-FIELDNAME 'POSNR'.
WA_FIELDCAT-OUTPUTLEN 4.
WA_FIELDCAT-SELTEXT_M 'ITEM'.
WA_FIELDCAT-KEY 'X'.

APPEND WA_FIELDCAT TO P_IT_FIELDCAT.
CLEAR WA_FIELDCAT.


WA_FIELDCAT-COL_POS 3.
WA_FIELDCAT-FIELDNAME 'VKORG'.
WA_FIELDCAT-OUTPUTLEN 4.
WA_FIELDCAT-SELTEXT_M 'SALES ORG'.


APPEND WA_FIELDCAT TO P_IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS 4.
WA_FIELDCAT-FIELDNAME 'MATNR'.
WA_FIELDCAT-OUTPUTLEN 18.
WA_FIELDCAT-SELTEXT_M 'MATERIAL NUMBER'.


APPEND WA_FIELDCAT TO P_IT_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS 5.
WA_FIELDCAT-FIELDNAME 'ARKTX'.
WA_FIELDCAT-OUTPUTLEN 40.
WA_FIELDCAT-SELTEXT_M 'SALES MATERIAL DES'.
WA_FIELDCAT-EDIT 'X'.

APPEND WA_FIELDCAT TO P_IT_FIELDCAT.
CLEAR WA_FIELDCAT.




endform.                    " FIELD_CATALOG
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_FIELDCAT  text
*      -->P_IT_SO  text
*----------------------------------------------------------------------*
form DISPLAY  using    p_it_fieldcat LIKE IT_FIELDCAT
                       p_it_so LIKE IT_SO.


  call function 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*     I_INTERFACE_CHECK                 = ' '
*     I_BYPASSING_BUFFER                = ' '
*     I_BUFFER_ACTIVE                   = ' '
     I_CALLBACK_PROGRAM                SY-REPID
*     I_CALLBACK_PF_STATUS_SET          = ' '
     I_CALLBACK_USER_COMMAND           'SAVE'
*     I_CALLBACK_TOP_OF_PAGE            = ' '
*     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*     I_CALLBACK_HTML_END_OF_LIST       = ' '
*     I_STRUCTURE_NAME                  =
*     I_BACKGROUND_ID                   = ' '
*     I_GRID_TITLE                      =
*     I_GRID_SETTINGS                   =
*     IS_LAYOUT                         =
     IT_FIELDCAT                       p_it_fieldcat
*     IT_EXCLUDING                      =
*     IT_SPECIAL_GROUPS                 =
*     IT_SORT                           =
*     IT_FILTER                         =
*     IS_SEL_HIDE                       =
*     I_DEFAULT                         = 'X'
*     I_SAVE                            = ' '
*     IS_VARIANT                        =
*     IT_EVENTS                         =
*     IT_EVENT_EXIT                     =
*     IS_PRINT                          =
*     IS_REPREP_ID                      =
*     I_SCREEN_START_COLUMN             = 0
*     I_SCREEN_START_LINE               = 0
*     I_SCREEN_END_COLUMN               = 0
*     I_SCREEN_END_LINE                 = 0
*     I_HTML_HEIGHT_TOP                 = 0
*     I_HTML_HEIGHT_END                 = 0
*     IT_ALV_GRAPHICS                   =
*     IT_HYPERLINK                      =
*     IT_ADD_FIELDCAT                   =
*     IT_EXCEPT_QINFO                   =
*     IR_SALV_FULLSCREEN_ADAPTER        =
*   IMPORTING
*     E_EXIT_CAUSED_BY_CALLER           =
*     ES_EXIT_CAUSED_BY_USER            =
    tables
      t_outtab                          =  p_it_so
   EXCEPTIONS
     PROGRAM_ERROR                     1
     OTHERS                            2
            .
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.


endform.                    " DISPLAY

FORM SAVE USING RCOMM TYPE SY-UCOMM
                SEL TYPE SLIS_SELFIELD.


  CASE SY-UCOMM.
    WHEN '&DATA_SAVE'.
      LOOP AT IT_SO INTO WA_SO.
        CLEAR WA_CPY.
        READ TABLE IT_CPY INTO WA_CPY INDEX SY-TABIX.
        IF  WA_SO NE WA_CPY.

          WA_VBAP-VBELN WA_SO-VBELN.
           WA_VBAP-POSNR WA_SO-POSNR.
           WA_VBAP-MATNR WA_SO-MATNR.
           WA_VBAP-ARKTX WA_SO-ARKTX.
          MODIFY VBAP FROM WA_VBAP.
          IF SY-SUBRC 0.
               MESSAGE 'RECORD HAS BEEN SAVED' TYPE 'S'.
          ENDIF.

        ENDIF.
      CLEAR WA_VBAP WA_SO.
      ENDLOOP.


  ENDCASE.


ENDFORM.




  • Save->Check->Activate->Execute.

Input



Output

  • Before Editing the  Sales material Description.

  • Edit the text and click on save.
 





  • Check the status in Status bar.






No comments:

Post a Comment