Pergunta

Como faço para interagir sobre um conjunto de registros em RPG (LE) com SQL embutido?

Foi útil?

Solução

Normalmente eu vou criar um cursor e buscar cada registro.

   //***********************************************************************
   // Main - Main Processing Routine
   begsr Main;

     exsr BldSqlStmt;

     if OpenSqlCursor() = SQL_SUCCESS;

       dow FetchNextRow() = SQL_SUCCESS;
         exsr ProcessRow;
       enddo;

       if sqlStt = SQL_NO_MORE_ROWS;
         CloseSqlCursor();
       endif;

     endif;

     CloseSqlCursor();

   endsr;    // Main 

Eu adicionei mais detalhes para esta resposta em um post no meu site .

Outras dicas

Como Mike disse, interagindo sobre um cursor é a melhor solução. Eu acrescentaria para dar um desempenho ligeiramente melhor, você pode querer buscar em uma matriz de processo em blocos ao invés de um registro de cada vez.

Exemplo:

  EXEC SQL                                                          
  OPEN order_history;                                             

  // Set the length                                                 
  len = %elem(results);                                             

  // Loop through all the results                                   
  dow (SqlState = Sql_Success);                                     
    EXEC SQL                                                        
      FETCH FROM order_history FOR :len ROWS INTO :results;         
    if (SQLER3 <> *zeros);                                                 
      for i = 1 to SQLER3 by 1;        
        // Load the output             
        eval-corr output = results(i); 
        // Do something 
      endfor;                          
    endif;                             
  enddo;                               

HTH, James R. Perkins

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top