2021年11月7日星期日

sap query skip record

 Have you ever wanted to skip or eliminate records from the results of your SAP Query without filters?  There are two easy ways.  You can do it through a small bit of ABAP in the Infoset or via a hidden selection variable in the Infoset.  In both cases, the criteria field for eliminating the records must exist in the join of your Infoset.

Method #1

Use the menu path Goto | Code | Record processing.

In the code window, enter code using the following template:

CHECK table-field NE value.

where table-field is the appropriate table name and field name and value is the criteria value.

In the example above, the criteria field is QMFE-KZLOESCH (deletion flag on quality notification items) and the criteria value is ‘X’.  The ABAP command CHECK effectively kicks out this record during the processing because it does not meet the criteria.  As you might expect, this method also provides some additional flexibility with respect to which records are skipped.  For example, if the criteria field is part of a table attached with a left outer join, you could add an IF…THEN statement to skip over the CHECK statement.  This method is quite concealed from the end user and may be difficult to troubleshoot for someone not familiar with coding in SAP Infosets.

Method #2

Use the menu path Goto | Selections (or press Shift+F7).

Click on the “Create” button (the blank white sheet of paper).

Make sure that the “Selection criterion” option is selected and enter a name for the selection variable.  Although this name does not need to be meaningful, if you have several variables a meaningful name will help you to differentiate them.

In the example above, I used a prefix “s” for selection criteria and “delflg” to indicate that this variable will reference the deletion flag.  Click the green check to continue.  Another popup window appears where you will need to provide additional information for this selection criterion.

At a minimum, you will need to provide a description and a reference field (“FOR”).  This reference field provides the link between this new variable and the table & field in your join – the system will confirm that you have provided an appropriate table & field name.  In the example above, the field is the same as mentioned previously, QMFE-KZLOESCH.  I make it a practice to enter the selection text as well.  If you entered no other data that what is described above, you would have a selection screen variable.

The trick that skips the record is found in the “Extras” field.  In this field, use the following template:

DEFAULT value OPTION NE NO-DISPLAY

where value is the criteria value discussed in method #1 which distinguishes the records to be skipped.  In this case, that value is ‘X’.  The keyword OPTION and modifier NE have the effect of excluding records that are not equal to ‘X’.  The keyword NO-DISPLAY hides the selection variable from the screen.  You could consider removing this keyword to provide full transparency to the end user.  The limitation of using this approach is that no additional criteria can be built around this variable.  Certainly, other selection criterion can be added as necessary.

没有评论:

发表评论

Customer Characteristic

  Characteristic Descriptions are stored in the table - CABNT - Language - SPRAS - Characteristic description - ATBEZ Characteristic Values ...