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

ALV doubt

Former Member
0 Likes
779

Hi,

I have a definition as follows :

DEFINE XA.

S1 = &1.

append S1 to int_1.

END-OF-DEFINITION

When I double click on XA I get the following:

FORM f1_1000.

XA 'MSEG MATNR 0101'.

XA 'MSEG WERKS 0202'.

XA 'MSEG LGORT 0303'.

XA 'MSEG BWART 0704'.

I need to underatand what the code above means.

Also in the field calatlog there is a loop on int_1 used above

FORM build_fieldcatalog.

...

LOOP AT int_1.

CLEAR fc_flat.

fc_flat-fieldname = int_1-fieldname.

fc_flat-ref_tabname = int_1-tabname.

fc_flat-ref_fieldname = int_1-fieldname.

Now I want to introduce new field in the field ALV and make it from 64 to 65 fields.

In order to do this I how should i change the field catalog. Thanks.

5 REPLIES 5
Read only

Former Member
0 Likes
740

Hi SV,

Refer this code :

form FIELDCAT using p_i_fieldcat TYPE SLIS_T_FIELDCAT_ALV.

REFRESH P_I_FIELDCAT.

PERFORM FILL_FCAT USING '1' 'PERNR' 'I_TAB' 'PERSONNEL NO' '15' '1' .

PERFORM FILL_FCAT USING '2' 'VORNA' 'I_TAB' 'FIRST NAME' '10' '1' .

PERFORM FILL_FCAT USING '3' 'MIDNM' 'I_TAB' 'MIDDLE NAME' '10' '1' .

PERFORM FILL_FCAT USING '4' 'NACHN' 'I_TAB' 'LAST NAME' '10' '1' .

form FILL_FCAT using P_COL_POS TYPE SLIS_FIELDCAT_ALV-COL_POS

P_FIELDNAME TYPE SLIS_FIELDCAT_ALV-FIELDNAME

P_TABNAME TYPE SLIS_FIELDCAT_ALV-TABNAME

P_SELTEXT TYPE SLIS_FIELDCAT_ALV-SELTEXT_L

P_OUTPUTLEN TYPE SLIS_FIELDCAT_ALV-OUTPUTLEN

P_ROW_POS TYPE SLIS_FIELDCAT_ALV-ROW_POS.

CLEAR L_FIELDCAT.

L_FIELDCAT-COL_POS = P_COL_POS.

L_FIELDCAT-FIELDNAME = P_FIELDNAME.

L_FIELDCAT-TABNAME = P_TABNAME.

L_FIELDCAT-SELTEXT_L = P_SELTEXT.

L_FIELDCAT-OUTPUTLEN = P_OUTPUTLEN.

L_FIELDCAT-ROW_POS = P_ROW_POS.

APPEND L_FIELDCAT TO I_FIELDCAT.

for adding a new field just add one for perform like this .

PERFORM FILL_FCAT USING '6' 'STRAS' 'I_TAB' 'HOME ADDRESS 1' '40' '1' .

Reward points if helpful.

Regards,

Hemant<b></b>

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
740

Hi,

Not very sure.But you can just try the new field at last.

FORM f1_1000.

XA 'MSEG MATNR 0101'.

XA 'MSEG WERKS 0202'.

XA 'MSEG LGORT 0303'.

XA 'MSEG BWART 0704'.

...

XA 'MSEG new_field

Read only

Former Member
0 Likes
740

Hi

See the following for your first part of doubt regarding MACROS.

Macros

If you want to reuse the same set of statements more than once in a program, you can include them in a macro. For example, this can be useful for long calculations or complex WRITE statements. You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.

The following statement block defines a macro macro:

DEFINE makro.

statements

END-OF-DEFINITION.

You must specify complete statements between DEFINE and END-OF-DEFINITION. These statements can contain up to nine placeholders &1, &2,...., &9). You must define the macro before the point in the program at which you want to use it.

Macros do not belong to the definition part of the program. This means that the DEFINE statement block is not interpreted before the processing blocks in the program. At the same time, however, macros are not operational statements that are executed within a processing block at runtime. When the program is generated, macro definitions are not taken into account at the point at which they are defined. For this reason, they do not appear in the overview of the structure of processing logic.

A macro definition inserts a form of shortcut at any point in a program and can be used at any subsequent point in the program. As the programmer, you must ensure that the macro definition occurs in the program before the macro itself is used. Particular care is required if you use both macros and include programs, since not all include programs are included in the syntax check (exception: TOP include).

To use a macro, use the following form:

makro [p1 p2... p9].

When the program is generated, the system replaces the macro by the appropriate statements and the placeholders &1, &2, …, &9 by the parameter p1, p2, …, p9. You can use macros within macros. However, a macro cannot call itself.

REPORT demo_mod_tech_macros.

DATA: result TYPE i,

n1 TYPE i VALUE 5,

n2 TYPE i VALUE 6.

DEFINE operation.

result = &1 &2 &3.

output &1 &2 &3 result.

END-OF-DEFINITION.

DEFINE output.

write: / 'The result of &1 &2 &3 is', &4.

END-OF-DEFINITION.

operation 4 + 3.

operation 2 ** 7.

operation n2 - n1.

This produces the following output:

The result of 4 + 3 is 7

The result of 2 ** 7 is 128

The result of N2 - N1 is 1

In this example, the two macros operation and output are defined. output is nested in operation. operation is called three times with different parameters. Note how the placeholders &1, &2,... are replaced in the macros.

The following example shows that a macro definition only works in the program lines following its definition. Do not copy it!

Let us have a look at a program with a subroutine test:

PROGRAM macro_test.

...

FORM test.

WRITE '...'.

ENDFORM.

We can rewrite the program by introducing a macro macro:

PROGRAM macro_test.

...

FORM test.

DEFINE macro.

WRITE '...'.

ENDFORM.

END-OF-DEFINITION.

MACRO.

Inserting the macro changes nothing in the generated form of the program. Processing blocks - here a subroutine - are always indivisible. We could also write the program as follows:

PROGRAM macro_test.

...

DEFINE macro.

WRITE '...'.

ENDFORM.

END-OF-DEFINITION.

...

FORM test.

MACRO.

The most essential feature of a macro definition is that it should occur before the macro is used.

Macro in ABAP

*

  • Macro in ABAP

*

*

REPORT ZMACRO.

DATA: RESULT TYPE I,

N1 TYPE I VALUE 5,

N2 TYPE I VALUE 6.

DEFINE OPERATION.

RESULT = &1 &2 &3.

OUTPUT &1 &2 &3 RESULT.

END-OF-DEFINITION.

DEFINE OUTPUT.

WRITE: / 'The result of &1 &2 &3 is', &4.

END-OF-DEFINITION.

OPERATION 4 + 3.

OPERATION 2 ** 7.

OPERATION N2 - N1.

*-- End of Program

Second part:

You add the new field in the internal table int_1 of Field catalog , fetch the value of it into that field and build the code for field catalog like any other field and use.

Reward points if useful

Regards

Anji

Read only

Former Member
0 Likes
740

For your first question

XA is a macro to build the field catalog

If you want to add one more field in fieldcatalog , just add that in XA macro,

but before that <b>can you show the declaration for int_1</b>

XA 'MSEG MATNR 0101'.

XA 'MSEG WERKS 0202'.

XA 'MSEG LGORT 0303'.

XA 'MSEG BWART 0704'.

<b>XA 'MSEG XXXXX 0704'.</b> " add the field here

Read only

Former Member
0 Likes
740

Hi,

It seems that for building field catalog it is getting fields from int_1 itab so check int_1 itab chk its structure. and add one record (i.e. the 65th field name which u want to add)

u can write that codes here...(bcoz it is only one..)


FORM build_fieldcatalog.
...
"Write ur codes to append one field in int_1 here
LOOP AT int_1.
CLEAR fc_flat.
fc_flat-fieldname = int_1-fieldname.
fc_flat-ref_tabname = int_1-tabname.
fc_flat-ref_fieldname = int_1-fieldname.

also,

add field here also...


XA 'MSEG MATNR +01+01'.
XA 'MSEG WERKS +02+02'.
XA 'MSEG LGORT +03+03'.
XA 'MSEG BWART +07+04'.
"ur new field... 

if i understood codes then this must do...

Summary: u just want to add one record to int_1 for ur new field thats all...

Message was edited by:

Jogdand M B

Message was edited by:

Jogdand M B