Skip to Content
0
Jan 11, 2021 at 07:14 PM

Data Shifted into Different Columns

45 Views Last edit Jan 11, 2021 at 07:15 PM 2 rev

Soooo close :) Any help would be greatly appreciated!

I am trying to get my report to include the Material Description from makt and am having display issues incorrect data under col names:

Not sure what I am doing wrong.

TABLES: MARA,
        MAKT,
        ZISELECTEXIG.

*& SELECTION SCREEN AND SELECT OPTIONS FOR USER INPUT

SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME.
PARAMETERS: P_RAD1 RADIOBUTTON GROUP RAD DEFAULT 'X' USER-COMMAND flag, "/ SAP GUI
            P_RAD2 RADIOBUTTON GROUP RAD.                               "/ CDS View
SELECTION-SCREEN END OF BLOCK BLK1.

SELECT-OPTIONS: mats FOR mara-matnr OBLIGATORY.

TYPES:
BEGIN OF itab,
  matnr TYPE mara-matnr,
  maktx TYPE makt-maktx,
  meins TYPE mara-meins,
  mtart TYPE mara-mtart,
END OF itab.

*& Initialization of Events

INITIALIZATION.
*mats-low = ''.
*mats-high = ''.

APPEND mats.
AT SELECTION-SCREEN.
  IF mats-low = ' '.
    MESSAGE I000(ZKMESSAGE).
    ELSEIF mats-high = ' '.
      MESSAGE I001(ZKMESSAGE).
      ENDIF.

*& TOP OF PAGE EVENT

TOP-OF-PAGE.
WRITE: /20 'List:', SY-DBCNT CENTERED.
ULINE.
END-OF-PAGE.

TYPE-POOLS: slis.                               " SLIS contains all the ALV data types

*& Data Declaration

*DATA: it_mara     TYPE TABLE OF mara.

DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.

DATA: BEGIN OF it_mara OCCURS 0,
 maktx like makt-maktx,
  matnr LIKE mara-matnr,
  meins LIKE mara-meins,
  mtart LIKE mara-mtart,
END OF it_mara.

*& START-OF-SELECTION

START-OF-SELECTION.

*Fetching data from database

IF P_RAD1 = 'X'.
    SELECT matnr, meins, mtart FROM mara
      INTO TABLE @it_mara
      WHERE matnr IN @mats.
  ELSEIF P_RAD2 = 'X'.
    SELECT * FROM ZI_SELECTEXIG
      INTO TABLE @it_mara.
ENDIF.

INITIALIZATION.       "to set titlebar on selection screen

START-OF-SELECTION.  "to set it once list is displayed

   IF P_RAD1 = 'X'.
    sy-title = 'SAP GUI'.
      ELSE. P_RAD2 = 'X'.
      sy-title = 'CDS View'.
      ENDIF.

      WRITE: /12 'Number of records returned:', SY-DBCNT CENTERED.

*Build field catalog

  wa_fieldcat-fieldname  = 'MAKTX'.             " Fieldname in the data table - Material Description
  wa_fieldcat-seltext_m  = 'Material Desc'.     " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

  wa_fieldcat-fieldname  = 'MATNR'.             " Fieldname in the data table - Material Number
  wa_fieldcat-seltext_m  = 'Material Number'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

  wa_fieldcat-fieldname  = 'MEINS'.             " Fieldname in the data table - Base Unit of Measure
  wa_fieldcat-seltext_m  = 'Unit'.              " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

  wa_fieldcat-fieldname  = 'MTART'.             " Fieldname in the data table - Base Unit of Measure
  wa_fieldcat-seltext_m  = 'Material Type.'.    " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.            " Append work area to internal table

*Pass data and field catalog to ALV function module to display ALV list

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_mara
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.

Here's my CDS View:

@AbapCatalog.sqlViewName: 'ZISELECTEXIG'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View - Personal Assign'


define view ZI_SELECTEXIG
    
    as select from mara
    inner join makt on mara.matkl = makt.maktx  {


    mara.matnr as Material,
    maktx as MaterialDesc,
    meins as Unit,
    mtart as MaterialType            
   
}

Attachments

qhsrk.png (10.6 kB)