on 2019 May 30 2:09 PM
"REUSE_ALV_GRID_DISPLAY" is used in this report.
I'm doing an ALV with a lot of parent's tables with thier child's tables and I want to show their rows with their respective parents like a "parent_sequence" and "child_sequence".
I mean, theres an unique record in the parent, but the children can generate another 2 records with the same parent, then, I would show them into an ALV.
I tried, but my ALV shows just one record from the children.
Please, help me!
EXAMPLE:
|--------------------------------------------------------------------------------------------------------------|
| Parent_record-ID | Child_record-name | Child2_record-address | | | Child2_record-address2 |
| | Child2_record-address3 |
|---------------------------------------------------------------------------------------------------------------|
Request clarification before answering.
You should rely on hierarchical ALV: check class CL_SALV_TREE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
finochio
Ok, i thought you wanted different rows with different structures so i was suggesting the tree structure
You have to play with data a bit to achieve this.
The dirt & quick solution is to sort table by your 3 fields, Loop it and check the keys are changing from the previous one: if not, clear the field, else show it.
Like
LOOP AT tab ASSIGNING <fs>.
If <fs>-parent = old_parent.
CLEAR: <fs>-parent, new_parent.
ELSE.
old_parent = <fs>-parent.
new_parent = abap_true.
ENDIF.
IF <fs>-1st_child = old_1st_child and new_parent IS INITIAL.
CLEAR <fs>-1st_child.
ELSE.
old_1st_child = <fs>-1st_child.
ENDIF.
ENDLOOP.Since it's an ALV, this will not work when the user begins to use the SORT option 🙂
I still think CL_SALV_TREE or CL_SALV_HIERSEQ_TABLE is a better solution, but i do not know the limits of your requirements.
+1 for using a tree (although it turned out to be not as great as I thought it'd be). It's impossible to achieve parent/child (or an odd variation of it shown in the screenshot) functionality in the grid without disabling all the ALV features which will break the fragile "faux hierarchy". And then what's the point of using ALV grid without those features?
Thanks you all guys, but i found a better way to do it.

take a look in the last loop:
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}
.L0S31 {
font-style: italic;
color: #808080;
}
.L0S32 {
color: #3399FF;
}
.L0S52 {
color: #0000FF;
}
.L0S55 {
color: #800080;
}
.L0S70 {
color: #808080;
}
LOOP AT lt_r119x INTO ls_r119
WHERE sequencia_pai = ls_r116-sequencia.
* IF ls_r119-sequencia_pai = ls_r116-sequencia.
* CLEAR: ls_r116-sequencia_pai, gv_novo_pai.
* ELSE.
* ls_r116-sequencia_pai = ls_r119-sequencia.
* ENDIF.
DO sy-tabix TIMES.
MOVE: ls_r119-indnif TO ls_excel-indnif,
ls_r119-nifbenef TO ls_excel-nifbenef,
ls_r119-frmtribut TO ls_excel-frmtribut.
APPEND ls_excel TO lt_tratamento.
ENDDO.
CLEAR: ls_r119-indnif, ls_r119-nifbenef, ls_r119-frmtribut.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDIF.
ELSE.
APPEND ls_excel TO lt_excel.
DELETE ADJACENT DUPLICATES FROM lt_excel.
CLEAR: ls_excel-branch,
ls_excel-cpfbenef,
ls_excel-nmbenef,
ls_excel-lifnr,
ls_excel-natrend,
ls_excel-paisresid,
ls_excel-dtfg,
ls_excel-vlrrendbruto,
ls_excel-vlrrendtrib,
ls_excel-vlrir,
ls_excel-vlrdeducao,
ls_excel-vlrisento,
ls_excel-indnif,
ls_excel-nifbenef,
ls_excel-frmtribut.
ENDIF.
APPEND ls_excel TO lt_tratamento.
DELETE ADJACENT DUPLICATES FROM lt_tratamento.
LOOP AT lt_tratamento INTO ls_tratamento.
CLEAR lt_excel.
ENDLOOP.
MOVE lt_tratamento TO lt_excel.
LOOP AT lt_tratamento INTO ls_tratamento.
CLEAR: ls_tratamento-vlrdeducao,
ls_tratamento-vlrisento,
ls_tratamento-vlrrendtrib,
ls_tratamento-vlrrendbruto,
ls_tratamento-vlrir.
APPEND ls_tratamento TO lt_excel.
ENDLOOP.
SORT lt_excel DESCENDING.
CLEAR: ls_excel-branch,
ls_excel-cpfbenef,
ls_excel-nmbenef,
ls_excel-lifnr,
ls_excel-natrend,
ls_excel-paisresid,
ls_excel-dtfg,
ls_excel-vlrrendbruto,
ls_excel-vlrrendtrib,
ls_excel-vlrir,
ls_excel-vlrdeducao,
ls_excel-vlrisento,
ls_excel-indnif,
ls_excel-nifbenef,
ls_excel-frmtribut.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
LOOP AT lt_excel INTO ls_excel.
IF sy-tabix = 1.
aux_cpf = ls_excel-cpfbenef.
aux_vlrrendbruto = ls_excel-vlrrendbruto.
CONTINUE.
ENDIF.
* IF ( sy-tabix MOD 2 ) <> 0.
IF sy-tabix > 1.
IF ls_excel-vlrrendbruto IS NOT INITIAL.
IF aux_cpf = ls_excel-cpfbenef AND aux_vlrrendbruto = ls_excel-vlrrendbruto.
DELETE lt_excel INDEX ( sy-tabix ).
ENDIF.
ENDIF.
ENDIF.
IF aux_cpf <> ls_excel-cpfbenef OR aux_vlrrendbruto <> ls_excel-vlrrendbruto.
IF ls_excel-vlrrendbruto IS NOT INITIAL.
aux_cpf = ls_excel-cpfbenef.
aux_vlrrendbruto = ls_excel-vlrrendbruto.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT lt_excel INTO ls_excel.
IF sy-tabix = 1.
aux_cpf = ls_excel-cpfbenef.
aux_vlrrendbruto = ls_excel-vlrrendbruto.
DELETE lt_excel INDEX ( sy-tabix + 1 ).
CONTINUE.
ENDIF.
IF aux_cpf <> ls_excel-cpfbenef.
aux_cpf = ls_excel-cpfbenef.
delete lt_excel index ( sy-tabix + 1 ).
ENDIF.
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 7 | |
| 6 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.