‎2021 Jun 09 5:38 PM
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.
‎2021 Jun 09 5:38 PM
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!
‎2021 Jun 09 5:54 PM
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...
‎2021 Jun 09 9:38 PM
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.
‎2021 Jun 10 12:07 PM