AMT Help Files

SEARCH

Serial Search

COBOL JAVA
SEARCH for (; <index> <= <occurs>; <index> += 1) {
  if (<condition>) {
    <code>;
  }
}

Syntax

for (; <index> <= <occurs>; <index> += 1) {
    if (<condition1>) {
        <code1>;
    }
    [if (<condition2>) {
        <code2>;
    }]
    [ ... ]
}

Parameter(s)

<index>
The index variable of the table or VARYING clause variable.

<occurs>
The value of the occurs clause of the table.

<condition1..N>
The conditional expression(s) for the search.

<code1..N>
The imperative statement(s) to be executed if the condition is met.

Ending code
The code should always end with a break, goto, return or throw statement.

Example(s)

COBOL Java
SEARCH T-Table
    WHEN T-DATA IS "Hello World"
    MOVE T-Table TO SEARCHRESULT.
                
for (; locDef.t.getIntValue() <= 9; locDef.t.add(1)) {
    if (locDef.t_Data.get(locDef.i.getIntValue()).equalTo("Hello World")) {
        locDef.searchresult.assign(locDef.t_Table.get(locDef.i.getIntValue()));
        break;
    }
}
                
SEARCH T-Table  VARYING Z
    WHEN T-DATA IS "Hello World"
    NEXT SENTENCE
    WHEN T-DATA IS "Foobar"
    DISPLAY "result found"
END-SEARCH.
                
for (; locDef.z.getIntValue() <= 9; locDef.z.add(1)) {
    if (locDef.t_Data.get(locDef.i.getIntValue()).equalTo("Hello World")) {
        jumpToLabel = Label_NextSentence_1; // NEXT SENTENCE
        continue mainLoop;
    }
    if (locDef.t_Data.get(locDef.i.getIntValue()).equalTo("Foobar")) {
        display("result found");
        break;
    }
    locDef.i.getIntValue() += 1;
}
                

Binary Search

COBOL JAVA
SEARCH ALL for (<index> = 1; <index> <= <occurs>; <index> += 1) {
  if (<condition>) {
    <code>;
  }
}

Syntax

for (<index> = 1; <index> <= <occurs>; <index> += 1) {
    if (<condition1>) {
        <code1>;
    }
    [if (<condition2>) {
        <code2>;
    }]
    [ ... ]
}

Parameter(s)

<index>
The index variable of the table or VARYING clause variable.

<occurs>
The value of the occurs clause of the table.

<condition1..N>
The conditional expression(s) for the search.

<code1..N>
The imperative statement(s) to be executed if the condition is met.

Ending code
The code should always end with a break, goto, return or throw statement.

Example(s)

COBOL Java
SEARCH ALL T-Table
    WHEN T-DATA IS EQUAL "Hello World"
    MOVE T-Table TO SEARCHRESULT.
                
for (m_LocDef.T_Idx.Value = 1; m_LocDef.T_Idx.Value <= 9; m_LocDef.T_Idx.Value += 1) {
    if (m_LocDef.T_Data.Value == "Hello World") {
        m_LocDef.Searchresult.Value = m_LocDef.T_Table.Value;
        break;
    }
}
for (locDef.t.getIntValue() = 1; locDef.t.getIntValue() <= 9; locDef.t.add(1)) {
    if (locDef.t_Data.get(locDef.t.getIntValue()).equalTo("Hello World")) {
        locDef.searchresult.assign(locDef.t_Table.get(locDef.t.getIntValue()).getValue());
        break;
    }
}
                
SEARCH T-Table  VARYING Z
    WHEN T-DATA IS "Hello World"
    NEXT SENTENCE
    WHEN T-DATA IS "Foobar"
    DISPLAY "result found"
END-SEARCH.
                
for (; locDef.z.getIntValue() <= 9; locDef.z.add(1)) {
    if (locDef.t_Data.get(locDef.i.getIntValue()).equalTo("Hello World")) {
        jumpToLabel = Label_NextSentence_1; // NEXT SENTENCE
        continue mainLoop;
    }
    if (locDef.t_Data.get(locDef.i.getIntValue()).equalTo("Foobar")) {
        display("result found");
        break;
    }
    locDef.i.getIntValue() += 1;
}
                

Binary Or Serial Search with AT END

COBOL JAVA
SEARCH [ALL] ... AT END for ([<index> = 1]; <index> <= <occurs+1>; <index> += 1) {
  if (<index> > <occurs>) {
    <code_at_end>;
  }
  if (<condition>) {
    <code>;
  }
}

Syntax

for ([<index> = 1]; <index> <= <occurs+1>; <index> += 1) {
    if (<index> > <occurs>) {
        <code_at_end>;
    }
    if (<condition1>) {
        <code1>;
    }
    [if (<condition2>) {
        <code2>;
    }]
    [ ... ]
}

Parameter(s)

<index>
The index variable of the table or VARYING clause variable.

<occurs+1>
The value of the occurs clause of the table plus one.

<occurs>
The value of the occurs clause of the table.

<code_at_end>
The imperative statement(s) to be executed at the end of the search.

<condition1..N>
The conditional expression(s) for the search.

<code1..N>
The imperative statement(s) to be executed if the condition is met.

Ending code
The code should always end with a break, goto, return or throw statement.

Example(s)

COBOL Java
SEARCH T-Table  AT END DISPLAY "Not found"
    WHEN T-DATA IS "Hello World"
    MOVE T-Table TO SEARCHRESULT.
                
for (; locDef.t_Idx.getIntValue() <= 10; locDef.t.add(1)) {
    if (locDef.t.getIntValue() > 9) {
        display("Not found");
        break;
    }
    if (locDef.t_Data.get(locDef.t.getIntvalue() == "Hello World")) {
        locDef.searchresult.assign(locDef.t_Table.get(locDef.t.getIntValue()).getValue());
        break;
    }
}
                
SEARCH ALL T-Table  AT END DISPLAY "Not found"
    WHEN T-DATA EQUAL "Hello World"
    AND  T-data2 equal "Foobar"
    MOVE T-Table TO SEARCHRESULT.
                
for (locDef.t_Idx.assign(1);
    locDef.t_Idx.getIntValue <= 10;
    locDef.t_Idx.assign(1)) {
    if (locDef.t.getIntValue > 9) {
        display("Not found");
        break;
    }
    if (locDef.t_Data.get(locDef.t.getIntValue).equalTo("Hello World") &&
    locDef.t.Data2.get(locDef.t.getIntValue()).equalTo("Foobar")) {
        locDef.searchresult.assign(locDef.t_Table.get(locDef.t.getIntValue()));
        break;
    }
}