question: static public MPrintFormat createFromReportView ( Properties ctx , int AD_ReportView_ID , String ReportName ) { int AD_Client_ID = Env . getAD_Client_ID ( ctx ) ; s_log . info ( "AD_ReportView_ID=" + AD_ReportView_ID + " - AD_Client_ID=" + AD_Client_ID + " - " + ReportName ) ; MPrintFormat pf = new MPrintFormat ( ctx , 0 , null ) ; pf . setAD_ReportView_ID ( AD_ReportView_ID ) ; String sql = "SELECT t.TableName," + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_ReportView_ID=rv.AD_ReportView_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID," + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID," + " t.AD_Table_ID " + "FROM AD_ReportView rv" + " INNER JOIN AD_Table t ON (rv.AD_Table_ID=t.AD_Table_ID)," + " AD_Client c" + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y')," + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp " + "WHERE rv.AD_ReportView_ID=? AND c.AD_Client_ID=?" + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'" ; PreparedStatement pstmt = null ; ResultSet rs = null ; boolean error = true ; try { pstmt = DB . prepareStatement ( sql , null ) ; pstmt . setInt ( 1 , AD_ReportView_ID ) ; pstmt . setInt ( 2 , AD_Client_ID ) ; rs = pstmt . executeQuery ( ) ; if ( rs . next ( ) ) { String name = ReportName ; if ( name == null || name . length ( ) == 0 ) name = rs . getString ( 1 ) ; int count = rs . getInt ( 2 ) ; if ( count > 0 ) name += "_" + count ; pf . setName ( name ) ; pf . setAD_PrintColor_ID ( rs . getInt ( 3 ) ) ; pf . setAD_PrintFont_ID ( rs . getInt ( 4 ) ) ; pf . setAD_PrintPaper_ID ( rs . getInt ( 5 ) ) ; pf . setAD_Table_ID ( rs . getInt ( 6 ) ) ; error = false ; } else s_log . log ( Level . SEVERE , "Not found: AD_ReportView_ID=" + AD_ReportView_ID ) ; } catch ( SQLException e ) { s_log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( error ) return null ; if ( ! pf . save ( ) ) return null ; pf . setItems ( createItems ( ctx , pf ) ) ; return pf ; }
target:  Create MPrintFormat for ReportView