Displaying the data in various languages using ALV

By B.Kalyan, YASH Technologies

REPORT  zalv_test NO STANDARD PAGE HEADING.
*"Table declarations.......................................................
TABLES:
  mara,
  makt.
*"Type-pools..............................................................
TYPE-POOLS: slis.
*" DATA declarations.......................................................
*"-------------------------------------------------------------------- *
* Data declaration for the internal table to hold the material *
* data   table MARA.                                                    *
*"--------------------------------------------------------------------  *
DATA: BEGIN OF t_mara OCCURS 0,
matnr LIKE mara-matnr,
meins LIKE mara-meins,
mtart LIKE mara-mtart,
END OF t_mara.
*" DATA declarations.......................................................
*"-------------------------------------------------------------------- *
* Data declaration for the internal table to hold the material *
* Descriptions table MAKT.                                              *
*"--------------------------------------------------------------------  *
DATA: BEGIN OF t_makt OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
spras LIKE makt-spras,
END OF t_makt.
*" DATA declarations......................................................
*"--------------------------------------------------------------------*
* Data declaration for the final internal table                        *
*"--------------------------------------------------------------------*
DATA: BEGIN OF t_final OCCURS 0,
matnr LIKE mara-matnr,
meins LIKE mara-meins,
mtart LIKE mara-mtart,
maktx LIKE makt-maktx,
END OF t_final.
*" DATA declarations.....................................................
*"--------------------------------------------------------------------*
* Data declaration for the fieldcat                                     *
*"--------------------------------------------------------------------*
DATA:
  t_fieldcat TYPE slis_t_fieldcat_alv,
  l_fieldcat TYPE slis_fieldcat_alv,
  t_layout TYPE slis_layout_alv.
*"Selection screen elements............................................
SELECTION-SCREEN BEGIN OF BLOCK blck WITH FRAME.
SELECT-OPTIONS:s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK blck.
*"Selection screen elements............................................
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME.
*"Parameters...........................................................
PARAMETERS:
  p_lang LIKE sy-langu.
*"Parameters...........................................................
PARAMETERS:
  p_rd1 RADIOBUTTON GROUP rg1 DEFAULT 'X' USER-COMMAND usr1,
  p_rd2 RADIOBUTTON GROUP rg1,
  p_rd3 RADIOBUTTON GROUP rg1.
SELECTION-SCREEN end OF BLOCK blk.
*"--------------------------------------------------------------------*
*   AT SELECTION-SCREEN OUTPUT                            *
*"--------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
*"IF p_rd1............................................................
  IF p_rd1 = 'X'.
     p_lang = 'EN'.
  ENDIF.                               " IF p_rad1 = 'X'.
*"IF p_rd2............................................................
  IF p_rd2 = 'X'.
     p_lang = 'DE'.
  ENDIF.                               " IF p_rad2 = 'X'.
*"IF p_rd3............................................................
  IF p_rd3 = 'X'.
     p_lang = 'FR'.
  ENDIF.                               " IF p_rad3 = 'X'.
*"-------------------------------------------------------------------- *
*   START-OF-SELECTION                                                *
*"-------------------------------------------------------------------- *
START-OF-SELECTION.
*"--------------------------------------------------------------------*
* Selection from MARA                                                  *
*"--------------------------------------------------------------------*
  SELECT matnr
  meins
  mtart
  FROM mara
  INTO TABLE t_mara
  WHERE matnr IN s_matnr.
*"--------------------------------------------------------------------*
* Selection From MAKT                                                 *
*"--------------------------------------------------------------------*
  SELECT matnr
  maktx
  spras
  FROM makt
  INTO TABLE t_makt
  FOR ALL ENTRIES IN t_mara
  WHERE matnr = t_mara-matnr
  AND spras = p_lang.
*"LOOP AT t_mara.......................................................
  LOOP AT t_mara.
    t_final-matnr = t_mara-matnr.
    t_final-meins = t_mara-meins.
    t_final-mtart = t_mara-mtart.
    READ TABLE t_makt WITH KEY matnr = t_mara-matnr.
    t_final-maktx = t_makt-maktx.
    APPEND t_final.
    CLEAR  t_final.
  ENDLOOP.
*&--------------------------------------------------------------------*
*&      Subroutines for the data display...                           *
*&--------------------------------------------------------------------*
   PERFORM t_fieldcat.
   PERFORM reuse_alv.
*&---------------------------------------------------------------------*
*&      Form  T_FIELDCAT                                               *
*&---------------------------------------------------------------------*
*  This Subroutine fill the fieldcatlog with the necessary        *
* fields..                                                               *
*----------------------------------------------------------------------  *
* There are no interface parameters to be passed to this s       *
* Subroutine.                                                            *
*----------------------------------------------------------------------  *
FORM t_fieldcat .
  PERFORM fill_field USING 'MATNR' 'Material Number'.
  PERFORM fill_field USING 'MEINS' 'Base Unit of Measure'.
  PERFORM fill_field USING 'MTART' 'Material Type'.
  PERFORM fill_field USING 'MAKTX' 'Material Description'.
ENDFORM.                    "T_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FILL_FIELD
*&---------------------------------------------------------------------*
*      This subroutine specifies the data for the fieldcatlog
*----------------------------------------------------------------------*
*  -->  p1        fieldname                                            *
*  <--  p2        seltext                                              *
*----------------------------------------------------------------------*
FORM fill_field USING   p_fieldname
                        p_seltext.
  l_fieldcat-fieldname  = p_fieldname.
  l_fieldcat-tabname    = 'T_FINAL'.
  l_fieldcat-seltext_m  = p_seltext.
  APPEND l_fieldcat TO t_fieldcat.
  CLEAR l_fieldcat.
ENDFORM.                    " FILL_FIELD
*&---------------------------------------------------------------------*
*&      Form  REUSE_ALV
*&---------------------------------------------------------------------*
* This Subroutine to call the function module                        *
* REUSE_ALV_GRID_DISPLAY                                        *
*---------------------------------------------------------------------- *
* There are no interface parameters to be passed to this         *
* Subroutine.                                                           *
*----------------------------------------------------------------------*
FORM reuse_alv .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      is_layout     = t_layout
      it_fieldcat   = t_fieldcat
    TABLES
      t_outtab      = t_final
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " REUSE_ALV

Output:

Click here to continue....
 

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image