2007 Jul 16 10:12 AM
Hi All,
i have to display a report in the following format.
MATNR BOOK PRICE
34763 abcd 123.00
xyz1
xyz2
xyz3
xyz4
34765 abce 234.00
mno1
mno2
mno3
mno4
I have the data in two separate internal tables.
gt_mara :
34763 abcd 123.00
34765 abce 234.00
gt_item
xyz1
xyz2
xyz3
xyz4
mno1
mno2
mno3
mno4
How do i merge them to get the above format for display.
Thanks in advance.
Regards,
Santosh Kotra
2007 Jul 16 10:22 AM
There should be something common in both tables to merge them with some conditions..
But in ur case..
If u have fix number of Records in table <b>gt_item</b> like 4 item records for each master record..
Then u can do..
data: v_start like sy-index, value 1
v_end like sy-index value 4.
Loop at gt_mara.
write:/ gt_mara- ....
loop at gt_item from v_start to v_end.
write:/
endloop.
v_start = v_start + 4.
v_end = v_end + 4.
endloop.
But I think there should be some common record like MATNR in both tables..
in that case u can do..
Loop at gt_mara.
write:/ gt_mara- ...
loop at gt_item where matnt = gt_mara-matnr.
write:/ gt_item...
endloop.
endloop.
Reward if useful..
Regards
Prax
2007 Jul 16 10:26 AM
Hi Santhosh,
if the items are related to matnr. certainly you need to have matnr in the second table and then to display.
loop at gt_mara.
write mara-matnr, etc.
loop at gt_item where matnr eq gt_mara-matnr.
write : gt_item-item.
endloop.
endloop.
if this relation is not there and you just want the above output.
loop at gt_item.
if V_flag ne gt_item-item(1).
read table gt_mara index v_index.
write mara-matnr.
v_flag = gt_item-item(1).
add 1 to v_index.
endif.
write : gt_item-item.
endloop.
Reward points if useful else getbk,
Aleem.
2007 Jul 16 10:26 AM
Hi Santosh,
You need to have common columns/fields in both internal tables.
and you need to mention them both as key fields before using them in the hierarchy sequential display form.
Check out this code below to have much clarity,
REPORT ZALV5_OBJECTS.
TABLES : EKKO.
TYPE-POOLS : SLIS.
TYPES : BEGIN OF TY_EKKO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
STATU TYPE EKPO-STATU,
AEDAT TYPE EKPO-AEDAT,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
MEINS TYPE EKPO-MEINS,
NETPR TYPE EKPO-NETPR,
PEINH TYPE EKPO-PEINH,
END OF TY_EKKO.
DATA: IT_EKKO TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
IT_EKPO TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
IT_EMPTYTAB TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
WA_EKKO TYPE TY_EKKO,
WA_EKPO TYPE TY_EKKO.
DATA: OK_CODE LIKE SY-UCOMM, "OK-Code
SAVE_OK LIKE SY-UCOMM.
*ALV data declarations
DATA: FIELDCATALOG TYPE LVC_T_FCAT WITH HEADER LINE.
DATA: GD_FIELDCAT TYPE LVC_T_FCAT,
GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
*ALVtree data declarations
CLASS CL_GUI_COLUMN_TREE DEFINITION LOAD.
CLASS CL_GUI_CFW DEFINITION LOAD.
DATA: GD_TREE TYPE REF TO CL_GUI_ALV_TREE,
GD_HIERARCHY_HEADER TYPE TREEV_HHDR,
GD_REPORT_TITLE TYPE SLIS_T_LISTHEADER,
GD_LOGO TYPE SDYDO_VALUE,
GD_VARIANT TYPE DISVARIANT.
*Create container for alv-tree
DATA: GD_TREE_CONTAINER_NAME(30) TYPE C,
GD_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
************************************************************************
*Includes
*INCLUDE ZDEMO_ALVTREEO01. "Screen PBO Modules
*INCLUDE ZDEMO_ALVTREEI01. "Screen PAI Modules
*INCLUDE ZDEMO_ALVTREEF01. "ABAP Subroutines(FORMS)
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
ALVtree setup data
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_HIERARCHY_HEADER CHANGING GD_HIERARCHY_HEADER.
PERFORM BUILD_REPORT_TITLE USING GD_REPORT_TITLE GD_LOGO.
PERFORM BUILD_VARIANT.
Display ALVtree report
CALL SCREEN 100.
&----
*& Form data_retrieval
&----
text
----
--> p1 text
<-- p2 text
----
FORM DATA_RETRIEVAL .
SELECT EBELN
UP TO 10 ROWS
FROM EKKO
INTO CORRESPONDING FIELDS OF TABLE IT_EKKO.
LOOP AT IT_EKKO INTO WA_EKKO.
SELECT EBELN EBELP STATU AEDAT MATNR MENGE MEINS NETPR PEINH
FROM EKPO
APPENDING TABLE IT_EKPO
WHERE EBELN EQ WA_EKKO-EBELN.
ENDLOOP.
ENDFORM. " data_retrieval
&----
*& Form build_fieldcatalog
&----
text
----
--> p1 text
<-- p2 text
----
FORM BUILD_FIELDCATALOG .
Please not there are a number of differences between the structure of
ALVtree fieldcatalogs and ALVgrid fieldcatalogs.
For example the field seltext_m is replace by scrtext_m in ALVtree.
FIELDCATALOG-FIELDNAME = 'EBELN'. "Field name in itab
FIELDCATALOG-SCRTEXT_M = 'Purchase Order'. "Column text
FIELDCATALOG-COL_POS = 0. "Column position
FIELDCATALOG-OUTPUTLEN = 15. "Column width
FIELDCATALOG-EMPHASIZE = 'X'. "Emphasize (X or SPACE)
FIELDCATALOG-KEY = 'X'. "Key Field? (X or SPACE)
fieldcatalog-do_sum = 'X'. "Sum Column?
fieldcatalog-no_zero = 'X'. "Don't display if zero
APPEND FIELDCATALOG TO GD_FIELDCAT.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'EBELP'.
FIELDCATALOG-SCRTEXT_M = 'PO Iten'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 1.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'STATU'.
FIELDCATALOG-SCRTEXT_M = 'Status'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 2.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'AEDAT'.
FIELDCATALOG-SCRTEXT_M = 'Item change date'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 3.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MATNR'.
FIELDCATALOG-SCRTEXT_M = 'Material Number'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 4.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MENGE'.
FIELDCATALOG-SCRTEXT_M = 'PO quantity'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 5.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'MEINS'.
FIELDCATALOG-SCRTEXT_M = 'Order Unit'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 6.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'NETPR'.
FIELDCATALOG-SCRTEXT_M = 'Net Price'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 7.
FIELDCATALOG-DATATYPE = 'CURR'.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'PEINH'.
FIELDCATALOG-SCRTEXT_M = 'Price Unit'.
FIELDCATALOG-OUTPUTLEN = 15.
FIELDCATALOG-COL_POS = 8.
APPEND FIELDCATALOG TO GD_FIELDCAT..
CLEAR FIELDCATALOG.
ENDFORM. " build_fieldcatalog
&----
*& Form build_layout
&----
text
----
--> p1 text
<-- p2 text
----
FORM BUILD_LAYOUT .
GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-TOTALS_TEXT = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'
ENDFORM. " build_layout
&----
*& Form build_hierarchy_header
&----
text
----
<--P_GD_HIERARCHY_HEADER text
----
FORM BUILD_HIERARCHY_HEADER CHANGING
P_HIERARCHY_HEADER TYPE TREEV_HHDR.
P_HIERARCHY_HEADER-HEADING = 'Hierarchy Header'(013).
P_HIERARCHY_HEADER-TOOLTIP = 'This is the Hierarchy Header !'(014).
P_HIERARCHY_HEADER-WIDTH = 30.
P_HIERARCHY_HEADER-WIDTH_PIX = ''.
ENDFORM. " build_hierarchy_header
&----
*& Form build_report_title
&----
text
----
-->P_GD_REPORT_TITLE text
-->P_GD_LOGO text
----
FORM BUILD_REPORT_TITLE USING PT_REPORT_TITLE TYPE SLIS_T_LISTHEADER
P_GD_LOGO TYPE SDYDO_VALUE.
DATA: LS_LINE TYPE SLIS_LISTHEADER,
LD_DATE(10) TYPE C.
List Heading Line(TYPE H)
CLEAR LS_LINE.
LS_LINE-TYP = 'H'.
ls_line-key "Not Used For This Type(H)
LS_LINE-INFO = 'PO ALVTree Display'.
APPEND LS_LINE TO PT_REPORT_TITLE.
Status Line(TYPE S)
LD_DATE(2) = SY-DATUM+6(2).
LD_DATE+2(1) = '/'.
LD_DATE3(2) = SY-DATUM4(2).
LD_DATE+5(1) = '/'.
LD_DATE+6(4) = SY-DATUM(4).
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'Date'.
LS_LINE-INFO = LD_DATE.
APPEND LS_LINE TO PT_REPORT_TITLE.
Action Line(TYPE A)
CLEAR LS_LINE.
LS_LINE-TYP = 'A'.
CONCATENATE 'Report: ' SY-REPID INTO LS_LINE-INFO SEPARATED BY SPACE.
APPEND LS_LINE TO PT_REPORT_TITLE.
ENDFORM. " build_report_title
&----
*& Form build_variant
&----
text
----
--> p1 text
<-- p2 text
----
FORM BUILD_VARIANT .
Set repid for storing variants
GD_VARIANT-REPORT = SY-REPID.
ENDFORM. " build_variant
<b>Reward points for useful Answers</b>
Kiran
2007 Jul 16 10:36 AM
You can use function module
REUSE_ALV_HIERSEQ_LIST_DISPLAY
to display report in desired format.
To see how to use this FM refer program
BALVHD01