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: 

Hi Experts...

Former Member
0 Kudos

can anyone plz help me with when to use rp_provide_from_last and loop at and also provide statements...

rewards for best answer assured.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

RP_PROVIDE_FROM_LAST

You use macro RP_PROVIDE_FROM_LAST in programs for the logical databases PNP and PAP where the last data record for a period (can be a subtype) is read from an infotype table. The infotype table has been filled earlier (for example, with GET PERNR or RP_READ_INFOTYPE). This macro is only helpful if the infotype (or subtype) has time constraint 1 or 2.

Prerequisites

• The validity begin date of the time period must be before or the same as the validity end date.

• Validity start and end dates are correct (preferably of the type DATE).

• The infotype table is sorted in ascending order. Otherwise, you would receive the last fitting table entry that might not necessarily correspond to the last time entry.

Features

The macro RP_PROVIDE_FROM_LAST makes sure that the last entry for a specified period is placed in the table header entry of the report output list.

Parameters

RP_PROVIDE_FROM_LAST inftytab subty beg end

IN : 1) Name of the internal table

2) Subtype required or SPACE if no subtype is being specified

3) Validity begin date of the time interval

4) Validity end date of the time interval

OUT: 1) PNP-SW-FOUND: has the value 0 if there is no matching entry in the infotype table in the given time period. Otherwise it has the value 1.

2) The matching table header entry if PNP-SW-FOUND = 1 or

the cleared table header entry if PNP-SW-FOUND = 0

Example:

RP_PROVIDE_FROM_LAST P0021 '1' PN-BEGDA PN-ENDDA.

IF PNP-SW-FOUND EQ '1'.

...

ENDIF.

OR

RP_PROVIDE_FROM_LAST P0001 SPACE PN-BEGDA PN-ENDDA.

IF PNP-SW-FOUND EQ '0'.

WRITE: / 'Error: Org. assignment is missing'. REJECT.

ENDIF.

Syntax Diagram

LOOP AT itab

Syntax

LOOP AT itab result [cond].

...

ENDLOOP.

Effect

The LOOP and ENDLOOP statements define a loop around a statement block. The LOOP statement reads lines from internal table itab sequentially. You can either read all the lines or specify conditions cond to restrict which lines to read. The output result determines when and where the line contents are read. The statement block between LOOP and ENDLOOP is executed once for each line. To exit processing of the statement block , you can use the statements described in Section leave loops.

The sequence in which the lines are read depends on the table type:

Standard tables and sorted tables

The lines are read by ascending table index.

Hashed Tables

The lines are processed in the sequence in which they were inserted in the table, and in the sort sequence following use of the SORT statement.

The loop continues to run until all the table lines that meet conditition cond have been read or until it is exited with a statement. If no appropriate lines are found or if the internal table is blank, the loop is not run at all.

System Fields

The LOOP ATstatement sets system field sy-tabix to the table index of the current table line for Standard tables and sorted Tables, and to 0 for Hashed-Tables, after every loop pass. It leaves sy-subrc unchanged. When the loop is exited with ENDLOOP, sy-tabix is reset to the value it had before the loop was entered, and the following applies sy-subrc: sy-subrc Relevance

0 The loop was run at least once.

4 The loop was not run at all.

The system fields sy-tfill and sy-tleng are also supplied with data.

Changing Internal tables in a loop

If you insert or delete lines in the statement block of a LOOP , this will have the following effects:

If you insert lines behind the current line, these new lines will be processed in the subsequent loop passes. An endless loop can result.

If you delete lines behind the current line, the deleted lines will no longer be processed in the subsequent loop passes.

If you insert lines in front of the current line, the internal loop counter is increased by one with each inserted line. This affects sy-tabix in the subsequent loop pass.

If you delete lines in front of the current line, the internal loop counter is decreased by one with each deleted line. This affects sy-tabix in the subsequent loop pass.

Notes

Within classes, you cannot change table itab in the statement block of the LOOP using statements that access the entire table. Statements such as CLEAR, FREE, LOCAL, REFRESH, SORT and all types of assignments to itab are not allowed.

If you specify the internal table itab through a Reference variable, then the loop is processed completely at the table referenced at entry. Possible changes of the reference variable do not have an effect on the loop. The respective object cannot be deleted from the Garbage Collector, as long as the loop is not completed.

Example

Nested LOOP-loops. The contents of the current row for the outer loop are analyzed in the WHERE-condition for the inner loop.

PARAMETERS p_name TYPE scarr-carrname DEFAULT '*'.

DATA: scarr_tab TYPE SORTED TABLE OF scarr

WITH UNIQUE KEY carrname,

spfli_tab TYPE SORTED TABLE OF spfli

WITH NON-UNIQUE KEY carrid.

FIELD-SYMBOLS LIKE LINE OF scarr_tab.

DATA spfli_line LIKE LINE OF spfli_tab.

SELECT *

FROM scarr

INTO TABLE scarr_tab.

SELECT *

FROM spfli

INTO TABLE spfli_tab.

LOOP AT scarr_tab ASSIGNING

WHERE carrname CP p_name.

LOOP AT spfli_tab INTO spfli_line

WHERE carrid = -carrid.

WRITE: / spfli_line-carrid,

spfli_line-connid.

ENDLOOP.

ENDLOOP.

Example

The following loop deletes all lines of an internal table since - through the short form of the DELETE statement - the current first line is always deleted.

DATA itab TYPE TABLE OF i.

DATA wa LIKE LINE OF itab.

LOOP AT itab INTO wa TO 6.

DELETE itab.

ENDLOOP.

Exceptions

Non-Catchable Exceptions

Cause: Illegal Conversion of the LOOP-Field symbol in the core of the loop.

Runtime Error: ITAB_ILLEGAL_REG

Cause: Illegal assignment to the LOOP-Reference in the core of the loop.

Runtime Error: MOVE_TO_LOOP_REF

2 REPLIES 2

Former Member
0 Kudos

RP_PROVIDE_FROM_LAST

You use macro RP_PROVIDE_FROM_LAST in programs for the logical databases PNP and PAP where the last data record for a period (can be a subtype) is read from an infotype table. The infotype table has been filled earlier (for example, with GET PERNR or RP_READ_INFOTYPE). This macro is only helpful if the infotype (or subtype) has time constraint 1 or 2.

Prerequisites

• The validity begin date of the time period must be before or the same as the validity end date.

• Validity start and end dates are correct (preferably of the type DATE).

• The infotype table is sorted in ascending order. Otherwise, you would receive the last fitting table entry that might not necessarily correspond to the last time entry.

Features

The macro RP_PROVIDE_FROM_LAST makes sure that the last entry for a specified period is placed in the table header entry of the report output list.

Parameters

RP_PROVIDE_FROM_LAST inftytab subty beg end

IN : 1) Name of the internal table

2) Subtype required or SPACE if no subtype is being specified

3) Validity begin date of the time interval

4) Validity end date of the time interval

OUT: 1) PNP-SW-FOUND: has the value 0 if there is no matching entry in the infotype table in the given time period. Otherwise it has the value 1.

2) The matching table header entry if PNP-SW-FOUND = 1 or

the cleared table header entry if PNP-SW-FOUND = 0

Example:

RP_PROVIDE_FROM_LAST P0021 '1' PN-BEGDA PN-ENDDA.

IF PNP-SW-FOUND EQ '1'.

...

ENDIF.

OR

RP_PROVIDE_FROM_LAST P0001 SPACE PN-BEGDA PN-ENDDA.

IF PNP-SW-FOUND EQ '0'.

WRITE: / 'Error: Org. assignment is missing'. REJECT.

ENDIF.

Syntax Diagram

LOOP AT itab

Syntax

LOOP AT itab result [cond].

...

ENDLOOP.

Effect

The LOOP and ENDLOOP statements define a loop around a statement block. The LOOP statement reads lines from internal table itab sequentially. You can either read all the lines or specify conditions cond to restrict which lines to read. The output result determines when and where the line contents are read. The statement block between LOOP and ENDLOOP is executed once for each line. To exit processing of the statement block , you can use the statements described in Section leave loops.

The sequence in which the lines are read depends on the table type:

Standard tables and sorted tables

The lines are read by ascending table index.

Hashed Tables

The lines are processed in the sequence in which they were inserted in the table, and in the sort sequence following use of the SORT statement.

The loop continues to run until all the table lines that meet conditition cond have been read or until it is exited with a statement. If no appropriate lines are found or if the internal table is blank, the loop is not run at all.

System Fields

The LOOP ATstatement sets system field sy-tabix to the table index of the current table line for Standard tables and sorted Tables, and to 0 for Hashed-Tables, after every loop pass. It leaves sy-subrc unchanged. When the loop is exited with ENDLOOP, sy-tabix is reset to the value it had before the loop was entered, and the following applies sy-subrc: sy-subrc Relevance

0 The loop was run at least once.

4 The loop was not run at all.

The system fields sy-tfill and sy-tleng are also supplied with data.

Changing Internal tables in a loop

If you insert or delete lines in the statement block of a LOOP , this will have the following effects:

If you insert lines behind the current line, these new lines will be processed in the subsequent loop passes. An endless loop can result.

If you delete lines behind the current line, the deleted lines will no longer be processed in the subsequent loop passes.

If you insert lines in front of the current line, the internal loop counter is increased by one with each inserted line. This affects sy-tabix in the subsequent loop pass.

If you delete lines in front of the current line, the internal loop counter is decreased by one with each deleted line. This affects sy-tabix in the subsequent loop pass.

Notes

Within classes, you cannot change table itab in the statement block of the LOOP using statements that access the entire table. Statements such as CLEAR, FREE, LOCAL, REFRESH, SORT and all types of assignments to itab are not allowed.

If you specify the internal table itab through a Reference variable, then the loop is processed completely at the table referenced at entry. Possible changes of the reference variable do not have an effect on the loop. The respective object cannot be deleted from the Garbage Collector, as long as the loop is not completed.

Example

Nested LOOP-loops. The contents of the current row for the outer loop are analyzed in the WHERE-condition for the inner loop.

PARAMETERS p_name TYPE scarr-carrname DEFAULT '*'.

DATA: scarr_tab TYPE SORTED TABLE OF scarr

WITH UNIQUE KEY carrname,

spfli_tab TYPE SORTED TABLE OF spfli

WITH NON-UNIQUE KEY carrid.

FIELD-SYMBOLS LIKE LINE OF scarr_tab.

DATA spfli_line LIKE LINE OF spfli_tab.

SELECT *

FROM scarr

INTO TABLE scarr_tab.

SELECT *

FROM spfli

INTO TABLE spfli_tab.

LOOP AT scarr_tab ASSIGNING

WHERE carrname CP p_name.

LOOP AT spfli_tab INTO spfli_line

WHERE carrid = -carrid.

WRITE: / spfli_line-carrid,

spfli_line-connid.

ENDLOOP.

ENDLOOP.

Example

The following loop deletes all lines of an internal table since - through the short form of the DELETE statement - the current first line is always deleted.

DATA itab TYPE TABLE OF i.

DATA wa LIKE LINE OF itab.

LOOP AT itab INTO wa TO 6.

DELETE itab.

ENDLOOP.

Exceptions

Non-Catchable Exceptions

Cause: Illegal Conversion of the LOOP-Field symbol in the core of the loop.

Runtime Error: ITAB_ILLEGAL_REG

Cause: Illegal assignment to the LOOP-Reference in the core of the loop.

Runtime Error: MOVE_TO_LOOP_REF