Setting Fields and Values in TCD Dynamically

Dynamic Setting of DYNPRO Fields and Values Inside a Loop

If you use the correct index of the line from the command interface where you want to dynamically modify the fieldname or the value, then for first execution this index is correct. Each modification (inside a DO…ENDDO) after the first TCD execution will not find the correct index unless you take account of how eCATT modifies the command interface.

For example, transaction SE16 with table SPFLI:

The following code causes an error on the second pass:

DO ( 2 ).

SE16_1-DYNPRO[2]-FIELD[4]-VALIN = 'LH'.

SE16_1-DYNPRO[2]-FIELD[9]-VALIN = 0400.

TCD ( SE16 , SE16_1 ).

ENDDO.

The command interface gets modified automatically during TCD execution. All lines which have the MODE  ‘I’ or ‘O’ are deleted because these are not needed during execution (they are needed only during maintenance of the eCATT script). The problem occurs at the next modification with the previously used index. The actual index will point to a different line and so the wrong lines will be modified. For the above example, the following code would work (however, see below for a simpler solution):

DO ( 2 ).

IF ( &LPC = 1 ).

SE16_1-DYNPRO[2]-FIELD[4]-VALIN = 'LH'.

SE16_1-DYNPRO[2]-FIELD[9]-VALIN = 0400.

ELSE.

SE16_1-DYNPRO[2]-FIELD[3]-VALIN = 'AA'.

SE16_1-DYNPRO[2]-FIELD[4]-VALIN = 0017.

ENDIF.

TCD ( SE16 , SE16_1 ).

ENDDO.

Solution

       1.      Open the TCD command interface in the structure editor and display the field list of the screen (Dynpro) whose fields will be modified later dynamically.

       2.      Sort the field list by moving all entries with MODE  ‘I’ or ‘O’ to the end of the list, so that these fields get higher indices than the fields with MODE  ‘S’, ‘C’ or ‘G’, which are used at the TCD execution.

       3.      Now you can modify the fields by using the correct indices, because the indices are not affected by the deletion of the field entries with higher index.