Application Development and Automation 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: 
Read only

Offset getting skipped

simantini_sh
Explorer
0 Likes
1,097

Experts,

In my report, after loop at, it goes directly to the move statement and skips the if...endif. How do I resolve that?

Thanks in Advance

DATA: lt_zfi_pr_details TYPE TABLE OF zfi_pr_details,

lw_zfi_pr_details TYPE zfi_pr_details,
lt_input TYPE zmt_hierarchy_profit_center.

DATA: lv_prctr TYPE string,
lv_name TYPE prctr,
lv_zpprctr TYPE string,
lv_pnode TYPE zfi_pprctr.

CLEAR lt_input.
lt_input = input.

LOOP AT lt_input-mt_hierarchy_profit_center-row INTO DATA(lw_input).
IF lv_name IS NOT INITIAL AND lv_pnode IS NOT INITIAL.
lv_name = lv_prctr+3(10).
lv_pnode = lv_zpprctr+3(10).
endif.
MOVE: lw_input-name TO lw_zfi_pr_details-prctr,
lw_input-parent_node TO lw_zfi_pr_details-zpprctr,
lw_input-description TO lw_zfi_pr_details-zpdesc.
APPEND: lw_zfi_pr_details TO lt_zfi_pr_details.
CLEAR: lw_input, lw_zfi_pr_details.
ENDLOOP.

4 REPLIES 4
Read only

former_member34
Product and Topic Expert
Product and Topic Expert
0 Likes
1,037

Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with our Q&A Tutorial: https://developers.sap.com/tutorials/community-qa.html, as it provides tips for preparing questions that draw responses from our members. Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a picture to your profile you encourage readers to respond: https://www.youtube.com/watch?v=46bt1juWUUM

Many thanks!

Read only

joltdx
Active Contributor
1,037

Hi!

Pleas use the CODE-button to format your code, it's much easier to read it like this:

DATA: lt_zfi_pr_details TYPE TABLE OF zfi_pr_details,
      lw_zfi_pr_details TYPE zfi_pr_details,
      lt_input TYPE zmt_hierarchy_profit_center.

DATA: lv_prctr TYPE string,
      lv_name TYPE prctr,
      lv_zpprctr TYPE string,
      lv_pnode TYPE zfi_pprctr.

CLEAR lt_input.
lt_input = input.

LOOP AT lt_input-mt_hierarchy_profit_center-row INTO DATA(lw_input).
  IF lv_name IS NOT INITIAL AND lv_pnode IS NOT INITIAL.
    lv_name = lv_prctr+3(10).
    lv_pnode = lv_zpprctr+3(10).
  endif.
  MOVE: lw_input-name TO lw_zfi_pr_details-prctr,
        lw_input-parent_node TO lw_zfi_pr_details-zpprctr,
        lw_input-description TO lw_zfi_pr_details-zpdesc.
  APPEND: lw_zfi_pr_details TO lt_zfi_pr_details.
  CLEAR: lw_input, lw_zfi_pr_details.
ENDLOOP.

Anyway, if this is your entire code, it looks like your are just declaring the lv_name and lv_pnode a few lines before the LOOP, and never assign them values. So they will be INITIAL in the loop, and then the

IF lv_name IS NOT INITIAL AND lv_pnode IS NOT INITIAL.

will of course not be fulfilled, and the code will continue at MOVE...

Read only

matt
Active Contributor
1,037

Next time use the code button in the sap.com editor. Makes things easier to read.

DATA: lt_zfi_pr_details TYPE TABLE OF zfi_pr_details,
lw_zfi_pr_details TYPE zfi_pr_details,
lt_input TYPE zmt_hierarchy_profit_center.

DATA: lv_prctr TYPE string,
lv_name TYPE prctr,
lv_zpprctr TYPE string,
lv_pnode TYPE zfi_pprctr.

CLEAR lt_input.
lt_input = input.

LOOP AT lt_input-mt_hierarchy_profit_center-row INTO DATA(lw_input).
  IF lv_name IS NOT INITIAL AND lv_pnode IS NOT INITIAL.
    lv_name = lv_prctr+3(10).
    lv_pnode = lv_zpprctr+3(10).
   endif.
   MOVE: lw_input-name TO lw_zfi_pr_details-prctr,
   lw_input-parent_node TO lw_zfi_pr_details-zpprctr,
   lw_input-description TO lw_zfi_pr_details-zpdesc.
   APPEND: lw_zfi_pr_details TO lt_zfi_pr_details.
  CLEAR: lw_input, lw_zfi_pr_details.
ENDLOOP.

If you debug it, you'll easily see what's wrong. The basic reason behind why it jumps over your IF clause is that the condition isn't satisfied.

Either lv_name is initial, or lv_pnode is not initial. Quite simple really. It does exactly what you've written. And has Jörgen pointed out, whose answer I just read - lv_pnode and lv_name aren't assigned a value when the IF clause is reached.

Again DEBUG and it is obvious.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,037

What do you intend to do later with those 2 variables (lv_name and lv_pnode) keep in memory the first or last non initial values or something I didn't think of?