Join two tables in alv
ZSTU TABLE
REPORT ZAJAY_STU.
TABLES: zstu,zstu1.Types: BEGIN OF ty_zstu,
zstu_id TYPE zstu-zstu_id,
zstu_name TYPE zstu-zstu_name,
zstu_dep TYPE zstu-zstu_dep,
zstu_fee TYPE zstu-zstu_fee,
END OF ty_zstu,
BEGIN OF ty_zstu1,
zstu_id TYPE zstu1-zstu_id,
zstu_marks TYPE zstu1-zstu_marks,
END OF ty_zstu1,
BEGIN OF ty_final,
zstu_id TYPE zstu-zstu_id,
zstu_name TYPE zstu-zstu_name,
zstu_dep TYPE zstu-zstu_dep,
zstu_fee TYPE zstu-zstu_fee,
zstu_marks TYPE zstu1-zstu_marks,
END OF ty_final.
SELECTION-SCREEN BEGIN OF BLOCK B1.
SELECT-OPTIONS : s_id for zstu-zstu_id.
SELECTION-SCREEN END OF BLOCK B1.
data: it_zstu type table of ty_zstu,
it_zstu1 type table of ty_zstu1,
wa_zstu type ty_zstu,
wa_zstu1 type ty_zstu1,
it_final type table of ty_final,
wa_final type ty_final.
data: wa_fieldcat TYPE slis_fieldcat_alv,
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_layout TYPE slis_layout_alv.
IF s_id is not INITIAL.
select zstu_id
zstu_name
zstu_dep
zstu_fee
from zstu
into table it_zstu
where zstu_id in s_id.
sort it_zstu by zstu_id.
SELECT zstu_id
zstu_marks
from zstu1
into table it_zstu1
where zstu_id in s_id.
sort it_zstu1 by zstu_id.
ENDIF.
LOOP AT it_zstu1 INTO wa_zstu1.
wa_final-zstu_id = wa_zstu1-zstu_id.
wa_final-zstu_marks = wa_zstu1-zstu_marks.
READ TABLE it_zstu INTO wa_zstu WITH KEY zstu_id = wa_zstu1-zstu_id.
IF sy-subrc = 0.
wa_final-zstu_id = wa_zstu-zstu_id.
wa_final-zstu_name = wa_zstu-zstu_name.
wa_final-zstu_dep = wa_zstu-zstu_dep.
wa_final-zstu_fee = wa_zstu-zstu_fee.
ENDIF.
APPEND wa_final to it_final.
clear: wa_zstu1,wa_zstu,wa_final.
ENDLOOP.
wa_fieldcat-col_pos = '1'.
wa_fieldcat-fieldname = 'ZSTU_ID'.
wa_fieldcat-seltext_m = 'STUDENT ID'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO it_fieldcat.
clear: wa_fieldcat.
wa_fieldcat-col_pos = '2'.
wa_fieldcat-fieldname = 'ZSTU_NAME'.
wa_fieldcat-seltext_m = 'STUDENT NAME'.
wa_fieldcat-outputlen = '15'.
APPEND wa_fieldcat TO it_fieldcat.
clear: wa_fieldcat.
wa_fieldcat-col_pos = '3'.
wa_fieldcat-fieldname = 'ZSTU_DEPT'.
wa_fieldcat-seltext_m = 'STUDENT DEP'.
wa_fieldcat-outputlen = '15'.
APPEND wa_fieldcat TO it_fieldcat.
clear: wa_fieldcat.
wa_fieldcat-col_pos = '4'.
wa_fieldcat-fieldname = 'ZSTU_FEE'.
wa_fieldcat-seltext_m = 'STUDENT FEE'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO it_fieldcat.
clear: wa_fieldcat.
wa_fieldcat-col_pos = '5'.
wa_fieldcat-fieldname = 'ZSTU_MARKS'.
wa_fieldcat-seltext_m = 'STUDENT_MARKS'.
wa_fieldcat-outputlen = '10'.
APPEND wa_fieldcat TO it_fieldcat.
clear: wa_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* 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 = 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 =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_final
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Input
Output
Comments
Post a Comment