cancel
Showing results for 
Search instead for 
Did you mean: 

"WA_TOP1" cannot be converted to the row type of "IT_TOP1". The reverse is also not possible.

rnegi
Discoverer
0 Kudos

Hi,

Experts,

i am facing issue in below code as per subject line kindly help me!

*&---------------------------------------------------------------------*
*& Report ZRAMN_ALVBOCKLIST_OOP
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZRAMN_ALVBOCKLIST_OOP.

TYPE-POOLS : slis.
TABLES: ekko, ekpo.

DATA: V_REPID TYPE sy-repid,
V_USER TYPE sy-uname,
V_DATE TYPE char12.
DATA: wa_top1 TYPE slis_listheader,
it_top1 TYPE TABLE OF slis_t_listheader,
wa_top2 TYPE slis_listheader,
it_top2 TYPE TABLE OF slis_t_listheader.

INITIALIZATION.
V_REPID = sy-repid.
V_USER = sy-uname.
V_DATE = sy-datum.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_ebeln for ekko-ebeln OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
*-------------------------------------------------------------------------*
* class cls1 definition
*-------------------------------------------------------------------------*
*
*--------------------------------------------------------------------------*
class cls1 DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
lifnr TYPE ekko-lifnr,
sel TYPE char1,
END OF ty_ekko,
BEGIN OF ty_ekpo,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
lgort TYPE ekpo-lgort,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
sel TYPE char1,
END OF ty_ekpo.
data: wa_ekko TYPE ty_ekko,
it_ekko TYPE STANDARD TABLE OF ty_ekko,
wa_ekpo TYPE ty_ekpo,
it_ekpo TYPE STANDARD TABLE OF ty_ekpo,

wa_fcat1 TYPE slis_fieldcat_alv,
it_fcat1 TYPE slis_t_fieldcat_alv,
wa_fcat2 TYPE slis_fieldcat_alv,
it_fcat2 TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv,
it_print TYPE slis_print_alv,

wa_event1 TYPE slis_alv_event,
wa_event2 TYPE slis_alv_event,
it_event1 TYPE slis_t_event,
it_event2 TYPE slis_t_event.
METHODS: m_ekko, m_ekpo , m_fcat, m_layout, m_event1,
m_event2 , m_disp.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
*-------------------------------------------------------------------------*
* class cls1 definition
*-------------------------------------------------------------------------*
*
*--------------------------------------------------------------------------*
CLASS cls1 IMPLEMENTATION.

METHOD m_ekko.
SELECT ebeln bukrs lifnr
FROM ekko INTO TABLE it_ekko
WHERE ebeln in s_ebeln.

if sy-subrc = 0.
SORT it_ekko by ebeln.
else.
MESSAGE 'Purchase order dos not existg' TYPE 'I'.
leave LIST-PROCESSING.
ENDIF.
endmethod.

METHOD m_ekpo.
if it_ekko is NOT INITIAL.
SELECT ebeln ebelp matnr werks lgort menge meins
FROM ekpo INTO TABLE it_ekpo FOR ALL ENTRIES IN
it_ekko WHERE ebeln = it_ekko-ebeln.
endif.
ENDMETHOD.

METHOD m_fcat.
clear wa_fcat1.
refresh it_fcat1.
data: lv_col TYPE i value 1.

wa_fcat1-col_pos = lv_col.
wa_fcat1-fieldname = 'EBELN'.
wa_fcat1-tabname = 'IT_EKKO'.
wa_fcat1-seltext_l = 'Purchase order'.
APPEND wa_fcat1 to it_fcat1.
CLEAR wa_fcat1.

wa_fcat1-col_pos = 1 + lv_col.
wa_fcat1-fieldname = 'BUKRS'.
wa_fcat1-tabname = 'IT_EKKO'.
wa_fcat1-seltext_l = 'Company code'.
APPEND wa_fcat1 to it_fcat1.
CLEAR wa_fcat1.

wa_fcat1-col_pos = 1 + lv_col.
wa_fcat1-fieldname = 'LIFNR'.
wa_fcat1-tabname = 'IT_EKKO'.
wa_fcat1-seltext_l = 'Vendor'.
APPEND wa_fcat1 to it_fcat1.
CLEAR wa_fcat1.

CLEAR wa_fcat2.
refresh it_fcat2.

lv_col = 1.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'EBELN'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'Purchase Oreder'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.

lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'EBELP'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'Item'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.

lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MATNR'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'MATERIAL'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.

lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'WERKS'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'Plant'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.

lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'LGORT'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'STORAGE LOCATION'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.

lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MENGE'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'Quantity'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.

lv_col = 1 + lv_col.
wa_fcat2-col_pos = lv_col.
wa_fcat2-fieldname = 'MEINS'.
wa_fcat2-tabname = 'IT_EKPO'.
wa_fcat2-seltext_l = 'UNIT'.
APPEND wa_fcat2 to it_fcat2.
CLEAR wa_fcat2.
ENDMETHOD.
METHOD m_layout.
wa_layout-zebra = 'X'.
wa_layout-colwidth_optimize = 'X'.
wa_layout-box_fieldname = 'SEL'.

ENDMETHOD.
METHOD m_event1.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = it_event1
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2
.
IF sy-subrc = 0.
CLEAR wa_event1.
READ TABLE it_event1 INTO wa_event1
with KEY name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
wa_event1-form = 'TOP1'.
modify it_event1 FROM wa_event1
INDEX sy-tabix TRANSPORTING form.
ENDIF.
ENDIF.
ENDMETHOD.

METHOD m_event2.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = it_event2
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2
.
IF sy-subrc = 0.
CLEAR wa_event2.
READ TABLE it_event2 INTO wa_event2
with KEY name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
wa_event2-form = 'TOP2'.
modify it_event2 FROM wa_event2
INDEX sy-tabix TRANSPORTING form.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD m_disp.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = V_REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout
it_fieldcat = it_fcat1
i_tabname = 'IT_EKKO'
it_events = it_event1
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_ekko
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = wa_layout
it_fieldcat = it_fcat2
i_tabname = 'IT_EKPO'
it_events = it_event2
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_ekpo
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
.
it_print-reserve_lines = 2.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
IS_PRINT = it_print
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
ENDMETHOD.
endclass.

START-OF-SELECTION.
data: obj1 TYPE REF TO cls1.
CREATE OBJECT obj1.
call METHOD: obj1->m_ekko,
obj1->m_ekpo,
obj1->m_fcat,
obj1->m_layout,
obj1->m_event1,
obj1->m_event2,
obj1->m_disp.

TOP-OF-PAGE.
PERFORM top1.
PERFORM top2.
*-------------------------------------------------------------------------------*
* form top1
*--------------------------------------------------------------------------------*
* text1
* text2
*--------------------------------------------------------------------------------*
FORM top1.
CLEAR wa_top1.
refresh it_top1.

wa_top1-typ = 'H'.
wa_top1-info = 'Purchase order Header'.
APPEND wa_top1 to it_top1.
CLEAR wa_top1.

wa_top1-typ = 'S'.
wa_top1-key = 'DATE:'.
CONCATENATE V_DATE+6(2) ':'
V_DATE+4(2) ':'
V_DATE(4)
wa_top1-info INTO wa_top1-info.
APPEND wa_top1 to it_top1.
CLEAR wa_top1.

wa_top1-typ = 'S'.
wa_top1-key = 'User:'.
CONCATENATE V_USER wa_top1-info INTO wa_top1-info.
APPEND wa_top1 to it_top1.
CLEAR wa_top1.

wa_top1-typ = 'S'.
wa_top1-key = 'Report:'.
CONCATENATE V_REPID wa_top1-info INTO wa_top1-info.
APPEND wa_top1 to it_top1.
CLEAR wa_top1.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_top1
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.
*-------------------------------------------------------------------------------*
* form top2
*--------------------------------------------------------------------------------*
* text1
* text2
*--------------------------------------------------------------------------------*
FORM top2.

CLEAR wa_top2.
refresh it_top2.

wa_top2-typ = 'H'.
wa_top2-info = 'Purchase order item ducuments' .
APPEND wa_top2 to it_top2.
CLEAR wa_top2.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_top2
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.

 

Sandra_Rossi
Active Contributor
0 Kudos
Please use the buttons "..." and "</>" to make the code easy to read. See here the detailed steps: https://community.sap.com/t5/questions-about-sap-websites/how-to-post-code-in-sap-community-gt-2024/...
Sandra_Rossi
Active Contributor
0 Kudos
Note that you're using outdated code, don't declare global variables, don't use TABLES. Instead, use inline declarations, constructor expressions and so on. Don't transfer the constant "SY-REPID" into an intermediate variable, use it directly without intermediate.
View Entire Topic
raymond_giuseppi
Active Contributor

You declared 

it_top1 TYPE TABLE OF slis_t_listheader,

So it_top1 is a table of tables of records of structure slis_listheader (slis_t_listheader is already a table type definition)