2007 Sep 19 1:16 PM
Hi folks,
how can i develop an abap report that first lists some master data as list with a expandable functionality so that at line selection the row is expanded and depending detail data are shown ?
help will be appreciated and points given instantly!
Clemens
2007 Sep 20 6:02 AM
Hi,
Try this for ur requirement.
REPORT z_inw_mat.
TABLES: mseg,
makt,
ekpo,
eban.
TYPE-POOLS: slis.
DATA: BEGIN OF itab OCCURS 0,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
maktx LIKE makt-maktx,
menge LIKE mseg-menge,
END OF itab.
DATA: BEGIN OF itab1 OCCURS 0,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
maktx LIKE makt-maktx,
menge LIKE mseg-menge,
END OF itab1.
DATA: BEGIN OF header OCCURS 0,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
maktx LIKE makt-maktx,
inw_qty LIKE mseg-menge,
END OF header.
DATA: BEGIN OF itab2 OCCURS 0,
werks LIKE ekpo-werks, "Plant
matnr LIKE ekpo-matnr, "Material Number
ebeln LIKE ekpo-ebeln, "PO Number
menge LIKE ekpo-menge, "Quantity ordered in PO
banfn LIKE ekpo-banfn, "PR Number
END OF itab2.
DATA: BEGIN OF itab3 OCCURS 0,
banfn LIKE eban-banfn,
menge LIKE eban-menge,
END OF itab3.
DATA: BEGIN OF itab4 OCCURS 0,
werks LIKE ekpo-werks, "Plant
matnr LIKE ekpo-matnr, "Material Number
ebeln LIKE ekpo-ebeln, "PO Number
menge LIKE ekpo-menge, "Quantity ordered in PO
banfn LIKE ekpo-banfn, "PR Number
pr_qty LIKE eban-menge, "Quantity requested from PR
END OF itab4.
DATA: BEGIN OF item OCCURS 0,
werks LIKE ekpo-werks, "Plant
matnr LIKE ekpo-matnr, "Material Number
ebeln LIKE ekpo-ebeln, "PO Number
menge LIKE ekpo-menge, "Quantity ordered in PO
banfn LIKE ekpo-banfn, "PR Number
pr_qty LIKE eban-menge, "Quantity requested from PR
maktx LIKE makt-maktx,
inw_qty LIKE mseg-menge, "Inward Quantity
END OF item.
DATA:f TYPE i.
DATA: alv_keyinfo TYPE slis_keyinfo_alv.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
t_eve TYPE slis_t_event.
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: werks FOR mseg-werks.
SELECT-OPTIONS: matnr FOR mseg-matnr.
SELECTION-SCREEN: END OF BLOCK blk1.
INITIALIZATION.
PERFORM cre_fieldcat USING t_fieldcat.
PERFORM cre_event.
START-OF-SELECTION.
PERFORM retrieve_data.
PERFORM display_data.
&---------------------------------------------------------------------*
& form cre_fieldcat
&---------------------------------------------------------------------*
text
----------------------------------------------------------------------*
-->f_cat text
----------------------------------------------------------------------*
FORM cre_fieldcat USING t_f_cat TYPE slis_t_fieldcat_alv.
DATA: wa TYPE slis_fieldcat_alv.
wa-tabname = 'HEADER'.
wa-fieldname = 'WERKS'.
wa-seltext_l = 'Plant'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'HEADER'.
wa-fieldname = 'MATNR'.
wa-seltext_l = 'Material Number'.
wa-outputlen = '15'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'HEADER'.
wa-fieldname = 'MAKTX'.
wa-seltext_l = 'Description'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'HEADER'.
wa-fieldname = 'INW_QTY'.
wa-seltext_l = 'Inward Quantity'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'EBELN'.
wa-seltext_l = 'PO Number'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'MENGE'.
wa-seltext_l = 'Order Quantity'.
wa-outputlen = '15'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'BANFN'.
wa-seltext_l = 'Pur Req Number'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'PR_QTY'.
wa-seltext_l = 'Pur Req Quantity'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
ENDFORM. "cre_fieldcat
&----
*& Form cre_event
&----
text
----
FORM cre_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = t_eve.
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. "cre_event
&----
*& Form retrieve_data
&----
text
----
FORM retrieve_data.
SELECT msegwerks msegmatnr maktmaktx msegmenge INTO CORRESPONDING FIELDS OF TABLE itab
FROM mseg INNER JOIN makt ON msegmatnr = maktmatnr
WHERE msegwerks IN werks AND msegmatnr IN matnr AND bwart = '101'.
SORT itab BY werks matnr.
LOOP AT itab.
MOVE-CORRESPONDING itab TO itab1.
COLLECT itab1.
ENDLOOP.
LOOP AT itab1.
SELECT werks matnr ebeln menge banfn INTO CORRESPONDING FIELDS OF TABLE itab2 FROM ekpo
FOR ALL ENTRIES IN itab1 WHERE werks = itab1-werks AND matnr = itab1-matnr.
ENDLOOP.
LOOP AT itab2.
SELECT banfn menge INTO CORRESPONDING FIELDS OF TABLE itab3 FROM eban FOR ALL ENTRIES IN itab2
WHERE eban~banfn = itab2-banfn.
ENDLOOP.
LOOP AT itab2.
f = 0.
LOOP AT itab3.
IF itab3-banfn = itab2-banfn.
MOVE-CORRESPONDING itab2 TO itab4.
MOVE-CORRESPONDING itab3 TO itab4.
itab4-pr_qty = itab3-menge.
APPEND itab4.
f = 1.
ENDIF.
ENDLOOP.
IF f = 0.
MOVE-CORRESPONDING itab2 TO itab4.
itab4-banfn = ''.
itab4-pr_qty = ''.
APPEND itab4.
ENDIF.
ENDLOOP.
LOOP AT itab1.
LOOP AT itab4.
IF itab1-matnr = itab4-matnr AND itab1-werks = itab4-werks.
MOVE-CORRESPONDING itab1 TO item.
item-inw_qty = itab1-menge.
MOVE-CORRESPONDING itab4 TO item.
APPEND item.
ENDIF.
ENDLOOP.
ENDLOOP.
WRITE:/.
*WRITE:/ 'Data of ITAB1'.
*LOOP AT itab1.
WRITE:/ itab1-werks,itab1-matnr,itab1-maktx,itab1-menge.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ 'Data of ITAB2'.
*LOOP AT itab2.
WRITE:/ itab2-werks,itab2-matnr,itab2-ebeln,itab2-menge,itab2-banfn.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ 'Data of ITAB3'.
*LOOP AT itab3.
WRITE:/ itab3-banfn,itab3-menge.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ '\nData of ITAB4\n'.
*LOOP AT itab4.
WRITE:/ itab4-werks,itab4-matnr,itab4-ebeln,itab4-menge,itab4-banfn,itab4-pr_qty.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ '\nData of ITEM\n'.
*LOOP AT item.
WRITE:/ item-werks,item-matnr,item-ebeln,item-menge,item-banfn,item-pr_qty,item-maktx,item-inw_qty.
*ENDLOOP.
ENDFORM. "retrieve_data
&----
*& Form display_data
&----
text
----
FORM display_data.
alv_keyinfo-header01 = 'WERKS'.
alv_keyinfo-item01 = 'WERKS'.
alv_keyinfo-header02 = 'MATNR'.
alv_keyinfo-item02 = 'MATNR'.
REFRESH header.
LOOP AT item.
ON CHANGE OF item-werks OR item-matnr.
MOVE-CORRESPONDING item TO header.
APPEND header.
ENDON.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = 'Z_INW_MAT'
it_fieldcat = t_fieldcat
it_events = t_eve
i_tabname_header = 'HEADER'
i_tabname_item = 'ITEM'
is_keyinfo = alv_keyinfo
TABLES
t_outtab_header = header
t_outtab_item = item
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. "display_data
2007 Sep 19 1:18 PM
hi,
Are u talking about interactive report? means u want detail in second list and u using classical or alv?
2007 Sep 19 3:13 PM
Hi Shah,
i thought of using 'REUSE_ALV_HIERSEQ_LIST_DISPLAY' - but how to do that ?
Clemens
2007 Sep 20 6:02 AM
Hi,
Try this for ur requirement.
REPORT z_inw_mat.
TABLES: mseg,
makt,
ekpo,
eban.
TYPE-POOLS: slis.
DATA: BEGIN OF itab OCCURS 0,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
maktx LIKE makt-maktx,
menge LIKE mseg-menge,
END OF itab.
DATA: BEGIN OF itab1 OCCURS 0,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
maktx LIKE makt-maktx,
menge LIKE mseg-menge,
END OF itab1.
DATA: BEGIN OF header OCCURS 0,
werks LIKE mseg-werks,
matnr LIKE mseg-matnr,
maktx LIKE makt-maktx,
inw_qty LIKE mseg-menge,
END OF header.
DATA: BEGIN OF itab2 OCCURS 0,
werks LIKE ekpo-werks, "Plant
matnr LIKE ekpo-matnr, "Material Number
ebeln LIKE ekpo-ebeln, "PO Number
menge LIKE ekpo-menge, "Quantity ordered in PO
banfn LIKE ekpo-banfn, "PR Number
END OF itab2.
DATA: BEGIN OF itab3 OCCURS 0,
banfn LIKE eban-banfn,
menge LIKE eban-menge,
END OF itab3.
DATA: BEGIN OF itab4 OCCURS 0,
werks LIKE ekpo-werks, "Plant
matnr LIKE ekpo-matnr, "Material Number
ebeln LIKE ekpo-ebeln, "PO Number
menge LIKE ekpo-menge, "Quantity ordered in PO
banfn LIKE ekpo-banfn, "PR Number
pr_qty LIKE eban-menge, "Quantity requested from PR
END OF itab4.
DATA: BEGIN OF item OCCURS 0,
werks LIKE ekpo-werks, "Plant
matnr LIKE ekpo-matnr, "Material Number
ebeln LIKE ekpo-ebeln, "PO Number
menge LIKE ekpo-menge, "Quantity ordered in PO
banfn LIKE ekpo-banfn, "PR Number
pr_qty LIKE eban-menge, "Quantity requested from PR
maktx LIKE makt-maktx,
inw_qty LIKE mseg-menge, "Inward Quantity
END OF item.
DATA:f TYPE i.
DATA: alv_keyinfo TYPE slis_keyinfo_alv.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
t_eve TYPE slis_t_event.
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: werks FOR mseg-werks.
SELECT-OPTIONS: matnr FOR mseg-matnr.
SELECTION-SCREEN: END OF BLOCK blk1.
INITIALIZATION.
PERFORM cre_fieldcat USING t_fieldcat.
PERFORM cre_event.
START-OF-SELECTION.
PERFORM retrieve_data.
PERFORM display_data.
&---------------------------------------------------------------------*
& form cre_fieldcat
&---------------------------------------------------------------------*
text
----------------------------------------------------------------------*
-->f_cat text
----------------------------------------------------------------------*
FORM cre_fieldcat USING t_f_cat TYPE slis_t_fieldcat_alv.
DATA: wa TYPE slis_fieldcat_alv.
wa-tabname = 'HEADER'.
wa-fieldname = 'WERKS'.
wa-seltext_l = 'Plant'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'HEADER'.
wa-fieldname = 'MATNR'.
wa-seltext_l = 'Material Number'.
wa-outputlen = '15'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'HEADER'.
wa-fieldname = 'MAKTX'.
wa-seltext_l = 'Description'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'HEADER'.
wa-fieldname = 'INW_QTY'.
wa-seltext_l = 'Inward Quantity'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'EBELN'.
wa-seltext_l = 'PO Number'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'MENGE'.
wa-seltext_l = 'Order Quantity'.
wa-outputlen = '15'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'BANFN'.
wa-seltext_l = 'Pur Req Number'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
wa-tabname = 'ITEM'.
wa-fieldname = 'PR_QTY'.
wa-seltext_l = 'Pur Req Quantity'.
wa-outputlen = '20'.
APPEND wa TO t_f_cat.
CLEAR wa.
ENDFORM. "cre_fieldcat
&----
*& Form cre_event
&----
text
----
FORM cre_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = t_eve.
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. "cre_event
&----
*& Form retrieve_data
&----
text
----
FORM retrieve_data.
SELECT msegwerks msegmatnr maktmaktx msegmenge INTO CORRESPONDING FIELDS OF TABLE itab
FROM mseg INNER JOIN makt ON msegmatnr = maktmatnr
WHERE msegwerks IN werks AND msegmatnr IN matnr AND bwart = '101'.
SORT itab BY werks matnr.
LOOP AT itab.
MOVE-CORRESPONDING itab TO itab1.
COLLECT itab1.
ENDLOOP.
LOOP AT itab1.
SELECT werks matnr ebeln menge banfn INTO CORRESPONDING FIELDS OF TABLE itab2 FROM ekpo
FOR ALL ENTRIES IN itab1 WHERE werks = itab1-werks AND matnr = itab1-matnr.
ENDLOOP.
LOOP AT itab2.
SELECT banfn menge INTO CORRESPONDING FIELDS OF TABLE itab3 FROM eban FOR ALL ENTRIES IN itab2
WHERE eban~banfn = itab2-banfn.
ENDLOOP.
LOOP AT itab2.
f = 0.
LOOP AT itab3.
IF itab3-banfn = itab2-banfn.
MOVE-CORRESPONDING itab2 TO itab4.
MOVE-CORRESPONDING itab3 TO itab4.
itab4-pr_qty = itab3-menge.
APPEND itab4.
f = 1.
ENDIF.
ENDLOOP.
IF f = 0.
MOVE-CORRESPONDING itab2 TO itab4.
itab4-banfn = ''.
itab4-pr_qty = ''.
APPEND itab4.
ENDIF.
ENDLOOP.
LOOP AT itab1.
LOOP AT itab4.
IF itab1-matnr = itab4-matnr AND itab1-werks = itab4-werks.
MOVE-CORRESPONDING itab1 TO item.
item-inw_qty = itab1-menge.
MOVE-CORRESPONDING itab4 TO item.
APPEND item.
ENDIF.
ENDLOOP.
ENDLOOP.
WRITE:/.
*WRITE:/ 'Data of ITAB1'.
*LOOP AT itab1.
WRITE:/ itab1-werks,itab1-matnr,itab1-maktx,itab1-menge.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ 'Data of ITAB2'.
*LOOP AT itab2.
WRITE:/ itab2-werks,itab2-matnr,itab2-ebeln,itab2-menge,itab2-banfn.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ 'Data of ITAB3'.
*LOOP AT itab3.
WRITE:/ itab3-banfn,itab3-menge.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ '\nData of ITAB4\n'.
*LOOP AT itab4.
WRITE:/ itab4-werks,itab4-matnr,itab4-ebeln,itab4-menge,itab4-banfn,itab4-pr_qty.
*ENDLOOP.
*
*WRITE:/.
*WRITE:/ '\nData of ITEM\n'.
*LOOP AT item.
WRITE:/ item-werks,item-matnr,item-ebeln,item-menge,item-banfn,item-pr_qty,item-maktx,item-inw_qty.
*ENDLOOP.
ENDFORM. "retrieve_data
&----
*& Form display_data
&----
text
----
FORM display_data.
alv_keyinfo-header01 = 'WERKS'.
alv_keyinfo-item01 = 'WERKS'.
alv_keyinfo-header02 = 'MATNR'.
alv_keyinfo-item02 = 'MATNR'.
REFRESH header.
LOOP AT item.
ON CHANGE OF item-werks OR item-matnr.
MOVE-CORRESPONDING item TO header.
APPEND header.
ENDON.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = 'Z_INW_MAT'
it_fieldcat = t_fieldcat
it_events = t_eve
i_tabname_header = 'HEADER'
i_tabname_item = 'ITEM'
is_keyinfo = alv_keyinfo
TABLES
t_outtab_header = header
t_outtab_item = item
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. "display_data