Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

unable to add text on top of page using cl_dd_document class

manish_malakar0316
Active Participant
0 Kudos

Hello experts,

I am working on an existing requirement where I have to display some text on the header of a report using CL_DD_DOCUMENT class. The issue is that after writing a few lines, I am unable to display the rest of the lines in the header. The space where I want to display the rest of the data is highlighted below:

I was trying the below syntax but still the header was coming blank and was not displaying any text.

"Row 6<br> 

 CALL METHOD qtable->new_row.

 CALL METHOD qtable->add_text

    EXPORTING    text  = text-070

     sap_fontsize = cl_dd_document=>small.  

CALL METHOD qtable->add_text

  EXPORTING    text  = text-071

  sap_fontsize = cl_dd_document=>small.   

CALL METHOD qtable->add_text

    EXPORTING     text         = ' '

     sap_fontsize = cl_dd_document=>small.

CALL METHOD qtable->add_text  

 EXPORTING     text         = text-072                "Account Assignment Category: R

      sap_fontsize = cl_dd_document=>small.

Any help is appreciated.

Manish

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

You must call the method NEW_ROW after each line you write to the table:

CALL METHOD qtable->new_row.

Minimal reproducible program:

REPORT.
PARAMETERS dummy.
DATA: o_docu   TYPE REF TO cl_dd_document,
      qtable   TYPE REF TO cl_dd_table_area.
AT SELECTION-SCREEN OUTPUT.
  CREATE OBJECT o_docu.
  o_docu->add_table( EXPORTING  no_of_columns      = 2
                     IMPORTING  tablearea          = qtable
                     EXCEPTIONS table_already_used = 1
                                OTHERS             = 2 ).
  qtable->add_text( text = 'hello' sap_emphasis = cl_dd_document=>strong ).
  qtable->add_text( text = 'world' sap_emphasis = cl_dd_document=>strong ).
  qtable->new_row( ).
  qtable->add_text( text = 'hello 2' sap_emphasis = cl_dd_document=>strong ).
  qtable->add_text( text = 'world 2' sap_emphasis = cl_dd_document=>strong ).
  qtable->new_row( ).
  o_docu->merge_document( ).
  o_docu->display_document( parent = cl_gui_container=>screen0 ).

9 REPLIES 9

Sandra_Rossi
Active Contributor

NB: for legibility, it's not recommended to indicate only TEXT-072, but instead use:

qtable->add_text( text         = 'Account Assignment Category: R'(072)
                  sap_fontsize = cl_dd_document=>small ).

(also use the short form to call the methods statically; CALL METHOD is obsolete)

Sandra_Rossi
Active Contributor
0 Kudos

NB: probably the code you have shared works alone (although you missed all declarations, ADD_TABLE and so on), but the rest of the code has a problem, and of course it's impossible to help if you don't share the rest of the code.

manish_malakar0316
Active Participant
0 Kudos

I have attached the full code for reference.code.txt

Sandra_Rossi
Active Contributor

You must call the method NEW_ROW after each line you write to the table:

CALL METHOD qtable->new_row.

Minimal reproducible program:

REPORT.
PARAMETERS dummy.
DATA: o_docu   TYPE REF TO cl_dd_document,
      qtable   TYPE REF TO cl_dd_table_area.
AT SELECTION-SCREEN OUTPUT.
  CREATE OBJECT o_docu.
  o_docu->add_table( EXPORTING  no_of_columns      = 2
                     IMPORTING  tablearea          = qtable
                     EXCEPTIONS table_already_used = 1
                                OTHERS             = 2 ).
  qtable->add_text( text = 'hello' sap_emphasis = cl_dd_document=>strong ).
  qtable->add_text( text = 'world' sap_emphasis = cl_dd_document=>strong ).
  qtable->new_row( ).
  qtable->add_text( text = 'hello 2' sap_emphasis = cl_dd_document=>strong ).
  qtable->add_text( text = 'world 2' sap_emphasis = cl_dd_document=>strong ).
  qtable->new_row( ).
  o_docu->merge_document( ).
  o_docu->display_document( parent = cl_gui_container=>screen0 ).

0 Kudos

It is done in the report. There are 6 header columns and every column has a text. I am writing the text under each column and then for the next line I am calling the NEW_ROW method. The issue is that the first 5 lines (including the header) are getting displayed. The text from line 6 is not getting displayed.

Before adding text to the new line I am calling the above method. It has worked for the first 5 lines, but not from 6th line onwards.

capture.png

capture.png

0 Kudos

You don't call NEW_ROW after ADD_TEXT, as I said.

As you can imagine, I cannot test your program. So, I recommend that you take the time to write a very short "minimal reproducible example", as I did, and I'll be happy to test and fix it.

0 Kudos

You can test the below code. Create the custom container as CONT in the screen painter. Still the 6th row is not displaying any text.

DATA : o_cust  TYPE REF TO cl_gui_custom_container,
o_spli TYPE REF TO cl_gui_splitter_container,
o_ref1 TYPE REF TO cl_gui_container,
o_ref2 TYPE REF TO cl_gui_container,
o_alv TYPE REF TO cl_gui_alv_grid,
o_docu TYPE REF TO cl_dd_document,
ok_code TYPE sy-ucomm.

DATA : it_fcat TYPE lvc_t_fcat,
wa_fcat TYPE lvc_s_fcat.

DATA : wa_layout TYPE lvc_s_layo, "Layout
wa_variant TYPE disvariant.


CLASS handle_event DEFINITION DEFERRED.
DATA : o_obj TYPE REF TO handle_event.

CLASS handle_event DEFINITION.

PUBLIC SECTION.

CLASS-METHODS : page_head FOR EVENT
top_of_page OF cl_gui_alv_grid.

ENDCLASS. "HANDLE_EVENT DEFINITION

CLASS handle_event IMPLEMENTATION.
METHOD page_head.
PERFORM top_of_page.
ENDMETHOD. "PAGE_HEAD
ENDCLASS. "HANDLE_EVENT IMPLEMENTATION
FORM top_of_page .
DATA: doctable TYPE REF TO cl_dd_table_element,
qtable TYPE REF TO cl_dd_table_area.

CALL METHOD o_docu->add_table
EXPORTING
* no_of_columns = 5 "desired number of columns
no_of_columns = 6 "desired number of columns
border = '0' "no border, as discussed before
width = '100%' "the table will occupy 100% of dynamic document control width
IMPORTING
table = doctable "return standard table
tablearea = qtable "and quick table
EXCEPTIONS
table_already_used = 1
OTHERS = 2.

"Row1 (header)
qtable->add_text(
EXPORTING
text = 'Opex Project'
sap_emphasis = cl_dd_document=>strong ).

qtable->add_text(
EXPORTING
text = 'Capex Project'
sap_emphasis = cl_dd_document=>strong ).

qtable->add_text(
EXPORTING
text = 'WIP'
sap_emphasis = cl_dd_document=>strong ).

qtable->add_text(
EXPORTING
text = 'Marketing'
sap_emphasis = cl_dd_document=>strong ).

qtable->add_text(
EXPORTING
text = 'Asset'
sap_emphasis = cl_dd_document=>strong ).

qtable->add_text(
EXPORTING
text = 'Cost of Sales'
sap_emphasis = cl_dd_document=>strong ).

"Row 2
qtable->new_row( ).

qtable->add_text(
EXPORTING
text = 'mandatory cost object'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'WBS type CN or CX (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'WBS type BC (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Asset number (mandatory to enter in PO)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'WBS type CS, NP or OB (mandatory)'
sap_emphasis = cl_dd_document=>small ).

"Row 3
qtable->new_row( ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Cost center (mandatory)'
sap_emphasis = cl_dd_document=>small ).


"Row 4
qtable->new_row( ).

qtable->add_text(
EXPORTING
text = 'Optional Cost Objects:'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '1. CN-testing4321 (level 3)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '1. BC-testing1234 (level 1)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'WBS type MK (mandatory)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '- WBS Code (mandatory to create Asset ID):'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '1. OB-testing123 (level 3)'
sap_emphasis = cl_dd_document=>small ).
  "Row 5
qtable->new_row( ).

qtable->add_text(
EXPORTING
text = '- WBS Code:'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '2testing76421-33 (level 3)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Account Assignment Category: B'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '1. MK-testing77663322 (level 3, along with the CC of the WBS)'
sap_emphasis = cl_dd_document=>small ).
  qtable->add_text(
EXPORTING
text = '1. CN-testig-678900 (level 3)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '1.testing77889900 (level 3)'
sap_emphasis = cl_dd_document=>small ).

"Row 6
qtable->new_row( ).

qtable->add_text(
EXPORTING
text = '1. Otesting-1bc1234(level 3, along with the CC of the WBS)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = '3. SP-testing123456 (level 3)'
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = ''
sap_emphasis = cl_dd_document=>small ).

qtable->add_text(
EXPORTING
text = 'Account Assignment Category: R'
sap_emphasis = cl_dd_document=>small ).
qtable->set_column_width(
EXPORTING
col_no = 1
width = '15%' ).

qtable->set_column_width(
EXPORTING
col_no = 2
width = '23%' ).

qtable->set_column_width(
EXPORTING
col_no = 3
width = '14%' ).

qtable->set_column_width(
EXPORTING
col_no = 4
width = '13%' ).

qtable->set_column_width(
EXPORTING
col_no = 5
width = '15%' ).

qtable->set_column_width(
EXPORTING
col_no = 6
width = '20%' ).

CALL METHOD o_docu->merge_document.


CALL METHOD o_docu->display_document
EXPORTING
reuse_control = 'X'
parent = o_ref1.


ENDFORM.

START-OF-SELECTION.

SELECT vbeln,vkorg,kunnr FROM vbak INTO TABLE @DATA(lt_vbak) UP TO 30 ROWS.
PERFORM build_fieldcatalog.
CALL SCREEN '9000'.
FORM build_fieldcatalog .

DATA : lv_col TYPE i.

lv_col = lv_col + 1.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-tabname = 'LT_VBAK'.
wa_fcat-scrtext_l = 'SALES ORDER'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = lv_col + 1.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'VKORG'.
wa_fcat-tabname = 'LT_VBAK'.
wa_fcat-scrtext_l = 'SALES ORG'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

lv_col = lv_col + 1.
wa_fcat-col_pos = lv_col.
wa_fcat-fieldname = 'KUNNR'.
wa_fcat-tabname = 'LT_VBAK'.
wa_fcat-scrtext_l = 'CUSTOMER NUMBER'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM.
MODULE status_9000 OUTPUT.
SET PF-STATUS 'PF_STATUS'.
ENDMODULE.
MODULE split_container OUTPUT.
PERFORM split_cont.
ENDMODULE.
FORM split_cont .
IF cl_gui_alv_grid=>offline( ) IS INITIAL.

IF o_cust IS NOT BOUND.
CREATE OBJECT o_cust
EXPORTING
container_name = 'CONT'.
CREATE OBJECT o_spli
EXPORTING
parent = o_cust
rows = 2
columns = 1.
CALL METHOD o_spli->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = o_ref1.
CALL METHOD o_spli->set_row_height
EXPORTING
id = 1
height = 20.
CALL METHOD o_spli->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = o_ref2.

CREATE OBJECT o_docu
EXPORTING
style = 'ALV_GRID'.
ENDIF.
ENDIF.

ENDFORM.
MODULE display_alv OUTPUT.
PERFORM dislay_alv_grid.
ENDMODULE.
FORM dislay_alv_grid .
IF o_alv IS NOT BOUND.

CREATE OBJECT o_alv
EXPORTING
i_parent = o_ref2.

CREATE OBJECT o_obj.

SET HANDLER o_obj->page_head FOR o_alv.

PERFORM save_variant.
PERFORM build_layout.

CALL METHOD o_alv->set_table_for_first_display
EXPORTING
is_layout = wa_layout
CHANGING
it_outtab = lt_vbak[]
it_fieldcatalog = it_fcat[].

CALL METHOD o_alv->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = o_docu.
ENDIF.
ENDFORM.
FORM build_layout .
wa_layout-sel_mode = 'A'.
wa_layout-cwidth_opt = 'X'.
wa_layout-zebra = 'X'.
ENDFORM.
FORM save_variant .
wa_variant-report = sy-repid.
ENDFORM.

FORM usr_cmmd .
CASE sy-ucomm.
WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. "Back, Cancel, Back
LEAVE TO SCREEN 0.
ENDCASE.
ENDFORM.
MODULE user_command_9000 INPUT.
PERFORM usr_cmmd.
ENDMODULE.

Thank you very much. It simplifies a lot and it solves the question definitely in an instant.

Sorry to say that WE are BOTH losing lot of time, because I told you TWICE that "You must call the method NEW_ROW after each line you write to the table" and still you didn't even try.

Without qtable->new_row( ) after the last write to the table:

With qtable->new_row( ) after the last write to the table:

Thanks, its not that I didnt try. I actually misunderstood your comment when you mentioned that "You don't call NEW_ROW after ADD_TEXT, as I said." I have added NEW_ROW method after ADD_TEXT method for the previous 5 rows, but NOT for the last (6th) row and hence this minor issue was dancing down my spine. If you had mentioned that I didnt call NEW_ROW method AFTER the 5th row, then I would have got your point instantly.

Nevertheless, thanks for your time and help. I appreciate it a lot.

Regards,

Manish