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: 

Initialization in an ALV report

Former Member
0 Kudos
628

Can any one help me?

I do not understand in the initialization, from where &1, &2,&3 etc values are passed.

In an ALV report, I have the following code:

data: g_tabname TYPE slis_tabname VALUE 'IT_OUTPUT'.

INITIALIZATION.

  DEFINE heading.

    clear ls_fieldcat.

    ls_fieldcat-tabname       = &1.

    ls_fieldcat-fieldname     = &2.

    ls_fieldcat-key           = &3.

    ls_fieldcat-reptext_ddic  = &4.

    ls_fieldcat-outputlen     = &5.

    ls_fieldcat-checkbox      = &6.

    ls_fieldcat-edit          = &7.

    ls_fieldcat-input         = &8.

    append ls_fieldcat to  gt_fieldcat.

  END-OF-DEFINITION.

.

.

.

START-OF-SELECTION.

PERFORM f_process_data.

  IF it_output[] IS INITIAL.

*    MESSAGE i000(z1) WITH text-031.

    MESSAGE text-078  TYPE c_i.

    STOP.

  ELSE.

    PERFORM f_layout_init USING gs_layout.

    PERFORM f_fieldcat_init USING gt_fieldcat[].

*    PERFORM f_eventtab_build USING gt_events[].

*    PERFORM SUB_EVENT.

    PERFORM f_call_alv.

  ENDIF.

*----------------------------------------------------------------------*

*&      Form  FIELDCAT_INIT  PWA                                            *

*&---------------------------------------------------------------------*

FORM f_fieldcat_init

      USING rt_fieldcat TYPE slis_t_fieldcat_alv.

  DATA: ls_fieldcat TYPE slis_fieldcat_alv.

  g_repid = sy-repid.

* Create Catalog for all the fields *

  heading g_tabname:

'BUKRS'        ' '      text-001  '6'   ' ' ' ' ' ',
'EBELN'        ' '      text-002  '10'   ' ' ' ' ' ',
'BEDAT'        ' '      text-003  '10'   ' ' ' ' ' ',
'UDATE'        ' '      text-079  '12'  ' ' ' ' ' ',
'EKORG'        ' '      text-004  '10'  ' ' ' ' ' ',
'EKGRP'        ' '      text-005  '2'  ' ' ' ' ' ',
'KNTTP'        ' '      text-006  '4'  ' ' ' ' ' ',


  """" I also do not understand why this colon space colon space colon space ... used in the above lines

.

.

.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

      i_program_name         = g_repid

      i_internal_tabname     = g_tabname

*      i_client_never_display = text-031

    CHANGING

      ct_fieldcat            = gt_fieldcat.

ENDFORM.                   

1 ACCEPTED SOLUTION

hemanth_kumar21
Contributor
0 Kudos
225

Hi Mohammed Pasha,

INITIALIZATION.

  DEFINE heading.

                       DEFINE is a keyword to declare a Macro.

                       the values &1 &2... are coming from  below code:

heading g_tabname

'BUKRS'        ' '      text-001  '6'   ' ' ' ' ' ',

BURKS         -> &1

text-001        -> &3

6                  -> &4 ... so on

'BUKRS'    ' '  text-001  '6'   ' ' ' ' ' ',

"""" I also do not understand why this colon space colon space colon space ... used in the above lines

  ls_fieldcat-tabname       = &1.

ls_fieldcat-fieldname     = &2.

ls_fieldcat-key           = &3.

ls_fieldcat-reptext_ddic  = &4.

ls_fieldcat-outputlen     = &5.

ls_fieldcat-checkbox      = &6.

ls_fieldcat-edit          = &7.

ls_fieldcat-input         = &8.

as per your code for BUKRS they want pass only fiedname, outputlen ...

as they dont want to pass the values for remaining field they are simply passing SPACE with colon.

you can find more information about macro in the below link.

https://help.sap.com/abapdocu_70/en/ABAPDEFINE.htm

I hope your query got resolved.

Thanks.

Regards,

Hemanth K M.

7 REPLIES 7

hemanth_kumar21
Contributor
0 Kudos
226

Hi Mohammed Pasha,

INITIALIZATION.

  DEFINE heading.

                       DEFINE is a keyword to declare a Macro.

                       the values &1 &2... are coming from  below code:

heading g_tabname

'BUKRS'        ' '      text-001  '6'   ' ' ' ' ' ',

BURKS         -> &1

text-001        -> &3

6                  -> &4 ... so on

'BUKRS'    ' '  text-001  '6'   ' ' ' ' ' ',

"""" I also do not understand why this colon space colon space colon space ... used in the above lines

  ls_fieldcat-tabname       = &1.

ls_fieldcat-fieldname     = &2.

ls_fieldcat-key           = &3.

ls_fieldcat-reptext_ddic  = &4.

ls_fieldcat-outputlen     = &5.

ls_fieldcat-checkbox      = &6.

ls_fieldcat-edit          = &7.

ls_fieldcat-input         = &8.

as per your code for BUKRS they want pass only fiedname, outputlen ...

as they dont want to pass the values for remaining field they are simply passing SPACE with colon.

you can find more information about macro in the below link.

https://help.sap.com/abapdocu_70/en/ABAPDEFINE.htm

I hope your query got resolved.

Thanks.

Regards,

Hemanth K M.

0 Kudos
225

Hi All,

Is using of Macros is not obsolete?

Regards,

Pasha

0 Kudos
225

MACROS are obsolete. I hope you are aware of that we can see those details in SLIN check.

venkat_aileni
Contributor
0 Kudos
225

Hello-

Below statement in your Initialization part defines a MACRO.

DEFINE makro.

   statements

END-OF-DEFINITION.

Secondly:

  heading g_tabname:

'BUKRS'        ' '      text-001  '6'   ' ' ' ' ' ',
'EBELN'        ' '      text-002  '10'   ' ' ' ' ' ',
'BEDAT'        ' '      text-003  '10'   ' ' ' ' ' ',
'UDATE'        ' '      text-079  '12'  ' ' ' ' ' ',
'EKORG'        ' '      text-004  '10'  ' ' ' ' ' ',
'EKGRP'        ' '      text-005  '2'  ' ' ' ' ' ',
'KNTTP'        ' '      text-006  '4'  ' ' ' ' ' ',


  """" I also do not understand why this colon space colon space colon space ... used in the above lines

It's just like in our sub-routine using parameters.

For more details refer below link:

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/content.htm

-Venkat

Former Member
0 Kudos
225

Dear Mohammed,

In ABAP, when a same set of code is to be reused in the program again and again, MACROS are used.

INITIALIZATION event in your program uses one such MACRO.

The MACRO in your code is named Heading an has the definition as shown below.

DEFINE heading.

   clear ls_fieldcat. 

    ls_fieldcat-tabname        = &1.

    ls_fieldcat-fieldname      = &2.

    ls_fieldcat-key                 = &3.

    ls_fieldcat-reptext_ddic  = &4.

    ls_fieldcat-outputlen        = &5.

    ls_fieldcat-checkbox      = &6.

    ls_fieldcat-edit                = &7.

    ls_fieldcat-input              = &8.

APPEND ls_fieldcat TO gt_fieldcat.

END-OF-DEFINITION.

Functionality of the above MACRO: The MACRO aims at filling the field catalog values from work area to an internal table.

&1, &2 etc refer to the different values which would be filled into the work area by the program when  the MACRO is called. To understand more, please see the details below.

After the MACRO is defined, it is called in the program. One such example is below.

The below line calls the MACRO that is already defined.

HEADING  tabname: 

Filling values is done by the below lines. 

'BUKRS'        ' '      text-001  '6'   ' ' ' ' ' ',

In runtime, the fields &1 would be replaced with 'BUKRS' and &2 with ' ' and so on respectively.

    ls_fieldcat-tabname              = &1. 

    ls_fieldcat-fieldname      = &2.

    ls_fieldcat-key                 = &3.

    ls_fieldcat-reptext_ddic  = &4.

    ls_fieldcat-outputlen        = &5.

    ls_fieldcat-checkbox      = &6.

    ls_fieldcat-edit                = &7.

    ls_fieldcat-input              = &8.

The ' ' means that an empty space is being moved into the work area.

Hope both of your queries is answered.

Warm Regards,

Ram


Former Member
0 Kudos
225

Hi Mohammed,

    ls_fieldcat-tabname       = &1.

    ls_fieldcat-fieldname     = &2.

    ls_fieldcat-key           = &3.

    ls_fieldcat-reptext_ddic  = &4.

    ls_fieldcat-outputlen     = &5.

    ls_fieldcat-checkbox      = &6.

    ls_fieldcat-edit          = &7.

    ls_fieldcat-input         = &8.

This is one of the method used to append data to field catalog.

&1,&2,&3,&4,&5,&6,&7,&8.

are the position of the fields that should be passed to the internal table of the field catlog ( IS_FIELDCAT).

In your case to this

'BUKRS'        ' '      text-001  '6'   ' ' ' ' ' ',

BUKRS  --- &1.

'TEXT-001 ' ----- &2.

Hope you understood now its simply an other way to fill the internal table of field catlog.

If  useful plz like   

With Regards,

ROUNAK


former_member184569
Active Contributor
0 Kudos
225

Hi Mohammed,

Check this document.. The first section clearly answers the gist of your question.

http://scn.sap.com/community/abap/blog/2012/10/28/use-macros-use-them-wisely

Also see this document on macros.

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db972835c111d1829f0000e829fbfe/content.htm