difference Skip and Break in Report

andy76andy76 Member Posts: 616
Sorry, I don't remember the difference when there are more dataitems indented.
I know that there were a lot of questions about thant in certification exams.
Could you please explain?

Thank you

Comments

  • kinekine Member Posts: 12,562
    What about reading the on-line help?
    BREAK (Dataport, Report, XMLport)
    Use this function to exit from a loop or a trigger in a data item trigger of a dataport, report or XMLport.

    BREAK
    Comments
    When used inside a loop - such as a WHILE..DO or REPEAT..UNTIL construction - BREAK causes the execution of the loop to end, and control will return to the statement that immediately follows the loop.

    When used outside a loop, BREAK causes the execution of the current trigger to end.

    Compare also with the QUIT function.

    Example
    The following shows how to use the BREAK function:

    REPEAT
    Myvar := Myvar +1;
    IF Myvar = 5 THEN
    CurrReport.BREAK;
    MESSAGE(Text000,Myvar);
    UNTIL Myvar = 10

    Create the following text constant in the C/AL Globals window:

    Text Constant
    ENU Value

    Text000
    'Myvar is now %1'


    When this code is run, the execution of the loop will end when MyVar is 5.
    SKIP (Dataport, Report, XMLport)
    Use this function to skip the current iteration of the current dataport, report or XMLport.

    SKIP
    Comments
    While you can use SHOWOUTPUT to suppress printing the output from a section in a report, SKIP allows you to suppress any processing at all and move on.

    Example
    If you perform some processing in the OnAfterGetRecord trigger of a data item, and do not want this processing to take place in some situations, you can use SKIP in this way:

    IF Balance = 0 THEN
    CurrReport.SKIP
    ELSE
    ... // some processing

    A typical situation where you will use SKIP like this is when you want to retrieve records from a related table, using values in the current record for forming a filter. If the values in the current record already indicate that no records from the related table will be retrieved, there is no need to perform this processing - and you can use SKIP to avoid it.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • andy76andy76 Member Posts: 616
    I already read the online help and Application Guide but there is not a real reply to my question

    CurrReport.SKIP
    or
    CurrReport.BREAK

    if I am in a dataitem A - on AfterGetRecord and I want to skip also records in dataitem B indented under A and C intented under B

    Thank you
  • kinekine Member Posts: 12,562
    If you really understand what is in the on-line help, than answer will be clear. Break will end whole dataitem A loop (and of course all nested dataitems). Skip will just skip actual record, and thus skipping all nested dataitems for that record... but will continue in loop for other records...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    if you have
    dataitem A
    --- dataitem B

    and you do either SKIP or BREAK, you're effectively saying "I am not interested anymore in this Record/Dataitem and everything that is related to it. With SKIP you jump to the next record of A (and you literally skip all indented dataitems), with BREAK you stop executing the entire dataitem, even when there are still records. Either way, dataitem B will not be processed.

    If you are 'done' with the record in dataitem A, but you still want to process dataitem B, you need to use EXIT in the OnAfterGetRecord trigger of dataitem A. This takes you to the end of the trigger right away, and will put you into indented dataitems.
  • sunnyksunnyk Member Posts: 280
    HI,
    I still have doubts in this. What if i have 5 dataitems A-E and B is indented under A, C is indented under B. D & E are indented under A. On Request option form i placed a boolean, if this is true than only B and D Should process. If i place at OnPreDataitem() of B and D, CurrReport.break, will it go and process the Data Item E if the boolean is false?
  • hemantOnehemantOne Member Posts: 98
    hi sunny,

    It will process Data-item E.If you use CurrReport.break on B or E dataitem it makes no effect on E.As E is indented under A if you use CurrReport.break on A dataitem then E will not executed.
    Regards,
    Hemant
    They can conquer who believe they can
    .
  • DenSterDenSter Member Posts: 8,307
    sunnyk wrote:
    HI,
    I still have doubts in this. What if i have 5 dataitems A-E and B is indented under A, C is indented under B. D & E are indented under A. On Request option form i placed a boolean, if this is true than only B and D Should process. If i place at OnPreDataitem() of B and D, CurrReport.break, will it go and process the Data Item E if the boolean is false?
    You are not making any sense to me with your description. With stuff like this you have to play around with it and figure it out yourself.
  • BeliasBelias Member Posts: 2,998
    A
    --B
    ----C
    --D
    --E

    is this you report? if so, what do you want to skip?can you explain it in detail what (and why) are you asking this?
    the "why" is important, because maybe you can structure your dataitems in another way to solve you problem...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • sunnyksunnyk Member Posts: 280
    Hi Belias,
    The structure is like
    A
    --B
    C
    --D
    ----E
    F
    --G
    ----H
    I
    J
    In This if i want to put One more dataitem indented under A,lets say X and i want that this data item will only be processed if the user select to run this at option tab.So can i use, if Condition = false than Currreport.break at OnPreDataitem X
    A
    --B
    --X
    C
    --D
    ----E
    F
    --G
    ----H
    I
    J
  • BeliasBelias Member Posts: 2,998
    yes, to skip dataitem x you can use currreport.break...you have to call it both in onpredataitem and onaftergetrecord (and in onpostdataitem, if you have code), because the break gets you out of the current trigger, not the whole dataitem...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • sunnyksunnyk Member Posts: 280
    TQ Belias.
  • nilesh4381nilesh4381 Member Posts: 33
    Example

    "CurrReport.SKIP" - will skip the current record execution & continue for next record execution

    Report Dataitem:

    Location
    Sales Header
    Sales Line
    Payment Terms


    - if u write code in Location Code OnAfterGetRecord()

    IF Code='BLUE' THEN
    CurrReport.SKIP; // It will SKIP the BLUE Location Record detail - its Sales Header & their line. But will continue By Next location code regular

    - if u write code in Sales Header OnAfterGetRecord()

    IF "Sales Header"."No." = '1011' THEN
    CurrReport.SKIP; // it will skip Sales Header 1011 & their lines for all location code - but so all other sales header & their line

    "CurrReport.BREAK" - will break the execution from current record & for all other record after it. it will break current Dataitem & their indented Dataitem.


    - if u write code in Sales Header OnAfterGetRecord()

    IF "Sales Header"."No." = '1011' THEN
    CurrReport.BREAK; //if this sales header is under Green location then - report will print other sales header before it. but when this
    //sales header is come it will break the execution from that sales header & all sales header after it in GREEN location
    //but it will continue for next location code GURGAON - and their sales header & their line
    // Note: Header Payment Terms is not related to Sales Header Dataitem so it will print all the break cash, CurrReport.BREAK
    //will not affect the Dataitem which is not related to Sales Header here.

    - if u write code in Location code OnAfterGetRecord()

    IF Code='GREEN' THEN
    CurrReport.BREAK; //it will print the all the location before come GREEN location - but when GREEN location will come it will skip that
    //location and all other location after it. - related Dataitem (sales header, sales line) all will break for all breaked location
    // but here, Payment Terms is independent Dataitem so it will print after the report break cause for location code "GREEN" it is not mean for that

    "CurrReport.QUIT" - will break the execution of current Dataitem & all the report Dataitem after come that - simply quit the report execution at that time.

    - if u write code in Sales Header OnAfterGetRecord()

    IF "Sales Header"."No." = '1011' THEN
    CurrReport.QUIT; // Here as per CurrReport.BREAK - Break the all the sales header execution under that location & all break all the
    // location code - and also does not print Payment Terms Dataitem record
    // in sort it will completely break/quit the execution of report - and does not print any record from any Dataitem after the
    // CurrReport.QUIT call



    SKIP - just skip the current record execution & continue for next report

    BREAK - Break the current record & all the other record come after that - but Dataitem not related to that will print

    QUIT - just quit the report execution when it was call

    :D
    Regards,
    Nilesh Gajjar

    Nav Technical Consultant
    http://www.intech-systems.com
  • CalicoCalico Member Posts: 31
    Five years after the last comment - BREAK behaviour in reports is quite inconsistent. If you BREAK in either the OnPreDataItem or OnAfterGetRecord, the OnPostDataItem trigger will still be executed; but a BREAK in OnPreDataItem will stop OnAfterGetRecord executing. I was hoping that the OnAfterGetRecord BREAK would stop OnPostDataItem from running because I want to run an existing batch processing report from NAS which is full of ERROR, QUIT and BREAK statements in a codeunit wrapper to trap any errors and check for BREAKs by retrieving a flag set in OnPostDataItem to determine if any BREAK statements were executed but unfortunately this is not going to work, so I guess I need to rewrite the report.
  • dewaliiidewaliii Member Posts: 4
    It appears the triggger are independent. If I have 3 triggers for an object e.g. a report, I have to primarily place the conditions on the Triggers
    If you love me, keep my commandment.
Sign In or Register to comment.