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: 

Rows as columns and dynamic alv display

Former Member
0 Kudos

Hi everyone,

I need to build a intenal table dynamically as well as dispaly few rows as columns in alv output.

I have seen posts where internal table has been created dynamicaaly as well seen the posts where rows of the table are displayed as columns but, can we achieve both the functionalities at same time.

I have table as:



SO     PO     Date    MAT    QTY   
1        A       X    Y1      10  
                       K1      15
                       M2      11
2       B       X1     Y2       5
                       M1      12
3       C       1x     Z1      15
                       K1       6
                       L1      10

Now the ouput has to be :

SO     PO   Date     MAT-Y1    MAT-K1    MAT-Y2   MAT-L1     Mat-Z1    MAT-M1   MAT-M2
1        A     X      10          15                                               11             
2        B     X1                         5                             12                 
3        C     1X                  6                10          15                                        

I will not be knowing the number of materials untill runtime(dynamic) and as well the rows has to be displayed as columns. Is it possible to do that.

Regards

Edited by: Madhu Posanipalli on Jun 6, 2011 4:51 PM

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

Hi Madhu Posanipalli,

I think you have all the keys to make your "transposed" ALV: build the list of distinct codes of materials, so you'll know how many columns you need. Then create the internal table dynamically. And fill it dynamically by reading the sorted input internal table, with breaks on SO, PO, and date fields, and using field symbols to address the corresponding column of the material...

BR

Sandra

11 REPLIES 11

Sandra_Rossi
Active Contributor
0 Kudos

Hi Madhu Posanipalli,

I think you have all the keys to make your "transposed" ALV: build the list of distinct codes of materials, so you'll know how many columns you need. Then create the internal table dynamically. And fill it dynamically by reading the sorted input internal table, with breaks on SO, PO, and date fields, and using field symbols to address the corresponding column of the material...

BR

Sandra

0 Kudos

HI,

Do I need to transpose first and build the internal table dynamically? The problem is, few of the columns in the display are fixed and few need to be transposed. For eg., SO PO Date need to be fixed at 1, 2,3 as columns and 4th & 5th column are transposed and alv has to spread dynamically.

In other words, dynamically transpose rows to columns.

Any suggestion in that directions will be of great help.

Regards.

0 Kudos

Hi Madhu Posanipalli,

I think my first answer is still applicable to your question, maybe I wasn't clear enough.

Here is the general algorithm how I would do it: The following procedure reads the input internal table by transposing certain fields, you provide the field names on the left (SO, PO, date), on the top (material), on the intersection (quantity), and it returns a new internal table, that you will then display by using ALV (SALV classes are the simplest to use).


FORM transpose_matrix
      USING
        it_data TYPE ANY TABLE
        it_top  TYPE ty_gt_fieldname
        it_left TYPE ty_gt_fieldname
        it_intersection TYPE ty_gt_fieldname
      CHANGING
        ert_data TYPE REF TO DATA.
* create table for containing TOP distinct values
LOOP AT it_TOP_field ASSIGNING <l_top_field>.
  ASSIGN COMPONENT <l_top_field> of structure <ls_any> TO <L_field>.
  ...
ENDLOOP.
L_ref_s_dyn_col = Cl_abap_structdescr=>create( ).
Assign l_ref_s_dyn_col->* TO <ls_dyn_col>.
L_ref_t_dyn_col = Cl_abap_tabledescr=>create( L_ref_s_dyn_col ).
Assign l_ref_t_dyn_col->* TO <lt_dyn_col>.

* fill internal table of TOP distinct values -> it will give the number of "dynamic columns"
* multiply these columns by the number of fields at the intersection
LOOP AT it_data ASSIGNING <ls_data>
  LOOP AT it_TOP_field ASSIGNING <l_top_field>.
    ASSIGN COMPONENT <l_top_field> of structure <ls_data> TO <L_data_field>.
    ASSIGN COMPONENT <l_top_field> of structure <ls_dyn_col> TO <L_dyn_col_field>.
    <l_dyn_col_field> = <l_data_field>.
  ENDLOOP.
  COLLECT <ls_dyn_col> INTO <lt_dyn_col>.
ENDLOOP.

* create the new internal table
LOOP AT <lt_dyn_col>
  LOOP AT it_intersection
*    new column of the new internal table
  ENDLOOP.
ENDLOOP.
cl_abap_structdescr( )
cl_abap_tabledescr( )

* fill the new internal table
LOOP AT it_data
* many dynamic ASSIGN again
ENDLOOP.

ENDFORM.

Have fun!!!

Sandra

0 Kudos

Hi Sandra,

Taken a hint from your post and did the coding as required. Now everything is in proper place and getting the output as desired. I got one issue where i need to delete few records from <fs> (to check one condition where shipping date is empty and delete that particular record) but unable to do so. Below is snippets of code of my object. Also suggest my if the performance can improve anyway (as i am using loops within loops--want to avoid totally if possible).

 
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE, 
               <dyn_wa>, 
               <dyn_field>. 
DATA: dy_table TYPE REF TO data, 
      dy_line  TYPE REF TO data, 
      xfc TYPE lvc_s_fcat, 
      ifc TYPE lvc_t_fcat, 
      it_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE, 
      g_audat  TYPE vbak-audat, 
      g_matnr  TYPE mara-matnr. 

DATA : BEGIN OF wa OCCURS 0, 
       fieldname TYPE dfies-fieldname, 
       fieldtext TYPE dfies-fieldtext, 
       outputlen TYPE dfies-outputlen, 
       datatype TYPE dfies-datatype, 
       inttype TYPE dfies-inttype, 
       decimals TYPE dfies-decimals, 
       intlen TYPE dfies-intlen, 
       END OF wa. 

*------for generating dynamic alv
 wa-fieldname = 'FKDAT'.
  wa-fieldtext = 'Date Shipped'.
  wa-outputlen = '000010'.
  wa-datatype = 'DATS'.
  wa-inttype  = 'D'.
  wa-decimals = '000000'.
  wa-intlen   = '000016'.
  APPEND wa.

  LOOP AT it_matnr INTO wa_matnr.

    READ TABLE it_maktx INTO wa_maktx WITH KEY matnr = wa_matnr-matnr.
    IF sy-subrc EQ 0.
      CONCATENATE wa_matnr-matnr '-' wa_maktx-maktx INTO lv_mat_desc.
    ENDIF.
    wa-fieldname = wa_matnr-matnr.
*    wa-fieldtext = wa_matnr-matnr.
    wa-fieldtext = lv_mat_desc.
    wa-outputlen = '000070'.
    wa-datatype = 'char'.
    wa-inttype  = 'C'.
    wa-decimals = '000000'.
    wa-intlen   = '000036'.
    APPEND wa.
    CLEAR: wa_matnr, wa_maktx, lv_mat_desc.
  ENDLOOP.

  LOOP AT wa.
    xfc-fieldname = wa-fieldname.
    xfc-scrtext_l = wa-fieldtext.
    xfc-outputlen = wa-outputlen.
    xfc-datatype  = wa-datatype.
    xfc-inttype   = wa-inttype.
    xfc-decimals  = wa-decimals.
    xfc-intlen    = wa-intlen.
    APPEND xfc TO ifc.
    CLEAR xfc.
    it_fcat-fieldname = wa-fieldname.
    it_fcat-seltext_l = wa-fieldtext.
    it_fcat-outputlen = wa-outputlen.
    APPEND it_fcat.
    CLEAR  it_fcat.
  ENDLOOP.

*--Create dynamic internal table.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog           = ifc
      i_length_in_byte          = 'X'
    IMPORTING
      ep_table                  = dy_table
    EXCEPTIONS
      generate_subpool_dir_full = 1
      OTHERS                    = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


0 Kudos

cond......

 ASSIGN dy_table->* TO <dyn_table>.
  CREATE DATA dy_line LIKE LINE OF <dyn_table>.
  ASSIGN dy_line->* TO <dyn_wa>.

  SORT: it_vbak BY vbeln, it_vbkd BY vbeln, it_lips BY vgbel, it_vbrp BY vbeln, it_vbrk BY vbeln.

  LOOP AT it_vbak INTO wa_vbak.                   "Sales Document header data
    LOOP AT it_lips INTO wa_lips WHERE vgbel = wa_vbak-vbeln.     "Delivery item data
      LOOP AT wa.                                                 
        ASSIGN COMPONENT wa-fieldname OF STRUCTURE <dyn_wa> TO <dyn_field>.
        IF  sy-tabix EQ 1.
          <dyn_field> = wa_vbak-audat.       "Date Received
        ELSEIF sy-tabix EQ 2.
          <dyn_field> = wa_vbak-vbeln.      "Sales Document
        ELSEIF sy-tabix EQ 3.
          READ TABLE it_vbkd INTO wa_vbkd WITH  KEY vbeln = wa_lips-vgbel.
*                                                      posnr = wa_lips-vgpos.
          IF sy-subrc EQ 0 .
            <dyn_field> =  wa_vbkd-bstkd.   "Purchase document
          ENDIF.
        ELSEIF sy-tabix EQ 4.
          READ TABLE it_vbrp INTO wa_vbrp WITH KEY vgbel = wa_lips-vbeln.
          IF sy-subrc EQ 0.
            READ TABLE it_vbrk INTO wa_vbrk WITH KEY vbeln = wa_vbrp-vbeln.
            IF sy-subrc EQ 0.
              <dyn_field> = wa_vbrk-fkdat.      "Shipping date
            ENDIF.
          ENDIF.
        ELSE.
          IF wa_lips-matnr EQ wa-fieldname.
            <dyn_field> = wa_lips-lfimg.        "Quantity
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDLOOP.
    IF sy-subrc EQ 0.
      APPEND <dyn_wa> TO <dyn_table>.
      CLEAR <dyn_wa>.
    ENDIF.
  ENDLOOP.


*------Display output
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      it_fieldcat        = it_fcat[]
    TABLES
      t_outtab           = <dyn_table>
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

Is it possible anyway to delete records from <dyn_table> before passing to alv grid for say , if shipping date is not present.

something similar to(which does not work in this case) :


loop at <dyn_table> assigning <dyn_wa> where  fkdat eq '00000000'.
delete <dyn_table> from <dyn_wa>.
endloop.

0 Kudos

Hey Madhu,

well done!

Is it possible anyway to delete records from <dyn_table> before passing to alv grid for say , if shipping date is not present. something similar to(which does not work in this case) :


loop at <dyn_table> assigning <dyn_wa> where  fkdat eq '00000000'.
  delete <dyn_table> from <dyn_wa>.
endloop.

As the internal table has an unknown structure, you cannot reference a component (FKDAT) statically. Either don't add the lines (maybe you can select database lines where FKDAT eq '0000000'?), or


loop at <dyn_table> assigning <dyn_wa>;
  assign component 'FKDAT' OF structure <dyn_wa> TO <fkdat>.
  if sy-subrc = 0 and <fkdat> eq '00000000'.
    delete <dyn_table> "it deletes current looped line, you don't need "from <dyn_wa>"
  endif.
endloop.

Sandra

PS: I would have been very happy if you had implemented a full dynamic procedure to transpose, and posted it here, another time maybe! 😄

0 Kudos

Hi Sandra,

Yes, when time permitts will definetly implement fully dynamic logic. Thanks for your help.

Former Member
0 Kudos

Hi Madhu Posanipalli,

you can create dynamically your table.

You can do this with:


* fill structure with the fields of your table
FORM f_set_fcat CHANGING  GT_FIELDCAT TYPE LVC_T_FCAT.
 
    DATA: l_fcat TYPE LVC_S_FCAT.
 
    l_fcat-fieldname = 'EE'.  "name of the field
   l_fcat-DATATYPE = 'CHAR'. "data type
 
    APPEND l_fcat TO  GT_FIELDCAT.
 
    l_fcat-fieldname = 'EE'.  "name of the field 2
   l_fcat-DATATYPE = 'CHAR'. "data type
 
    APPEND l_fcat TO  GT_FIELDCAT.
 
    CLEAR l_fcat.
 
ENDFORM.

* Create dynamic table
FORM BUILD_DYNTAB TABLES   P_RULES  STRUCTURE IT_RULES
                  USING    P_STBASE LIKE      ST_BASETABLA.

DATA: NEW_TABLE     TYPE REF TO DATA,
      NEW_LINE      TYPE REF TO DATA.

* Crea la tabla interna y la asignamos al Field Symbol
  CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
    EXPORTING IT_FIELDCATALOG = GT_FIELDCAT
    IMPORTING EP_TABLE        = NEW_TABLE.

  ASSIGN NEW_TABLE->* TO <G_DYNTABLE>.

  CREATE DATA NEW_LINE LIKE LINE OF <G_DYNTABLE>.
  ASSIGN NEW_LINE->* TO <G_DYNWA>.
ENDFORM.

* Fill data 
* Call ALV

0 Kudos

Hi,

I don't advise to use this old method CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE, as it is counter-performant (and dump-prone after 36 executions in the same internal session) as it uses GENERATE SUBROUTINE POOL statement. Instead, use RTTC (CL_ABAP_TABLEDESCR, and other classes of the RTTC/RTTS family, have a look at the documentation and forum).

Sandra

0 Kudos

Hi,

>

> I don't advise to use this old method CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE, as it is counter-performant (and dump-prone after 36 executions in the same internal session) as it uses GENERATE SUBROUTINE POOL statement. Instead, use RTTC (CL_ABAP_TABLEDESCR, and other classes of the RTTC/RTTS family, have a look at the documentation and forum).

>

> Sandra

Although I agree with Sandra, just a reference for those curious

[A workaround for > 36 dyn programs - part1|;

[A workaround for > 36 dyn programs - part2|]

Regards

Marcin

Former Member
0 Kudos

Hi,

Check below code. It will work definitly.

&----


*& Report YTEST_PROG_RP

*&

&----


*&

*&

&----


REPORT YTEST_PROG_RP.

type-POOLs slis.

TYPES: BEGIN OF ty_tab,

so TYPE i,

po TYPE c,

date(2) TYPE c,

mat(2) TYPE c,

qty TYPE i,

END OF ty_tab.

DATA: itab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,

jtab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,

ktab TYPE STANDARD TABLE OF ty_tab INITIAL SIZE 0,

wa_tab TYPE ty_tab, wa_j TYPE ty_tab, wa_k TYPE ty_tab.

FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,

<fs_dyntable>,

<fs_fldval> type any.

*ALV data declarations

data: fieldcatalog type LVC_T_FCAT, " with header line, "slis_t_fieldcat_alv with header line,

fieldcatalog1 TYPE LVC_s_FCAT,

fieldcatalog2 type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid,

gt_events type slis_t_event,

gd_prntparams type slis_print_alv.

DATA t_newtable TYPE REF TO data.

DATA t_newline TYPE REF TO data.

DATA wa_flname TYPE string.

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

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform dynamic_table.

perform build_layout.

perform build_events.

perform build_print_params.

perform display_alv_report.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

DATA: lv_field1 TYPE string, lv_cnt LIKE sy-tabix VALUE 3, itab_lines TYPE i.

DATA: fieldname(20) TYPE c.

DATA: fieldvalue(10) TYPE c.

DATA: index(3) TYPE c.

DATA: wa_cat LIKE LINE OF fieldcatalog2,

wa_colno(2) TYPE n,

wa_flname(5) TYPE c. .

fieldcatalog1-fieldname = 'SO'.

  • fieldcatalog1-seltext = 'SO'.

fieldcatalog1-col_pos = 1.

fieldcatalog1-outputlen = 2.

  • fieldcatalog-emphasize = 'X'.

  • fieldcatalog-key = 'X'.

  • fieldcatalog-do_sum = 'X'.

  • fieldcatalog-no_zero = 'X'.

append fieldcatalog1 to fieldcatalog.

clear fieldcatalog1.

fieldcatalog1-fieldname = 'PO'.

  • fieldcatalog1-seltext = 'PO'.

fieldcatalog1-col_pos = 2.

fieldcatalog1-outputlen = 2.

append fieldcatalog1 to fieldcatalog.

clear fieldcatalog1.

fieldcatalog1-fieldname = 'DATE'.

  • fieldcatalog1-seltext = 'Date'.

fieldcatalog1-col_pos = 3.

fieldcatalog1-outputlen = 2.

append fieldcatalog1 to fieldcatalog.

clear fieldcatalog1.

LOOP AT itab INTO wa_tab.

lv_cnt = lv_cnt + 1.

CONCATENATE 'MAT-' wa_tab-mat into lv_field1.

TRANSLATE lv_field1 TO UPPER CASE.

fieldcatalog1-fieldname = lv_field1.

  • fieldcatalog1-seltext = lv_field1.

fieldcatalog1-col_pos = lv_cnt.

fieldcatalog1-outputlen = 6.

append fieldcatalog1 to fieldcatalog.

clear fieldcatalog1.

CLEAR: lv_field1, wa_tab.

ENDLOOP.

CLEAR lv_cnt.

  • Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = fieldcatalog

IMPORTING

ep_table = t_newtable.

ASSIGN t_newtable->* TO <t_dyntable>.

CREATE DATA t_newline LIKE LINE OF <t_dyntable>.

ASSIGN t_newline->* TO <fs_dyntable>.

  • DESCRIBE TABLE fieldcatalog LINES itab_lines.

loop at fieldcatalog INTO fieldcatalog1.

CLEAR wa_cat.

wa_cat-fieldname = fieldcatalog1-fieldname.

wa_cat-seltext_s = fieldcatalog1-fieldname.

wa_cat-outputlen = fieldcatalog1-outputlen.

APPEND wa_cat TO fieldcatalog2.

CLEAR fieldcatalog1.

ENDLOOP.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

  • gd_layout-no_input = 'X'.

  • gd_layout-colwidth_optimize = 'X'.

  • gd_layout-totals_text = 'Totals'(201).

    • gd_layout-totals_only = 'X'.

    • gd_layout-f2code = 'DISP'. "Sets fcode for when double

    • "click(press f2)

    • gd_layout-zebra = 'X'.

    • gd_layout-group_change_edit = 'X'.

    • gd_layout-header_text = 'helllllo'.

endform. " BUILD_LAYOUT

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

  • i_callback_program = gd_repid

  • i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

  • i_callback_user_command = 'USER_COMMAND'

  • i_grid_title = outtext

  • is_layout = gd_layout

it_fieldcat = fieldcatalog2[]

  • it_special_groups = gd_tabgroup

  • it_events = gt_events

  • is_print = gd_prntparams

  • i_save = 'X'

  • is_variant = z_template

tables

t_outtab = <t_dyntable>

exceptions

program_error = 1

others = 2.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " DISPLAY_ALV_REPORT

&----


*& Form DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

DATA: lv_index LIKE sy-tabix.

wa_tab-so = 1.

wa_tab-po = 'A'.

wa_tab-date = 'X'.

wa_tab-mat = 'Y1'.

wa_tab-qty = 10.

append wa_tab to itab.

clear wa_tab.

wa_tab-mat = 'K1'.

wa_tab-qty = 15.

append wa_tab to itab.

CLEAR wa_tab.

wa_tab-mat = 'M2'.

wa_tab-qty = 11.

append wa_tab to itab.

CLEAR wa_tab.

wa_tab-so = 2.

wa_tab-po = 'B'.

wa_tab-date = 'X1'.

wa_tab-mat = 'Y2'.

wa_tab-qty = 5.

append wa_tab to itab.

CLEAR wa_tab.

wa_tab-mat = 'M1'.

wa_tab-qty = 12.

append wa_tab to itab.

CLEAR wa_tab.

wa_tab-so = 3.

wa_tab-po = 'C'.

wa_tab-date = '1x1'.

wa_tab-mat = 'Z1'.

wa_tab-qty = 15.

append wa_tab to itab.

CLEAR wa_tab.

  • wa_tab-mat = 'K1'.

  • wa_tab-qty = 6.

  • append wa_tab to itab.

  • CLEAR wa_tab.

wa_tab-mat = 'L1'.

wa_tab-qty = 10.

append wa_tab to itab.

CLEAR wa_tab.

LOOP AT itab INTO wa_tab.

if wa_tab-so is NOT INITIAL AND wa_tab-po is NOT INITIAL AND wa_tab-date is NOT INITIAL.

wa_j-so = wa_tab-so.

wa_j-po = wa_tab-po.

wa_j-date = wa_tab-date.

lv_index = wa_tab-so.

else.

READ TABLE itab INTO wa_j WITH KEY so = lv_index.

ENDIF.

wa_j-mat = wa_tab-mat.

wa_j-qty = wa_tab-qty.

APPEND wa_j to jtab.

CLEAR: wa_tab, wa_j.

ENDLOOP.

endform. " DATA_RETRIEVAL

----


  • Form TOP-OF-PAGE *

----


  • ALV Report Header *

----


Form top-of-page.

**ALV Header declarations

*data: t_header type slis_t_listheader,

  • wa_header type slis_listheader,

  • t_line like wa_header-info,

  • ld_lines type i,

  • ld_linesc(10) type c.

*

    • Title

  • wa_header-typ = 'H'.

*

  • wa_header-info = 'EKKO Table Report'.

  • append wa_header to t_header.

  • clear wa_header.

*

    • Date

  • wa_header-typ = 'S'.

  • wa_header-key = 'Date: '.

  • CONCATENATE sy-datum+6(2) '.'

  • sy-datum+4(2) '.'

  • sy-datum(4) INTO wa_header-info. "todays date

  • append wa_header to t_header.

  • clear: wa_header.

*

    • Total No. of Records Selected

  • describe table it_ekko lines ld_lines.

  • ld_linesc = ld_lines.

  • concatenate 'Total No. of Records Selected: ' ld_linesc

  • into t_line separated by space.

  • wa_header-typ = 'A'.

  • wa_header-info = t_line.

  • append wa_header to t_header.

  • clear: wa_header, t_line.

*

  • call function 'REUSE_ALV_COMMENTARY_WRITE'

  • exporting

  • it_list_commentary = t_header.

    • i_logo = 'Z_LOGO'.

endform. "top-of-page

----


  • FORM USER_COMMAND *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

    • Check function code

  • CASE r_ucomm.

  • WHEN '&IC1'.

    • Check field clicked on within ALVgrid report

  • IF rs_selfield-fieldname = 'EBELN'.

    • Read data table, using index of row user clicked on

  • READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.

    • Set parameter ID for transaction screen field

  • SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.

    • Sxecute transaction ME23N, and skip initial data entry screen

  • CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.

  • ENDIF.

  • ENDCASE.

ENDFORM. "user_command

&----


*& Form BUILD_EVENTS

&----


  • Build events table

----


form build_events.

  • data: ls_event type slis_alv_event.

*

  • call function 'REUSE_ALV_EVENTS_GET'

  • exporting

  • i_list_type = 0

  • importing

  • et_events = gt_events[].

  • read table gt_events with key name = slis_ev_end_of_page

  • into ls_event.

  • if sy-subrc = 0.

  • move 'END_OF_PAGE' to ls_event-form.

  • append ls_event to gt_events.

  • endif.

*

  • read table gt_events with key name = slis_ev_end_of_list

  • into ls_event.

  • if sy-subrc = 0.

  • move 'END_OF_LIST' to ls_event-form.

  • append ls_event to gt_events.

  • endif.

endform. " BUILD_EVENTS

&----


*& Form BUILD_PRINT_PARAMS

&----


  • Setup print parameters

----


form build_print_params.

  • gd_prntparams-reserve_lines = '3'. "Lines reserved for footer

  • gd_prntparams-no_coverpage = 'X'.

endform. " BUILD_PRINT_PARAMS

&----


*& Form END_OF_PAGE

&----


form END_OF_PAGE.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

write: sy-uline(50).

skip.

write:/40 'Page:', sy-pagno .

endform. "END_OF_PAGE

&----


*& Form END_OF_LIST

&----


form END_OF_LIST.

data: listwidth type i,

ld_pagepos(10) type c,

ld_page(10) type c.

skip.

write:/40 'Page:', sy-pagno .

endform. "END_OF_LIST

&----


*& Form dynamic_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM dynamic_table .

DATA: lv_s1 TYPE string, lv_s2 TYPE string.

DATA lv_mat TYPE string.

DATA: fieldvalue(10) TYPE c.

ktab[] = jtab[].

delete ADJACENT DUPLICATES FROM ktab COMPARING so.

loop at ktab INTO wa_tab.

  • Field1

wa_flname = 'SO'.

fieldvalue = wa_tab-so.

CONDENSE fieldvalue NO-GAPS.

ASSIGN COMPONENT wa_flname

OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

<fs_fldval> = fieldvalue.

CLEAR fieldvalue.

  • Field2

wa_flname = 'PO'.

fieldvalue = wa_tab-po.

CONDENSE fieldvalue NO-GAPS.

ASSIGN COMPONENT wa_flname

OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

<fs_fldval> = fieldvalue.

CLEAR fieldvalue.

  • Field3

wa_flname = 'DATE'.

fieldvalue = wa_tab-date.

CONDENSE fieldvalue NO-GAPS.

ASSIGN COMPONENT wa_flname

OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

<fs_fldval> = fieldvalue.

CLEAR fieldvalue.

loop at jtab INTO wa_j WHERE so = wa_tab-so.

CONCATENATE 'MAT-' wa_j-mat INTO lv_mat.

wa_flname = lv_mat.

fieldvalue = wa_j-qty.

CONDENSE fieldvalue NO-GAPS.

ASSIGN COMPONENT wa_flname

OF STRUCTURE <fs_dyntable> TO <fs_fldval>.

<fs_fldval> = fieldvalue.

CLEAR: wa_j, fieldvalue.

ENDLOOP.

APPEND <fs_dyntable> TO <t_dyntable>.

CLEAR wa_tab.

FREE <fs_dyntable>.

ENDLOOP.

ENDFORM. " dynamic_table

Ram.