Application Development and Automation 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: 
Read only

Reg ALV

Former Member
0 Likes
539

Hi,

In ALV I need to display column headers in 2 rows.

like

parent header(A1)........parent header(B1)

child header(AC1),AC2....BC1,BC2....

Plz guide me reg this.

Thanks,

Albert.

1 ACCEPTED SOLUTION
Read only

dani_mn
Active Contributor
0 Likes
510

Hi,

check this program for your requirment.

<b>REPORT ZWA_ALV_HEADER_ITEM .


type-pools:slis.

tables: bkpf,bseg.

data:begin of it_bkpf occurs 0,

bukrs like bkpf-bukrs,
belnr like bkpf-belnr,
gjahr like bkpf-gjahr,
blart like bkpf-BLART,
bldat like bkpf-BLDAT,
end of it_bkpf.


data: begin of it_bseg occurs 0,
buk   like   bseg-bukrs,
sno   like   bseg-belnr,
year  like   bseg-gjahr,

hkont like bseg-HKONT,
kostl like bseg-kostl,
wrbtr like bseg-wrbtr,
end of it_bseg.

data v_repid like sy-repid.

data it_fieldcat type slis_fieldcat_alv occurs 0 with header line.
data x_keyinfo type slis_keyinfo_alv.

select-options:  bukrs for bkpf-bukrs,
                 gjahr for bkpf-gjahr,
                 belnr for bkpf-belnr,
                 blart for bkpf-blart,
                 bldat for bkpf-bldat.


initialization.
  v_repid = sy-repid.
*s_ebeln-low = '1000'.
*s_ebeln-sign = 'I'.
*s_ebeln-option = 'EQ'.
*S_ebeln-high = '5000'.




start-of-selection.
  perform get_data.
  perform get_field.

  perform get_key.
  perform key_modify.

  perform display.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data.

  select bukrs belnr gjahr
         blart bldat
  from bkpf into table it_bkpf
       where belnr in belnr AND
             bukrs in bukrs AND
             gjahr in gjahr AND
             blart in blart AND
             bldat in bldat.

  select bukrs belnr
         gjahr hkont
         kostl wrbtr
     from bseg into table it_bseg
          where belnr in belnr AND
             bukrs in bukrs AND
             gjahr in gjahr.



  EXPORT it_bkpf TO DATABASE indx(dn) ID 'ZCA'.

endform. " get_data
*&---------------------------------------------------------------------*
*& Form get_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_field.

  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name     = v_repid
            i_internal_tabname = 'IT_BKPF'
            i_inclname         = v_repid
       CHANGING
            ct_fieldcat        = it_fieldcat[].


  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name     = v_repid
            i_internal_tabname = 'IT_BSEG'
            i_inclname         = v_repid
       CHANGING
            ct_fieldcat        = it_fieldcat[].

endform. " get_field
*&---------------------------------------------------------------------*
*& Form get_key
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_key.
  x_keyinfo-header01 = 'BUKRS'.
  x_keyinfo-item01 = 'BUK'.
  x_keyinfo-header02 = 'BELNR'.
  x_keyinfo-item02   = 'SNO'.
  x_keyinfo-header03 = 'GJAHR'.
  x_keyinfo-item03   = 'YEAR'.

endform. " get_key
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display.

  call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
       EXPORTING
            i_callback_program = v_repid
            it_fieldcat        = it_fieldcat[]
            i_tabname_header   = 'IT_BKPF'
            i_tabname_item     = 'IT_BSEG'
            is_keyinfo         = x_keyinfo
       TABLES
            t_outtab_header    = it_bkpf
            t_outtab_item      = it_bseg.

endform. " DISPLAY
*&---------------------------------------------------------------------*
*& Form key_modify
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form key_modify.
  loop at it_fieldcat. "Avoid Repitiotion of data.
    case it_fieldcat-fieldname.
      when 'SNO'.
        if it_fieldcat-tabname = 'IT_BKPF'.
          it_fieldcat-no_out = 'X'.
          it_fieldcat-key = space.
        endif.
    endcase.
    modify it_fieldcat index sy-tabix.
  endloop.
  .
endform.</b>

Regards,

Wasim Ahmed

Hi,

In ALV I need to display column headers in 2 rows.

like

parent header(A1)........parent header(B1)

child header(AC1),AC2....BC1,BC2....

Plz guide me reg this.

Thanks,

Albert.

3 REPLIES 3
Read only

Former Member
0 Likes
510

Use FM 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

Create two internal tables one for parent and one for child and pass these two to the FM.

Check this sample program and try to map it to your requirement.

REPORT ZHIER_ALV.

TYPE-POOLS:SLIS.

TABLES: EKKO,EKPO.

DATA : BEGIN OF IT_EKKO OCCURS 0,

EBELN LIKE EKKO-EBELN,

BUKRS LIKE EKKO-BUKRS,

LIFNR LIKE EKKO-LIFNR,

BEDAT LIKE EKKO-BEDAT,

END OF IT_EKKO.

DATA : BEGIN OF IT_EKPO OCCURS 0,

SNO LIKE EKPO-EBELN,

EBELP LIKE EKPO-EBELP,

MENGE LIKE EKPO-MENGE,

NETWR LIKE EKPO-NETWR,

END OF IT_EKPO.

DATA V_REPID LIKE SY-REPID.

DATA IT_FIELDCAT TYPE SLIS_FIELDCAT_ALV OCCURS 0 WITH HEADER LINE.

DATA X_KEYINFO TYPE SLIS_KEYINFO_ALV.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:S_EBELN FOR EKKO-EBELN.

SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.

V_REPID = SY-REPID.

S_EBELN-LOW = '4500000000'.

S_EBELN-SIGN = 'I'.

S_EBELN-OPTION = 'EQ'.

S_EBELN-HIGH = '6000000270'.

APPEND S_EBELN.

START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM GET_FIELD.

PERFORM GET_KEY.

PERFORM KEY_MODIFY.

PERFORM DISPLAY.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_DATA.

SELECT EBELN BUKRS LIFNR BEDAT

FROM EKKO

INTO TABLE IT_EKKO

WHERE EBELN IN S_EBELN.

SELECT EBELN EBELP MENGE NETWR

FROM EKPO

INTO TABLE IT_EKPO

WHERE EBELN IN S_EBELN.

ENDFORM. " get_data

&----


*& Form get_field

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_FIELD.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_EKKO'

I_INCLNAME = V_REPID

CHANGING

CT_FIELDCAT = IT_FIELDCAT[].

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = V_REPID

I_INTERNAL_TABNAME = 'IT_EKPO'

I_INCLNAME = V_REPID

CHANGING

CT_FIELDCAT = IT_FIELDCAT[]

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

ENDFORM. " get_field

&----


*& Form get_key

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GET_KEY.

X_KEYINFO-HEADER01 = 'EBELN'.

X_KEYINFO-ITEM01 = 'SNO'.

ENDFORM. " get_key

&----


*& Form DISPLAY

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

IT_FIELDCAT = IT_FIELDCAT[]

I_TABNAME_HEADER = 'IT_EKKO'

I_TABNAME_ITEM = 'IT_EKPO'

IS_KEYINFO = X_KEYINFO

TABLES

T_OUTTAB_HEADER = IT_EKKO

T_OUTTAB_ITEM = IT_EKPO

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ENDFORM. " DISPLAY

&----


*& Form key_modify

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM KEY_MODIFY.

LOOP AT IT_FIELDCAT. "Avoid Repitiotion of data.

CASE IT_FIELDCAT-FIELDNAME.

WHEN 'SNO'.

IF IT_FIELDCAT-TABNAME = 'IT_EKPO'.

IT_FIELDCAT-NO_OUT = 'X'.

IT_FIELDCAT-KEY = SPACE.

ENDIF.

ENDCASE.

MODIFY IT_FIELDCAT INDEX SY-TABIX.

ENDLOOP.

ENDFORM. " key_modify

Message was edited by: mukesh kumar

Read only

Former Member
0 Likes
510

Hi Albert,

You can do this using ALV Hierarchial Report and ALV Tree Report. There is a function Module for doing these.

Cheers,

Prashanth

Read only

dani_mn
Active Contributor
0 Likes
511

Hi,

check this program for your requirment.

<b>REPORT ZWA_ALV_HEADER_ITEM .


type-pools:slis.

tables: bkpf,bseg.

data:begin of it_bkpf occurs 0,

bukrs like bkpf-bukrs,
belnr like bkpf-belnr,
gjahr like bkpf-gjahr,
blart like bkpf-BLART,
bldat like bkpf-BLDAT,
end of it_bkpf.


data: begin of it_bseg occurs 0,
buk   like   bseg-bukrs,
sno   like   bseg-belnr,
year  like   bseg-gjahr,

hkont like bseg-HKONT,
kostl like bseg-kostl,
wrbtr like bseg-wrbtr,
end of it_bseg.

data v_repid like sy-repid.

data it_fieldcat type slis_fieldcat_alv occurs 0 with header line.
data x_keyinfo type slis_keyinfo_alv.

select-options:  bukrs for bkpf-bukrs,
                 gjahr for bkpf-gjahr,
                 belnr for bkpf-belnr,
                 blart for bkpf-blart,
                 bldat for bkpf-bldat.


initialization.
  v_repid = sy-repid.
*s_ebeln-low = '1000'.
*s_ebeln-sign = 'I'.
*s_ebeln-option = 'EQ'.
*S_ebeln-high = '5000'.




start-of-selection.
  perform get_data.
  perform get_field.

  perform get_key.
  perform key_modify.

  perform display.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data.

  select bukrs belnr gjahr
         blart bldat
  from bkpf into table it_bkpf
       where belnr in belnr AND
             bukrs in bukrs AND
             gjahr in gjahr AND
             blart in blart AND
             bldat in bldat.

  select bukrs belnr
         gjahr hkont
         kostl wrbtr
     from bseg into table it_bseg
          where belnr in belnr AND
             bukrs in bukrs AND
             gjahr in gjahr.



  EXPORT it_bkpf TO DATABASE indx(dn) ID 'ZCA'.

endform. " get_data
*&---------------------------------------------------------------------*
*& Form get_field
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_field.

  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name     = v_repid
            i_internal_tabname = 'IT_BKPF'
            i_inclname         = v_repid
       CHANGING
            ct_fieldcat        = it_fieldcat[].


  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            i_program_name     = v_repid
            i_internal_tabname = 'IT_BSEG'
            i_inclname         = v_repid
       CHANGING
            ct_fieldcat        = it_fieldcat[].

endform. " get_field
*&---------------------------------------------------------------------*
*& Form get_key
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_key.
  x_keyinfo-header01 = 'BUKRS'.
  x_keyinfo-item01 = 'BUK'.
  x_keyinfo-header02 = 'BELNR'.
  x_keyinfo-item02   = 'SNO'.
  x_keyinfo-header03 = 'GJAHR'.
  x_keyinfo-item03   = 'YEAR'.

endform. " get_key
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display.

  call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
       EXPORTING
            i_callback_program = v_repid
            it_fieldcat        = it_fieldcat[]
            i_tabname_header   = 'IT_BKPF'
            i_tabname_item     = 'IT_BSEG'
            is_keyinfo         = x_keyinfo
       TABLES
            t_outtab_header    = it_bkpf
            t_outtab_item      = it_bseg.

endform. " DISPLAY
*&---------------------------------------------------------------------*
*& Form key_modify
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form key_modify.
  loop at it_fieldcat. "Avoid Repitiotion of data.
    case it_fieldcat-fieldname.
      when 'SNO'.
        if it_fieldcat-tabname = 'IT_BKPF'.
          it_fieldcat-no_out = 'X'.
          it_fieldcat-key = space.
        endif.
    endcase.
    modify it_fieldcat index sy-tabix.
  endloop.
  .
endform.</b>

Regards,

Wasim Ahmed