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: 

Dynamic report / ALV

Former Member
0 Kudos
91

Hi Experts,

I have to make a dynamic ALV(if not possible in my case then a dynamic report).

I have to show long text of materials in new columns insted of new lines, I did that but it shows wrong values if the data exceeds after 9 colums, It should be dynamic so that there is no limit for the material long text, any number of lines in long text we can see in colums. Code for 10 colums is attached here, plase tell me how to make this code dynamic (either dynamic alv or dynamic report).

&----


*& Report ZMMTEST_MAT_DESC

*&

&----


REPORT ZMMTEST_MAT_DESC.

TABLES : ekpo,MAKT, t001w.

TYPE-POOLS: slis.

DATA : thread LIKE thead.

DATA : l_index LIKE sy-tabix.

DATA : p_index LIKE sy-tabix.

DATA: BEGIN OF INT_OUT OCCURS 0,

MATNR LIKE MAKT-MATNR,

MAKTX LIKE MAKT-MAKTX,

TDLINE1 LIKE TLINE-TDLINE,

TDLINE2 LIKE TLINE-TDLINE,

TDLINE3 LIKE TLINE-TDLINE,

TDLINE4 LIKE TLINE-TDLINE,

TDLINE5 LIKE TLINE-TDLINE,

TDLINE6 LIKE TLINE-TDLINE,

TDLINE7 LIKE TLINE-TDLINE,

TDLINE8 LIKE TLINE-TDLINE,

TDLINE9 LIKE TLINE-TDLINE,

TDLINE10 LIKE TLINE-TDLINE,

WERKS LIKE EKPO-WERKS,

END OF INT_OUT.

DATA: BEGIN OF INT_OUT_new OCCURS 0,

MATNR LIKE MAKT-MATNR,

MAKTX LIKE MAKT-MAKTX,

TDLINE1 LIKE TLINE-TDLINE,

TDLINE2 LIKE TLINE-TDLINE,

TDLINE3 LIKE TLINE-TDLINE,

TDLINE4 LIKE TLINE-TDLINE,

TDLINE5 LIKE TLINE-TDLINE,

TDLINE6 LIKE TLINE-TDLINE,

TDLINE7 LIKE TLINE-TDLINE,

TDLINE8 LIKE TLINE-TDLINE,

TDLINE9 LIKE TLINE-TDLINE,

TDLINE10 LIKE TLINE-TDLINE,

tline like tline occurs 0,

WERKS LIKE EKPO-WERKS,

END OF INT_OUT_new.

DATA: it_tlines LIKE tline OCCURS 10 WITH HEADER LINE.

**************************

****ALV list definintion

*************************

DATA: ws_cat TYPE slis_fieldcat_alv ,

int_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA: g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',

g_custom_container TYPE REF TO cl_gui_custom_container.

DATA : it_heading TYPE slis_t_listheader WITH HEADER LINE.

*DATA : it_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.

DATA : lay TYPE slis_layout_alv.

DATA : it_sort_subtotal TYPE slis_t_sortinfo_alv WITH HEADER LINE.

DATA : it_event TYPE slis_t_event WITH HEADER LINE.

.

DATA: v_repid LIKE sy-repid.

*****************

*selection-screen

*****************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: S_WERKS FOR EKPO-WERKS OBLIGATORY .

SELECT-OPTIONS: S_MATNR FOR MAKT-MATNR OBLIGATORY .

SELECTION-SCREEN END OF BLOCK b1.

*SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 .

*

*PARAMETERS : r1 RADIOBUTTON GROUP g1 DEFAULT 'X' .

*PARAMETERS : r2 RADIOBUTTON GROUP g1 .

*PARAMETERS : r3 RADIOBUTTON GROUP g1 .

*

*SELECTION-SCREEN END OF BLOCK b2.

INITIALIZATION.

AT SELECTION-SCREEN.

SELECT SINGLE * FROM t001w WHERE werks IN S_WERKS.

IF sy-subrc NE 0.

MESSAGE e001(319) WITH 'Plant does not Exist!'.

ENDIF.

SELECT SINGLE * FROM makt WHERE matnr IN s_matnr.

IF sy-subrc <> 0.

MESSAGE e001(319) WITH 'Material does not Exist!'.

ENDIF.

START-OF-SELECTION.

BREAK-POINT.

PERFORM get_data.

  • PERFORM field_catalog.

  • PERFORM display_data.

END-OF-SELECTION.

*FORM GET_DATA.

form get_data.

DATA: l_index LIKE sy-tabix.

*To Fetch Data From Makt.

SELECT b~werks a~MATNR a~MAKTX

INTO CORRESPONDING FIELDS OF TABLE int_out

FROM MAKT AS a INNER JOIN marc AS b ON a~matnr = b~matnr

WHERE a~MATNR IN S_MATNR

AND b~werks IN S_WERKS.

LOOP AT int_out.

l_index = sy-tabix.

  • read table int_out_new with key matnr = int_out-matnr.

int_out_new-werks = int_out-werks.

int_out_new-matnr = int_out-matnr.

int_out_new-maktx = int_out-maktx.

*

thread-tdname = int_out-matnr.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = 'BEST'

language = sy-langu

name = thread-tdname

object = 'MATERIAL'

TABLES

lines = it_tlines

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8.

*Loop on it_tlines where long text is coming .

loop at it_tlines.

IF sy-subrc = 0.

p_index = sy-tabix.

IF p_index = 1.

int_out_new-tdline1 = it_tlines-tdline.

ELSEIF p_index = 2.

int_out_new-tdline2 = it_tlines-tdline.

ELSEIF p_index = 3.

int_out_new-tdline3 = it_tlines-tdline.

ELSEIF p_index = 4.

int_out_new-tdline4 = it_tlines-tdline.

ELSEIF p_index = 5.

int_out_new-tdline5 = it_tlines-tdline.

ELSEIF p_index = 6.

int_out_new-tdline6 = it_tlines-tdline.

ELSEIF p_index = 7.

int_out_new-tdline7 = it_tlines-tdline.

ELSEIF p_index = 8.

int_out_new-tdline8 = it_tlines-tdline.

ELSEIF p_index = 9.

int_out_new-tdline9 = it_tlines-tdline.

ELSEIF p_index GE 10.

int_out_new-tdline10 = it_tlines-tdline.

ENDIF.

ENDIF.

endloop.

delete adjacent duplicates from INT_OUT .

append int_out_new.

clear int_out_new.

ENDLOOP.

  • Field Catalog

***MATERIAL NO no

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'WERKS'.

int_fcat-reptext_ddic = 'Plant'.

APPEND int_fcat .

***MATERIAL NO no

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'MATNR'.

int_fcat-reptext_ddic = 'Material N0'.

APPEND int_fcat .

*material Short Description

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'MAKTX'.

int_fcat-reptext_ddic = 'Material Short Description'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '45'.

APPEND int_fcat .

    • Material Long Description1

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE1'.

int_fcat-reptext_ddic = 'Material Long Description1'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description2

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE2'.

int_fcat-reptext_ddic = 'Material Long Description2'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description3

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE3'.

int_fcat-reptext_ddic = 'Material Long Description3'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description4

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE4'.

int_fcat-reptext_ddic = 'Material Long Description4'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description5

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE5'.

int_fcat-reptext_ddic = 'Material Long Description5'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description5

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE5'.

int_fcat-reptext_ddic = 'Material Long Description5'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description5

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE5'.

int_fcat-reptext_ddic = 'Material Long Description5'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description6

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE6'.

int_fcat-reptext_ddic = 'Material Long Description6'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description7

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE7'.

int_fcat-reptext_ddic = 'Material Long Description7'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description8

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE8'.

int_fcat-reptext_ddic = 'Material Long Description8'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description9

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE9'.

int_fcat-reptext_ddic = 'Material Long Description9'.

int_fcat-datatype = 'CHAR'.

int_fcat-outputlen = '75'.

APPEND int_fcat .

    • Material Long Description10

int_fcat-tabname = 'INT_OUT_NEW'.

int_fcat-fieldname = 'TDLINE10'.

int_fcat-reptext_ddic = 'Material Long Description10'.

int_fcat-datatype = 'CHAR'.

  • int_fcat-outputlen = '75'.

APPEND int_fcat .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = int_fcat[]

TABLES

t_outtab = int_out_NEW

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDFORM. "display_data

Regards

Nikhil

3 REPLIES 3

Former Member
0 Kudos
52

while checking in MM03 it displays long text in the script with 72 char each line.

I have an upload prog, we break long text in the file with 72 char per column depending on the text and upload it, it displays in MM03 line by line with 72 char per line. I created the above report to put these lines in a new colums.

THe basic requirement it the upload and the download text should be same but without dynamic report it is not possible

Regards

Nikhil

former_member194669
Active Contributor
0 Kudos
52

Hi,

If material long text have 250 pages then (250*65) number of columns ? and also print out will be possible of 255 char length limitation.

if you want then code something like this


loop at it_tlines.
concatenate 'int_out_new-tdline' sy-tabix into v_fieldname.
condense v_fieldname.
assign (v_fieldname) to <fs>.
write it_tlines-tdline to <fs.
endloop.


create a field catalog with default of 2000 colums.

* here deleting unused material long text columns from field catalog

read table i_fieldcat with key fieldname = v_fieldname.
if sy-subrc eq 0.
  v_tabix = sy-tabix.
  do.
    read table i_fieldcat index v_tabix.
    if sy-subrc eq 0.
      delete i_fieldcat index v_tabix.
   else.
      exit.
   endif.
  enddo.

endif.

aRs

0 Kudos
52

Hi

aRs

U said to create a dynamic field catlog ..I never did any dynamic ALV befor, i dnt no how to create that as i am new to SAP. earlier what i was doing is i was assigning values dorectly to field to display, now u put values in fs how to proceed i dnt no please help me out as its a critical issue.

Nikhil