2023 Sep 11 8:09 AM
Hi, In a mailer with HTML coding I want to merge rows dynamically based on one particular field Working Hours in the Group Loop. How to do that in 7.40?
```
LOOP AT lt_wip_plant INTO DATA(wa_wip_plant) GROUP BY wa_wip_plant-wrkng_hrs.
DATA(lv_tabix) = sy-tabix.
add_html:
'<tr>',
'<b>',
'<font color="BLACK" width="75" FACE="Calibri" size="2">',
'<td BGCOLOR="#B0D1ED" align="center" rowspan =', lv_count,'>', wa_wip_plant-wrkng_hrs ,'</td>',
'</b>',
'</tr>'.
CLEAR: lv_span.
LOOP AT GROUP wa_wip_plant INTO DATA(wip_hrs).
lv_count = sy-tabix.
IF sy-tabix EQ lv_tabix.
CONTINUE.
ENDIF.
endloop.
endloop.
```
I want to merge the rows based on Working Hours as shown below:
2023 Sep 11 8:09 AM
Welcome to the SAP Community. Thank you for visiting us to get answers to your questions.
Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.
First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Second, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html, as that will help you when submitting questions to the community.
I also recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.
Now for some specific suggestions on how you might improve your question:
* Outline what steps you took to find answers (and why they weren't helpful) -- so members don't make suggestions that you've already tried.
* Share screenshots of what you've seen/done (if possible), as images always helps our members better understand your problem.
Should you wish, you can revise your question by selecting Actions, then Edit.
The more details you provide (in questions tagged correctly), the more likely it is that members will be able to respond.
I hope you find this advice useful, and we're happy to have you as part of SAP Community!
2023 Sep 11 7:22 PM
If you don't know what ABAP 7.40 is, but you just want some code, you may ask ChatGPT.
2023 Sep 12 11:12 AM
Thank you for the Reply Sandra. I have wrote code based on 7.4 only, inside the group loop I am using HTML coding to send the mailer in that I want to do Row Span based on that particular field that's no.of.records will change dynamically so at the end of that specific record I want the row span to be performed. Since it is a group Loop unable to use AT END is there any other alternate option for that?
LOOP AT lt_wip_plant INTO DATA(wa_wip_plant) GROUP BY wa_wip_plant-wrkng_hrs.
DATA(lv_tabix) = sy-tabix.
add_html:
'<tr>',
'<b>',
'<font color="BLACK" width="75" FACE="Calibri" size="2">',
'<td BGCOLOR="#B0D1ED" align="center" rowspan =', lv_count,'>', wa_wip_plant-wrkng_hrs ,'</td>',
'</b>',
'</tr>'.
CLEAR: lv_span.
LOOP AT GROUP wa_wip_plant INTO DATA(wip_hrs).
lv_count = sy-tabix.
IF sy-tabix EQ lv_tabix.
CONTINUE.
ENDIF.
endloop.
endloop.
Here, I am getting the no.of.records in lv_count since we are passing it in outside loop the rows get spanned for next record instead of the previous one.
2023 Sep 12 11:13 AM
Thank you for the Reply Sandra. I have wrote code based on 7.4 only, inside the group loop I am using HTML coding to send the mailer in that I want to do Row Span based on that particular field that's no.of.records will change dynamically so at the end of that specific record I want the row span to be performed. Since it is a group Loop unable to use AT END is there any other alternate option for that?
LOOP AT lt_wip_plant INTO DATA(wa_wip_plant) GROUP BY wa_wip_plant-wrkng_hrs.
DATA(lv_tabix) = sy-tabix.
add_html:
'<tr>',
'<b>',
'<font color="BLACK" width="75" FACE="Calibri" size="2">',
'<td BGCOLOR="#B0D1ED" align="center" rowspan =', lv_count,'>', wa_wip_plant-wrkng_hrs ,'</td>',
'</b>',
'</tr>'.
CLEAR: lv_span.
LOOP AT GROUP wa_wip_plant INTO DATA(wip_hrs).
lv_count = sy-tabix.
IF sy-tabix EQ lv_tabix.
CONTINUE.
ENDIF.
endloop.
endloop.
Here, I am getting the no.of.records in lv_count since we are passing it in outside loop the rows get spanned for next record instead of the previous one.
2023 Sep 12 6:22 PM
You'd better indicate LOOP AT GROUP BY in the title.
With ABAP 7.40, there's no good reason to use the macro "add_html" 😞
Please edit your question (Actions>Edit), paste your code there and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!
Concerning your question, use GROUP SIZE:
CLASS ltc_main DEFINITION
FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS test FOR TESTING.
ENDCLASS.
CLASS ltc_main IMPLEMENTATION.
METHOD test.
SELECT * FROM sflight INTO TABLE @DATA(flights).
DATA(lines) = VALUE string_table( ).
LOOP AT flights REFERENCE INTO DATA(flight)
GROUP BY ( carrid = flight->carrid
gs = GROUP SIZE )
REFERENCE INTO DATA(group_flights).
INSERT |Airline: { group_flights->carrid }. Total flights: { group_flights->gs }|
INTO TABLE lines.
LOOP AT GROUP group_flights REFERENCE INTO DATA(flight_2).
INSERT | Flight: { flight_2->connid } { flight_2->fldate }|
INTO TABLE lines.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
ENDCLASS.<br>
2023 Sep 13 1:50 PM
Hi Sandra,
Really thank you for you response given.
Could you please help me with the solution in a procedural way, based on HTML table in Mailer? Since I am unable to get the expected output based on above solution.
Thanks in advance
2023 Sep 13 6:47 PM
If you want ABAP 7.40, it's logical to use ABAP Objects. Otherwise, continue using old ABAP.
Output is debugger of internal table LINES.
But sorry, look at code between METHOD and ENDMETHOD, it's procedural, no?
2023 Sep 13 11:55 AM
Thank you for the Reply Sandra. I have wrote code based on 7.4 only, inside the group loop I am using HTML coding to send the mailer in that I want to do Row Span based on that particular field that's no.of.records will change dynamically so at the end of that specific record I want the row span to be performed. Since it is a group Loop unable to use AT END is there any other alternate option for that?
LOOP AT lt_wip_plant INTO DATA(wa_wip_plant) GROUP BY wa_wip_plant-wrkng_hrs.
DATA(lv_tabix) = sy-tabix.
add_html:
'<tr>',
'<b>',
'<font color="BLACK" width="75" FACE="Calibri" size="2">',
'<td BGCOLOR="#B0D1ED" align="center" rowspan =', lv_count,'>', wa_wip_plant-wrkng_hrs ,'</td>',
'</b>',
'</tr>'.
CLEAR: lv_span.
LOOP AT GROUP wa_wip_plant INTO DATA(wip_hrs).
lv_count = sy-tabix.
IF sy-tabix EQ lv_tabix.
CONTINUE.
ENDIF.
endloop.
endloop.
Here, I am getting the no.of.records in lv_count since we are passing it in outside loop the rows get spanned for next record instead of the previous one.