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: 

Chain and field Statement

Former Member
0 Kudos

Hi

What are the “field” and “chain” Statements and use?

Regards

Prajwal.K

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Input Checks in Dialog Modules :

You cannot perform input checks in PAI modules of programs until you have transported the contents of the input fields to the ABAP program. You can then use logical expressions to check the values that the user entered. You should then allow the user to correct any wrong entries before calling further modules.

You can do this by sending warning (type W) or error (type E) messages from PAI modules that are called in conjunction with the statements FIELD and CHAIN.

Checking Single Fields

If you send a warning or error message from a module mod that you called using a FIELDstatement as follows:

FIELD f MODULE mod.

the corresponding input field on the current screen is made ready for input again, allowing the user to enter a new value. If the field is only checked once, the PAI processing continues directly after the FIELDstatement, and the preceding modules are not called again.

Checking a Set of Fields

If a warning or an error message is sent in a module mod1 mod2 … that you called within a processing chain:

CHAIN.

FIELD: f1, f2,...

MODULE mod1.

FIELD: g1, g2,...

MODULE mod2.

...

ENDCHAIN.

all of the input fields on the current screen that belong to the processing chain are made ready for input again – including those that are in FIELD statements after the MODULEstatement. All the other fields are not ready for input. Even if a MODULE statement appears within a processing chain, combined with a FIELD statement, all of the input fields in the chain are made ready for input again – not just the field in question. The user can repeat the input. If the fields in the processing chain are only checked once, the PAI processing continues directly after the automatic checks at the CHAINstatement, and the preceding modules are not called again.

Controlling Input and Data Transport

If you use the FIELD statement outside a processing chain, only a single field is made ready for input when a warning or error message is displayed. If you use FIELD statements between CHAIN - ENDCHAIN, this controls a set of fields. All of the fields controlled by a FIELDstatement are transported back to the screen, bypassing PBO processing. This means that any changes made to the field contents before the message become visible on the screen. This also applies to information

Checking Fields Repeatedly

You may sometimes need to specify the same field in more than one FIELD or CHAIN statement. If one of the corresponding modules sends a warning or error message, PAI processing resumes with the value that the user corrected. However, in this case, processing cannot simply resume at the corresponding FIELD or CHAIN statement if the field in question has already been included in an earlier FIELD or CHAIN statement.

Instead, all of the FIELD and CHAIN statements containing a field in which an error occurred are repeated. PAI processing resumes at the first FIELD or CHAINstatement containing one or several of the fields in which the error occurred and that the user changed the last time the screen was displayed.

PROCESS AFTER INPUT.

FIELD f1 MODULE m1.

FIELD f2 MODULE m2.

CHAIN.

FIELD: f1, f2, f3.

FIELD: f4, f5, f1.

MODULE m3.

MODULE m4.

ENDCHAIN.

CHAIN.

FIELD: f6.

MODULE m5.

ENDCHAIN.

CHAIN.

FIELD f4.

MODULE m6.

ENDCHAIN.

If module m6contains a warning or error message, the screen is displayed again, after which processing resumes with the first CHAIN statement. Module m3 is called since this is the first occurrence of the field f4.

Remaining Functions in the FIELD Statement

All of the functions of the FIELD and CHAINstatements for controlling data transport and conditional module calls can also be used in combination with warning and error messages. The contents of each field are transported at the FIELD statement in which the field occurs. If a warning or error message occurs in a conditional module of a processing chain, all of the fields in that chain will be ready for input when the screen is redisplayed, although not all of the fields will have been transported.

If a warning or error message occurs in a module that is not linked with a FIELD or CHAIN statement, none of the fields on the screen will be ready for input. In this case, the user can only exit the program, but only if a corresponding unconditional module call is provided.

Input Checks in Dialog Modules

PROGRAM demo_dynpro_field_chain.

DATA: ok_code TYPE sy-ucomm,

input1 TYPE i, input2 TYPE i, input3 TYPE i,

input4 TYPE i, input5 TYPE i, input6 TYPE i,

sum TYPE i.

CALL SCREEN 100.

MODULE init_screen_100 OUTPUT.

CLEAR: input1, input2, input3, input4, input5, input6.

SET PF-STATUS 'STATUS_100'.

ENDMODULE.

MODULE cancel INPUT.

LEAVE PROGRAM.

ENDMODULE.

MODULE module_1 INPUT.

IF input1 < 50.

MESSAGE e888(sabapdocu) WITH text-001 '50' text-002.

ENDIF.

ENDMODULE.

MODULE module_2 INPUT.

IF input2 < 100.

MESSAGE e888(sabapdocu) WITH text-001 '100' text-002.

ENDIF.

ENDMODULE.

MODULE module_3 INPUT.

IF input3 < 150.

MESSAGE e888(sabapdocu) WITH text-001 '150' text-002.

ENDIF.

ENDMODULE.

MODULE chain_module_1 INPUT.

IF input4 < 10.

MESSAGE e888(sabapdocu) WITH text-003 '10' text-002.

ENDIF.

ENDMODULE.

MODULE chain_module_2 INPUT.

CLEAR sum.

sum = sum + : input4, input5, input6.

IF sum <= 100.

MESSAGE e888(sabapdocu) WITH text-004 '100' text-002.

ENDIF.

ENDMODULE.

MODULE execution INPUT.

MESSAGE i888(sabapdocu) WITH text-005.

ENDMODULE.

The next screen (statically defined) for screen 100 is 100. It has the following layout:

The screen fields input1 through input6 are assigned to the input fields. The function code of the pushbutton is EXECUTE.

In the GUI status STATUS_100, the icon (F12) is active with function code CANCEL and function type E. Furthermore, the function key F8 is assigned to the function code EXECUTE with the function type <blank>.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

MODULE init_screen_100.

PROCESS AFTER INPUT.

MODULE cancel AT EXIT-COMMAND.

FIELD input1 MODULE module_1.

FIELD input2 MODULE module_2.

FIELD input3 MODULE module_3.

CHAIN.

FIELD input4.

MODULE chain_module_1.

FIELD input5.

FIELD input6 MODULE chain_module_2.

ENDCHAIN.

MODULE EXECUTION.

This program demonstrates how you can check input fields in dialog modules.

The fields input1 through input3 are checked independently of each other in the modules module_1 through module_3. As long as the user does not enter a corresponding value, the screen is repeatedly displayed with the appropriate field ready for input.

The fields input4 through input6 are checked together in a processing chain. If input4 does not satisfy the condition in chain_module_1, all three fields are again ready for input. The same applies if the three fields do not satisfy the condition in chain_module_2.

The EXECUTION module, from which an information message is displayed, is not executed until all six fields satisfy the appropriate conditions.

plz reward if helpful,

thanks and regards,

GAURAV J.

3 REPLIES 3

Former Member
0 Kudos

Input Checks in Dialog Modules :

You cannot perform input checks in PAI modules of programs until you have transported the contents of the input fields to the ABAP program. You can then use logical expressions to check the values that the user entered. You should then allow the user to correct any wrong entries before calling further modules.

You can do this by sending warning (type W) or error (type E) messages from PAI modules that are called in conjunction with the statements FIELD and CHAIN.

Checking Single Fields

If you send a warning or error message from a module mod that you called using a FIELDstatement as follows:

FIELD f MODULE mod.

the corresponding input field on the current screen is made ready for input again, allowing the user to enter a new value. If the field is only checked once, the PAI processing continues directly after the FIELDstatement, and the preceding modules are not called again.

Checking a Set of Fields

If a warning or an error message is sent in a module mod1 mod2 … that you called within a processing chain:

CHAIN.

FIELD: f1, f2,...

MODULE mod1.

FIELD: g1, g2,...

MODULE mod2.

...

ENDCHAIN.

all of the input fields on the current screen that belong to the processing chain are made ready for input again – including those that are in FIELD statements after the MODULEstatement. All the other fields are not ready for input. Even if a MODULE statement appears within a processing chain, combined with a FIELD statement, all of the input fields in the chain are made ready for input again – not just the field in question. The user can repeat the input. If the fields in the processing chain are only checked once, the PAI processing continues directly after the automatic checks at the CHAINstatement, and the preceding modules are not called again.

Controlling Input and Data Transport

If you use the FIELD statement outside a processing chain, only a single field is made ready for input when a warning or error message is displayed. If you use FIELD statements between CHAIN - ENDCHAIN, this controls a set of fields. All of the fields controlled by a FIELDstatement are transported back to the screen, bypassing PBO processing. This means that any changes made to the field contents before the message become visible on the screen. This also applies to information

Checking Fields Repeatedly

You may sometimes need to specify the same field in more than one FIELD or CHAIN statement. If one of the corresponding modules sends a warning or error message, PAI processing resumes with the value that the user corrected. However, in this case, processing cannot simply resume at the corresponding FIELD or CHAIN statement if the field in question has already been included in an earlier FIELD or CHAIN statement.

Instead, all of the FIELD and CHAIN statements containing a field in which an error occurred are repeated. PAI processing resumes at the first FIELD or CHAINstatement containing one or several of the fields in which the error occurred and that the user changed the last time the screen was displayed.

PROCESS AFTER INPUT.

FIELD f1 MODULE m1.

FIELD f2 MODULE m2.

CHAIN.

FIELD: f1, f2, f3.

FIELD: f4, f5, f1.

MODULE m3.

MODULE m4.

ENDCHAIN.

CHAIN.

FIELD: f6.

MODULE m5.

ENDCHAIN.

CHAIN.

FIELD f4.

MODULE m6.

ENDCHAIN.

If module m6contains a warning or error message, the screen is displayed again, after which processing resumes with the first CHAIN statement. Module m3 is called since this is the first occurrence of the field f4.

Remaining Functions in the FIELD Statement

All of the functions of the FIELD and CHAINstatements for controlling data transport and conditional module calls can also be used in combination with warning and error messages. The contents of each field are transported at the FIELD statement in which the field occurs. If a warning or error message occurs in a conditional module of a processing chain, all of the fields in that chain will be ready for input when the screen is redisplayed, although not all of the fields will have been transported.

If a warning or error message occurs in a module that is not linked with a FIELD or CHAIN statement, none of the fields on the screen will be ready for input. In this case, the user can only exit the program, but only if a corresponding unconditional module call is provided.

Input Checks in Dialog Modules

PROGRAM demo_dynpro_field_chain.

DATA: ok_code TYPE sy-ucomm,

input1 TYPE i, input2 TYPE i, input3 TYPE i,

input4 TYPE i, input5 TYPE i, input6 TYPE i,

sum TYPE i.

CALL SCREEN 100.

MODULE init_screen_100 OUTPUT.

CLEAR: input1, input2, input3, input4, input5, input6.

SET PF-STATUS 'STATUS_100'.

ENDMODULE.

MODULE cancel INPUT.

LEAVE PROGRAM.

ENDMODULE.

MODULE module_1 INPUT.

IF input1 < 50.

MESSAGE e888(sabapdocu) WITH text-001 '50' text-002.

ENDIF.

ENDMODULE.

MODULE module_2 INPUT.

IF input2 < 100.

MESSAGE e888(sabapdocu) WITH text-001 '100' text-002.

ENDIF.

ENDMODULE.

MODULE module_3 INPUT.

IF input3 < 150.

MESSAGE e888(sabapdocu) WITH text-001 '150' text-002.

ENDIF.

ENDMODULE.

MODULE chain_module_1 INPUT.

IF input4 < 10.

MESSAGE e888(sabapdocu) WITH text-003 '10' text-002.

ENDIF.

ENDMODULE.

MODULE chain_module_2 INPUT.

CLEAR sum.

sum = sum + : input4, input5, input6.

IF sum <= 100.

MESSAGE e888(sabapdocu) WITH text-004 '100' text-002.

ENDIF.

ENDMODULE.

MODULE execution INPUT.

MESSAGE i888(sabapdocu) WITH text-005.

ENDMODULE.

The next screen (statically defined) for screen 100 is 100. It has the following layout:

The screen fields input1 through input6 are assigned to the input fields. The function code of the pushbutton is EXECUTE.

In the GUI status STATUS_100, the icon (F12) is active with function code CANCEL and function type E. Furthermore, the function key F8 is assigned to the function code EXECUTE with the function type <blank>.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

MODULE init_screen_100.

PROCESS AFTER INPUT.

MODULE cancel AT EXIT-COMMAND.

FIELD input1 MODULE module_1.

FIELD input2 MODULE module_2.

FIELD input3 MODULE module_3.

CHAIN.

FIELD input4.

MODULE chain_module_1.

FIELD input5.

FIELD input6 MODULE chain_module_2.

ENDCHAIN.

MODULE EXECUTION.

This program demonstrates how you can check input fields in dialog modules.

The fields input1 through input3 are checked independently of each other in the modules module_1 through module_3. As long as the user does not enter a corresponding value, the screen is repeatedly displayed with the appropriate field ready for input.

The fields input4 through input6 are checked together in a processing chain. If input4 does not satisfy the condition in chain_module_1, all three fields are again ready for input. The same applies if the three fields do not satisfy the condition in chain_module_2.

The EXECUTION module, from which an information message is displayed, is not executed until all six fields satisfy the appropriate conditions.

plz reward if helpful,

thanks and regards,

GAURAV J.

Former Member
0 Kudos

Chained Statements

The ABAP programming language allows you to concatenate consecutive statements with an identical first part into a chain statement. To do this, you write the identical part for all statements only once and place a colon ( after it. After the colon, write the remaining parts of the individual statements, separating them with commas (,). Ensure that you place a period (.) after the last part to inform the system where the chain ends. When the program is executed, the chained statement is handled the same way as the single ABAP statements would be in their defined sequence.

Statement sequence:

WRITE spfli-cityfrom.

WRITE spfli-cityto.

WRITE spfli-airpto.

Chain statement:

WRITE: spfli-cityfrom, spfli-cityto, spfli-airpto.

In the chain, a colon separates the beginning of the statement from the variable parts. After the colon or commas, you can insert any number of spaces.

You could, for example, write the same statement like this:

WRITE: spfli-cityfrom,

spfli-cityto,

spfli-airpto.

In a chain statement, the first part (before the colon) is not limited to the keyword of the statements.

Statement sequence:

sum = sum + 1.

sum = sum + 2.

sum = sum + 3.

sum = sum + 4.

Chain statement:

sum = sum + : 1, 2, 3, 4.

Comments

Comments are texts that you can write between the statements of your ABAP program to explain their purpose to a reader. Comments are distinguished by the preceding signs * (at the beginning of a line) and " (at any position in a line). If you want the entire line to be a comment, enter an asterisk (*) at the beginning of the line. The system then ignores the entire line when it generates the program. If you want part of a line to be a comment, enter a double quotation mark (") before the comment. The system interprets comments indicated by double quotation marks as spaces.

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

  • PROGRAM SAPMTEST *

  • WRITTEN BY CHARLIE BYTE, 06/27/1995 *

  • LAST CHANGED BY RITA DIGIT, 10/01/1995 *

  • TASK: DEMONSTRATION *

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

PROGRAM sapmtest.

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

  • DECLARATIONS *

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

DATA: flag(1) TYPE c, " global flag

number TYPE i. " counter

......

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

  • PROCESSING BLOCKS *

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

......

The FIELD statement in the screen flow logic allows you to control the moment at which data is passed from screen fields to their corresponding ABAP fields.

To specify this point, use the following statement in the PAI flow logic:

FIELD f.

Data is not transported from the screen field finto the ABAP field f until the FIELD statement is processed. If a field occurs in more than one FIELD statement, its value is passed to the program when the first of the statements is reached.

Only screen fields that do not appear in a FIELDS statement are transferred at the beginning of the PAI event. Do not use fields in PAI modules until they have been passed to the program from the screen. Otherwise the ABAP field will contain the same value as at the end of the previous dialog step.

The exception to this are fields that were initial in the PBO event and are not changed by the user. These are not transported by the FIELD statement. If a field of this type is filled with a value in a PAI module before its corresponding FIELDstatement is executed, any value that you assign to it is not overwritten.

The FIELD statement together with the MODULE statement has further functions in connection with conditional module calls and validity checks .

Controlling the data transfer

PROGRAM demo_dynpro_field.

DATA: ok_code TYPE sy-ucomm,

save_ok LIKE ok_code,

box1(1) TYPE c, box2(1) TYPE c, box3(1) TYPE c, box4(1) TYPE c,

mod1_result1(1) TYPE c, mod1_result2(1) TYPE c,

mod1_result3(1) TYPE c, mod1_result4(1) TYPE c,

mod2_result1(1) TYPE c, mod2_result2(1) TYPE c,

mod2_result3(1) TYPE c, mod2_result4(1) TYPE c,

mod3_result1(1) TYPE c, mod3_result2(1) TYPE c,

mod3_result3(1) TYPE c, mod3_result4(1) TYPE c.

CALL SCREEN 100.

MODULE init_screen_100 OUTPUT.

SET PF-STATUS 'STATUS_100'.

CLEAR: box1, box2, box3, box4.

ENDMODULE.

MODULE user_command_0100 INPUT.

save_ok = ok_code.

CLEAR ok_code.

IF save_ok = 'CANCEL'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE.

MODULE module_1 INPUT.

mod1_result1 = box1.

mod1_result2 = box2.

mod1_result3 = box3.

mod1_result4 = box4.

ENDMODULE.

MODULE module_2 INPUT.

mod2_result1 = box1.

mod2_result2 = box2.

mod2_result3 = box3.

mod2_result4 = box4.

ENDMODULE.

MODULE module_3 INPUT.

mod3_result1 = box1.

mod3_result2 = box2.

mod3_result3 = box3.

mod3_result4 = box4.

ENDMODULE.

The next screen (statically defined) for screen 100 is 100. It has the following layout:

The screen fields box1, box2, box3and box4are assigned to the checkboxes on the left that are ready for input.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

MODULE init_screen_100.

PROCESS AFTER INPUT.

MODULE user_command_0100.

MODULE module_1.

FIELD box2.

MODULE module_2.

FIELD: box1, box3.

MODULE module_3.

In the GUI status STATUS_100, the icon (F12) is active with function code CANCEL.

When the user selects the checkboxes and chooses ENTER to trigger the PAI event, the output fields show the dialog modules in which each screen field is available.

If all of the checkboxes are selected, the result is:

· The screen field box4 is transported in the PAI event, since it does not occur in any FIELDstatements.

· box2 is not transported until before the dialog module module_2, and is therefore not available in user_command_0100 und module_1.

· box1 and box3 are transported before dialog module module_3, and are therefore only available in that module.

Former Member
0 Kudos

hi

We use 'chain' 'End Chain' if we want particular group of fields to be filled in compulsorily. That is the group of fields are mandatory for further processing.

Giving a group of fields in chain-end chain will ensure that all the fields are duly filled in or else it would prompt you to fill the fields

See the below example.

You have two input fields in the selection screen field1 and field2.

You need to open the two fields for input if an error message occurs in a module say, module check.

Then u need to code like this:

chain

field: field1,field2 .

module check.

endchain.

This will help in opening multiple fields(field1 and field2) for input.

if you code as:

field field1 module check.

Then only one field ie, field1 will be opened for input when an error comes in the module check.