Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
47 views

Chain - Module Pool Programming

The document discusses using CHAIN and ENDCHAIN statements in ABAP to validate input fields and allow them to remain enabled after an error message. It provides the syntax, an example problem of an input field becoming disabled after an error, and the solution of using CHAIN and ENDCHAIN to keep the field enabled so the user can correct invalid input.

Uploaded by

sajad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Chain - Module Pool Programming

The document discusses using CHAIN and ENDCHAIN statements in ABAP to validate input fields and allow them to remain enabled after an error message. It provides the syntax, an example problem of an input field becoming disabled after an error, and the solution of using CHAIN and ENDCHAIN to keep the field enabled so the user can correct invalid input.

Uploaded by

sajad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Using CHAIN and ENDCHAIN for

Input Field Validation in SAP


ABAP Module Pool
Programming

In SAP ABAP programming, CHAIN and ENDCHAIN are control statements used within
module pools to iterate over a set of records and perform operations on them.
Here's how they work:

CHAIN: The CHAIN statement is used to begin a loop that iterates over a set of
records in a specified internal table. It's often followed by FETCH NEXT CURSOR
statement to fetch the next record in the internal table. Each iteration of the
loop processes one record at a time.

ENDCHAIN: The ENDCHAIN statement marks the end of the loop initiated by
CHAIN . It's used to close the loop block.

Purpose :-
The Purpose of CHAIN and ENDCHAIN is to validate the field input.

Usually in Input screen, Whenever the user gives an input and there is no
record present, User input is restricted by an error. This error message
disables the input screen and now the user cannot provide correct values in
the input field as it is disabled by the message.

To overcome this issue, Chain and ENDCHAIN comes into the flow logic of
the screen where the input fields are validated and remain enabled after
error message.

Syntax :-

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 1
CHAIN.
FIELD : ( Field1, Field2 ——— ) Module ( Module name ).
ENDCHAIN.

Requirement :-
Suppose, We are running our previous program that we have used in the
previous part.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 2
Suppose, I am passing a wrong order number and now What I want is that the
System should give a message that Order Number is not correct.

Solution :-
Step 1 :- Go to se91 and write a message in message class.

Step 2 :- Open the PAI logic of our program.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 3
Step 3 :- Now execute the program and provide some incorrect order number
and click on submit button.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 4
Note :- We are getting the message as Order number is not correct.

But there is a measure problem with the code, the input field of order
number is now disabled and we cannot pass any input to it.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 5
But Customer wants that, the field should be enabled so that He / She can
pass the correct order number.

So, for that purpose, we will use Chain and ENDCHAIN.

Step 4 :- Open the flow logic of our screen, write the below code for CHAIN
and ENDCHAIN.

Step 5 :- Double click on the Validate → It will give a popup → Click on yes →
Select master program and press enter.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 6
Step 6 :- Write the code into the above module.

Code :-
*&--------------------------------------------------------------
*& Modulpool ZAR_SUB_SCREEN
*&--------------------------------------------------------------
*&
*&--------------------------------------------------------------
PROGRAM zar_sub_screen.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 7
TABLES : zar_header.
TYPES : BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
END OF ty_header.

DATA : lt_header TYPE TABLE OF ty_header,


ls_header TYPE ty_header.
*&--------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
*&--------------------------------------------------------------
*&
*&--------------------------------------------------------------
MODULE status_0100 OUTPUT.
SET PF-STATUS 'HEADER'.
SET TITLEBAR 'HDR'.
ENDMODULE.
*&--------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
*&--------------------------------------------------------------
* text
*---------------------------------------------------------------
MODULE user_command_0100 INPUT.
IF sy-ucomm EQ 'SUBMIT'.
SELECT order_number order_date
payment_mode total_amount currency
FROM zar_header INTO TABLE lt_header
WHERE order_number = zar_header-order_number.

IF lt_header IS NOT INITIAL.


READ TABLE lt_header INTO ls_header INDEX 1.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 8
IF sy-subrc EQ 0.
zar_header-order_date = ls_header-order_date.
zar_header-payment_mode = ls_header-payment_mode.
zar_header-total_amount = ls_header-total_amount.
zar_header-currency = ls_header-currency.
ENDIF.

ENDIF.
ENDIF.

IF sy-ucomm EQ 'BACK'.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE.
*&--------------------------------------------------------------
*& Module EXIT INPUT
*&--------------------------------------------------------------
* text
*---------------------------------------------------------------
MODULE exit INPUT.
IF sy-ucomm EQ 'CANCEL'.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE.
*&--------------------------------------------------------------
*& Module VALIDATE INPUT
*&--------------------------------------------------------------
* text
*---------------------------------------------------------------
MODULE validate INPUT.
SELECT order_number order_date
payment_mode total_amount currency
FROM zar_header INTO TABLE lt_header
WHERE order_number = zar_header-order_number.

IF lt_header IS INITIAL.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 9
MESSAGE e001(zar_msg).
ENDIF.
ENDMODULE.

Execute the code :-

Provide a wrong input and click on submit button.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 10
We are getting the message but still the Order number field is enabled and we
can pass the correct input into it.

Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 11
Using CHAIN and ENDCHAIN for Input Field Validation in SAP ABAP Module Pool Programming 12

You might also like