cancel
Showing results for 
Search instead for 
Did you mean: 

ALV Print Version: Wrap text in column?

mh97
Contributor
0 Kudos

Hi,

I am working with an ALV table in a web dynpro. We have text wrapping allowed for the columns. Some columns have long text entries so, when printed these need to be wrapped in the printout as well. However, when we use the standard Print Version function, the wrapping that is kept on the screen is not used in the PDF, but instead the text is all kept on one line, making the print version either in very small font size or spread onto multiple pages (which the user does not want).

For example,

The text in the cell is:

The quick brown fox jumped over the lazy dog.

The column width is set on the screen to show it like:

The quick brown fox

jumped over the

lazy dog.

The Print Version output has:

The quick brown fox jumped over the lazy dog.

The user wants to see in the Print Version (reflecting the screen column width):

The quick brown fox

jumped over the

lazy dog.

In the SAP Help and ALV classes I have not found any way to maintain the text wrapping in the PDF output from the standard Print Version button. But I'm hoping I'm just missing something.

Any ideas?

Thanks,

Margaret

Accepted Solutions (1)

Accepted Solutions (1)

JonathanM
Contributor
0 Kudos

Hi Margaret,

You should define the colomn settings yourself.

By default is taking the full length (on your screen) but on a print page, this is shorter.

You can specify the parameters of your ALV table in the WDDOINIT or WDDOMODIFYVIEW:

  DATA: LR_IF_CONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE,
        LR_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE,
        LR_CMDL TYPE REF TO CL_SALV_WD_CONFIG_TABLE,
        LR_TABLE_SETTING TYPE REF TO IF_SALV_WD_TABLE_SETTINGS.

  LR_CMP_USAGE = WD_THIS->WD_CPUSE_ALV_TAB( ).

  IF LR_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.
    LR_CMP_USAGE->CREATE_COMPONENT( ).
  ENDIF.

*  get reference to the ALV model
  LR_IF_CONTROLLER = WD_THIS->WD_CPIFC_ALV_TAB( ).
  LR_CMDL = LR_IF_CONTROLLER->GET_MODEL( ).
  LR_TABLE_SETTING ?= LR_CMDL.

*LR_CMDL->if_salv_wd_std_functions~set_pdf_allowed( abap_false ).

*  LR_CMDL->IF_SALV_WD_TABLE_SETTINGS~SET_WIDTH( VALUE = '900px' ).

  LR_CMDL = LR_IF_CONTROLLER->GET_MODEL( ).
  LR_TABLE_SETTING ?= LR_CMDL.

  DATA LR_COL TYPE REF TO CL_SALV_WD_COLUMN.
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'PERNR' ).
  LR_COL->SET_WIDTH( '60' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'NAME' ).
  LR_COL->SET_WIDTH( '110' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'WEEK' ).
  LR_COL->SET_WIDTH( '55' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'WOSTD' ).
  LR_COL->SET_WIDTH( '65' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'STDAZ' ).
  LR_COL->SET_WIDTH( '65' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'BEGTI' ).
  LR_COL->SET_WIDTH( '80' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'AWART' ).
  LR_COL->SET_WIDTH( '50' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'BEGDA' ).
  LR_COL->SET_WIDTH( '80' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'ENDDA' ).
  LR_COL->SET_WIDTH( '80' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'KOANZ' ).
  LR_COL->SET_WIDTH( '70' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'REST' ).
  LR_COL->SET_WIDTH( '70' ) .
  LR_COL = LR_CMDL->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'ETEXT' ).
  LR_COL->SET_WIDTH( '50' ) .
  LR_TABLE_SETTING->SET_FIXED_TABLE_LAYOUT( ABAP_TRUE ).

Best regards,

Jonathan

mh97
Contributor
0 Kudos

Hi Jonathan,

Thanks for your response. However, I have already set the column widths explicitly like you show, as well as setting text wrapping to true. This works fine for what is displayed on the screen, but when the user clicks "Print Version", the displayed PDF doesn't wrap the texts, but instead puts all the text on one line, and increases the relative column width. If at the same time I have the scaling set to "fit to page" the font size is shrunk.

I am looking for a way that the PDF output will reflect the text wrapping that is shown on the screen.

Margaret

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Margaret,

Please try the below code.

Data  lr_pdf_settings    type ref to if_salv_wd_pdf_settings.

    lr_pdf_settings ?= wd_this->r_config_model.

     lr_pdf_settings->set_page_layout(

       exporting

            VALUE = IF_SALV_WD_C_PDF_SETTINGS=> LAYOUT_FIT_TO_PAGE.

Explore the interfaces IF_SALV_WD_PDF_SETTINGS and IF_SALV_WD_C_PDF_SETTINGS to do additional changes that fits your requirement.

Pavan.

mh97
Contributor
0 Kudos

Hi Pavan,

Thanks for your suggestion. I did try that and other methods in IF_SALV_WD_PDF_SETTINGS. So far I have not found any setting that solves the problem. If I use fit to page or fit horizontal it is still keeping all text for the column on one line, even though it is wrapped on the screen and the ALV column settings include explicitly setting the column width and text wrapping enabled.

I think the answer is that it cannot be done. I am looking for anyone who has done this with the ALV "Print Version" function and gotten the pdf to include the text wrapping as displayed in the screen.

Thanks,

Margaret

Former Member
0 Kudos

Hello Margret,

at the moment I'm facing the same issue. Did you find any solution in the meanwhile?

Are you now able to print the line breaks of the column in the pdf?

Thanks in adavnce.

Kind regardss

Fabian

mh97
Contributor
0 Kudos

Hi Fabian,

Sorry, I was not able to find any solution to this at the time. I don't recall solving it since and I am currently not working with this technology.

For the application where I first posted this, I ended up creating a custom pdf in SFP. This meant that users could not pick their columns. I think I also left the ability to get the standard print version but then they had the issue with the text not wrapping. So we also limited the amount of text that would display in that column in the webdynpro, so there would be some predictability in the output.

SAP may have since fixed this. I would recommend taking another look at the various classes for ALV elements.

Good luck!

Margaret