0% found this document useful (0 votes)
22 views2 pages

Answer

Uploaded by

geethagini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Answer

Uploaded by

geethagini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Powered by AI

Copilot

Sure! Let’s go through the code step by step to understand how it works.

Step 1: Define the Internal Table


First, we define an internal table LT_HDR with the same structure as the database table /SIAPP/L_REQ_HDR.
DATA: LT_HDR TYPE TABLE OF /SIAPP/L_REQ_HDR.

Step 2: Build the WHERE Condition

We need to build a dynamic WHERE condition based on the non-initial parameters. This condition will be used to
filter the records when selecting data from the database table.
DATA: LV_WHERE_COND TYPE STRING.

* Build the WHERE condition based on the parameters


IF IV_REQUEST_ID IS NOT INITIAL.
CONCATENATE LV_WHERE_COND 'REQUEST_ID = ' IV_REQUEST_ID INTO LV_WHERE_COND SEPARATED BY ' AND '.
ENDIF.

IF IV_REPLACED_USER IS NOT INITIAL.


CONCATENATE LV_WHERE_COND 'REPLACED_USER = ' IV_REPLACED_USER INTO LV_WHERE_COND SEPARATED BY ' AND '.
ENDIF.

IF IV_DELEGATED_USER IS NOT INITIAL.


CONCATENATE LV_WHERE_COND 'DELEGATED_USER = ' IV_DELEGATED_USER INTO LV_WHERE_COND SEPARATED BY ' AND '.
ENDIF.

IF IV_DELEGATION_FROM IS NOT INITIAL.


CONCATENATE LV_WHERE_COND 'DELEGATION_FROM = ' IV_DELEGATION_FROM INTO LV_WHERE_COND SEPARATED BY ' AND '.
ENDIF.

IF IV_DELEGATION_TO IS NOT INITIAL.


CONCATENATE LV_WHERE_COND 'DELEGATION_TO = ' IV_DELEGATION_TO INTO LV_WHERE_COND SEPARATED BY ' AND '.
ENDIF.

Here, we check each parameter to see if it is not initial. If a parameter is not initial, we add a condition to the
LV_WHERE_COND string. The CONCATENATE statement is used to build the condition string, separating each condition
with ’ AND '.

Step 3: Remove Trailing ‘AND’


After building the WHERE condition, we need to remove any trailing ’ AND ’ from the condition string.
* Remove the trailing ' AND ' if any
IF LV_WHERE_COND CP '* AND '.
LV_WHERE_COND = LV_WHERE_COND+0(*-4).
ENDIF.

This step ensures that the WHERE condition string is correctly formatted without any trailing ’ AND '.

Step 4: Select Data from the Database Table

We use the WHERE condition to select data from the database table /SIAPP/L_REQ_HDR into the internal table LT_HDR.
* Select data from the table based on the WHERE condition
IF LV_WHERE_COND IS NOT INITIAL.
SELECT * FROM /SIAPP/L_REQ_HDR INTO TABLE LT_HDR WHERE (LV_WHERE_COND).
ELSE.
SELECT * FROM /SIAPP/L_REQ_HDR INTO TABLE LT_HDR.
ENDIF.

If the WHERE condition is not empty, we use it to filter the records. Otherwise, we select all records from the table.

Step 5: Process the Results


Finally, we loop through the internal table LT_HDR to process each entry as needed.
* Process the results
LOOP AT LT_HDR INTO DATA(wa_hdr).
" Process each entry as needed
ENDLOOP.

In this loop, you can add any logic to process the data retrieved from the database table.

Summary

1. Define the internal table LT_HDR.


2. Build a dynamic WHERE condition based on non-initial parameters.
3. Remove any trailing ’ AND ’ from the WHERE condition.
4. Select data from the database table using the WHERE condition.
5. Process the data in the internal table LT_HDR.

This approach ensures that you only retrieve records that match the specified parameters, making your data
selection more efficient and relevant.

Does this explanation help? Let me know if you have any more questions!

You might also like